From: Nigel Tao Date: Fri, 3 Jun 2011 03:18:15 +0000 (+1000) Subject: image: rename Contains and ContainsRectangle to In. X-Git-Tag: weekly.2011-06-09~76 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=f531ef3279cd18315c01966d5beb318af6195e9b;p=gostls13.git image: rename Contains and ContainsRectangle to In. R=r CC=golang-dev https://golang.org/cl/4539104 --- diff --git a/src/pkg/exp/draw/clip_test.go b/src/pkg/exp/draw/clip_test.go index c4bdc21ceb..db40d82f54 100644 --- a/src/pkg/exp/draw/clip_test.go +++ b/src/pkg/exp/draw/clip_test.go @@ -174,18 +174,18 @@ func TestClip(t *testing.T) { // Check that the clipped rectangle is contained by the dst / src / mask // rectangles, in their respective co-ordinate spaces. - if !c.dr.ContainsRectangle(r) { + if !r.In(c.dr) { t.Errorf("%s: c.dr %v does not contain r %v", c.desc, c.dr, r) } // sr is r translated into src's co-ordinate space. sr := r.Add(c.sp.Sub(c.dr.Min)) - if !c.sr.ContainsRectangle(sr) { + if !sr.In(c.sr) { t.Errorf("%s: c.sr %v does not contain sr %v", c.desc, c.sr, sr) } if !c.nilMask { // mr is r translated into mask's co-ordinate space. mr := r.Add(c.mp.Sub(c.dr.Min)) - if !c.mr.ContainsRectangle(mr) { + if !mr.In(c.mr) { t.Errorf("%s: c.mr %v does not contain mr %v", c.desc, c.mr, mr) } } diff --git a/src/pkg/image/geom.go b/src/pkg/image/geom.go index 913e228f52..667aee6259 100644 --- a/src/pkg/image/geom.go +++ b/src/pkg/image/geom.go @@ -38,6 +38,12 @@ func (p Point) Div(k int) Point { return Point{p.X / k, p.Y / k} } +// In returns whether p is in r. +func (p Point) In(r Rectangle) bool { + return r.Min.X <= p.X && p.X < r.Max.X && + r.Min.Y <= p.Y && p.Y < r.Max.Y +} + // Mod returns the point q in r such that p.X-q.X is a multiple of r's width // and p.Y-q.Y is a multiple of r's height. func (p Point) Mod(r Rectangle) Point { @@ -190,21 +196,15 @@ func (r Rectangle) Overlaps(s Rectangle) bool { r.Min.Y < s.Max.Y && s.Min.Y < r.Max.Y } -// Contains returns whether r contains p. -func (r Rectangle) Contains(p Point) bool { - return r.Min.X <= p.X && p.X < r.Max.X && - r.Min.Y <= p.Y && p.Y < r.Max.Y -} - -// ContainsRectangle returns whether r contains every point in s. -func (r Rectangle) ContainsRectangle(s Rectangle) bool { - if s.Empty() { +// In returns whether every point in r is in s. +func (r Rectangle) In(s Rectangle) bool { + if r.Empty() { return true } - // Note that s.Max is an exclusive bound for s, so that r.ContainsRectangle(s) - // does not require that r.Contains(s.Max). - return r.Min.X <= s.Min.X && s.Max.X <= r.Max.X && - r.Min.Y <= s.Min.Y && s.Max.Y <= r.Max.Y + // Note that r.Max is an exclusive bound for r, so that r.In(s) + // does not require that r.Max.In(s). + return s.Min.X <= r.Min.X && r.Max.X <= s.Max.X && + s.Min.Y <= r.Min.Y && r.Max.Y <= s.Max.Y } // Canon returns the canonical version of r. The returned rectangle has minimum diff --git a/src/pkg/image/image.go b/src/pkg/image/image.go index 1bdac36f5e..bf75a51261 100644 --- a/src/pkg/image/image.go +++ b/src/pkg/image/image.go @@ -38,21 +38,21 @@ func (p *RGBA) ColorModel() ColorModel { return RGBAColorModel } func (p *RGBA) Bounds() Rectangle { return p.Rect } func (p *RGBA) At(x, y int) Color { - if !p.Rect.Contains(Point{x, y}) { + if !(Point{x, y}.In(p.Rect)) { return RGBAColor{} } return p.Pix[y*p.Stride+x] } func (p *RGBA) Set(x, y int, c Color) { - if !p.Rect.Contains(Point{x, y}) { + if !(Point{x, y}.In(p.Rect)) { return } p.Pix[y*p.Stride+x] = toRGBAColor(c).(RGBAColor) } func (p *RGBA) SetRGBA(x, y int, c RGBAColor) { - if !p.Rect.Contains(Point{x, y}) { + if !(Point{x, y}.In(p.Rect)) { return } p.Pix[y*p.Stride+x] = c @@ -107,21 +107,21 @@ func (p *RGBA64) ColorModel() ColorModel { return RGBA64ColorModel } func (p *RGBA64) Bounds() Rectangle { return p.Rect } func (p *RGBA64) At(x, y int) Color { - if !p.Rect.Contains(Point{x, y}) { + if !(Point{x, y}.In(p.Rect)) { return RGBA64Color{} } return p.Pix[y*p.Stride+x] } func (p *RGBA64) Set(x, y int, c Color) { - if !p.Rect.Contains(Point{x, y}) { + if !(Point{x, y}.In(p.Rect)) { return } p.Pix[y*p.Stride+x] = toRGBA64Color(c).(RGBA64Color) } func (p *RGBA64) SetRGBA64(x, y int, c RGBA64Color) { - if !p.Rect.Contains(Point{x, y}) { + if !(Point{x, y}.In(p.Rect)) { return } p.Pix[y*p.Stride+x] = c @@ -176,21 +176,21 @@ func (p *NRGBA) ColorModel() ColorModel { return NRGBAColorModel } func (p *NRGBA) Bounds() Rectangle { return p.Rect } func (p *NRGBA) At(x, y int) Color { - if !p.Rect.Contains(Point{x, y}) { + if !(Point{x, y}.In(p.Rect)) { return NRGBAColor{} } return p.Pix[y*p.Stride+x] } func (p *NRGBA) Set(x, y int, c Color) { - if !p.Rect.Contains(Point{x, y}) { + if !(Point{x, y}.In(p.Rect)) { return } p.Pix[y*p.Stride+x] = toNRGBAColor(c).(NRGBAColor) } func (p *NRGBA) SetNRGBA(x, y int, c NRGBAColor) { - if !p.Rect.Contains(Point{x, y}) { + if !(Point{x, y}.In(p.Rect)) { return } p.Pix[y*p.Stride+x] = c @@ -245,21 +245,21 @@ func (p *NRGBA64) ColorModel() ColorModel { return NRGBA64ColorModel } func (p *NRGBA64) Bounds() Rectangle { return p.Rect } func (p *NRGBA64) At(x, y int) Color { - if !p.Rect.Contains(Point{x, y}) { + if !(Point{x, y}.In(p.Rect)) { return NRGBA64Color{} } return p.Pix[y*p.Stride+x] } func (p *NRGBA64) Set(x, y int, c Color) { - if !p.Rect.Contains(Point{x, y}) { + if !(Point{x, y}.In(p.Rect)) { return } p.Pix[y*p.Stride+x] = toNRGBA64Color(c).(NRGBA64Color) } func (p *NRGBA64) SetNRGBA64(x, y int, c NRGBA64Color) { - if !p.Rect.Contains(Point{x, y}) { + if !(Point{x, y}.In(p.Rect)) { return } p.Pix[y*p.Stride+x] = c @@ -314,21 +314,21 @@ func (p *Alpha) ColorModel() ColorModel { return AlphaColorModel } func (p *Alpha) Bounds() Rectangle { return p.Rect } func (p *Alpha) At(x, y int) Color { - if !p.Rect.Contains(Point{x, y}) { + if !(Point{x, y}.In(p.Rect)) { return AlphaColor{} } return p.Pix[y*p.Stride+x] } func (p *Alpha) Set(x, y int, c Color) { - if !p.Rect.Contains(Point{x, y}) { + if !(Point{x, y}.In(p.Rect)) { return } p.Pix[y*p.Stride+x] = toAlphaColor(c).(AlphaColor) } func (p *Alpha) SetAlpha(x, y int, c AlphaColor) { - if !p.Rect.Contains(Point{x, y}) { + if !(Point{x, y}.In(p.Rect)) { return } p.Pix[y*p.Stride+x] = c @@ -383,21 +383,21 @@ func (p *Alpha16) ColorModel() ColorModel { return Alpha16ColorModel } func (p *Alpha16) Bounds() Rectangle { return p.Rect } func (p *Alpha16) At(x, y int) Color { - if !p.Rect.Contains(Point{x, y}) { + if !(Point{x, y}.In(p.Rect)) { return Alpha16Color{} } return p.Pix[y*p.Stride+x] } func (p *Alpha16) Set(x, y int, c Color) { - if !p.Rect.Contains(Point{x, y}) { + if !(Point{x, y}.In(p.Rect)) { return } p.Pix[y*p.Stride+x] = toAlpha16Color(c).(Alpha16Color) } func (p *Alpha16) SetAlpha16(x, y int, c Alpha16Color) { - if !p.Rect.Contains(Point{x, y}) { + if !(Point{x, y}.In(p.Rect)) { return } p.Pix[y*p.Stride+x] = c @@ -452,21 +452,21 @@ func (p *Gray) ColorModel() ColorModel { return GrayColorModel } func (p *Gray) Bounds() Rectangle { return p.Rect } func (p *Gray) At(x, y int) Color { - if !p.Rect.Contains(Point{x, y}) { + if !(Point{x, y}.In(p.Rect)) { return GrayColor{} } return p.Pix[y*p.Stride+x] } func (p *Gray) Set(x, y int, c Color) { - if !p.Rect.Contains(Point{x, y}) { + if !(Point{x, y}.In(p.Rect)) { return } p.Pix[y*p.Stride+x] = toGrayColor(c).(GrayColor) } func (p *Gray) SetGray(x, y int, c GrayColor) { - if !p.Rect.Contains(Point{x, y}) { + if !(Point{x, y}.In(p.Rect)) { return } p.Pix[y*p.Stride+x] = c @@ -507,21 +507,21 @@ func (p *Gray16) ColorModel() ColorModel { return Gray16ColorModel } func (p *Gray16) Bounds() Rectangle { return p.Rect } func (p *Gray16) At(x, y int) Color { - if !p.Rect.Contains(Point{x, y}) { + if !(Point{x, y}.In(p.Rect)) { return Gray16Color{} } return p.Pix[y*p.Stride+x] } func (p *Gray16) Set(x, y int, c Color) { - if !p.Rect.Contains(Point{x, y}) { + if !(Point{x, y}.In(p.Rect)) { return } p.Pix[y*p.Stride+x] = toGray16Color(c).(Gray16Color) } func (p *Gray16) SetGray16(x, y int, c Gray16Color) { - if !p.Rect.Contains(Point{x, y}) { + if !(Point{x, y}.In(p.Rect)) { return } p.Pix[y*p.Stride+x] = c @@ -604,21 +604,21 @@ func (p *Paletted) At(x, y int) Color { if len(p.Palette) == 0 { return nil } - if !p.Rect.Contains(Point{x, y}) { + if !(Point{x, y}.In(p.Rect)) { return p.Palette[0] } return p.Palette[p.Pix[y*p.Stride+x]] } func (p *Paletted) ColorIndexAt(x, y int) uint8 { - if !p.Rect.Contains(Point{x, y}) { + if !(Point{x, y}.In(p.Rect)) { return 0 } return p.Pix[y*p.Stride+x] } func (p *Paletted) SetColorIndex(x, y int, index uint8) { - if !p.Rect.Contains(Point{x, y}) { + if !(Point{x, y}.In(p.Rect)) { return } p.Pix[y*p.Stride+x] = index diff --git a/src/pkg/image/ycbcr/ycbcr.go b/src/pkg/image/ycbcr/ycbcr.go index c1c58b708b..f2de3d6fbc 100644 --- a/src/pkg/image/ycbcr/ycbcr.go +++ b/src/pkg/image/ycbcr/ycbcr.go @@ -142,7 +142,7 @@ func (p *YCbCr) Bounds() image.Rectangle { } func (p *YCbCr) At(x, y int) image.Color { - if !p.Rect.Contains(image.Point{x, y}) { + if !(image.Point{x, y}.In(p.Rect)) { return YCbCrColor{} } switch p.SubsampleRatio {