-
Notifications
You must be signed in to change notification settings - Fork 19
/
stitch.go
41 lines (34 loc) · 967 Bytes
/
stitch.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package terrarium
import (
"image"
"image/draw"
)
func stitchTile(cache *Cache, z, x, y int) (*image.RGBA, error) {
n := 1 << uint(z)
x0 := x
y0 := y
x1 := (x0 + 1) % n
y1 := (y0 + 1) % n
im00, err := cache.getTileImage(z, x0, y0)
if err != nil {
return nil, err
}
im01, err := cache.getTileImage(z, x0, y1)
if err != nil {
return nil, err
}
im10, err := cache.getTileImage(z, x1, y0)
if err != nil {
return nil, err
}
im11, err := cache.getTileImage(z, x1, y1)
if err != nil {
return nil, err
}
im := image.NewRGBA(image.Rect(0, 0, TileSize+1, TileSize+1))
draw.Draw(im, image.Rect(0, 0, TileSize, TileSize), im00, image.ZP, draw.Over)
draw.Draw(im, image.Rect(0, TileSize, TileSize, TileSize+1), im01, image.ZP, draw.Over)
draw.Draw(im, image.Rect(TileSize, 0, TileSize+1, TileSize), im10, image.ZP, draw.Over)
draw.Draw(im, image.Rect(TileSize, TileSize, TileSize+1, TileSize+1), im11, image.ZP, draw.Over)
return im, nil
}