A generic quadtree data structure for storing spatial entities.
abstract class
|
SpatialQuadtree
|
with
|
<TEntity>
|
Returns the number of quadtree nodes.
public
property
|
Count
{
get
}
|
||
type
|
int32
|
||
value
|
|
The number of quadtree nodes. |
Adds the given spatial entity to the quadtree.
public
method
|
Add
(TEntity entity)
|
||
params
|
entity
|
The entity to add. |
Clears the quadtree.
public
method
|
Clear
()
|
Deserializes the quadtree nodes.
public
method
|
Deserialize
(ISerializer data,
ITypeSerializer<TEntity> entity)
|
||
params
|
data
|
[not-null]
|
The serializer object. |
entity
|
[not-null]
|
The type serializer for quadtree nodes. |
Grows the quadtree until it contains the given bounds.
public
method
|
Grow
(Box2D bounds)
|
||
params
|
bounds
|
To bounds to cover. |
Finds the smallest distance from the given point to any spatial entity in the quadtree.
public
method
|
Nearest
(float64 x,
float64 y,
float64 nearest = Maths.MaxDouble)
|
||
type
|
float64
|
||
params
|
x
|
X-coordinate of point. | |
y
|
Y-coordinate of point. | ||
nearest
|
The maximum value to return. Defaults to MaxDouble. | ||
returns
|
The smallest distance. |
Finds the smallest distance from the given point to any spatial entity in the quadtree.
public
method
|
Nearest
(float64 x,
float64 y,
out Vec3I vertices,
out Vec3D weights,
float64 nearest = Maths.MaxDouble)
|
||
type
|
float64
|
||
params
|
x
|
X-coordinate of point. | |
y
|
Y-coordinate of point. | ||
vertices
|
Vertex indices that describe the location of the nearest spatial entity feature. | ||
weights
|
Location
of
the
nearest
spatial
entity
feature,
given
as
relative
weights
(i.e.
the
weight
sum
is
1 )
of
vertices.
The
weights
are
sorted
in
descending
order,
i.e.
X
always
holds
the
greatest
weight
and
Z
always
holds
the
smallest
weight.
|
||
nearest
|
The maximum value to return. Defaults to MaxDouble. | ||
returns
|
The smallest distance. |
Serializes the quadtree nodes.
public
method
|
Serialize
(ISerializer data,
ITypeSerializer<TEntity> entity)
|
||
params
|
data
|
[not-null]
|
The serializer object. |
entity
|
[not-null]
|
The type serializer for quadtree nodes. |
Creates a new instance of SpatialQuadtree.
protected
constructor
|
SpatialQuadtree
()
|
Checks if the given spatial entity intersects with the specified bounds.
protected
abstract
method
|
CheckIntersection
(TEntity entity,
Box2D bounds)
|
||
type
|
int32
|
||
params
|
entity
|
The spatial entity. | |
bounds
|
The axis-aligned bounds. | ||
returns
|
-1
if
entity
and
bounds
are
disjoint.
0
if
entity
and
bounds
intersect.
1
if
bounds
fully
contains
entity.
2
if
entity
fully
contains
bounds.
|
Computes the nearest distance from the given point to the spatial entity.
protected
abstract
method
|
DistanceTo
(float64 x,
float64 y,
float64 distance,
TEntity entity)
|
||
type
|
float64
|
||
params
|
x
|
X-coordinate of point. | |
y
|
Y-coordinate of point. | ||
distance
|
The current nearest distance. | ||
entity
|
The spatial entity. | ||
returns
|
The nearest distance. |
Computes the nearest distance from the given point to the spatial entity.
[EmptyBody]
|
||||
protected
virtual
method
|
DistanceTo
(float64 x,
float64 y,
float64 distance,
TEntity entity,
out Vec3I vertices,
out Vec3D weights)
|
|||
type
|
float64
|
|||
params
|
x
|
X-coordinate of point. | ||
y
|
Y-coordinate of point. | |||
distance
|
The current nearest distance. | |||
entity
|
The spatial entity. | |||
vertices
|
Vertex indices that describe the location of the nearest spatial entity feature. If the spatial entity does not have any vertices, Zero is returned. Vertex index values with a weight of zero are ignored, but their value is retained. | |||
weights
|
Location
of
the
nearest
spatial
entity
feature,
given
as
relative
weights
(i.e.
the
weight
sum
is
1 )
of
vertices.
The
weights
are
sorted
in
descending
order,
i.e.
X
always
holds
the
greatest
weight
and
Z
always
holds
the
smallest
weight.
The
sum
of
all
weights
is
1 .
If
the
spatial
entity
does
not
have
any
vertices,
Zero
is
returned.
|
|||
returns
|
The nearest distance. |
Remarks:
The default implementation forwards to DistanceTo and sets vertices to Zero and weights to Zero.
Checks if the given spatial entities are equal.
protected
abstract
method
|
Equals
(TEntity a,
TEntity b)
|
||
type
|
bool
|
||
params
|
a
|
First entity. | |
b
|
Second entity. | ||
returns
|
true
if
entities
are
equal,
false
if
not. |
Remarks:
Two spatial entities are considered to be equal if CheckIntersection returns the same value for both entities, given any bounds.