--- /dev/null
+// 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
+}
--- /dev/null
+// 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
+)
+`,
+ },
+}
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}
}