Class PointQueryService
A static class to perform a "closest n points query" in 3D.
Inheritance
Namespace: Unity.Tiny.PointQuery
Syntax
public static class PointQueryService
Methods
AddPointsToQueryStruct(EntityManager, Entity, NativeList<float3>, NativeList<Entity>)
Adds a group of points to the query structure.
Declaration
public static void AddPointsToQueryStruct(EntityManager mgr, Entity eQuery, NativeList<float3> points, NativeList<Entity> ids)
Parameters
Type | Name | Description |
---|---|---|
EntityManager | mgr | |
Entity | eQuery | |
NativeList<float3> | points | List of points to add. Length must match |
NativeList<Entity> | ids | List of entities to add. Length must match |
Remarks
The id Entity does not have to be a valid entity, and can be treated
as an integer id.
The only disallowed id is the
AddPointToQueryStruct(EntityManager, Entity, float3, Entity)
Adds a single point to the query structure.
Declaration
public static void AddPointToQueryStruct(EntityManager mgr, Entity eQuery, float3 point, Entity id)
Parameters
Type | Name | Description |
---|---|---|
EntityManager | mgr | |
Entity | eQuery | |
float3 | point | |
Entity | id |
Remarks
The id Entity does not have to be a valid entity, and can be treated
as an integer id.
The only disallowed id is the
CreatePointQueryStruct(EntityManager)
Creates a new entity that has a point query structure, and can be passed to other functions in this service.
Declaration
public static Entity CreatePointQueryStruct(EntityManager mgr)
Parameters
Type | Name | Description |
---|---|---|
EntityManager | mgr |
Returns
Type | Description |
---|---|
Entity |
Remarks
Calls to the PointQueryService are synchronous and immediate; you don't have wait for a System or World update.
The created entity has an internal hidden component, and an external PointQueryStructTag component.
To free the allocated memory used by the structure, destroy the entity.
NumberOfQueryStructsAllocated()
Declaration
public static int NumberOfQueryStructsAllocated()
Returns
Type | Description |
---|---|
System.Int32 |
QueryClosestPoint(EntityManager, Entity, float3, Single, Single)
Query for the closest Entity to point
. (When the Entity was added to this structure.)
Declaration
public static Entity QueryClosestPoint(EntityManager mgr, Entity eQuery, float3 point, float maxDist, float minDist)
Parameters
Type | Name | Description |
---|---|---|
EntityManager | mgr | |
Entity | eQuery | |
float3 | point | |
System.Single | maxDist | |
System.Single | minDist |
Returns
Type | Description |
---|---|
Entity |
Remarks
Closeness is based on Euclidean distance. This query only considers
points inside the hull around the point, which is described by maxDist
(exclusive)
and minDist
(inclusive).
QueryNClosestPoints(EntityManager, Entity, float3, Single, Single, Int32)
Query for the n
closest points to point
in in the query structure.
Declaration
public static NativeList<QueryResult> QueryNClosestPoints(EntityManager mgr, Entity eQuery, float3 point, float maxDist, float minDist, int n)
Parameters
Type | Name | Description |
---|---|---|
EntityManager | mgr | |
Entity | eQuery | |
float3 | point | |
System.Single | maxDist | |
System.Single | minDist | |
System.Int32 | n |
Returns
Type | Description |
---|---|
NativeList<QueryResult> |
Remarks
Closeness is based on Euclidean distance. This query only considers
points inside the hull around the point, which is described by maxDist
(exclusive)
and minDist
(inclusive).
Returns a list of ids and distances of the closest points, sorted by
most distant first.
This is slower than single-point queries. For best results, n
should
not be too large.
ResetPointQueryStruct(EntityManager, Entity, Int32)
Prepares and resets a point query structure. You can use this to clear a query structure, or optimize allocations when the number of items is known ahead of time.
Declaration
public static void ResetPointQueryStruct(EntityManager mgr, Entity eQuery, int numExpectedPoints)
Parameters
Type | Name | Description |
---|---|---|
EntityManager | mgr | |
Entity | eQuery | Entity created via createPointQueryStruct |
System.Int32 | numExpectedPoints | Number of points expected. This is an optional hint for performance and does not need to match exactly. |
TestKDTree()
Declaration
public static bool TestKDTree()
Returns
Type | Description |
---|---|
System.Boolean |