]> Cypherpunks repositories - gostls13.git/commitdiff
image: rename image.Tiled to image.Repeated.
authorNigel Tao <nigeltao@golang.org>
Wed, 11 Jan 2012 01:35:05 +0000 (12:35 +1100)
committerNigel Tao <nigeltao@golang.org>
Wed, 11 Jan 2012 01:35:05 +0000 (12:35 +1100)
What package image currently provides is a larger image consisting
of many copies of a smaller image.

More generally, a tiled image could be a quilt consisting of different
smaller images (like Google Maps), or a technique to view a portion of
enormous images without requiring the whole thing in memory.

This richer construct might not ever belong in the standard library (and
is definitely out of scope for Go 1), but I would like the option for
image.Tiled to be its name.

R=r, rsc
CC=golang-dev
https://golang.org/cl/5530062

src/cmd/gofix/Makefile
src/cmd/gofix/imagetiled.go [new file with mode: 0644]
src/cmd/gofix/imagetiled_test.go [new file with mode: 0644]
src/pkg/image/names.go

index 91caa44cd5a076ca5b31d7f4a2df15ac80322f24..a00ec34733031c303349df45b4355b6c843e84d5 100644 (file)
@@ -20,6 +20,7 @@ GOFILES=\
        httputil.go\
        imagecolor.go\
        imagenew.go\
+       imagetiled.go\
        imageycbcr.go\
        iocopyn.go\
        main.go\
diff --git a/src/cmd/gofix/imagetiled.go b/src/cmd/gofix/imagetiled.go
new file mode 100644 (file)
index 0000000..d8f3f79
--- /dev/null
@@ -0,0 +1,40 @@
+// Copyright 2012 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import (
+       "go/ast"
+)
+
+func init() {
+       register(imagetiledFix)
+}
+
+var imagetiledFix = fix{
+       "imagetiled",
+       "2012-01-10",
+       imagetiled,
+       `Rename image.Tiled to image.Repeated.
+
+http://codereview.appspot.com/5530062
+`,
+}
+
+func imagetiled(f *ast.File) bool {
+       if !imports(f, "image") {
+               return false
+       }
+
+       fixed := false
+       walk(f, func(n interface{}) {
+               s, ok := n.(*ast.SelectorExpr)
+               if !ok || !isTopName(s.X, "image") || s.Sel.String() != "Tiled" {
+                       return
+               }
+               s.Sel = &ast.Ident{Name: "Repeated"}
+               fixed = true
+       })
+       return fixed
+}
diff --git a/src/cmd/gofix/imagetiled_test.go b/src/cmd/gofix/imagetiled_test.go
new file mode 100644 (file)
index 0000000..98a9c0a
--- /dev/null
@@ -0,0 +1,41 @@
+// Copyright 2012 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+func init() {
+       addTestCases(imagetiledTests, imagetiled)
+}
+
+var imagetiledTests = []testCase{
+       {
+               Name: "imagetiled.0",
+               In: `package main
+
+import (
+       "foo"
+       "image"
+)
+
+var (
+       _ foo.Tiled
+       _ image.RGBA
+       _ image.Tiled
+)
+`,
+               Out: `package main
+
+import (
+       "foo"
+       "image"
+)
+
+var (
+       _ foo.Tiled
+       _ image.RGBA
+       _ image.Repeated
+)
+`,
+       },
+}
index a7d1a5798315d35b0cce25004b35695acf123485..b830f88e1c454cb760aedd0b954b888447a8408a 100644 (file)
@@ -51,25 +51,25 @@ func NewUniform(c color.Color) *Uniform {
        return &Uniform{c}
 }
 
-// A Tiled is an infinite-sized Image that repeats another Image in both
-// directions. Tiled{i, p}.At(x, y) will equal i.At(x+p.X, y+p.Y) for all
+// Repeated is an infinite-sized Image that repeats another Image in both
+// directions. Repeated{i, p}.At(x, y) will equal i.At(x+p.X, y+p.Y) for all
 // points {x+p.X, y+p.Y} within i's Bounds.
-type Tiled struct {
+type Repeated struct {
        I      Image
        Offset Point
 }
 
-func (t *Tiled) ColorModel() color.Model {
-       return t.I.ColorModel()
+func (r *Repeated) ColorModel() color.Model {
+       return r.I.ColorModel()
 }
 
-func (t *Tiled) Bounds() Rectangle { return Rectangle{Point{-1e9, -1e9}, Point{1e9, 1e9}} }
+func (r *Repeated) Bounds() Rectangle { return Rectangle{Point{-1e9, -1e9}, Point{1e9, 1e9}} }
 
-func (t *Tiled) At(x, y int) color.Color {
-       p := Point{x, y}.Add(t.Offset).Mod(t.I.Bounds())
-       return t.I.At(p.X, p.Y)
+func (r *Repeated) At(x, y int) color.Color {
+       p := Point{x, y}.Add(r.Offset).Mod(r.I.Bounds())
+       return r.I.At(p.X, p.Y)
 }
 
-func NewTiled(i Image, offset Point) *Tiled {
-       return &Tiled{i, offset}
+func NewRepeated(i Image, offset Point) *Repeated {
+       return &Repeated{i, offset}
 }