Documentation
¶
Index ¶
- type EqualsFunc
- type FilterFunc
- type Item
- type RTree
- func (r *RTree) All() []Item
- func (r *RTree) Bounds() vmath.Rectf
- func (r *RTree) BulkLoad(items []Item) *RTree
- func (r *RTree) Clear() *RTree
- func (r *RTree) Height() int
- func (r *RTree) Insert(item Item) *RTree
- func (r *RTree) Intersects(area vmath.Rectf) bool
- func (r *RTree) IterateInternalNodes(fn func(bounds vmath.Rectf, height int, leaf bool) bool)
- func (r *RTree) IterateItems(fn func(item Item) bool)
- func (r *RTree) NearestNeighbor(pos vmath.Vec2f) Item
- func (r *RTree) NearestNeighborWithin(pos vmath.Vec2f, maxDistance float32) Item
- func (r *RTree) Remove(item Item, equalsFn EqualsFunc) *RTree
- func (r *RTree) Search(area vmath.Rectf, mustCover bool) []Item
- func (r *RTree) SearchFiltered(area vmath.Rectf, mustCover bool, filter FilterFunc) []Item
- func (r *RTree) SearchN(area vmath.Rectf, mustCover bool, maxResults int) []Item
- func (r *RTree) SearchPos(pos vmath.Vec2f) []Item
- func (r *RTree) SearchPosN(pos vmath.Vec2f, maxResults int) []Item
- func (r *RTree) Size() int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EqualsFunc ¶
EqualsFunc checks if the two items are identical.
type FilterFunc ¶
FilterFunc filters items by arbitrary properties
type RTree ¶
type RTree struct {
// contains filtered or unexported fields
}
func NewConf ¶ added in v0.1.0
NewConf creates a new RTree with the given maximum for children-per-node. Higher values mean faster insertion and slower search, and vice versa. The minimum value is 4.
func (*RTree) Bounds ¶
Bounds returns the bounding box of all items. Returns an infinitely small bounding box if there are no items.
func (*RTree) BulkLoad ¶
BulkLoad inserts big data sets at once.
Bulk insertion can be ~5-6 times faster than inserting items one by one. Subsequent search queries are also ~2-3 times faster.
Note that when you do bulk insertion into an existing tree, it bulk-loads the given items into a separate tree and inserts the smaller tree into the larger tree. This means that bulk insertion works very well for clustered data (where items in one update are close to each other), but makes query performance worse if the data is scattered.
func (*RTree) Height ¶
Height returns the height of the R-Tree. This function is useful for graphically visualizing the R-Tree internals.
func (*RTree) Insert ¶
Insert adds a single item. The item's bounds must be normalized and must not change until the item is removed from the tree.
func (*RTree) Intersects ¶
Intersects returns true if there are any items overlapping with the given area. Touching rectangles where floats are exactly equal are not considered to intersect.
func (*RTree) IterateInternalNodes ¶
IterateInternalNodes calls the provided function for every internal tree node until true (=abort) is returned. The order in which nodes are iterated is undefined. This function is useful for graphically visualizing the R-Tree internals.
func (*RTree) IterateItems ¶
IterateAllItems calls the provided function for every stored item until true (=abort) is returned. The order in which items are iterated is undefined.
func (*RTree) NearestNeighbor ¶ added in v0.1.0
NearestNeighbor returns the item that is closest to the given position. Returns nil if the tree is empty.
func (*RTree) NearestNeighborWithin ¶ added in v0.1.0
NearestNeighbor returns the item that is closest to the given position but within the given max. distance. Returns nil if the tree is empty or if there are no items within the given distance.
func (*RTree) Remove ¶
func (r *RTree) Remove(item Item, equalsFn EqualsFunc) *RTree
Remove the given item from the tree. equalsFn is optional. It is useful if you only have a copy of the originally inserted item.
func (*RTree) Search ¶
Search returns all items within the area. If mustCover is true, items are only returned if they are fully within the search area. If false, items are returned if they intersect the search area.
func (*RTree) SearchFiltered ¶
SearchFiltered returns all items within the area that are filtered. If 'filter' returns false, the item is discarded. If mustCover is true, items are only returned if they are fully within the search area. If false, items are returned if they intersect the search area.
func (*RTree) SearchN ¶ added in v0.1.0
Search returns all items within the area. Stops searching after 'maxResults' have found. If mustCover is true, items are only returned if they are fully within the search area. If false, items are returned if they intersect the search area.
func (*RTree) SearchPosN ¶ added in v0.1.0
SearchPos returns all items at the given position. Stops searching after 'maxResults' have found.