Documentation ¶
Overview ¶
Package treenode .
Package treenode .
Package treenode .
Package treenode provides the implementation of a tree node used in spatial indexing.
Index ¶
- type D2
- type D3
- type IDimensionNode
- type TreeNode
- func (n *TreeNode) Add(spatial siface.ISpatial) bool
- func (n *TreeNode) Bound() bounds.Bound
- func (n *TreeNode) Capacity() int
- func (n *TreeNode) Children() IDimensionNode
- func (n *TreeNode) Clear()
- func (n *TreeNode) ClearChildren()
- func (n *TreeNode) Contains(spatial siface.ISpatial) bool
- func (n *TreeNode) Depth() int
- func (n *TreeNode) DivideIf() bool
- func (n *TreeNode) FindEntities(center geo.Vec3Int, radius float32, ...) []siface.ISpatial
- func (n *TreeNode) FindEntitiesInBound(bound bounds.Bound, radius float32, ...) []siface.ISpatial
- func (n *TreeNode) GetEntityList() *list.List
- func (n *TreeNode) Index() int
- func (n *TreeNode) Intersects(bound bounds.Bound) bool
- func (n *TreeNode) IsLeaf() bool
- func (n *TreeNode) MaxDepth() int
- func (n *TreeNode) MergeIf() bool
- func (n *TreeNode) Parent() *TreeNode
- func (n *TreeNode) Range(f func(n *TreeNode) bool)
- func (n *TreeNode) RangeEntities(f func(entity siface.ISpatial) bool)
- func (n *TreeNode) Remove(spatialId int64, merge ...bool) bool
- func (n *TreeNode) Size() int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type D2 ¶
type D2 struct {
// contains filtered or unexported fields
}
D2 .
func (*D2) ChildrenCount ¶
ChildrenCount returns the number of children.
func (*D2) Contains ¶
Contains checks if the spatial entity is within the bounds of the node.
Parameters: - spatial: The spatial entity to check.
Returns: - true if the entity is within the bounds, false otherwise.
type D3 ¶
type D3 struct {
// contains filtered or unexported fields
}
D3 .
func (*D3) ChildrenCount ¶
ChildrenCount return the number of children.
func (*D3) Contains ¶
Contains checks if the spatial entity is within the bounds of the node.
Parameters: - spatial: The spatial entity to check.
Returns: - true if the entity is within the bounds, false otherwise.
type IDimensionNode ¶
type TreeNode ¶
type TreeNode struct {
// contains filtered or unexported fields
}
TreeNode is a node in the tree.
Not thread-safe, only works in a single thread(goroutine).
func NewTreeNode ¶
func NewTreeNode(dim consts.Dim, parent *TreeNode, bound bounds.Bound, index, depth, maxDepth, capacity int) (*TreeNode, error)
NewTreeNode creates a new tree node.
Parameters: - dim: The dimension of the tree (e.g., 2D, 3D). - bound: The spatial boundaries of the node. - capacity: The maximum number of entities that the node can hold.
Returns: - A pointer to the newly created TreeNode.
func (*TreeNode) Add ¶
Add adds a spatial entity to the node.
Parameters: - spatial: The spatial entity to add.
Returns: - true if the entity was added successfully, false otherwise.
func (*TreeNode) Children ¶
func (n *TreeNode) Children() IDimensionNode
Children returns the children of the node.
func (*TreeNode) ClearChildren ¶
func (n *TreeNode) ClearChildren()
func (*TreeNode) Contains ¶
Contains checks if the spatial entity is within the bounds of the node.
Parameters: - spatial: The spatial entity to check.
Returns: - true if the entity is within the bounds, false otherwise.
func (*TreeNode) DivideIf ¶
DivideIf divides the node into 8 children if the number of entities exceeds the capacity. if the depth of the node exceeds the maximum depth, the node will not be divided.
Returns: - true if the node was divided, false otherwise.
func (*TreeNode) FindEntities ¶
func (n *TreeNode) FindEntities(center geo.Vec3Int, radius float32, filters ...func(entity siface.ISpatial) bool) []siface.ISpatial
FindEntities finds entities within a radius of a center point.
func (*TreeNode) FindEntitiesInBound ¶
func (n *TreeNode) FindEntitiesInBound(bound bounds.Bound, radius float32, filters ...func(entity siface.ISpatial) bool) []siface.ISpatial
FindEntitiesInBound finds entities within a bound.
func (*TreeNode) GetEntityList ¶
GetEntityList returns the list of entities in the node.
Returns: - A pointer to the list of entities.
func (*TreeNode) Intersects ¶
Intersects checks if the bound intersects with the node.
func (*TreeNode) MergeIf ¶
MergeIf merges the node with its children if the number of entities in the node is less than the capacity. not suggested to use this method, it's not efficient.
func (*TreeNode) RangeEntities ¶
RangeEntities ranges the entities in the node.
func (*TreeNode) Remove ¶
Remove removes a spatial entity from the node by its ID.
Parameters: - spatialId: The ID of the spatial entity to remove. - merge: Whether to merge the node with its children after removing the entity.
Returns: - true if the entity was removed successfully, false otherwise.