9 const size_t u,
const size_t v)
11 for (
size_t t = 0; t <
r.triangles.size(); ++t)
13 const auto & tri =
r.triangles(t);
14 size_t vs[3] = {tri.i, tri.j, tri.k};
15 for (
int e = 0; e < 3; ++e)
17 const size_t a = vs[e], b = vs[(e + 1) % 3];
18 if ((a == u
and b == v) or (a == v
and b == u))
28 for (
size_t i = 0; i < sites.
size(); ++i)
31 return ~static_cast<size_t>(0);
41 if (u == ~
static_cast<size_t>(0) or v == ~
static_cast<size_t>(0))
44 for (
size_t i = 0; i <
r.constrained_edges.size(); ++i)
46 const auto & e =
r.constrained_edges(i);
47 if ((e.u == u
and e.v == v) or (e.u == v
and e.v == u))
60 struct EdgeKey {
size_t u, v; };
62 for (
size_t i = 0; i <
r.constrained_edges.size(); ++i)
64 const auto & e =
r.constrained_edges(i);
65 const size_t a = e.u < e.v ? e.u : e.v;
66 const size_t b = e.u < e.v ? e.v : e.u;
67 con_edges.
append(EdgeKey{a, b});
70 auto is_constrained = [&](
size_t a,
size_t b) ->
bool
72 if (a > b) {
const size_t t = a; a = b; b = t; }
73 for (
size_t i = 0; i < con_edges.
size(); ++i)
74 if (con_edges(i).u == a
and con_edges(i).v == b)
81 for (
size_t t1 = 0; t1 <
r.triangles.size(); ++t1)
83 const auto & tri1 =
r.triangles(t1);
84 size_t vs1[3] = {tri1.i, tri1.j, tri1.k};
86 for (
int e = 0; e < 3; ++e)
88 const size_t ea = vs1[e], eb = vs1[(e + 1) % 3];
89 if (is_constrained(ea, eb))
93 for (
size_t t2 = t1 + 1; t2 <
r.triangles.size(); ++t2)
95 const auto & tri2 =
r.triangles(t2);
96 size_t vs2[3] = {tri2.i, tri2.j, tri2.k};
99 size_t opp = ~static_cast<size_t>(0);
100 for (
int f = 0; f < 3; ++f)
102 const size_t fa = vs2[f], fb = vs2[(f + 1) % 3];
103 if ((fa == ea
and fb == eb) or (fa == eb
and fb == ea))
106 opp = vs2[(f + 2) % 3];
118 if (o == Orientation::COLLINEAR)
122 r.sites(tri1.i),
r.sites(tri1.j),
123 r.sites(tri1.k),
r.sites(opp));
125 if (o == Orientation::CCW
and det > 0)
127 if (o == Orientation::CW
and det < 0)
150 auto result = cdt(pts, constraints);
152 EXPECT_EQ(result.sites.size(), 3u);
153 EXPECT_EQ(result.triangles.size(), 1u);
154 EXPECT_TRUE(result.constrained_edges.is_empty());
159 Point a(0, 0), b(4, 0), c(4, 4), d(0, 4);
169 auto result = cdt(pts, constraints);
171 EXPECT_EQ(result.sites.size(), 4u);
172 EXPECT_EQ(result.triangles.size(), 2u);
178 const size_t ia =
find_site(result.sites, a);
179 const size_t ic =
find_site(result.sites, c);
186 Point a(0, 0), b(6, 0), c(3, 5);
195 auto result = cdt(pts, constraints);
197 EXPECT_EQ(result.triangles.size(), 1u);
204 Point a(0, 0), b(2, 1), c(4, 0), d(2, -1);
214 auto result = cdt(pts, constraints);
216 EXPECT_EQ(result.sites.size(), 4u);
217 EXPECT_EQ(result.triangles.size(), 2u);
220 const size_t ia =
find_site(result.sites, a);
221 const size_t ic =
find_site(result.sites, c);
227 Point a(0, 0), b(6, 0), c(6, 6), d(0, 6), e(3, 3);
238 auto result = cdt(pts, constraints);
240 EXPECT_GE(result.sites.size(), 5u);
241 EXPECT_GE(result.triangles.size(), 4u);
254 Point p0(0, 0), p1(2, 3), p2(4, 0), p3(6, 3), p4(8, 0);
267 auto result = cdt(pts, constraints);
269 EXPECT_EQ(result.sites.size(), 5u);
270 EXPECT_GE(result.triangles.size(), 3u);
288 auto result = cdt(pts, constraints);
290 EXPECT_TRUE(result.triangles.is_empty());
302 auto result = cdt(pts, constraints);
304 EXPECT_TRUE(result.triangles.is_empty());
317 auto result = cdt(pts, constraints);
319 EXPECT_TRUE(result.triangles.is_empty());
325 Point a(0, 0), b(4, 0), c(2, 3);
335 auto result = cdt(pts, constraints);
337 EXPECT_EQ(result.sites.size(), 3u);
338 EXPECT_EQ(result.triangles.size(), 1u);
348 Point a(0, 0), b(2, 0), c(4, 0), d(2, 3);
357 auto result = cdt(pts, constraints);
359 EXPECT_EQ(result.sites.size(), 4u);
360 EXPECT_GE(result.triangles.size(), 2u);
363 const size_t ia =
find_site(result.sites, a);
364 const size_t ib =
find_site(result.sites, b);
365 const size_t ic =
find_site(result.sites, c);
372 Point a(0, 0), b(4, 0), c(2, 3);
381 auto result = cdt(pts, constraints);
383 EXPECT_EQ(result.sites.size(), 3u);
384 EXPECT_EQ(result.triangles.size(), 1u);
389 Point a(0, 0), b(4, 0), c(2, 3);
400 auto result = cdt(pts, constraints);
402 EXPECT_EQ(result.sites.size(), 3u);
403 EXPECT_EQ(result.triangles.size(), 1u);
414 Point p0(0, 0), p1(5, 0), p2(5, 5), p3(0, 5);
415 Point p4(1, 1), p5(4, 1), p6(4, 4), p7(1, 4);
429 auto result = cdt(pts, constraints);
431 EXPECT_GE(result.sites.size(), 8u);
434 for (
size_t i = 0; i < result.constrained_edges.size(); ++i)
436 const auto & e = result.constrained_edges(i);
438 <<
"Constrained edge (" << e.u <<
"," << e.v <<
") not in triangulation";
449 Point p0(0, 0), p1(6, 0), p2(6, 6), p3(0, 6), p4(3, 3);
460 auto result = cdt(pts, constraints);
463 <<
"Delaunay property violated for non-constrained edges";
468 Point a(0, 0), b(4, 0), c(4, 4), d(0, 4), e(2, 2);
478 auto result = cdt(pts, constraints);
480 EXPECT_NE(
find_site(result.sites, a), ~
static_cast<size_t>(0));
481 EXPECT_NE(
find_site(result.sites, b), ~
static_cast<size_t>(0));
482 EXPECT_NE(
find_site(result.sites, c), ~
static_cast<size_t>(0));
483 EXPECT_NE(
find_site(result.sites, d), ~
static_cast<size_t>(0));
484 EXPECT_NE(
find_site(result.sites, e), ~
static_cast<size_t>(0));
489 Point p0(0, 0), p1(6, 0), p2(6, 4), p3(0, 4), p4(3, 2);
499 auto result = cdt(pts, constraints);
502 for (
size_t t = 0; t < result.triangles.size(); ++t)
504 const auto & tri = result.triangles(t);
507 result.sites(tri.k));
508 EXPECT_NE(o, Orientation::COLLINEAR) <<
"Degenerate triangle " << t;
520 for (
int y = 0;
y < 4; ++
y)
521 for (
int x = 0; x < 4; ++x)
526 for (
int y = 0;
y < 3; ++
y)
527 for (
int x = 0; x < 3; ++x)
531 auto result = cdt(pts, constraints);
533 EXPECT_EQ(result.sites.size(), 16u);
534 EXPECT_GE(result.triangles.size(), 18u);
537 for (
int y = 0;
y < 3; ++
y)
538 for (
int x = 0; x < 3; ++x)
546 Point p0(2, 0), p1(4, 1.5), p2(3, 4), p3(1, 4), p4(0, 1.5);
561 auto result = cdt(pts, constraints);
563 EXPECT_EQ(result.sites.size(), 6u);
564 EXPECT_GE(result.triangles.size(), 4u);
575 Point a(0, 0), b(4, 0), c(2, 3);
584 auto result = cdt(pts, constraints);
587 EXPECT_EQ(triangles.
size(), result.triangles.size());
597 EXPECT_EQ(result.sites.size(), 4u);
598 EXPECT_EQ(result.triangles.size(), 2u);
619 auto result = cdt(pts, constraints);
621 EXPECT_GE(result.triangles.size(), 6u);
Simple dynamic array with automatic resizing and functional operations.
constexpr size_t size() const noexcept
Return the number of elements stored in the stack.
T & append(const T &data)
Append a copy of data
Constrained Delaunay Triangulation via Sloan's flip-based method.
static DynList< Triangle > as_triangles(const Result &result)
Convert indexed triangulation to geometric triangles.
Doubly-linked list (defined in tpl_dynList.H).
T & append(const T &item)
size_t size() const noexcept
Return the number of items of the list, in constant time.
Represents a point with rectangular coordinates in a 2D plane.
Represents a line segment between two points.
TEST_F(GeomAlgorithmsTest, CDT_TriangleNoConstraints)
static bool cdt_has_edge(const ConstrainedDelaunayTriangulation::Result &r, const size_t u, const size_t v)
static bool has_constrained_edge(const ConstrainedDelaunayTriangulation::Result &r, const Point &p, const Point &q)
static bool check_delaunay_for_non_constrained(const ConstrainedDelaunayTriangulation::Result &r)
static size_t find_site(const Array< Point > &sites, const Point &p)
Orientation
Classification of three-point orientation.
Geom_Number in_circle_determinant(const Point &a, const Point &b, const Point &c, const Point &p)
Return the exact in-circle determinant for (a,b,c,p).
and
Check uniqueness with explicit hash + equality functors.
Orientation orientation(const Point &a, const Point &b, const Point &c)
Return the orientation of the triple (a, b, c).