SpatialQuadtree

Description

abstract class Tinman.Terrain.Util.SpatialQuadtree<TEntity>

A generic quadtree data structure for storing spatial entities.

Public / Methods

Add


public method Add → (1)

entity in : TEntity

The entity to add.

Adds the given spatial entity to the quadtree.

Clear


public method Clear → ()

Clears the quadtree.

Deserialize


public method Deserialize → (2)

data in : ISerializer

[not-null]
The serializer object.

entity in : ITypeSerializer<TEntity>

[not-null]
The type serializer for quadtree nodes.

Deserializes the quadtree nodes.

IOException

If an I/O error has occurred.

Grow


public method Grow → (1)

bounds in : Box2D

To bounds to cover.

Grows the quadtree until it contains the given bounds.

Nearest

2 overloads


public method Nearest1 → (3)

in : float64

X-coordinate of point.

in : float64

Y-coordinate of point.

nearest opt : float64 = Maths.MaxDouble

The maximum value to return.

returns → float64

The smallest distance.

Finds the smallest distance from the given point to any spatial entity in the quadtree.


public method Nearest2 → (5)

in : float64

X-coordinate of point.

in : float64

Y-coordinate of point.

vertices out : Vec3I

Vertex indices that describe the location of the nearest spatial entity feature.

weights out : Vec3D

Location of the nearest spatial entity feature, given as relative weights (i.e. the weight sum is 1) of vertices out. The weights are sorted in descending order, i.e. Vec3D.X always holds the greatest weight and Vec3D.Z always holds the smallest weight.

nearest opt : float64 = Maths.MaxDouble

The maximum value to return.

returns → float64

The smallest distance.

Finds the smallest distance from the given point to any spatial entity in the quadtree.

Serialize


public method Serialize → (2)

data in : ISerializer

[not-null]
The serializer object.

entity in : ITypeSerializer<TEntity>

[not-null]
The type serializer for quadtree nodes.

Serializes the quadtree nodes.

IOException

If an I/O error has occurred.

Public / Attributes

Count


public attribute Count → (get)

value : int32

[>0]
The number of quadtree nodes.

Returns the number of quadtree nodes.

Protected / Constructors

SpatialQuadtree


protected constructor SpatialQuadtree → ()

Creates a new instance of SpatialQuadtree.

Protected / Methods

CheckIntersection


protected abstract method CheckIntersection → (2)

entity in : TEntity

The spatial entity.

bounds in : Box2D

The axis-aligned bounds.

returns → int32

-1 if entity in and bounds in are disjoint.
0 if entity in and bounds in intersect.
1 if bounds in fully contains entity in.
2 if entity in fully contains bounds in.

Checks if the given spatial entity intersects with the specified bounds.

DistanceTo

2 overloads


protected abstract method DistanceTo1 → (4)

in : float64

X-coordinate of point.

in : float64

Y-coordinate of point.

distance in : float64

The current nearest distance.

entity in : TEntity

The spatial entity.

returns → float64

The nearest distance.

Computes the nearest distance from the given point to the spatial entity.


[EmptyBody]
protected virtual method DistanceTo2 → (6)

in : float64

X-coordinate of point.

in : float64

Y-coordinate of point.

distance in : float64

The current nearest distance.

entity in : TEntity

The spatial entity.

vertices out : Vec3I

Vertex indices that describe the location of the nearest spatial entity feature. If the spatial entity does not have any vertices, Vec3I.Zero is returned. Vertex index values with a weight of zero are ignored, but their value is retained.

weights out : Vec3D

Location of the nearest spatial entity feature, given as relative weights (i.e. the weight sum is 1) of vertices out. The weights are sorted in descending order, i.e. Vec3D.X always holds the greatest weight and Vec3D.Z always holds the smallest weight. The sum of all weights is 1. If the spatial entity does not have any vertices, Vec3D.Zero is returned.

returns → float64

The nearest distance.

Computes the nearest distance from the given point to the spatial entity.

The default implementation forwards to DistanceTo1 and sets vertices out to Vec3I.Zero and weights out to Vec3D.Zero.

Equals


protected abstract method Equals → (2)

in : TEntity

First entity.

in : TEntity

Second entity.

returns → bool

true if entities are equal, false if not.

Checks if the given spatial entities are equal.

Two spatial entities are considered to be equal if CheckIntersection returns the same value for both entities, given any bounds.