-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainBound.html
293 lines (237 loc) · 22.6 KB
/
mainBound.html
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
<!DOCTYPE html>
<html>
<head>
<title>ConstrainoDelaunato - because I went down that rabbit hole</title>
<style>
body { margin: 0; text-align: center; font-family: sans-serif; }
canvas { border: 1px solid #ccc; position: relative; }
a, a:visited { color: #09f }
</style>
</head>
<body>
<h2><a>ConstrainoDelaunato</a> demo</h2>
<canvas id="canvas"></canvas>
<br>
<span id="coords">Coords show here<span>
<script src="constrainodelaunato.js"></script>
<script>
var realbound1 = [[196680.83,751521.82],[196680.83,751523.82],[196680.83,751525.82],[196682.83,751521.82],[196682.83,751523.82],[196682.83,751525.82],[196682.83,751527.82],[196684.83,751521.82],[196684.83,751523.82],[196684.83,751525.82],[196684.83,751527.82],[196686.83,751521.82],[196686.83,751523.82],[196686.83,751525.82]];
var realbound2 = [[196702.83,751554.82],[196702.83,751556.82],[196704.83,751552.82],[196704.83,751554.82],[196704.83,751556.82],[196706.83,751552.82],[196706.83,751554.82],[196706.83,751556.82],[196708.83,751552.82],[196708.83,751554.82],[196708.83,751556.82]];
var realbound3 = [[196716.83,751520.82],[196716.83,751522.82],[196716.83,751524.82],[196718.83,751520.82],[196718.83,751522.82],[196718.83,751524.82],[196720.83,751520.82],[196720.83,751522.82],[196720.83,751524.82]];
var realbound4 = [[196700.19,751519.54],[196700.96,751528.65],[196709.48,751528.77],[196708.38,751518.53] ,[196706.38,751518.53],[196701.38,751518.53]];
var points =
[[196678.83,751510.82],[196678.83,751512.82],[196678.83,751514.82],[196678.83,751516.82],[196678.83,751518.82],[196678.83,751520.82],[196678.83,751522.82],[196680.83,751510.82],[196680.83,751512.82],[196680.83,751514.82],[196680.83,751516.82],[196680.83,751518.82],[196680.83,751520.82],[196682.83,751508.82],[196682.83,751510.82],[196682.83,751512.82],[196682.83,751514.82],[196682.83,751516.82],[196682.83,751518.82],[196682.83,751520.82],[196682.83,751528.82],[196684.83,751508.82],[196684.83,751510.82],[196684.83,751512.82],[196684.83,751514.82],[196684.83,751516.82],[196684.83,751518.82],[196684.83,751520.82],[196684.83,751528.82],[196684.83,751530.82],[196686.83,751506.82],[196686.83,751508.82],[196686.83,751510.82],[196686.83,751512.82],[196686.83,751514.82],[196686.83,751516.82],[196686.83,751518.82],[196686.83,751520.82],[196686.83,751528.82],[196686.83,751530.82],[196686.83,751532.82],[196686.83,751534.82],[196688.83,751506.82],[196688.83,751508.82],[196688.83,751510.82],[196688.83,751512.82],[196688.83,751514.82],[196688.83,751516.82],[196688.83,751518.82],[196688.83,751520.82],[196688.83,751522.82],[196688.83,751524.82],[196688.83,751526.82],[196688.83,751528.82],[196688.83,751530.82],[196688.83,751532.82],[196688.83,751534.82],[196688.83,751536.82],[196690.83,751504.82],[196690.83,751506.82],[196690.83,751508.82],[196690.83,751510.82],[196690.83,751512.82],[196690.83,751514.82],[196690.83,751516.82],[196690.83,751518.82],[196690.83,751520.82],[196690.83,751522.82],[196690.83,751524.82],[196690.83,751526.82],[196690.83,751528.82],[196690.83,751530.82],[196690.83,751532.82],[196690.83,751534.82],[196690.83,751536.82],[196690.83,751538.82],[196690.83,751540.82],[196692.83,751504.82],[196692.83,751506.82],[196692.83,751508.82],[196692.83,751510.82],[196692.83,751512.82],[196692.83,751514.82],[196692.83,751516.82],[196692.83,751518.82],[196692.83,751520.82],[196692.83,751522.82],[196692.83,751524.82],[196692.83,751526.82],[196692.83,751528.82],[196692.83,751530.82],[196692.83,751532.82],[196692.83,751534.82],[196692.83,751536.82],[196692.83,751538.82],[196692.83,751540.82],[196692.83,751542.82],[196694.83,751504.82],[196694.83,751506.82],[196694.83,751508.82],[196694.83,751510.82],[196694.83,751512.82],[196694.83,751514.82],[196694.83,751516.82],[196694.83,751518.82],[196694.83,751520.82],[196694.83,751522.82],[196694.83,751524.82],[196694.83,751526.82],[196694.83,751528.82],[196694.83,751530.82],[196694.83,751532.82],[196694.83,751534.82],[196694.83,751536.82],[196694.83,751538.82],[196694.83,751540.82],[196694.83,751542.82],[196694.83,751544.82],[196694.83,751546.82],[196696.83,751502.82],[196696.83,751504.82],[196696.83,751506.82],[196696.83,751508.82],[196696.83,751510.82],[196696.83,751512.82],[196696.83,751514.82],[196696.83,751516.82],[196696.83,751518.82],[196696.83,751520.82],[196696.83,751522.82],[196696.83,751524.82],[196696.83,751526.82],[196696.83,751528.82],[196696.83,751530.82],[196696.83,751532.82],[196696.83,751534.82],[196696.83,751536.82],[196696.83,751538.82],[196696.83,751540.82],[196696.83,751542.82],[196696.83,751544.82],[196696.83,751546.82],[196696.83,751548.82],[196698.83,751502.82],[196698.83,751504.82],[196698.83,751506.82],[196698.83,751508.82],[196698.83,751510.82],[196698.83,751512.82],[196698.83,751514.82],[196698.83,751516.82],[196698.83,751518.82],[196698.83,751520.82],[196698.83,751522.82],[196698.83,751524.82],[196698.83,751526.82],[196698.83,751528.82],[196698.83,751530.82],[196698.83,751532.82],[196698.83,751534.82],[196698.83,751536.82],[196698.83,751538.82],[196698.83,751540.82],[196698.83,751542.82],[196698.83,751544.82],[196698.83,751546.82],[196698.83,751548.82],[196698.83,751550.82],[196700.83,751500.82],[196700.83,751502.82],[196700.83,751504.82],[196700.83,751506.82],[196700.83,751508.82],[196700.83,751510.82],[196700.83,751512.82],[196700.83,751514.82],[196700.83,751516.82],[196700.83,751518.82],[196700.83,751528.82],[196700.83,751530.82],[196700.83,751532.82],[196700.83,751534.82],[196700.83,751536.82],[196700.83,751538.82],[196700.83,751540.82],[196700.83,751542.82],[196700.83,751544.82],[196700.83,751546.82],[196700.83,751548.82],[196700.83,751550.82],[196700.83,751552.82],[196700.83,751554.82],[196702.83,751500.82],[196702.83,751502.82],[196702.83,751504.82],[196702.83,751506.82],[196702.83,751508.82],[196702.83,751510.82],[196702.83,751512.82],[196702.83,751514.82],[196702.83,751516.82],[196702.83,751518.82],[196702.83,751528.82],[196702.83,751530.82],[196702.83,751532.82],[196702.83,751534.82],[196702.83,751536.82],[196702.83,751538.82],[196702.83,751540.82],[196702.83,751542.82],[196702.83,751544.82],[196702.83,751546.82],[196702.83,751548.82],[196702.83,751550.82],[196702.83,751552.82],[196704.83,751500.82],[196704.83,751502.82],[196704.83,751504.82],[196704.83,751506.82],[196704.83,751508.82],[196704.83,751510.82],[196704.83,751512.82],[196704.83,751514.82],[196704.83,751516.82],[196704.83,751518.82],[196704.83,751528.82],[196704.83,751530.82],[196704.83,751532.82],[196704.83,751534.82],[196704.83,751536.82],[196704.83,751538.82],[196704.83,751540.82],[196704.83,751542.82],[196704.83,751544.82],[196704.83,751546.82],[196704.83,751548.82],[196704.83,751550.82],[196704.83,751558.82],[196704.83,751560.82],[196706.83,751500.82],[196706.83,751502.82],[196706.83,751504.82],[196706.83,751506.82],[196706.83,751508.82],[196706.83,751510.82],[196706.83,751512.82],[196706.83,751514.82],[196706.83,751516.82],[196706.83,751528.82],[196706.83,751530.82],[196706.83,751532.82],[196706.83,751534.82],[196706.83,751536.82],[196706.83,751538.82],[196706.83,751540.82],[196706.83,751542.82],[196706.83,751544.82],[196706.83,751546.82],[196706.83,751548.82],[196706.83,751550.82],[196706.83,751558.82],[196706.83,751560.82],[196708.83,751502.82],[196708.83,751504.82],[196708.83,751506.82],[196708.83,751508.82],[196708.83,751510.82],[196708.83,751512.82],[196708.83,751514.82],[196708.83,751516.82],[196708.83,751518.82],[196708.83,751520.82],[196708.83,751528.82],[196708.83,751530.82],[196708.83,751532.82],[196708.83,751534.82],[196708.83,751536.82],[196708.83,751538.82],[196708.83,751540.82],[196708.83,751542.82],[196708.83,751544.82],[196708.83,751546.82],[196708.83,751548.82],[196708.83,751550.82],[196708.83,751558.82],[196708.83,751560.82],[196710.83,751506.82],[196710.83,751508.82],[196710.83,751510.82],[196710.83,751512.82],[196710.83,751514.82],[196710.83,751516.82],[196710.83,751518.82],[196710.83,751520.82],[196710.83,751522.82],[196710.83,751524.82],[196710.83,751526.82],[196710.83,751528.82],[196710.83,751530.82],[196710.83,751532.82],[196710.83,751534.82],[196710.83,751536.82],[196710.83,751538.82],[196710.83,751540.82],[196710.83,751542.82],[196710.83,751544.82],[196710.83,751546.82],[196710.83,751548.82],[196710.83,751550.82],[196710.83,751552.82],[196710.83,751554.82],[196710.83,751556.82],[196710.83,751558.82],[196710.83,751560.82],[196712.83,751508.82],[196712.83,751510.82],[196712.83,751512.82],[196712.83,751514.82],[196712.83,751516.82],[196712.83,751518.82],[196712.83,751520.82],[196712.83,751522.82],[196712.83,751524.82],[196712.83,751526.82],[196712.83,751528.82],[196712.83,751530.82],[196712.83,751532.82],[196712.83,751534.82],[196712.83,751536.82],[196712.83,751538.82],[196712.83,751540.82],[196712.83,751542.82],[196712.83,751544.82],[196712.83,751546.82],[196712.83,751548.82],[196712.83,751550.82],[196712.83,751552.82],[196712.83,751554.82],[196712.83,751556.82],[196712.83,751558.82],[196714.83,751512.82],[196714.83,751514.82],[196714.83,751516.82],[196714.83,751518.82],[196714.83,751520.82],[196714.83,751522.82],[196714.83,751524.82],[196714.83,751526.82],[196714.83,751528.82],[196714.83,751530.82],[196714.83,751532.82],[196714.83,751534.82],[196714.83,751536.82],[196714.83,751538.82],[196714.83,751540.82],[196714.83,751542.82],[196714.83,751544.82],[196714.83,751546.82],[196714.83,751548.82],[196714.83,751550.82],[196714.83,751552.82],[196714.83,751554.82],[196714.83,751556.82],[196714.83,751558.82],[196716.83,751514.82],[196716.83,751516.82],[196716.83,751518.82],[196716.83,751526.82],[196716.83,751528.82],[196716.83,751530.82],[196716.83,751532.82],[196716.83,751534.82],[196716.83,751536.82],[196716.83,751538.82],[196716.83,751540.82],[196716.83,751542.82],[196716.83,751544.82],[196716.83,751546.82],[196716.83,751548.82],[196716.83,751550.82],[196716.83,751552.82],[196716.83,751554.82],[196716.83,751556.82],[196716.83,751558.82],[196718.83,751518.82],[196718.83,751526.82],[196718.83,751528.82],[196718.83,751530.82],[196718.83,751532.82],[196718.83,751534.82],[196718.83,751536.82],[196718.83,751538.82],[196718.83,751540.82],[196718.83,751542.82],[196718.83,751544.82],[196718.83,751546.82],[196718.83,751548.82],[196718.83,751550.82],[196718.83,751552.82],[196718.83,751554.82],[196718.83,751556.82],[196720.83,751526.82],[196720.83,751528.82],[196720.83,751530.82],[196720.83,751532.82],[196720.83,751534.82],[196720.83,751536.82],[196720.83,751538.82],[196720.83,751540.82],[196720.83,751542.82],[196720.83,751544.82],[196720.83,751546.82],[196720.83,751548.82],[196720.83,751550.82],[196720.83,751552.82],[196720.83,751554.82],[196722.83,751524.82],[196722.83,751526.82],[196722.83,751528.82],[196722.83,751530.82],[196722.83,751532.82],[196722.83,751534.82],[196722.83,751536.82],[196722.83,751538.82],[196722.83,751540.82],[196722.83,751542.82],[196722.83,751544.82],[196722.83,751546.82],[196722.83,751548.82],[196722.83,751550.82],[196722.83,751552.82],[196724.83,751526.82],[196724.83,751528.82],[196724.83,751530.82],[196724.83,751532.82],[196724.83,751534.82],[196724.83,751536.82],[196724.83,751538.82],[196724.83,751540.82],[196724.83,751542.82],[196724.83,751544.82],[196724.83,751546.82],[196724.83,751548.82],[196724.83,751550.82],[196726.83,751528.82],[196726.83,751530.82],[196726.83,751532.82],[196726.83,751534.82],[196726.83,751536.82],[196726.83,751538.82],[196726.83,751540.82],[196726.83,751542.82],[196726.83,751544.82],[196726.83,751546.82],[196726.83,751548.82],[196726.83,751550.82],[196728.83,751532.82],[196728.83,751534.82],[196728.83,751536.82],[196728.83,751538.82],[196728.83,751540.82],[196728.83,751542.82],[196728.83,751544.82],[196728.83,751546.82],[196728.83,751548.82],[196730.83,751534.82],[196730.83,751536.82],[196730.83,751538.82],[196730.83,751540.82],[196730.83,751542.82],[196730.83,751544.82],[196730.83,751546.82],[196732.83,751538.82],[196732.83,751540.82],[196732.83,751542.82],[196732.83,751544.82],[196732.83,751546.82],[196734.83,751540.82],[196734.83,751542.82],[196734.83,751544.82],[196736.83,751542.82],[196708.83,751502.82],[196709.83,751502.82],[196709.83,751503.82],[196710.83,751503.82],[196710.83,751505.82],[196711.83,751505.82],[196711.83,751506.82],[196712.83,751506.82],[196712.83,751508.82],[196713.83,751508.82],[196713.83,751509.82],[196714.83,751509.82],[196714.83,751511.82],[196715.83,751511.82],[196715.83,751512.82],[196716.83,751512.82],[196716.83,751514.82],[196717.83,751514.82],[196717.83,751516.82],[196718.83,751516.82],[196718.83,751517.82],[196719.83,751517.82],[196719.83,751519.82],[196720.83,751519.82],[196720.83,751520.82],[196716.83,751520.82],[196716.83,751525.82],[196717.83,751525.82],[196717.83,751526.82],[196722.83,751526.82],[196722.83,751523.82],[196723.83,751523.82],[196723.83,751524.82],[196724.83,751524.82],[196724.83,751526.82],[196725.83,751526.82],[196725.83,751527.82],[196726.83,751527.82],[196726.83,751528.82],[196727.83,751528.82],[196727.83,751530.82],[196728.83,751530.82],[196728.83,751531.82],[196729.83,751531.82],[196729.83,751533.82],[196730.83,751533.82],[196730.83,751534.82],[196731.83,751534.82],[196731.83,751535.82],[196732.83,751535.82],[196732.83,751537.82],[196733.83,751537.82],[196733.83,751538.82],[196734.83,751538.82],[196734.83,751539.82],[196735.83,751539.82],[196735.83,751541.82],[196736.83,751541.82],[196736.83,751542.82],[196737.83,751542.82],[196737.83,751544.82],[196736.83,751544.82],[196736.83,751545.82],[196735.83,751545.82],[196735.83,751546.82],[196733.83,751546.82],[196733.83,751547.82],[196731.83,751547.82],[196731.83,751548.82],[196730.83,751548.82],[196730.83,751549.82],[196728.83,751549.82],[196728.83,751550.82],[196727.83,751550.82],[196727.83,751551.82],[196725.83,751551.82],[196725.83,751552.82],[196724.83,751552.82],[196724.83,751553.82],[196723.83,751553.82],[196723.83,751554.82],[196722.83,751554.82],[196722.83,751555.82],[196721.83,751555.82],[196721.83,751556.82],[196720.83,751556.82],[196720.83,751557.82],[196719.83,751557.82],[196719.83,751558.82],[196718.83,751558.82],[196718.83,751559.82],[196716.83,751559.82],[196716.83,751560.82],[196711.83,751560.82],[196711.83,751561.82],[196704.83,751561.82],[196704.83,751560.82],[196703.83,751560.82],[196703.83,751558.82],[196708.83,751558.82],[196708.83,751557.82],[196709.83,751557.82],[196709.83,751552.82],[196704.83,751552.82],[196704.83,751553.82],[196702.83,751553.82],[196702.83,751557.82],[196701.83,751557.82],[196701.83,751555.82],[196700.83,751555.82],[196700.83,751554.82],[196699.83,751554.82],[196699.83,751552.82],[196698.83,751552.82],[196698.83,751551.82],[196697.83,751551.82],[196697.83,751550.82],[196696.83,751550.82],[196696.83,751548.82],[196695.83,751548.82],[196695.83,751547.82],[196694.83,751547.82],[196694.83,751545.82],[196693.83,751545.82],[196693.83,751544.82],[196692.83,751544.82],[196692.83,751542.82],[196691.83,751542.82],[196691.83,751541.82],[196690.83,751541.82],[196690.83,751539.82],[196689.83,751539.82],[196689.83,751538.82],[196688.83,751538.82],[196688.83,751536.82],[196687.83,751536.82],[196687.83,751535.82],[196686.83,751535.82],[196686.83,751533.82],[196685.83,751533.82],[196685.83,751532.82],[196684.83,751532.82],[196684.83,751530.82],[196683.83,751530.82],[196683.83,751529.82],[196682.83,751529.82],[196682.83,751528.82],[196686.83,751528.82],[196686.83,751527.82],[196687.83,751527.82],[196687.83,751526.82],[196688.83,751526.82],[196688.83,751521.82],[196680.83,751521.82],[196680.83,751525.82],[196679.83,751525.82],[196679.83,751523.82],[196678.83,751523.82],[196678.83,751510.82],[196679.83,751510.82],[196679.83,751509.82],[196681.83,751509.82],[196681.83,751508.82],[196683.83,751508.82],[196683.83,751507.82],[196685.83,751507.82],[196685.83,751506.82],[196687.83,751506.82],[196687.83,751505.82],[196689.83,751505.82],[196689.83,751504.82],[196692.83,751504.82],[196692.83,751503.82],[196695.83,751503.82],[196695.83,751502.82],[196697.83,751502.82],[196697.83,751501.82],[196700.83,751501.82],[196700.83,751500.82],[196708.83,751500.82]]
console.time('delaunay');
var delaunay = new ConstrainoDelaunato(points, 3, true); // , realbound4);
// var delaunay = new ConstrainoDelaunato(realbound4, 3); // realbound1, realbound2, realbound3, realbound4);
var updateArr = delaunay.coords2D;
var onlyNew = [];
console.timeEnd('delaunay');
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
var minX = Infinity;
var minY = Infinity;
var maxX = -Infinity;
var maxY = -Infinity;
for (var i = 0; i < updateArr.length; i++) {
var x = updateArr[i][0];
var y = updateArr[i][1];
if (x < minX) minX = x;
if (y < minY) minY = y;
if (x > maxX) maxX = x;
if (y > maxY) maxY = y;
}
var padding = 5;
var w = 1024;
var h = (w - 2 * padding) * (maxY - minY) / (maxX - minX) + 2 * padding;
canvas.style.width = w + 'px';
canvas.style.height = h + 'px';
canvas.width = w;
canvas.height = h;
if (window.devicePixelRatio >= 2) {
canvas.width = w * 2;
canvas.height = h * 2;
ctx.scale(2, 2);
}
var ratio = (w - 2 * padding) / Math.max(maxX - minX, maxY - minY);
ctx.lineJoin = 'round';
ctx.lineCap = 'round';
var updated = true;
var updateArray = [];
canvas.onmousemove = function (e) {
var point = [];
point.push([
(e.layerX - padding) / ratio + minX,
(e.layerY - padding) / ratio + minY
]);
points.push(point.flat());
// updateArr.push(point.flat());
onlyNew.push(point.flat());
// delaunay.update(point);
updated = true;
let temp = points[points.length - 1]
document.getElementById('coords').textContent = `(${Math.floor(temp[0])}, ${Math.floor(temp[1])})`
}
function getX(i) {
return padding + ratio * (updateArr[i][0] - minX);
}
function getY(i) {
return padding + ratio * (updateArr[i][1] - minY);
}
function frame() {
requestAnimationFrame(frame);
draw();
}
frame();
function drawArrowhead(context, from, to, radius) {
var x_center = to.x;
var y_center = to.y;
var angle;
var x;
var y;
context.beginPath();
angle = Math.atan2(to.y - from.y, to.x - from.x)
x = radius * Math.cos(angle) + x_center;
y = radius * Math.sin(angle) + y_center;
context.moveTo(x, y);
angle += (1.0/3.0) * (2 * Math.PI)
x = radius * Math.cos(angle) + x_center;
y = radius * Math.sin(angle) + y_center;
context.lineTo(x, y);
angle += (1.0/3.0) * (2 * Math.PI)
x = radius *Math.cos(angle) + x_center;
y = radius *Math.sin(angle) + y_center;
context.lineTo(x, y);
context.closePath();
context.fillStyle = 'blue';
context.fill();
}
function draw() {
if (!updated) return;
updated = false;
ctx.clearRect(0, 0, w, h);
var triangles = delaunay.triangles;
ctx.beginPath();
for (var i = 0; i < triangles.length; i += 3) {
var p0 = triangles[i];
var p1 = triangles[i + 1];
var p2 = triangles[i + 2];
ctx.moveTo(getX(p0), getY(p0));
ctx.lineTo(getX(p1), getY(p1));
ctx.lineTo(getX(p2), getY(p2));
ctx.closePath();
}
ctx.strokeStyle = 'rgba(0,200,0,1)';
ctx.lineWidth = 0.5;
ctx.stroke();
// ctx.fillStyle = 'rgba(255,255,0,0.1)';
// ctx.fill();
ctx.beginPath();
for (const i of delaunay.hull) {
ctx.lineTo(getX(i), getY(i));
}
ctx.closePath();
ctx.lineWidth = 1;
ctx.strokeStyle = 'red';
ctx.stroke();
ctx.fillStyle = 'black';
ctx.beginPath();
for (var i = 0; i < updateArr.length; i++) {
ctx.rect(getX(i) - 1.5, getY(i) - 1.5, 3, 3);
}
ctx.fill();
// const b = delaunay.boundaries[delaunay.boundaries.length - 1];
const b = delaunay.boundaries[0];
ctx.fillStyle = 'cyan';
ctx.beginPath();
ctx.rect(padding + ratio * (b.minX.x - minX) - 3, padding + ratio * (b.minX.y - minY) - 3, 10, 10);
ctx.fill();
ctx.rect(padding + ratio * (b.minY.x - minX) - 3, padding + ratio * (b.minY.y - minY) - 3, 10, 10);
ctx.fill();
//var bound = delaunay.boundaries[2].hullCoords;
var bound = delaunay.boundaries[delaunay.boundaries.length - 1].hullCoords;
ctx.beginPath();
for (var i = 0; i < bound.length; i++) {
let oldpoint = {
x: padding + ratio * (bound[i - 2] - minX),
y: padding + ratio * (bound[i - 1] - minY)
};
let newpoint = {
x: padding + ratio * (bound[i++] - minX),
y: padding + ratio * (bound[i] - minY)
};
drawArrowhead(ctx, oldpoint, newpoint, 5);
ctx.beginPath();
ctx.moveTo(oldpoint.x, oldpoint.y);
ctx.lineTo(newpoint.x, newpoint.y);
ctx.closePath();
ctx.lineWidth = 3;
ctx.strokeStyle = 'blue';
ctx.stroke();
}
for ( let bound of [this.realbound1, this.realbound2, this.realbound3, this.realbound4]) {
ctx.beginPath();
for (var i = 0; i < bound.length - 1; i ++) {
let oldpoint = {
x: padding + ratio * (bound[i][0] - minX),
y: padding + ratio * (bound[i][1] - minY)
};
let newpoint = {
x: padding + ratio * (bound[i + 1][0] - minX),
y: padding + ratio * (bound[i + 1][1] - minY)
};
ctx.lineTo(oldpoint.x, oldpoint.y);
ctx.lineTo(newpoint.x, newpoint.y);
}
ctx.closePath();
ctx.lineWidth = 1;
ctx.strokeStyle = 'black';
ctx.stroke();
}
ctx.fillStyle = 'red';
ctx.beginPath();
ctx.rect(padding + ratio * (b.ray.x0 - minX) - 3, padding + ratio * (b.ray.y0 - minY) - 3, 6, 6);
ctx.moveTo(padding + ratio * (b.ray.x0 - minX), padding + ratio * (b.ray.y0 - minY));
ctx.lineTo(padding + ratio * (b.ray.x1 - minX), padding + ratio * (b.ray.y1 - minY));
ctx.fill();
ctx.strokeStyle = 'red';
ctx.lineWidth = 3;
ctx.stroke();
ctx.beginPath();
for (var i = 0; i < delaunay.boundaries[delaunay.boundaries.length - 1].cPoints.length; i++) {
let op = {
x: delaunay.coords[delaunay.boundaries[delaunay.boundaries.length - 1].cPoints[i]],
y: delaunay.coords[delaunay.boundaries[delaunay.boundaries.length - 1].cPoints[i] + 1]
};
ctx.fillStyle = 'magenta';
ctx.rect(padding + ratio * (op.x - minX) - 3, padding + ratio * (op.y - minY) - 3, 10, 10);
ctx.fill();
}
//triangles = delaunay.holes[2].triangles;
// const c1D = delaunay.holes[2].coords;
triangles = delaunay.holes[delaunay.holes.length - 1].triangles;
var oldUpdateArr = updateArr.slice()
const c2D = [];
const c1D = delaunay.holes[delaunay.holes.length - 1].coords;
for (let i = 0; i < c1D.length; i += 2) {
c2D.push([c1D[i], c1D[i + 1]])
}
updateArr = c2D;
ctx.beginPath();
for (var i = 0; i < triangles.length; i += 3) {
var p0 = triangles[i];
var p1 = triangles[i + 1];
var p2 = triangles[i + 2];
ctx.moveTo(getX(p0), getY(p0));
ctx.lineTo(getX(p1), getY(p1));
ctx.lineTo(getX(p2), getY(p2));
ctx.closePath();
}
ctx.strokeStyle = 'rgba(0,0,200,1)';
ctx.lineWidth = 0.5;
ctx.stroke();
updateArr = oldUpdateArr;
}
</script>
</body>
</html>