예제 #1
0
func TestQuadGridExtent(t *testing.T) {
	qg := QuadGrid{extent: geom.Rect(0, 1, 2, 3)}
	expected := map[Coord]geom.Rectangle{
		Coord{0, 0, 0, 1}: geom.Rect(0, 1, 2, 3),
		Coord{1, 0, 0, 1}: geom.Rect(0, 2, 1, 3),
		Coord{1, 0, 1, 1}: geom.Rect(0, 1, 1, 2),
		Coord{1, 1, 0, 1}: geom.Rect(1, 2, 2, 3),
		Coord{1, 1, 1, 1}: geom.Rect(1, 1, 2, 2),
		Coord{2, 0, 0, 1}: geom.Rect(0, 2.5, 0.5, 3),
		Coord{2, 1, 1, 1}: geom.Rect(0.5, 2, 1, 2.5),
		Coord{2, 2, 2, 1}: geom.Rect(1, 1.5, 1.5, 2),
		Coord{2, 3, 3, 1}: geom.Rect(1.5, 1, 2, 1.5),
	}
	for in, out := range expected {
		if x, ok := qg.Extent(in); !ok || x != out {
			t.Errorf("%v.Extent(&%v) = %v, %v, want %v, true", qg, in, x, ok, out)
		}
	}
}
예제 #2
0
func (qg *QuadGrid) Extent(c Coord) (geom.Rectangle, bool) {
	size := qg.extent.Size()
	min := qg.extent.Min
	n := math.Pow(2, float64(c.Z))
	y := c.Y
	if !qg.flipY {
		y = 1<<uint(c.Z) - y - c.N
	}
	minX := min.X + size.Width*float64(c.X)/n
	minY := min.Y + size.Height*float64(y)/n
	maxX := min.X + size.Width*float64(c.X+c.N)/n
	maxY := min.Y + size.Height*float64(y+c.N)/n
	return geom.Rect(minX, minY, maxX, maxY), true
}
예제 #3
0
func TestQuadGridCoord(t *testing.T) {
	qg := QuadGrid{extent: geom.Rect(0, 1, 2, 3), MaxZ: 4}
	for z := 0; z < 4; z++ {
		n := 1 << uint(z)
		for x := 0; x < n; x++ {
			for y := 0; y < n; y++ {
				out := Coord{z, x, y, 1}
				r, ok1 := qg.Extent(out)
				if !ok1 {
					t.Errorf("%v.Extent(%v) = %v, %v, want _, true", qg, out, r, ok1)
				}
				in := r.Min
				if x, ok2 := qg.Coord(z, in); !ok2 || x != out {
					t.Errorf("%v.Coord(%v, &%v) = %v, %v, want %v, true", qg, z, in, x, ok2, out)
				}
			}
		}
	}
}