diff options
| author | Nigel Tao <nigeltao@golang.org> | 2015-03-03 12:59:23 +1100 |
|---|---|---|
| committer | Nigel Tao <nigeltao@golang.org> | 2015-03-04 00:03:46 +0000 |
| commit | 848e2feac68be7b97e36d0064c28be7a850b033d (patch) | |
| tree | fa0db9707b2cbe661b1f4fadc194526dbe2d31de /src/image | |
| parent | b745ab95af0daaddb733f845ad0a5a7123889f8f (diff) | |
| download | go-848e2feac68be7b97e36d0064c28be7a850b033d.tar.xz | |
image: make Rectangle implement Image.
Change-Id: I01e328fc3644b679bacf2209c3d7ade9d8bffe53
Reviewed-on: https://go-review.googlesource.com/6551
Reviewed-by: Rob Pike <r@golang.org>
Diffstat (limited to 'src/image')
| -rw-r--r-- | src/image/geom.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/image/geom.go b/src/image/geom.go index 70e3ff0288..e1cd4dc1e3 100644 --- a/src/image/geom.go +++ b/src/image/geom.go @@ -5,6 +5,7 @@ package image import ( + "image/color" "strconv" ) @@ -77,6 +78,10 @@ func Pt(X, Y int) Point { // It is well-formed if Min.X <= Max.X and likewise for Y. Points are always // well-formed. A rectangle's methods always return well-formed outputs for // well-formed inputs. +// +// A Rectangle is also an Image whose bounds are the rectangle itself. At +// returns color.Opaque for points in the rectangle and color.Transparent +// otherwise. type Rectangle struct { Min, Max Point } @@ -226,6 +231,24 @@ func (r Rectangle) Canon() Rectangle { return r } +// At implements the Image interface. +func (r Rectangle) At(x, y int) color.Color { + if (Point{x, y}).In(r) { + return color.Opaque + } + return color.Transparent +} + +// Bounds implements the Image interface. +func (r Rectangle) Bounds() Rectangle { + return r +} + +// ColorModel implements the Image interface. +func (r Rectangle) ColorModel() color.Model { + return color.Alpha16Model +} + // ZR is the zero Rectangle. var ZR Rectangle |
