Documentation ¶
Index ¶
- func HasZonePrefix(zone, prefix Zone) bool
- func ZoneDepth(zone Zone) int
- type Dimension
- type Option
- type Options
- type Point
- type PointValue
- type Range
- type Tree
- func (qt *Tree[A]) Insert(p Point, v A) bool
- func (qt *Tree[A]) QueryPoint(p Point) []PointValue[A]
- func (qt *Tree[A]) QueryRange(qr Range) []PointValue[A]
- func (qt *Tree[A]) QueryZone(zone Zone) []PointValue[A]
- func (qt *Tree[A]) Values() (output []PointValue[A])
- func (qt *Tree[A]) ValuesAll() (output []PointValue[A])
- func (qt *Tree[A]) VisitDepth(fn func(*Tree[A]))
- func (qt *Tree[A]) ZoneForPoint(p Point) (zone Zone, ok bool)
- type Zone
- type ZoneElem
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HasZonePrefix ¶
HasZonePrefix returns if a given child exists within a given parent zone.
It should be used to figure out if a given zone matches an arbitrary prefix.
HasZonePrefix(EncodeZone(2,1,2), EncodeZone(2,1,2,3,1)) => true
Types ¶
type Option ¶
type Option func(*Options)
Option is a function that mutates QuadTreeOptions
func OptHalfDimensions ¶
OptHalfDimensions sets the `HalfDimensions` field on the options.
func OptMaxValuesPerQuad ¶
OptMaxValuesPerQuad sets the `MaxValuesPerQuad` field on the options.
func OptPreallocateValueStorage ¶
OptPreallocateValueStorage sets the `PreallocateValueStorage` field on the options.
type Options ¶
type Options struct { MaxValuesPerQuad int Center Point HalfDimensions Dimension PreallocateValueStorage bool }
Options is options for a quad tree's constructor.
type PointValue ¶
PointValue is a point with a value.
type Range ¶
Range is a boundary box given by a center point and dimensions.
func RangeFromPoints ¶
RangeFromPoints returns a new quad range from two given points.
func (*Range) Bounds ¶
Bounds returns the top left and bottom right points that bound the quad range box.
func (*Range) ContainsPoint ¶
ContainsPoint returns if a given bounds contains a given point.
func (*Range) Intersects ¶
Intersects returns if a given range intersects with another given range.
type Tree ¶
Tree creates a quad tree structure to organize values with given points for fast lookups.
func (*Tree[A]) QueryPoint ¶
func (qt *Tree[A]) QueryPoint(p Point) []PointValue[A]
QueryPoint gets all the values in the quad tree boundary as found by a single point within the smallest boundary of the tree.
func (*Tree[A]) QueryRange ¶
func (qt *Tree[A]) QueryRange(qr Range) []PointValue[A]
QueryRange queries the tree for all points within a given range as denoted by a given QuadRange.
func (*Tree[A]) QueryZone ¶
func (qt *Tree[A]) QueryZone(zone Zone) []PointValue[A]
QueryRange queries the tree for all points within a given range as denoted by a given QuadRange.
func (*Tree[A]) Values ¶
func (qt *Tree[A]) Values() (output []PointValue[A])
Values yields the values in the current tree node.
func (*Tree[A]) ValuesAll ¶
func (qt *Tree[A]) ValuesAll() (output []PointValue[A])
ValuesAll yields all the values in the tree.
func (*Tree[A]) VisitDepth ¶
VisitDepth visits all the nodes of a quad tree in depth first order according to the z-traversal rules.
E.g we visit SW, SE, NW, NE for each node.
type Zone ¶
type Zone string
Zone is a quadrant zone identifier.
func AppendZone ¶
AppendZone adds a new index to a given parent.
It works, basically, by prepending the new quadrant on the existing parent, shifting the parent over by two bits.
func EncodeZone ¶
EncodeZone encodes a zone value from a given list of quadrant choices.
Quadrants are encoded according to a Z order such that - SW => A - SE => B - NW => C - NE => D
type ZoneElem ¶
type ZoneElem rune
ZoneElem is an individual element of the zone identifier.
func DecodeZone ¶
Decode zone decodes a zone value fully into a slice of "quad" choices as a query traverses the quad tree fully.
func DecodeZoneHigh ¶
DecodeZoneHigh decodes _just_ the high order two bits of a given zone id.