func (m *Grid) pagesWithin(nw, se Point, fn pageFn) {
	if !se.WithinSize(m.Size) {
		se = At(m.Size.X-1, m.Size.Y-1)
	}
	for x := nw.X / 3; x <= se.X/3; x++ {
		for y := nw.Y / 3; y <= se.Y/3; y++ {
			fn(&m.pages[m.indexOf(x, y)])
		}
	}
}
pagesWithin selects the pages within a specifid bounding box which is specified
by north-west and south-east coordinates.
package tile
import (
	"reflect"
	"runtime"
	"sync/atomic"
	"unsafe"
)
type Iterator = func(Point, Tile)
type pageFn = func(*page)
type indexFn = func(x, y int16) int
type pointFn = func(i int) Point
type Grid struct {
	pages      []page   
	pageWidth  int16    
	pageHeight int16    
	observers  pubsub   
	Size       Point    
	indexOf    indexFn  
}
func NewGrid(width, height int16) *Grid {
	width, height = width/3, height/3
	max := int32(width) * int32(height)
	pages := make([]page, max)
	m := &Grid{
		pages:      pages,
		pageWidth:  width,
		pageHeight: height,
		observers:  pubsub{},
		Size:       At(width*3, height*3),
	}
	var pointAt func(i int) Point = func(i int) Point {
		return At(int16(i%int(width)), int16(i/int(width)))
	}
	m.indexOf = m.pointToFlat
	if width == height && (width&(width-1)) == 0 {
		pointAt = deinterleavePoint
		m.indexOf = m.pointToZ
	}
	for i := 0; i < int(max); i++ {
		pages[i].point = pointAt(i).MultiplyScalar(3)
	}
	return m
}
func (m *Grid) pointToFlat(x, y int16) int {
	return int(x) + int(m.pageWidth)*int(y)
}
func (m *Grid) pointToZ(x, y int16) int {
	return int(At(x, y).Interleave())
}
func (m *Grid) Each(fn Iterator) {
	until := int(m.pageHeight) * int(m.pageWidth)
	for i := 0; i < until; i++ {
		m.pages[i].Each(fn)
	}
}
func (m *Grid) Within(nw, se Point, fn Iterator) {
	m.pagesWithin(nw, se, func(page *page) {
		page.Each(func(p Point, tile Tile) {
			if p.Within(nw, se) {
				fn(p, tile)
			}
		})
	})
}