mirror of
https://github.com/golang/go
synced 2024-11-22 04:24:39 -07:00
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
This commit is contained in:
parent
cbdbdc4f61
commit
415f15b667
@ -20,6 +20,7 @@ GOFILES=\
|
|||||||
httputil.go\
|
httputil.go\
|
||||||
imagecolor.go\
|
imagecolor.go\
|
||||||
imagenew.go\
|
imagenew.go\
|
||||||
|
imagetiled.go\
|
||||||
imageycbcr.go\
|
imageycbcr.go\
|
||||||
iocopyn.go\
|
iocopyn.go\
|
||||||
main.go\
|
main.go\
|
||||||
|
40
src/cmd/gofix/imagetiled.go
Normal file
40
src/cmd/gofix/imagetiled.go
Normal file
@ -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
|
||||||
|
}
|
41
src/cmd/gofix/imagetiled_test.go
Normal file
41
src/cmd/gofix/imagetiled_test.go
Normal file
@ -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
|
||||||
|
)
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
}
|
@ -51,25 +51,25 @@ func NewUniform(c color.Color) *Uniform {
|
|||||||
return &Uniform{c}
|
return &Uniform{c}
|
||||||
}
|
}
|
||||||
|
|
||||||
// A Tiled is an infinite-sized Image that repeats another Image in both
|
// Repeated 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
|
// 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.
|
// points {x+p.X, y+p.Y} within i's Bounds.
|
||||||
type Tiled struct {
|
type Repeated struct {
|
||||||
I Image
|
I Image
|
||||||
Offset Point
|
Offset Point
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tiled) ColorModel() color.Model {
|
func (r *Repeated) ColorModel() color.Model {
|
||||||
return t.I.ColorModel()
|
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 {
|
func (r *Repeated) At(x, y int) color.Color {
|
||||||
p := Point{x, y}.Add(t.Offset).Mod(t.I.Bounds())
|
p := Point{x, y}.Add(r.Offset).Mod(r.I.Bounds())
|
||||||
return t.I.At(p.X, p.Y)
|
return r.I.At(p.X, p.Y)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTiled(i Image, offset Point) *Tiled {
|
func NewRepeated(i Image, offset Point) *Repeated {
|
||||||
return &Tiled{i, offset}
|
return &Repeated{i, offset}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user