DOTS Geometry
 
Loading...
Searching...
No Matches
NativePolygon2D Struct Reference

A 2D polygon, that can be used within Unitys Job System. Supports holes, and is the basis for many advanced geometry algorithms. More...

Public Member Functions

void AddHole (List< Vector2 > points)
 Appends a hole to the polygon. The order of the points added should be counter-clockwise (the algorithms sort it out later)
 
void AddHole (NativeArray< float2 > points)
 Appends a hole to the polygon. The order of the points added should be counter-clockwise (the algorithms sort it out later)
 
void AddHole (NativeList< float2 > points)
 Appends a hole to the polygon. The order of the points added should be counter-clockwise (the algorithms sort it out later)
 
void AddHole (Vector2[] points)
 Appends a hole to the polygon. The order of the points added should be counter-clockwise (the algorithms sort it out later)
 
float Area ()
 Calculates the area of the polygon.
 
bool AreHolesValid ()
 Returns false if the separators in the polygon contain negative length holes.
 
void Clear ()
 Clears all vertices and holes in the polygon.
 
void DeserializeBinary (byte[] data)
 
void Dispose ()
 
JobHandle Dispose (JobHandle jobHandle)
 
Rect GetBoundingRect ()
 
Vector2 GetCenter ()
 Returns the average position of all the points of the polygon. This is not the real centroid of the polygon, but the more useful variant in most cases.
 
UnsafeList< float2 > GetPoints ()
 
float GetWindingNumber (Vector2 point)
 Calculates the winding number of the point (i.e. how often is the boundary going around in circles around the point). An even number means the point is outside the polygon, while an odd number means it is inside.
 
void InsertPoint (int idx, float2 point)
 Insert a point at any index in the polygon (method will handle holes/subsurfaces etc.)
 
bool IsConvex ()
 
bool IsPointInside (Vector2 point)
 
bool IsSimple ()
 
void LoadFromBinary (string filePath)
 
 NativePolygon2D (Allocator allocator, float2[] points)
 
 NativePolygon2D (Allocator allocator, float2[] points, int[] separators)
 
 NativePolygon2D (Allocator allocator, int nrOfPoints)
 
 NativePolygon2D (Allocator allocator, List< float2 > points)
 
unsafe NativePolygon2D (Allocator allocator, List< Vector2 > points)
 
 NativePolygon2D (Allocator allocator, NativeArray< float2 > points)
 
 NativePolygon2D (Allocator allocator, NativeList< float2 > points)
 
unsafe NativePolygon2D (Allocator allocator, NativeList< float2 > points, NativeList< int > separators)
 
 NativePolygon2D (Allocator allocator, UnsafeList< float2 > points, UnsafeList< int > separators)
 
unsafe NativePolygon2D (Allocator allocator, Vector2[] points)
 
unsafe NativePolygon2D (Allocator allocator, Vector2[] points, int[] separators)
 
int NumberOfHoles ()
 
void OnAfterDeserialize ()
 
void OnBeforeSerialize ()
 
void RemoveHole (int subsurfaceIdx)
 Removes the hole with the specified subsurface (the index of the hole)
 
void RemovePoint (int idx, out int removedSubsurface)
 Removes a point at any index in the polygon (method will handle holes/subsurfaces etc.)
 
void SaveAsBinary (string filePath)
 
byte[] SerializeBinary ()
 
- Public Member Functions inherited from IBinaryPersistable
- Public Member Functions inherited from ISavable

Static Public Member Functions

static unsafe DCEL ConvertToDCEL (NativePolygon2D polygon, int faceID, Allocator allocator=Allocator.TempJob)
 Converts a polygon to a doubly-connected edge list (DCEL)
 
static float Distance (NativePolygon2D polygon, Vector2 point, out int closestIndex, out int closestSubsurface, bool signed=false)
 
static NativePolygon2D Flip (Allocator allocator, NativePolygon2D polygon)
 Flips the polygon - i.e. it reverses the vertex order so it faces the other way.
 
static NativePolygon2D MakeSimple (Allocator allocator, NativePolygon2D polygon2D)
 Removes all holes but keeps the appearance by adding bridge edges from the border of the polygon to the previous holes.
 
static NativePolygon2D RemoveColinearVertices (Allocator allocator, NativePolygon2D polygon, float epsilon=0.01f)
 Removes colinear vertices of the polygon (Runtime = O(n)) and returns a copy.
 
static void SwitchHolesByAngle (int idx, List< float2 > tempPoints)
 

Public Attributes

UnsafeList< float2 > points
 All points of the polygon. As native containers are unable to hold other native containers, an unsafe list is used instead (necessary for Voronoi)
 
UnsafeList< int > separators
 Separate the polygon into subsurfaces. The first subsurface is always considered the outer boundary of the polygon. Subsequent ones are considered to be holes As native containers are unable to hold other native containers, an unsafe list is used instead (necessary for Voronoi)
 

Properties

bool IsCreated [get]
 

Detailed Description

A 2D polygon, that can be used within Unitys Job System. Supports holes, and is the basis for many advanced geometry algorithms.

Member Function Documentation

◆ AddHole() [1/4]

void AddHole ( List< Vector2 > points)

Appends a hole to the polygon. The order of the points added should be counter-clockwise (the algorithms sort it out later)

Parameters
points

◆ AddHole() [2/4]

void AddHole ( NativeArray< float2 > points)

Appends a hole to the polygon. The order of the points added should be counter-clockwise (the algorithms sort it out later)

Parameters
points

◆ AddHole() [3/4]

void AddHole ( NativeList< float2 > points)

Appends a hole to the polygon. The order of the points added should be counter-clockwise (the algorithms sort it out later)

Parameters
points

◆ AddHole() [4/4]

void AddHole ( Vector2[] points)

Appends a hole to the polygon. The order of the points added should be counter-clockwise (the algorithms sort it out later)

Parameters
points

◆ Area()

float Area ( )

Calculates the area of the polygon.

Returns

◆ AreHolesValid()

bool AreHolesValid ( )

Returns false if the separators in the polygon contain negative length holes.

Returns

◆ ConvertToDCEL()

static unsafe DCEL ConvertToDCEL ( NativePolygon2D polygon,
int faceID,
Allocator allocator = Allocator::TempJob )
static

Converts a polygon to a doubly-connected edge list (DCEL)

Parameters
polygonThe polygon to convert
faceIDA pointer that is stored in the face record, to point to attribute data or for identification
allocator
Returns

◆ DeserializeBinary()

void DeserializeBinary ( byte[] data)

Implements IBinaryPersistable.

◆ Distance()

static float Distance ( NativePolygon2D polygon,
Vector2 point,
out int closestIndex,
out int closestSubsurface,
bool signed = false )
static
Parameters
polygon
point
Returns
The shortest distance between the point and the polygon. If signed, the distances inside the polygon are negative

◆ Flip()

static NativePolygon2D Flip ( Allocator allocator,
NativePolygon2D polygon )
static

Flips the polygon - i.e. it reverses the vertex order so it faces the other way.

Parameters
allocator
polygon
Returns

◆ GetBoundingRect()

Rect GetBoundingRect ( )
Returns
The minimum rectangle that contains all the points of the polygon

◆ GetCenter()

Vector2 GetCenter ( )

Returns the average position of all the points of the polygon. This is not the real centroid of the polygon, but the more useful variant in most cases.

Returns

◆ GetWindingNumber()

float GetWindingNumber ( Vector2 point)

Calculates the winding number of the point (i.e. how often is the boundary going around in circles around the point). An even number means the point is outside the polygon, while an odd number means it is inside.

Parameters
point
Returns

◆ InsertPoint()

void InsertPoint ( int idx,
float2 point )

Insert a point at any index in the polygon (method will handle holes/subsurfaces etc.)

Parameters
idx
point

◆ IsConvex()

bool IsConvex ( )
Returns
Returns true, if the polygon does not contain any reflex vertices

◆ IsPointInside()

bool IsPointInside ( Vector2 point)
Parameters
point
Returns
True, if point lies inside the surface of the polygon and not outside boundary of it or inside a hole. False, otherwise

◆ IsSimple()

bool IsSimple ( )
Returns
Returns true if the polygon does not contain any holes

◆ LoadFromBinary()

void LoadFromBinary ( string filePath)

Implements IBinaryPersistable.

◆ MakeSimple()

static NativePolygon2D MakeSimple ( Allocator allocator,
NativePolygon2D polygon2D )
static

Removes all holes but keeps the appearance by adding bridge edges from the border of the polygon to the previous holes.

Parameters
allocator
polygon2D
Returns

◆ OnAfterDeserialize()

void OnAfterDeserialize ( )

Implements ISavable.

◆ OnBeforeSerialize()

void OnBeforeSerialize ( )

Implements ISavable.

◆ RemoveColinearVertices()

static NativePolygon2D RemoveColinearVertices ( Allocator allocator,
NativePolygon2D polygon,
float epsilon = 0::01f )
static

Removes colinear vertices of the polygon (Runtime = O(n)) and returns a copy.

Parameters
polygon
epsilon
Returns

◆ RemoveHole()

void RemoveHole ( int subsurfaceIdx)

Removes the hole with the specified subsurface (the index of the hole)

Parameters
subsurfaceIdx

◆ RemovePoint()

void RemovePoint ( int idx,
out int removedSubsurface )

Removes a point at any index in the polygon (method will handle holes/subsurfaces etc.)

Parameters
idx

◆ SaveAsBinary()

void SaveAsBinary ( string filePath)

Implements IBinaryPersistable.

◆ SerializeBinary()

byte[] SerializeBinary ( )

Implements IBinaryPersistable.