From: Nigel Tao Date: Wed, 11 Jan 2012 01:35:05 +0000 (+1100) Subject: image: rename image.Tiled to image.Repeated. X-Git-Tag: weekly.2012-01-15~85 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=415f15b66746d8e0cd6f01e89dceed41e617be5f;p=gostls13.git image: rename image.Tiled to image.Repeated. 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 --- diff --git a/src/cmd/gofix/Makefile b/src/cmd/gofix/Makefile index 91caa44cd5..a00ec34733 100644 --- a/src/cmd/gofix/Makefile +++ b/src/cmd/gofix/Makefile @@ -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 index 0000000000..d8f3f79806 --- /dev/null +++ b/src/cmd/gofix/imagetiled.go @@ -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 index 0000000000..98a9c0a8d2 --- /dev/null +++ b/src/cmd/gofix/imagetiled_test.go @@ -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 +) +`, + }, +} diff --git a/src/pkg/image/names.go b/src/pkg/image/names.go index a7d1a57983..b830f88e1c 100644 --- a/src/pkg/image/names.go +++ b/src/pkg/image/names.go @@ -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} }