This repository has been archived by the owner on Mar 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDirichletTessellation.cs
74 lines (57 loc) · 2.18 KB
/
DirichletTessellation.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using Unity.Collections;
using Unity.Mathematics;
public struct DirichletTessellation
{
NativeList<float2> edgeVertices;
NativeList<float2x2> adjacentCellPositions;
float2 centerPoint;
VectorUtil vectorUtil;
public NativeList<float2> Tessalate(NativeArray<float2x4> triangles, float3 point, UnityEngine.Color debugColor, out NativeArray<float2x2> adjacentPositions)
{
this.edgeVertices = new NativeList<float2>(Allocator.Temp);
this.adjacentCellPositions = new NativeList<float2x2>(Allocator.Temp);
this.centerPoint = new float2(point.x, (float)point.z);
GatherCellEdgeVertices(triangles, centerPoint);
vectorUtil.SortVerticesClockwise(edgeVertices, centerPoint);
DrawEdges(debugColor);//DEBUG
//DrawAdjacent(debugColor);//DEBUG
adjacentPositions = adjacentCellPositions;
return edgeVertices;
}
void GatherCellEdgeVertices(NativeArray<float2x4> triangles, float2 centerPoint)
{
for(int t = 0; t < triangles.Length; t++)
{
float2x4 triangle = triangles[t];
float2 circumcenter = triangle[3];
bool triangleInCell = false;
int floatIndex = 0;
float2x2 adjacentCellPair = float2x2.zero;
for(int i = 0; i < 3; i++)
if(triangle[i].Equals(centerPoint))
{
triangleInCell = true;
}
else
{
if(floatIndex > 1)
continue;
adjacentCellPair[floatIndex] = triangle[i];
floatIndex++;
}
if(triangleInCell)
{
edgeVertices.Add(circumcenter);
adjacentCellPositions.Add(adjacentCellPair);
}
}
}
void RemoveDuplicateVertices(NativeList<float2> originalVertices)
{
NativeArray<float2> copy = new NativeArray<float2>(originalVertices.Length, Allocator.Temp);
copy.CopyFrom(originalVertices);
originalVertices.Clear();
for(int i = 0; i < copy.Length;i += 2)
originalVertices.Add(copy[i]);
}
}