Commit 415f15b6 authored by Nigel Tao's avatar Nigel Tao

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
parent cbdbdc4f
......@@ -20,6 +20,7 @@ GOFILES=\
httputil.go\
imagecolor.go\
imagenew.go\
imagetiled.go\
imageycbcr.go\
iocopyn.go\
main.go\
......
// 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
}
// 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
)
`,
},
}
......@@ -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}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment