-
Notifications
You must be signed in to change notification settings - Fork 3
/
TestTriangulatePoly2D.js
109 lines (88 loc) · 2.1 KB
/
TestTriangulatePoly2D.js
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#pragma strict
function TestHole()
{
var p = new Mesh2D();
// monotone test
p.pts = new Vector2[6];
var i = 0;
p.pts[i++] = Vector2( 0,0 );
p.pts[i++] = Vector2( 10,0 );
p.pts[i++] = Vector2( 0,10 );
p.pts[i++] = Vector2( 2,2 );
p.pts[i++] = Vector2( 2,4 );
p.pts[i++] = Vector2( 4,2 );
p.edgeA = [0, 1, 2, 3, 4, 5];
p.edgeB = [1, 2, 0, 4, 5, 3];
var mesh = gameObject.GetComponent(MeshFilter).mesh;
ProGeo.TriangulateSimplePolygon( p, mesh, false );
}
function TestColinear()
{
var p = new Mesh2D();
// monotone test
p.pts = new Vector2[8];
var i = 0;
p.pts[i++] = Vector2( 0,0 );
p.pts[i++] = Vector2( 1,0 );
p.pts[i++] = Vector2( 1,1 );
p.pts[i++] = Vector2( 1,2 );
p.pts[i++] = Vector2( 1,3 );
p.pts[i++] = Vector2( 0,3 );
p.pts[i++] = Vector2( 0,2 );
p.pts[i++] = Vector2( 0,1 );
var N = p.pts.length;
p.edgeA = new int[N];
p.edgeB = new int[N];
for( i = 0; i < N; i++ ) {
p.edgeA[i] = i;
p.edgeB[i] = (i+1)%N;
}
var mesh = gameObject.GetComponent(MeshFilter).mesh;
ProGeo.TriangulateSimplePolygon( p, mesh, false );
}
function TestSimple()
{
var p = new Mesh2D();
// monotone test
p.pts = new Vector2[5];
p.pts[0] = Vector2( 0,0 );
p.pts[1] = Vector2( 2,0 );
p.pts[2] = Vector2( 1,1 );
p.pts[3] = Vector2( 2,2 );
p.pts[4] = Vector2( 0,2 );
var N = p.pts.length;
p.edgeA = new int[N];
p.edgeB = new int[N];
for( var i = 0; i < N; i++ ) {
p.edgeA[i] = i;
p.edgeB[i] = (i+1)%N;
}
var mesh = gameObject.GetComponent(MeshFilter).mesh;
ProGeo.TriangulateSimplePolygon( p, mesh, false );
}
function TestMonotone()
{
var p = new Mesh2D();
// monotone test
p.pts = new Vector2[7];
p.pts[0] = Vector2( 0,0 );
p.pts[1] = Vector2( 1.5,0 );
p.pts[2] = Vector2( 2,1 );
p.pts[3] = Vector2( 3.0,2 );
p.pts[4] = Vector2( 1.5,2 );
p.pts[5] = Vector2( 1,1 );
p.pts[6] = Vector2( 0.5,1 );
var N = p.pts.length;
p.edgeA = new int[N];
p.edgeB = new int[N];
for( var i = 0; i < N; i++ ) {
p.edgeA[i] = i;
p.edgeB[i] = (i+1)%N;
}
var mesh = gameObject.GetComponent(MeshFilter).mesh;
ProGeo.TriangulateSimplePolygon( p, mesh, false );
}
function Awake()
{
TestHole();
}