Debian Codegraph @

packages/stk/stk_unit_tests/stk_middle_mesh/test_intersection.cpp

raw
1 #include "gtest/gtest.h"
2
3 #include <cmath>
4
5 #include "stk_middle_mesh/mesh_entity.hpp"
6 #include "stk_middle_mesh/predicates/intersection.hpp"
7
8 namespace stk {
9 namespace middle_mesh {
10 namespace impl {
11
12 using namespace predicates::impl;
13
14 namespace {
15
16 void expect_near(const utils::Point& pt1, const utils::Point& pt2, double tol)
17 {
18 for (int i = 0; i < 3; ++i)
19 EXPECT_NEAR(pt1[i], pt2[i], tol);
20 }
21
22 } // namespace
23
24 TEST(PointClassifier, Triangle)
25 {
26 auto mesh = mesh::make_empty_mesh();
27 auto v1 = mesh->create_vertex(0, 0);
28 auto v2 = mesh->create_vertex(1, 0);
29 auto v3 = mesh->create_vertex(0, 1);
30 auto el = mesh->create_triangle_from_verts(v1, v2, v3);
31
32 PointClassifier c;
33 utils::Point pt;
34 PointRecord r;
35
36 // verts
37 pt = utils::Point(0, 0);
38 r = c.classify(el, pt);
39 EXPECT_EQ(r.type, PointClassification::Vert);
40 EXPECT_EQ(r.id, 0);
41
42 pt = utils::Point(1, 0);
43 r = c.classify(el, pt);
44 EXPECT_EQ(r.type, PointClassification::Vert);
45 EXPECT_EQ(r.id, 1);
46
47 pt = utils::Point(0, 1);
48 r = c.classify(el, pt);
49 EXPECT_EQ(r.type, PointClassification::Vert);
50 EXPECT_EQ(r.id, 2);
51
52 // edges
53 pt = utils::Point(0.5, 0);
54 r = c.classify(el, pt);
55 EXPECT_EQ(r.type, PointClassification::Edge);
56 EXPECT_EQ(r.id, 0);
57
58 pt = utils::Point(0.5, 0.5);
59 r = c.classify(el, pt);
60 EXPECT_EQ(r.type, PointClassification::Edge);
61 EXPECT_EQ(r.id, 1);
62
63 pt = utils::Point(0, 0.5);
64 r = c.classify(el, pt);
65 EXPECT_EQ(r.type, PointClassification::Edge);
66 EXPECT_EQ(r.id, 2);
67
68 // interior
69 pt = utils::Point(0.25, 0.25);
70 r = c.classify(el, pt);
71 EXPECT_EQ(r.type, PointClassification::Interior);
72
73 pt = utils::Point(0.5, 0.25);
74 r = c.classify(el, pt);
75 EXPECT_EQ(r.type, PointClassification::Interior);
76
77 pt = utils::Point(0.25, 0.5);
78 r = c.classify(el, pt);
79 EXPECT_EQ(r.type, PointClassification::Interior);
80
81 // exterior
82 pt = utils::Point(1.5, 0);
83 r = c.classify(el, pt);
84 EXPECT_EQ(r.type, PointClassification::Exterior);
85
86 pt = utils::Point(-0.5, 0);
87 r = c.classify(el, pt);
88 EXPECT_EQ(r.type, PointClassification::Exterior);
89
90 pt = utils::Point(0, 1.5);
91 r = c.classify(el, pt);
92 EXPECT_EQ(r.type, PointClassification::Exterior);
93
94 pt = utils::Point(0, -0.5);
95 r = c.classify(el, pt);
96 EXPECT_EQ(r.type, PointClassification::Exterior);
97
98 pt = utils::Point(1.5, -0.5);
99 r = c.classify(el, pt);
100 EXPECT_EQ(r.type, PointClassification::Exterior);
101
102 pt = utils::Point(0.5, 2.5);
103 r = c.classify(el, pt);
104 EXPECT_EQ(r.type, PointClassification::Exterior);
105
106 pt = utils::Point(0.25, -0.25);
107 r = c.classify(el, pt);
108 EXPECT_EQ(r.type, PointClassification::Exterior);
109
110 pt = utils::Point(-0.25, 0.25);
111 r = c.classify(el, pt);
112 EXPECT_EQ(r.type, PointClassification::Exterior);
113
114 pt = utils::Point(1.25, 0.25);
115 r = c.classify(el, pt);
116 EXPECT_EQ(r.type, PointClassification::Exterior);
117 }
118
119 TEST(PointClassifier, Quad)
120 {
121 auto mesh = mesh::make_empty_mesh();
122 auto v1 = mesh->create_vertex(0, 0);
123 auto v2 = mesh->create_vertex(1, 0);
124 auto v3 = mesh->create_vertex(1, 1);
125 auto v4 = mesh->create_vertex(0, 1);
126 auto el = mesh->create_quad_from_verts(v1, v2, v3, v4);
127
128 PointClassifier c;
129 utils::Point pt;
130 PointRecord r;
131
132 // verts
133 pt = utils::Point(0, 0);
134 r = c.classify(el, pt);
135 EXPECT_EQ(r.type, PointClassification::Vert);
136 EXPECT_EQ(r.id, 0);
137
138 pt = utils::Point(1, 0);
139 r = c.classify(el, pt);
140 EXPECT_EQ(r.type, PointClassification::Vert);
141 EXPECT_EQ(r.id, 1);
142
143 pt = utils::Point(1, 1);
144 r = c.classify(el, pt);
145 EXPECT_EQ(r.type, PointClassification::Vert);
146 EXPECT_EQ(r.id, 2);
147
148 pt = utils::Point(0, 1);
149 r = c.classify(el, pt);
150 EXPECT_EQ(r.type, PointClassification::Vert);
151 EXPECT_EQ(r.id, 3);
152
153 // edges
154 pt = utils::Point(0.5, 0);
155 r = c.classify(el, pt);
156 EXPECT_EQ(r.type, PointClassification::Edge);
157 EXPECT_EQ(r.id, 0);
158
159 pt = utils::Point(1, 0.5);
160 r = c.classify(el, pt);
161 EXPECT_EQ(r.type, PointClassification::Edge);
162 EXPECT_EQ(r.id, 1);
163
164 pt = utils::Point(0.5, 1);
165 r = c.classify(el, pt);
166 EXPECT_EQ(r.type, PointClassification::Edge);
167 EXPECT_EQ(r.id, 2);
168
169 pt = utils::Point(0, 0.5);
170 r = c.classify(el, pt);
171 EXPECT_EQ(r.type, PointClassification::Edge);
172 EXPECT_EQ(r.id, 3);
173
174 // interior
175 pt = utils::Point(0.25, 0.25);
176 r = c.classify(el, pt);
177 EXPECT_EQ(r.type, PointClassification::Interior);
178
179 pt = utils::Point(0.75, 0.25);
180 r = c.classify(el, pt);
181 EXPECT_EQ(r.type, PointClassification::Interior);
182
183 pt = utils::Point(0.75, 0.75);
184 r = c.classify(el, pt);
185 EXPECT_EQ(r.type, PointClassification::Interior);
186
187 pt = utils::Point(0.25, 0.75);
188 r = c.classify(el, pt);
189 EXPECT_EQ(r.type, PointClassification::Interior);
190
191 // exterior
192 pt = utils::Point(1.5, 0);
193 r = c.classify(el, pt);
194 EXPECT_EQ(r.type, PointClassification::Exterior);
195
196 pt = utils::Point(-0.5, 0);
197 r = c.classify(el, pt);
198 EXPECT_EQ(r.type, PointClassification::Exterior);
199
200 pt = utils::Point(1.5, 1);
201 r = c.classify(el, pt);
202 EXPECT_EQ(r.type, PointClassification::Exterior);
203
204 pt = utils::Point(-0.5, 1);
205 r = c.classify(el, pt);
206 EXPECT_EQ(r.type, PointClassification::Exterior);
207
208 pt = utils::Point(0, 1.5);
209 r = c.classify(el, pt);
210 EXPECT_EQ(r.type, PointClassification::Exterior);
211
212 pt = utils::Point(0, -0.5);
213 r = c.classify(el, pt);
214 EXPECT_EQ(r.type, PointClassification::Exterior);
215
216 pt = utils::Point(1, 1.5);
217 r = c.classify(el, pt);
218 EXPECT_EQ(r.type, PointClassification::Exterior);
219
220 pt = utils::Point(1, -0.5);
221 r = c.classify(el, pt);
222 EXPECT_EQ(r.type, PointClassification::Exterior);
223 }
224
225 TEST(PointClassifier, EdgeXiQuad)
226 {
227 auto mesh = mesh::make_empty_mesh();
228 auto v1 = mesh->create_vertex(0, 0);
229 auto v2 = mesh->create_vertex(1, 0);
230 auto v3 = mesh->create_vertex(1, 1);
231 auto v4 = mesh->create_vertex(0, 1);
232 auto el = mesh->create_quad_from_verts(v1, v2, v3, v4);
233
234 PointClassifier c;
235 utils::Point pt;
236 PointRecord r;
237
238 pt = utils::Point(0.5, 0);
239 r = c.classify(el, pt);
240 EXPECT_EQ(r.type, PointClassification::Edge);
241 EXPECT_FLOAT_EQ(c.get_edge_xi(r), 0.5);
242
243 pt = utils::Point(1, 0.5);
244 r = c.classify(el, pt);
245 EXPECT_EQ(r.type, PointClassification::Edge);
246 EXPECT_FLOAT_EQ(c.get_edge_xi(r), 0.5);
247
248 pt = utils::Point(0.5, 1);
249 r = c.classify(el, pt);
250 EXPECT_EQ(r.type, PointClassification::Edge);
251 EXPECT_FLOAT_EQ(c.get_edge_xi(r), 0.5);
252
253 pt = utils::Point(0, 0.5);
254 r = c.classify(el, pt);
255 EXPECT_EQ(r.type, PointClassification::Edge);
256 EXPECT_FLOAT_EQ(c.get_edge_xi(r), 0.5);
257 }
258
259 TEST(PointClassifier, EdgeXiTriangle)
260 {
261 auto mesh = mesh::make_empty_mesh();
262 auto v1 = mesh->create_vertex(0, 0);
263 auto v2 = mesh->create_vertex(1, 0);
264 auto v3 = mesh->create_vertex(0, 1);
265 auto el = mesh->create_triangle_from_verts(v1, v2, v3);
266
267 PointClassifier c;
268 utils::Point pt;
269 PointRecord r;
270
271 pt = utils::Point(0.5, 0);
272 r = c.classify(el, pt);
273 EXPECT_EQ(r.type, PointClassification::Edge);
274 EXPECT_FLOAT_EQ(c.get_edge_xi(r), 0.5);
275
276 pt = utils::Point(0.5, 0.5);
277 r = c.classify(el, pt);
278 EXPECT_EQ(r.type, PointClassification::Edge);
279 EXPECT_FLOAT_EQ(c.get_edge_xi(r), 0.5);
280
281 pt = utils::Point(0, 0.5);
282 r = c.classify(el, pt);
283 EXPECT_EQ(r.type, PointClassification::Edge);
284 EXPECT_FLOAT_EQ(c.get_edge_xi(r), 0.5);
285 }
286
287 TEST(PointClassifier, LineEdgeXiQuad)
288 {
289 auto mesh = mesh::make_empty_mesh();
290 auto v1 = mesh->create_vertex(0, 0);
291 auto v2 = mesh->create_vertex(1, 0);
292 auto v3 = mesh->create_vertex(1, 1);
293 auto v4 = mesh->create_vertex(0, 1);
294 auto el = mesh->create_quad_from_verts(v1, v2, v3, v4);
295
296 const double eps = 1e-8; // set eps large to test fallback cases
297 const double smallSlopeEps = 1e-6;
298 PointClassifier c(eps, smallSlopeEps);
299 utils::Point pt1, pt2;
300 PointRecord r1, r2;
301 PossibleEdgeIntersection p;
302
303 pt1 = utils::Point(0.5, 0.5);
304 r1 = c.classify(el, pt1);
305 EXPECT_EQ(r1.type, PointClassification::Interior);
306
307 // bisect edges
308 pt2 = utils::Point(0.5, -1);
309 r2 = c.classify(el, pt2);
310 EXPECT_EQ(r2.type, PointClassification::Exterior);
311 p = c.get_edge_xi(r1, r2);
312 EXPECT_EQ(p.record.type, PointClassification::Edge);
313 EXPECT_EQ(p.record.id, 0);
314 EXPECT_FLOAT_EQ(p.edgeXi, 0.5);
315
316 pt2 = utils::Point(1.5, 0.5);
317 r2 = c.classify(el, pt2);
318 EXPECT_EQ(r2.type, PointClassification::Exterior);
319 p = c.get_edge_xi(r1, r2);
320 EXPECT_EQ(p.record.type, PointClassification::Edge);
321 EXPECT_EQ(p.record.id, 1);
322 EXPECT_FLOAT_EQ(p.edgeXi, 0.5);
323
324 pt2 = utils::Point(0.5, 2);
325 r2 = c.classify(el, pt2);
326 EXPECT_EQ(r2.type, PointClassification::Exterior);
327 p = c.get_edge_xi(r1, r2);
328 EXPECT_EQ(p.record.type, PointClassification::Edge);
329 EXPECT_EQ(p.record.id, 2);
330 EXPECT_FLOAT_EQ(p.edgeXi, 0.5);
331
332 pt2 = utils::Point(-0.5, 0.5);
333 r2 = c.classify(el, pt2);
334 EXPECT_EQ(r2.type, PointClassification::Exterior);
335 p = c.get_edge_xi(r1, r2);
336 EXPECT_EQ(p.record.type, PointClassification::Edge);
337 EXPECT_EQ(p.record.id, 3);
338 EXPECT_FLOAT_EQ(p.edgeXi, 0.5);
339
340 // diagonal lines
341 pt2 = utils::Point(0.25, -0.25);
342 r2 = c.classify(el, pt2);
343 EXPECT_EQ(r2.type, PointClassification::Exterior);
344 p = c.get_edge_xi(r1, r2);
345 EXPECT_EQ(p.record.type, PointClassification::Edge);
346 EXPECT_EQ(p.record.id, 0);
347 EXPECT_FLOAT_EQ(p.edgeXi, 1.0 / 3.0);
348
349 pt2 = utils::Point(1.25, 0.25);
350 r2 = c.classify(el, pt2);
351 EXPECT_EQ(r2.type, PointClassification::Exterior);
352 p = c.get_edge_xi(r1, r2);
353 EXPECT_EQ(p.record.type, PointClassification::Edge);
354 EXPECT_EQ(p.record.id, 1);
355 EXPECT_FLOAT_EQ(p.edgeXi, 1.0 / 3.0);
356
357 // fallback cases
358 pt1 = utils::Point(2 * eps, 0.25);
359 pt2 = utils::Point(-2 * eps, 0.75);
360 r1 = c.classify(el, pt1);
361 r2 = c.classify(el, pt2);
362 EXPECT_EQ(r1.type, PointClassification::Interior);
363 EXPECT_EQ(r2.type, PointClassification::Exterior);
364 p = c.get_edge_xi(r1, r2);
365 EXPECT_EQ(p.record.type, PointClassification::Edge);
366 EXPECT_EQ(p.record.id, 3);
367 EXPECT_FLOAT_EQ(p.edgeXi, 0.5);
368
369 pt1 = utils::Point(0.25, 2 * eps);
370 pt2 = utils::Point(0.75, -2 * eps);
371 r1 = c.classify(el, pt1);
372 r2 = c.classify(el, pt2);
373 EXPECT_EQ(r1.type, PointClassification::Interior);
374 EXPECT_EQ(r2.type, PointClassification::Exterior);
375 p = c.get_edge_xi(r1, r2);
376 EXPECT_EQ(p.record.type, PointClassification::Edge);
377 EXPECT_EQ(p.record.id, 0);
378 EXPECT_FLOAT_EQ(p.edgeXi, 0.5);
379
380 // test with point inside the lower left triangle
381 pt1 = utils::Point(0.25, 0.5);
382 r1 = c.classify(el, pt1);
383 EXPECT_EQ(r1.type, PointClassification::Interior);
384
385 // edge intersections
386 pt2 = utils::Point(0.25, -1);
387 r2 = c.classify(el, pt2);
388 EXPECT_EQ(r2.type, PointClassification::Exterior);
389 p = c.get_edge_xi(r1, r2);
390 EXPECT_EQ(p.record.type, PointClassification::Edge);
391 EXPECT_EQ(p.record.id, 0);
392 EXPECT_FLOAT_EQ(p.edgeXi, 0.25);
393
394 pt2 = utils::Point(1.5, 0.5);
395 r2 = c.classify(el, pt2);
396 EXPECT_EQ(r2.type, PointClassification::Exterior);
397 p = c.get_edge_xi(r1, r2);
398 EXPECT_EQ(p.record.type, PointClassification::Edge);
399 EXPECT_EQ(p.record.id, 1);
400 EXPECT_FLOAT_EQ(p.edgeXi, 0.50);
401
402 pt2 = utils::Point(0.25, 2);
403 r2 = c.classify(el, pt2);
404 EXPECT_EQ(r2.type, PointClassification::Exterior);
405 p = c.get_edge_xi(r1, r2);
406 EXPECT_EQ(p.record.type, PointClassification::Edge);
407 EXPECT_EQ(p.record.id, 2);
408 EXPECT_FLOAT_EQ(p.edgeXi, 0.75);
409
410 pt2 = utils::Point(-0.5, 0.5);
411 r2 = c.classify(el, pt2);
412 EXPECT_EQ(r2.type, PointClassification::Exterior);
413 p = c.get_edge_xi(r1, r2);
414 EXPECT_EQ(p.record.type, PointClassification::Edge);
415 EXPECT_EQ(p.record.id, 3);
416 EXPECT_FLOAT_EQ(p.edgeXi, 0.5);
417
418 // vertex intersections
419 // (there are two possible solutions for each of these, which result is
420 // returned is implementation defined)
421 pt2 = utils::Point(-1, -2);
422 r2 = c.classify(el, pt2);
423 EXPECT_EQ(r2.type, PointClassification::Exterior);
424 p = c.get_edge_xi(r1, r2);
425 EXPECT_EQ(p.record.type, PointClassification::Vert);
426 EXPECT_EQ(p.record.id, 0);
427 // EXPECT_FLOAT_EQ(p.edgeXi, 0);
428
429 pt2 = utils::Point(1.75, -0.5);
430 r2 = c.classify(el, pt2);
431 EXPECT_EQ(r2.type, PointClassification::Exterior);
432 p = c.get_edge_xi(r1, r2);
433 EXPECT_EQ(p.record.type, PointClassification::Vert);
434 EXPECT_EQ(p.record.id, 1);
435 // EXPECT_FLOAT_EQ(p.edgeXi, 1);
436
437 // TODO: missing vertex 2 case
438
439 pt2 = utils::Point(-1, 3);
440 r2 = c.classify(el, pt2);
441 EXPECT_EQ(r2.type, PointClassification::Exterior);
442 p = c.get_edge_xi(r1, r2);
443 EXPECT_EQ(p.record.type, PointClassification::Vert);
444 EXPECT_EQ(p.record.id, 3);
445 // EXPECT_FLOAT_EQ(p.edgeXi, 1);
446
447 // test with point inside the upper right triangle
448 pt1 = utils::Point(0.75, 0.5);
449 r1 = c.classify(el, pt1);
450 EXPECT_EQ(r1.type, PointClassification::Interior);
451
452 // edge intersections
453 pt2 = utils::Point(-1, -3);
454 r2 = c.classify(el, pt2);
455 EXPECT_EQ(r2.type, PointClassification::Exterior);
456 p = c.get_edge_xi(r1, r2);
457 EXPECT_EQ(p.record.type, PointClassification::Edge);
458 EXPECT_EQ(p.record.id, 0);
459 EXPECT_FLOAT_EQ(p.edgeXi, 0.5);
460
461 pt2 = utils::Point(2, 0.5);
462 r2 = c.classify(el, pt2);
463 EXPECT_EQ(r2.type, PointClassification::Exterior);
464 p = c.get_edge_xi(r1, r2);
465 EXPECT_EQ(p.record.type, PointClassification::Edge);
466 EXPECT_EQ(p.record.id, 1);
467 EXPECT_FLOAT_EQ(p.edgeXi, 0.5);
468
469 pt2 = utils::Point(0, 2);
470 r2 = c.classify(el, pt2);
471 EXPECT_EQ(r2.type, PointClassification::Exterior);
472 p = c.get_edge_xi(r1, r2);
473 EXPECT_EQ(p.record.type, PointClassification::Edge);
474 EXPECT_EQ(p.record.id, 2);
475 EXPECT_FLOAT_EQ(p.edgeXi, 0.5);
476
477 pt2 = utils::Point(-1, 0.5);
478 r2 = c.classify(el, pt2);
479 EXPECT_EQ(r2.type, PointClassification::Exterior);
480 p = c.get_edge_xi(r1, r2);
481 EXPECT_EQ(p.record.type, PointClassification::Edge);
482 EXPECT_EQ(p.record.id, 3);
483 EXPECT_FLOAT_EQ(p.edgeXi, 0.5);
484
485 // vertex intersections
486 pt2 = utils::Point(-1.5, -1);
487 r2 = c.classify(el, pt2);
488 EXPECT_EQ(r2.type, PointClassification::Exterior);
489 p = c.get_edge_xi(r1, r2);
490 EXPECT_EQ(p.record.type, PointClassification::Vert);
491 EXPECT_EQ(p.record.id, 0);
492 // EXPECT_FLOAT_EQ(p.edgeXi, 0);
493
494 pt2 = utils::Point(2, -2);
495 r2 = c.classify(el, pt2);
496 EXPECT_EQ(r2.type, PointClassification::Exterior);
497 p = c.get_edge_xi(r1, r2);
498 EXPECT_EQ(p.record.type, PointClassification::Vert);
499 EXPECT_EQ(p.record.id, 1);
500 // EXPECT_FLOAT_EQ(p.edgeXi, 1);
501
502 pt2 = utils::Point(2, 3);
503 r2 = c.classify(el, pt2);
504 EXPECT_EQ(r2.type, PointClassification::Exterior);
505 p = c.get_edge_xi(r1, r2);
506 EXPECT_EQ(p.record.type, PointClassification::Vert);
507 EXPECT_EQ(p.record.id, 2);
508 // EXPECT_FLOAT_EQ(p.edgeXi, 0);
509
510 pt2 = utils::Point(-1.5, 2);
511 r2 = c.classify(el, pt2);
512 EXPECT_EQ(r2.type, PointClassification::Exterior);
513 p = c.get_edge_xi(r1, r2);
514 EXPECT_EQ(p.record.type, PointClassification::Vert);
515 EXPECT_EQ(p.record.id, 3);
516 // EXPECT_FLOAT_EQ(p.edgeXi, 1);
517 }
518
519 TEST(PointClassifier, LineEdgeXiTriangle)
520 {
521 auto mesh = mesh::make_empty_mesh();
522 auto v1 = mesh->create_vertex(0, 0);
523 auto v2 = mesh->create_vertex(1, 0);
524 auto v3 = mesh->create_vertex(0, 1);
525 auto el = mesh->create_triangle_from_verts(v1, v2, v3);
526
527 const double eps = 1e-8; // set eps large to test fallback cases
528 const double smallSlopeEps = 1e-6;
529 PointClassifier c(eps, smallSlopeEps);
530 utils::Point pt1, pt2;
531 PointRecord r1, r2;
532 PossibleEdgeIntersection p;
533
534 pt1 = utils::Point(0.25, 0.25);
535 r1 = c.classify(el, pt1);
536 EXPECT_EQ(r1.type, PointClassification::Interior);
537
538 pt2 = utils::Point(0.25, -0.25);
539 r2 = c.classify(el, pt2);
540 EXPECT_EQ(r2.type, PointClassification::Exterior);
541 p = c.get_edge_xi(r1, r2);
542 EXPECT_EQ(p.record.type, PointClassification::Edge);
543 EXPECT_EQ(p.record.id, 0);
544 EXPECT_FLOAT_EQ(p.edgeXi, 0.25);
545
546 pt2 = utils::Point(-0.25, 0.25);
547 r2 = c.classify(el, pt2);
548 EXPECT_EQ(r2.type, PointClassification::Exterior);
549 p = c.get_edge_xi(r1, r2);
550 EXPECT_EQ(p.record.type, PointClassification::Edge);
551 EXPECT_EQ(p.record.id, 2);
552 EXPECT_FLOAT_EQ(p.edgeXi, 0.75);
553
554 pt2 = utils::Point(1.25, 0.25);
555 r2 = c.classify(el, pt2);
556 EXPECT_EQ(r2.type, PointClassification::Exterior);
557 p = c.get_edge_xi(r1, r2);
558 EXPECT_EQ(p.record.type, PointClassification::Edge);
559 EXPECT_EQ(p.record.id, 1);
560 EXPECT_FLOAT_EQ(p.edgeXi, 0.25);
561
562 pt2 = utils::Point(0.25, 1.25);
563 r2 = c.classify(el, pt2);
564 EXPECT_EQ(r2.type, PointClassification::Exterior);
565 p = c.get_edge_xi(r1, r2);
566 EXPECT_EQ(p.record.type, PointClassification::Edge);
567 EXPECT_EQ(p.record.id, 1);
568 EXPECT_FLOAT_EQ(p.edgeXi, 0.75);
569
570 // test fallback cases
571 pt1 = utils::Point(2 * eps, 0.25);
572 pt2 = utils::Point(-2 * eps, 0.75);
573 r1 = c.classify(el, pt1);
574 r2 = c.classify(el, pt2);
575 EXPECT_EQ(r1.type, PointClassification::Interior);
576 EXPECT_EQ(r2.type, PointClassification::Exterior);
577 p = c.get_edge_xi(r1, r2);
578 EXPECT_EQ(p.record.type, PointClassification::Edge);
579 EXPECT_EQ(p.record.id, 2);
580 EXPECT_FLOAT_EQ(p.edgeXi, 0.5);
581
582 pt1 = utils::Point(0.25, 2 * eps);
583 pt2 = utils::Point(0.75, -2 * eps);
584 r1 = c.classify(el, pt1);
585 r2 = c.classify(el, pt2);
586 EXPECT_EQ(r1.type, PointClassification::Interior);
587 EXPECT_EQ(r2.type, PointClassification::Exterior);
588 p = c.get_edge_xi(r1, r2);
589 EXPECT_EQ(p.record.type, PointClassification::Edge);
590 EXPECT_EQ(p.record.id, 0);
591 EXPECT_FLOAT_EQ(p.edgeXi, 0.5);
592 }
593
594 TEST(PointClassifier, EdgeCorner)
595 {
596 auto mesh = mesh::make_empty_mesh();
597 auto v1 = mesh->create_vertex(0, 0);
598 auto v2 = mesh->create_vertex(1, 0);
599 auto v3 = mesh->create_vertex(1, 1);
600 auto v4 = mesh->create_vertex(0, 1);
601 auto el = mesh->create_quad_from_verts(v1, v2, v3, v4);
602
603 const double eps = 1e-8; // set eps large to test fallback cases
604 const double smallSlopeEps = 1e-6;
605 PointClassifier c(eps, smallSlopeEps);
606 utils::Point pt1, pt2;
607 PointRecord r1, r2;
608 CornerRecord r3;
609
610 // horizontal line
611 pt1 = utils::Point(0.25, -0.25);
612 pt2 = utils::Point(0.25, 1.25);
613 r1 = c.classify(el, pt1);
614 r2 = c.classify(el, pt2);
615 EXPECT_EQ(r1.type, PointClassification::Exterior);
616 EXPECT_EQ(r2.type, PointClassification::Exterior);
617 r3 = c.get_edge_xi_corner(r1, r2);
618 EXPECT_TRUE(r3.hasIntersection);
619 EXPECT_EQ(r3.record1.type, PointClassification::Edge);
620 EXPECT_EQ(r3.record2.type, PointClassification::Edge);
621 EXPECT_EQ(r3.record1.id, 0);
622 EXPECT_EQ(r3.record2.id, 2);
623 EXPECT_FLOAT_EQ(r3.xi1, 0.25);
624 EXPECT_FLOAT_EQ(r3.xi2, 0.75);
625
626 // vertical line
627 pt1 = utils::Point(-0.25, 0.25);
628 pt2 = utils::Point(1.25, 0.25);
629 r1 = c.classify(el, pt1);
630 r2 = c.classify(el, pt2);
631 EXPECT_EQ(r1.type, PointClassification::Exterior);
632 EXPECT_EQ(r2.type, PointClassification::Exterior);
633 r3 = c.get_edge_xi_corner(r1, r2);
634 EXPECT_TRUE(r3.hasIntersection);
635 EXPECT_EQ(r3.record1.type, PointClassification::Edge);
636 EXPECT_EQ(r3.record2.type, PointClassification::Edge);
637 EXPECT_EQ(r3.record1.id, 3);
638 EXPECT_EQ(r3.record2.id, 1);
639 EXPECT_FLOAT_EQ(r3.xi1, 0.75);
640 EXPECT_FLOAT_EQ(r3.xi2, 0.25);
641
642 // general line
643 pt1 = utils::Point(-0.5, 0);
644 pt2 = utils::Point(1, 1.5);
645 r1 = c.classify(el, pt1);
646 r2 = c.classify(el, pt2);
647 EXPECT_EQ(r1.type, PointClassification::Exterior);
648 EXPECT_EQ(r2.type, PointClassification::Exterior);
649 r3 = c.get_edge_xi_corner(r1, r2);
650 EXPECT_TRUE(r3.hasIntersection);
651 EXPECT_EQ(r3.record1.type, PointClassification::Edge);
652 EXPECT_EQ(r3.record2.type, PointClassification::Edge);
653 EXPECT_EQ(r3.record1.id, 3);
654 EXPECT_EQ(r3.record2.id, 2);
655 EXPECT_FLOAT_EQ(r3.xi1, 0.5);
656 EXPECT_FLOAT_EQ(r3.xi2, 0.5);
657
658 pt1 = utils::Point(-1.5, 3);
659 pt2 = utils::Point(2, -0.5);
660 r1 = c.classify(el, pt1);
661 r2 = c.classify(el, pt2);
662 EXPECT_EQ(r1.type, PointClassification::Exterior);
663 EXPECT_EQ(r2.type, PointClassification::Exterior);
664 r3 = c.get_edge_xi_corner(r1, r2);
665 EXPECT_TRUE(r3.hasIntersection);
666 EXPECT_EQ(r3.record1.type, PointClassification::Edge);
667 EXPECT_EQ(r3.record2.type, PointClassification::Edge);
668 EXPECT_EQ(r3.record1.id, 2);
669 EXPECT_EQ(r3.record2.id, 1);
670 EXPECT_FLOAT_EQ(r3.xi1, 0.5);
671 EXPECT_FLOAT_EQ(r3.xi2, 0.5);
672
673 pt1 = utils::Point(-1.5, 2);
674 pt2 = utils::Point(2, -1.5);
675 r1 = c.classify(el, pt1);
676 r2 = c.classify(el, pt2);
677 EXPECT_EQ(r1.type, PointClassification::Exterior);
678 EXPECT_EQ(r2.type, PointClassification::Exterior);
679 r3 = c.get_edge_xi_corner(r1, r2);
680 EXPECT_TRUE(r3.hasIntersection);
681 EXPECT_EQ(r3.record1.type, PointClassification::Edge);
682 EXPECT_EQ(r3.record2.type, PointClassification::Edge);
683 EXPECT_EQ(r3.record1.id, 0);
684 EXPECT_EQ(r3.record2.id, 3);
685 EXPECT_FLOAT_EQ(r3.xi1, 0.5);
686 EXPECT_FLOAT_EQ(r3.xi2, 0.5);
687
688 // non intersection
689 pt1 = utils::Point(-0.25, -0.25);
690 pt2 = utils::Point(-0.25, 1.25);
691 r1 = c.classify(el, pt1);
692 r2 = c.classify(el, pt2);
693 EXPECT_EQ(r1.type, PointClassification::Exterior);
694 EXPECT_EQ(r2.type, PointClassification::Exterior);
695 r3 = c.get_edge_xi_corner(r1, r2);
696 EXPECT_FALSE(r3.hasIntersection);
697
698 pt1 = utils::Point(-0.5, 0);
699 pt2 = utils::Point(-0.25, 1.5);
700 r1 = c.classify(el, pt1);
701 r2 = c.classify(el, pt2);
702 EXPECT_EQ(r1.type, PointClassification::Exterior);
703 EXPECT_EQ(r2.type, PointClassification::Exterior);
704 r3 = c.get_edge_xi_corner(r1, r2);
705 EXPECT_FALSE(r3.hasIntersection);
706 }
707
708 TEST(PointClassifier, EdgeIntersectionXiQuad)
709 {
710 auto mesh = mesh::make_empty_mesh();
711 auto v1 = mesh->create_vertex(0, 0);
712 auto v2 = mesh->create_vertex(1, 0);
713 auto v3 = mesh->create_vertex(1, 1);
714 auto v4 = mesh->create_vertex(0, 1);
715 auto el = mesh->create_quad_from_verts(v1, v2, v3, v4);
716
717 const double eps = 1e-13;
718 const double smallSlopeEps = 1e-13;
719 PointClassifier c(eps, smallSlopeEps);
720 utils::Point pt1, pt2;
721 PointRecord r1, r2;
722 PossibleEdgeIntersection p;
723 ///*
724 // test vertex to external
725 pt1 = utils::Point(0, 0);
726 r1 = c.classify(el, pt1);
727 EXPECT_EQ(r1.type, PointClassification::Vert);
728 EXPECT_EQ(r1.id, 0);
729
730 // intersection points are excluded verts: should be excluded
731 {
732 pt2 = utils::Point(2, 0);
733 r2 = c.classify(el, pt2);
734 EXPECT_EQ(r2.type, PointClassification::Exterior);
735 p = c.get_edge_intersection_xi(r1, r2);
736 EXPECT_EQ(p.record.type, PointClassification::Vert);
737 EXPECT_EQ(p.record.id, 1);
738
739 pt2 = utils::Point(0, 2);
740 r2 = c.classify(el, pt2);
741 EXPECT_EQ(r2.type, PointClassification::Exterior);
742 p = c.get_edge_intersection_xi(r1, r2);
743 EXPECT_EQ(p.record.type, PointClassification::Vert);
744 EXPECT_EQ(p.record.id, 3);
745 }
746
747 // no intersections at all
748 {
749 pt2 = utils::Point(0.5, -0.5);
750 r2 = c.classify(el, pt2);
751 EXPECT_EQ(r2.type, PointClassification::Exterior);
752 p = c.get_edge_intersection_xi(r1, r2);
753 EXPECT_EQ(p.record.id, -1);
754
755 pt2 = utils::Point(-0.5, 0.5);
756 r2 = c.classify(el, pt2);
757 EXPECT_EQ(r2.type, PointClassification::Exterior);
758 p = c.get_edge_intersection_xi(r1, r2);
759 EXPECT_EQ(p.record.id, -1);
760 }
761
762 // edge intersections
763 {
764 pt2 = utils::Point(2, 1);
765 r2 = c.classify(el, pt2);
766 EXPECT_EQ(r2.type, PointClassification::Exterior);
767 p = c.get_edge_intersection_xi(r1, r2);
768 EXPECT_EQ(p.record.type, PointClassification::Edge);
769 EXPECT_EQ(p.record.id, 1);
770 EXPECT_FLOAT_EQ(p.edgeXi, 0.5);
771
772 pt2 = utils::Point(2, 0.5);
773 r2 = c.classify(el, pt2);
774 EXPECT_EQ(r2.type, PointClassification::Exterior);
775 p = c.get_edge_intersection_xi(r1, r2);
776 EXPECT_EQ(p.record.type, PointClassification::Edge);
777 EXPECT_EQ(p.record.id, 1);
778 EXPECT_FLOAT_EQ(p.edgeXi, 0.25);
779
780 pt2 = utils::Point(0.5, 2);
781 r2 = c.classify(el, pt2);
782 EXPECT_EQ(r2.type, PointClassification::Exterior);
783 p = c.get_edge_intersection_xi(r1, r2);
784 EXPECT_EQ(p.record.type, PointClassification::Edge);
785 EXPECT_EQ(p.record.id, 2);
786 EXPECT_FLOAT_EQ(p.edgeXi, 0.75);
787 }
788
789 // vertex intersection
790 {
791 pt2 = utils::Point(2, 2);
792 r2 = c.classify(el, pt2);
793 EXPECT_EQ(r2.type, PointClassification::Exterior);
794 p = c.get_edge_intersection_xi(r1, r2);
795 EXPECT_EQ(p.record.type, PointClassification::Vert);
796 EXPECT_EQ(p.record.id, 2);
797 }
798
799 // test shared vertex to external
800 pt1 = utils::Point(1, 0);
801 r1 = c.classify(el, pt1);
802 EXPECT_EQ(r1.type, PointClassification::Vert);
803 EXPECT_EQ(r1.id, 1);
804
805 // intersection points are excluded verts: should be excluded
806 {
807 pt2 = utils::Point(-1, 0);
808 r2 = c.classify(el, pt2);
809 EXPECT_EQ(r2.type, PointClassification::Exterior);
810 p = c.get_edge_intersection_xi(r1, r2);
811 EXPECT_EQ(r1.type, PointClassification::Vert);
812 EXPECT_EQ(p.record.id, 0);
813
814 pt2 = utils::Point(1, 2);
815 r2 = c.classify(el, pt2);
816 EXPECT_EQ(r2.type, PointClassification::Exterior);
817 p = c.get_edge_intersection_xi(r1, r2);
818 EXPECT_EQ(r1.type, PointClassification::Vert);
819 EXPECT_EQ(p.record.id, 2);
820 }
821
822 // no intersections at all
823 {
824 pt2 = utils::Point(0.5, -0.5);
825 r2 = c.classify(el, pt2);
826 EXPECT_EQ(r2.type, PointClassification::Exterior);
827 p = c.get_edge_intersection_xi(r1, r2);
828 EXPECT_EQ(p.record.id, -1);
829
830 pt2 = utils::Point(1.5, 0.5);
831 r2 = c.classify(el, pt2);
832 EXPECT_EQ(r2.type, PointClassification::Exterior);
833 p = c.get_edge_intersection_xi(r1, r2);
834 EXPECT_EQ(p.record.id, -1);
835 }
836
837 // edge intersections
838 {
839 pt2 = utils::Point(0, 2);
840 r2 = c.classify(el, pt2);
841 EXPECT_EQ(r2.type, PointClassification::Exterior);
842 p = c.get_edge_intersection_xi(r1, r2);
843 EXPECT_EQ(p.record.type, PointClassification::Edge);
844 EXPECT_EQ(p.record.id, 2);
845 EXPECT_FLOAT_EQ(p.edgeXi, 0.5);
846
847 pt2 = utils::Point(-1, 1);
848 r2 = c.classify(el, pt2);
849 EXPECT_EQ(r2.type, PointClassification::Exterior);
850 p = c.get_edge_intersection_xi(r1, r2);
851 EXPECT_EQ(p.record.type, PointClassification::Edge);
852 EXPECT_EQ(p.record.id, 3);
853 EXPECT_FLOAT_EQ(p.edgeXi, 0.5);
854 }
855
856 // vertex intersection
857 {
858 pt2 = utils::Point(-1, 2);
859 r2 = c.classify(el, pt2);
860 EXPECT_EQ(r2.type, PointClassification::Exterior);
861 p = c.get_edge_intersection_xi(r1, r2);
862 EXPECT_EQ(p.record.type, PointClassification::Vert);
863 EXPECT_EQ(p.record.id, 3);
864 }
865 // test edge to external
866 pt1 = utils::Point(0.5, 0);
867 r1 = c.classify(el, pt1);
868 EXPECT_EQ(r1.type, PointClassification::Edge);
869 EXPECT_EQ(r1.id, 0);
870
871 // intersection points are excluded verts: should be excluded
872 {
873 pt2 = utils::Point(-1, 0);
874 r2 = c.classify(el, pt2);
875 EXPECT_EQ(r2.type, PointClassification::Exterior);
876 p = c.get_edge_intersection_xi(r1, r2);
877 EXPECT_EQ(p.record.type, PointClassification::Vert);
878 EXPECT_EQ(p.record.id, 0);
879
880 pt2 = utils::Point(2, 0);
881 r2 = c.classify(el, pt2);
882 EXPECT_EQ(r2.type, PointClassification::Exterior);
883 p = c.get_edge_intersection_xi(r1, r2);
884 EXPECT_EQ(p.record.type, PointClassification::Vert);
885 EXPECT_EQ(p.record.id, 1);
886 }
887
888 // no intersections at all
889 {
890 pt2 = utils::Point(0.25, -0.5);
891 r2 = c.classify(el, pt2);
892 EXPECT_EQ(r2.type, PointClassification::Exterior);
893 p = c.get_edge_intersection_xi(r1, r2);
894 EXPECT_EQ(p.record.id, -1);
895
896 pt2 = utils::Point(0.75, -0.5);
897 r2 = c.classify(el, pt2);
898 EXPECT_EQ(r2.type, PointClassification::Exterior);
899 p = c.get_edge_intersection_xi(r1, r2);
900 EXPECT_EQ(p.record.id, -1);
901
902 pt2 = utils::Point(0.50, -0.5);
903 r2 = c.classify(el, pt2);
904 EXPECT_EQ(r2.type, PointClassification::Exterior);
905 p = c.get_edge_intersection_xi(r1, r2);
906 EXPECT_EQ(p.record.id, -1);
907 }
908
909 // edge intersections
910 {
911 pt2 = utils::Point(2, 1.5);
912 r2 = c.classify(el, pt2);
913 EXPECT_EQ(r2.type, PointClassification::Exterior);
914 p = c.get_edge_intersection_xi(r1, r2);
915 EXPECT_EQ(p.record.type, PointClassification::Edge);
916 EXPECT_EQ(p.record.id, 1);
917 EXPECT_FLOAT_EQ(p.edgeXi, 0.5);
918
919 pt2 = utils::Point(2, 6);
920 r2 = c.classify(el, pt2);
921 EXPECT_EQ(r2.type, PointClassification::Exterior);
922 p = c.get_edge_intersection_xi(r1, r2);
923 EXPECT_EQ(p.record.type, PointClassification::Edge);
924 EXPECT_EQ(p.record.id, 2);
925 EXPECT_FLOAT_EQ(p.edgeXi, 0.25);
926
927 pt2 = utils::Point(0, 2);
928 r2 = c.classify(el, pt2);
929 EXPECT_EQ(r2.type, PointClassification::Exterior);
930 p = c.get_edge_intersection_xi(r1, r2);
931 EXPECT_EQ(p.record.type, PointClassification::Edge);
932 EXPECT_EQ(p.record.id, 2);
933 EXPECT_FLOAT_EQ(p.edgeXi, 0.75);
934
935 pt2 = utils::Point(0.5, 2);
936 r2 = c.classify(el, pt2);
937 EXPECT_EQ(r2.type, PointClassification::Exterior);
938 p = c.get_edge_intersection_xi(r1, r2);
939 EXPECT_EQ(p.record.type, PointClassification::Edge);
940 EXPECT_EQ(p.record.id, 2);
941 EXPECT_FLOAT_EQ(p.edgeXi, 0.50);
942
943 pt2 = utils::Point(-1, 1.5);
944 r2 = c.classify(el, pt2);
945 EXPECT_EQ(r2.type, PointClassification::Exterior);
946 p = c.get_edge_intersection_xi(r1, r2);
947 EXPECT_EQ(p.record.type, PointClassification::Edge);
948 EXPECT_EQ(p.record.id, 3);
949 EXPECT_FLOAT_EQ(p.edgeXi, 0.5);
950 }
951
952 // vertex intersection
953 {
954 pt2 = utils::Point(2, 3);
955 r2 = c.classify(el, pt2);
956 EXPECT_EQ(r2.type, PointClassification::Exterior);
957 p = c.get_edge_intersection_xi(r1, r2);
958 EXPECT_EQ(p.record.type, PointClassification::Vert);
959 EXPECT_EQ(p.record.id, 2);
960
961 pt2 = utils::Point(-1, 3);
962 r2 = c.classify(el, pt2);
963 EXPECT_EQ(r2.type, PointClassification::Exterior);
964 p = c.get_edge_intersection_xi(r1, r2);
965 EXPECT_EQ(p.record.type, PointClassification::Vert);
966 EXPECT_EQ(p.record.id, 3);
967 }
968 }
969
970 TEST(PointClassifier, EdgeIntersectionXiQuadOverlappedEdges)
971 {
972 auto mesh = mesh::make_empty_mesh();
973 auto v1 = mesh->create_vertex(0, 0);
974 auto v2 = mesh->create_vertex(1, 0);
975 auto v3 = mesh->create_vertex(1, 1);
976 auto v4 = mesh->create_vertex(0, 1);
977 auto el = mesh->create_quad_from_verts(v1, v2, v3, v4);
978
979 const double eps = 1e-13;
980 const double smallSlopeEps = 1e-13;
981 PointClassifier c(eps, smallSlopeEps);
982 PointRecord r1, r2;
983 PossibleEdgeIntersection p, p2;
984
985 {
986 // edge bisects element
987 r1 = c.classify(el, {0.5, 0});
988 r2 = c.classify(el, {0, 1.5});
989 p = c.get_edge_intersection_xi(r1, r2);
990
991 EXPECT_EQ(p.record.type, PointClassification::Edge);
992 EXPECT_EQ(p.record.id, 2);
993 }
994
995 {
996 // edges overlap
997 r1 = c.classify(el, {0.5, 0});
998 r2 = c.classify(el, {1.5, 0});
999 p = c.get_edge_intersection_xi(r1, r2);
1000
1001 EXPECT_EQ(p.record.type, PointClassification::Vert);
1002 EXPECT_EQ(p.record.id, 1);
1003 }
1004
1005 {
1006 // edge passes through non-adjacent vertex
1007 r1 = c.classify(el, {0.5, 0});
1008 r2 = c.classify(el, {1.5, 2});
1009 p = c.get_edge_intersection_xi(r1, r2);
1010
1011 EXPECT_EQ(p.record.type, PointClassification::Vert);
1012 EXPECT_EQ(p.record.id, 2);
1013 }
1014
1015 {
1016 // edge passes through non-adjacent vertex
1017 r1 = c.classify(el, {0.5, 0});
1018 r2 = c.classify(el, {-1.5, 4});
1019 p = c.get_edge_intersection_xi(r1, r2);
1020
1021 EXPECT_EQ(p.record.type, PointClassification::Vert);
1022 EXPECT_EQ(p.record.id, 3);
1023 }
1024
1025 {
1026 // edges has endpoint on edge 1, passes through another edge
1027 r1 = c.classify(el, {1, 0.5});
1028 r2 = c.classify(el, {-1, 0.5});
1029 p = c.get_edge_intersection_xi(r1, r2);
1030
1031 EXPECT_EQ(p.record.type, PointClassification::Edge);
1032 EXPECT_EQ(p.record.id, 3);
1033 }
1034
1035 {
1036 // edges has endpoint on edge 1, passes through another edge
1037 r1 = c.classify(el, {1, 0.5});
1038 r2 = c.classify(el, {-1, -1});
1039 p = c.get_edge_intersection_xi(r1, r2);
1040
1041 EXPECT_EQ(p.record.type, PointClassification::Edge);
1042 EXPECT_EQ(p.record.id, 0);
1043 }
1044
1045 {
1046 // edge passes through adjacent vert, starting on edge 1
1047 r1 = c.classify(el, {1, 0.5});
1048 r2 = c.classify(el, {1, 2});
1049 p = c.get_edge_intersection_xi(r1, r2);
1050
1051 EXPECT_EQ(p.record.type, PointClassification::Vert);
1052 EXPECT_EQ(p.record.id, 2);
1053 }
1054 }
1055
1056 TEST(PointClassifier, EdgeIntersectionXiTriangle)
1057 {
1058 auto mesh = mesh::make_empty_mesh();
1059 auto v1 = mesh->create_vertex(0, 0);
1060 auto v2 = mesh->create_vertex(1, 0);
1061 auto v3 = mesh->create_vertex(0, 1);
1062 auto el = mesh->create_triangle_from_verts(v1, v2, v3);
1063
1064 const double eps = 1e-13;
1065 const double smallSlopeEps = 1e-13;
1066 PointClassifier c(eps, smallSlopeEps);
1067 utils::Point pt1, pt2;
1068 PointRecord r1, r2;
1069 PossibleEdgeIntersection p;
1070
1071 // test vertex to external
1072 pt1 = utils::Point(0, 0);
1073 r1 = c.classify(el, pt1);
1074 EXPECT_EQ(r1.type, PointClassification::Vert);
1075 EXPECT_EQ(r1.id, 0);
1076
1077 // intersection points are excluded verts: should be excluded
1078 {
1079 pt2 = utils::Point(2, 0);
1080 r2 = c.classify(el, pt2);
1081 EXPECT_EQ(r2.type, PointClassification::Exterior);
1082 p = c.get_edge_intersection_xi(r1, r2);
1083 EXPECT_EQ(p.record.id, -1);
1084
1085 pt2 = utils::Point(0, 2);
1086 r2 = c.classify(el, pt2);
1087 EXPECT_EQ(r2.type, PointClassification::Exterior);
1088 p = c.get_edge_intersection_xi(r1, r2);
1089 EXPECT_EQ(p.record.id, -1);
1090 }
1091
1092 // no intersections at all
1093 {
1094 pt2 = utils::Point(0.5, -0.5);
1095 r2 = c.classify(el, pt2);
1096 EXPECT_EQ(r2.type, PointClassification::Exterior);
1097 p = c.get_edge_intersection_xi(r1, r2);
1098 EXPECT_EQ(p.record.id, -1);
1099
1100 pt2 = utils::Point(-0.5, 0.5);
1101 r2 = c.classify(el, pt2);
1102 EXPECT_EQ(r2.type, PointClassification::Exterior);
1103 p = c.get_edge_intersection_xi(r1, r2);
1104 EXPECT_EQ(p.record.id, -1);
1105 }
1106
1107 // edge intersections
1108 {
1109 pt2 = utils::Point(1, 1);
1110 r2 = c.classify(el, pt2);
1111 EXPECT_EQ(r2.type, PointClassification::Exterior);
1112 p = c.get_edge_intersection_xi(r1, r2);
1113 EXPECT_EQ(p.record.type, PointClassification::Edge);
1114 EXPECT_EQ(p.record.id, 1);
1115 EXPECT_FLOAT_EQ(p.edgeXi, 0.5);
1116 }
1117
1118 // test with internal point on edge
1119 pt1 = utils::Point(0.5, 0);
1120 r1 = c.classify(el, pt1);
1121 EXPECT_EQ(r1.type, PointClassification::Edge);
1122 EXPECT_EQ(r1.id, 0);
1123
1124 {
1125 pt2 = utils::Point(-0.5, 1);
1126 r2 = c.classify(el, pt2);
1127 EXPECT_EQ(r2.type, PointClassification::Exterior);
1128 p = c.get_edge_intersection_xi(r1, r2);
1129 EXPECT_EQ(p.record.type, PointClassification::Edge);
1130 EXPECT_EQ(p.record.id, 2);
1131 EXPECT_FLOAT_EQ(p.edgeXi, 0.5);
1132
1133 pt2 = utils::Point(1, 0.5);
1134 r2 = c.classify(el, pt2);
1135 EXPECT_EQ(r2.type, PointClassification::Exterior);
1136 p = c.get_edge_intersection_xi(r1, r2);
1137 EXPECT_EQ(p.record.type, PointClassification::Edge);
1138 EXPECT_EQ(p.record.id, 1);
1139 EXPECT_FLOAT_EQ(p.edgeXi, 0.25);
1140
1141 // vertex intersection
1142 pt2 = utils::Point(-1, 3);
1143 r2 = c.classify(el, pt2);
1144 EXPECT_EQ(r2.type, PointClassification::Exterior);
1145 p = c.get_edge_intersection_xi(r1, r2);
1146 EXPECT_EQ(p.record.type, PointClassification::Vert);
1147 EXPECT_EQ(p.record.id, 2);
1148 }
1149 }
1150
1151 TEST(PointClassifier, OrthogonalProj)
1152 {
1153 auto mesh = mesh::make_empty_mesh();
1154 auto v1 = mesh->create_vertex(0, 0);
1155 auto v2 = mesh->create_vertex(1, 0);
1156 auto v3 = mesh->create_vertex(1, 1);
1157 auto v4 = mesh->create_vertex(0, 1);
1158 auto el = mesh->create_quad_from_verts(v1, v2, v3, v4);
1159
1160 PointClassifier c;
1161 utils::Point pt;
1162 PointRecord r;
1163
1164 pt = utils::Point(0.25, 0.35);
1165 r = c.classify(el, pt);
1166 EXPECT_FLOAT_EQ(c.compute_orthogonal_dist(r, 0), 0.35);
1167 EXPECT_FLOAT_EQ(c.compute_orthogonal_dist(r, 1), 0.75);
1168 EXPECT_FLOAT_EQ(c.compute_orthogonal_dist(r, 2), 0.65);
1169 EXPECT_FLOAT_EQ(c.compute_orthogonal_dist(r, 3), 0.25);
1170
1171 EXPECT_FLOAT_EQ(c.get_edge_xi_orthogonal(r, 0), 0.25);
1172 EXPECT_FLOAT_EQ(c.get_edge_xi_orthogonal(r, 1), 0.35);
1173 EXPECT_FLOAT_EQ(c.get_edge_xi_orthogonal(r, 2), 0.75);
1174 EXPECT_FLOAT_EQ(c.get_edge_xi_orthogonal(r, 3), 0.65);
1175 }
1176
1177 TEST(PointClassifier, XYZCoordsTriangle)
1178 {
1179 auto mesh = mesh::make_empty_mesh();
1180 auto v1 = mesh->create_vertex(0, 0);
1181 auto v2 = mesh->create_vertex(1, 0);
1182 auto v3 = mesh->create_vertex(0, 1);
1183 auto el = mesh->create_triangle_from_verts(v1, v2, v3);
1184
1185 PointClassifier c;
1186 utils::Point pt;
1187 PointRecord r;
1188
1189 pt = utils::Point(0.25, 0.35);
1190 r = c.classify(el, pt);
1191 EXPECT_EQ(r.type, PointClassification::Interior);
1192 expect_near(c.compute_xyz_coords(r), pt, 1e-13);
1193
1194 pt = utils::Point(0, 0);
1195 r = c.classify(el, pt);
1196 EXPECT_EQ(r.type, PointClassification::Vert);
1197 expect_near(c.compute_xyz_coords(r), pt, 1e-13);
1198
1199 pt = utils::Point(1, 0);
1200 r = c.classify(el, pt);
1201 EXPECT_EQ(r.type, PointClassification::Vert);
1202 expect_near(c.compute_xyz_coords(r), pt, 1e-13);
1203
1204 pt = utils::Point(0, 1);
1205 r = c.classify(el, pt);
1206 EXPECT_EQ(r.type, PointClassification::Vert);
1207 expect_near(c.compute_xyz_coords(r), pt, 1e-13);
1208
1209 pt = utils::Point(0.5, 0);
1210 r = c.classify(el, pt);
1211 EXPECT_EQ(r.type, PointClassification::Edge);
1212 expect_near(c.compute_xyz_coords(r), pt, 1e-13);
1213
1214 pt = utils::Point(0.5, 0.5);
1215 r = c.classify(el, pt);
1216 EXPECT_EQ(r.type, PointClassification::Edge);
1217 expect_near(c.compute_xyz_coords(r), pt, 1e-13);
1218
1219 pt = utils::Point(0, 0.5);
1220 r = c.classify(el, pt);
1221 EXPECT_EQ(r.type, PointClassification::Edge);
1222 expect_near(c.compute_xyz_coords(r), pt, 1e-13);
1223 }
1224
1225 } // namespace impl
1226 } // namespace middle_mesh
1227 } // namespace stk