Class SegmentHashGrid2d<T>
Hash Grid for 2D segments. You provide the 'segment' type. If you have an indexable
set of segments this can just be int, or can be more complex segment data structure
(but be careful w/ structs...)
Segments are stored in the grid cell that contains the segment center. We keep track
of the extent of the longest segment that has been added. The search radius for
distance queries is expanded by this extent.
So, distance queries ARE NOT EFFICIENT if you even one very long segment.
[TODO] make a multi-level hash
Does not actually store 2D segments. So, to remove a segment
you must also know it's 2D center, so we can look up the cell coordinates.
Hence, to 'update' a segment, you need to know both it's old and new 2D centers.
Inheritance
SegmentHashGrid2d<T>
Namespace: g3
Assembly: cs.temp.dll.dll
Syntax
public class SegmentHashGrid2d<T>
Type Parameters
Constructors
SegmentHashGrid2d(Double, T)
"invalid" value will be returned by queries if no valid result is found (eg bounded-distance query)
Declaration
public SegmentHashGrid2d(double cellSize, T invalidValue)
Parameters
Type |
Name |
Description |
Double |
cellSize |
|
T |
invalidValue |
|
Methods
FindNearestInRadius(Vector2d, Double, Func<T, Double>, Func<T, Boolean>)
Find nearest segment in grid, within radius, without locking / thread-safety
You must provided distF which returns distance between query_pt and the segment argument
You can ignore specific segments via ignoreF lambda - return true to ignore
Return value is pair (nearest_index,min_dist) or (invalidValue,double.MaxValue)
Declaration
public KeyValuePair<T, double> FindNearestInRadius(Vector2d query_pt, double radius, Func<T, double> distF, Func<T, bool> ignoreF = null)
Parameters
Returns
FindNearestInSquaredRadius(Vector2d, Double, Func<T, Double>, Func<T, Boolean>)
Variant of FindNearestInRadius that works with squared-distances.
Return value is pair (nearest_index,min_dist) or (invalidValue,double.MaxValue)
Declaration
public KeyValuePair<T, double> FindNearestInSquaredRadius(Vector2d query_pt, double radiusSqr, Func<T, double> distSqrF, Func<T, bool> ignoreF = null)
Parameters
Returns
InsertSegment(T, Vector2d, Double)
Insert segment at position. This function is thread-safe, uses a SpinLock internally
Declaration
public void InsertSegment(T value, Vector2d center, double extent)
Parameters
InsertSegmentUnsafe(T, Vector2d, Double)
Insert segment without locking / thread-safety
Declaration
public void InsertSegmentUnsafe(T value, Vector2d center, double extent)
Parameters
RemoveSegment(T, Vector2d)
Remove segment. This function is thread-safe, uses a SpinLock internally
Declaration
public bool RemoveSegment(T value, Vector2d center)
Parameters
Type |
Name |
Description |
T |
value |
|
Vector2d |
center |
|
Returns
RemoveSegmentUnsafe(T, Vector2d)
Remove segment without locking / thread-safety
Declaration
public bool RemoveSegmentUnsafe(T value, Vector2d center)
Parameters
Type |
Name |
Description |
T |
value |
|
Vector2d |
center |
|
Returns
UpdateSegment(T, Vector2d, Vector2d, Double)
Move segment from old to new position. This function is thread-safe, uses a SpinLock internally
Declaration
public void UpdateSegment(T value, Vector2d old_center, Vector2d new_center, double new_extent)
Parameters
UpdateSegmentUnsafe(T, Vector2d, Vector2d, Double)
Move segment from old to new position without locking / thread-safety
Declaration
public void UpdateSegmentUnsafe(T value, Vector2d old_center, Vector2d new_center, double new_extent)
Parameters