37 EXPECT_GE(result.size(), 1u);
42 if (result.size() >= 1)
43 EXPECT_GE(result(0).
size(), 3u);
71 EXPECT_GE(result.size(), 1u);
76 if (result.size() == 1)
77 EXPECT_GT(result(0).
size(), 4u);
103 EXPECT_EQ(result.size(), 1u);
106 EXPECT_EQ(result(0).
size(), 8u);
131 EXPECT_EQ(result.size(), 1u);
133 if (result.size() == 1)
134 EXPECT_EQ(result(0).
size(), 6u);
159 EXPECT_EQ(inter.size(), 1u);
160 if (inter.size() == 1)
161 EXPECT_EQ(inter(0).
size(), 4u);
165 EXPECT_EQ(uni.size(), 1u);
167 EXPECT_EQ(uni(0).
size(), 4u);
171 EXPECT_EQ(
diff.size(), 1u);
213 auto ixj = i.
cross(j);
221 auto kxi =
k.cross(i);
240 EXPECT_EQ(p2d,
Point(3, 4));
243 EXPECT_EQ(lifted,
Point3D(1, 2, 0));
246 EXPECT_EQ(lifted_z,
Point3D(1, 2, 7));
252 Point3D a(0, 0, 0), b(3, 4, 0);
284 EXPECT_EQ(n,
Point3D(0, 0, 1));
309 EXPECT_EQ(c,
Point3D(1, 1, 0));
406 EXPECT_EQ(c,
Point3D(1, 1, 1));
417 auto f = tet.
faces();
419 for (
int i = 0; i < 4; ++i)
420 EXPECT_FALSE(f.f[i].is_degenerate());
447 std::ostringstream os;
449 EXPECT_NE(os.str().find(
"Point("), std::string::npos);
450 EXPECT_NE(os.str().find(
"3"), std::string::npos);
451 EXPECT_NE(os.str().find(
"4"), std::string::npos);
457 std::ostringstream os;
459 EXPECT_NE(os.str().find(
"Segment("), std::string::npos);
465 std::ostringstream os;
467 EXPECT_NE(os.str().find(
"Triangle("), std::string::npos);
473 std::ostringstream os;
475 EXPECT_NE(os.str().find(
"Rectangle("), std::string::npos);
481 std::ostringstream os;
483 EXPECT_NE(os.str().find(
"Ellipse("), std::string::npos);
489 std::ostringstream os;
491 EXPECT_NE(os.str().find(
"RotatedEllipse("), std::string::npos);
504 std::ostringstream os;
506 EXPECT_NE(os.str().find(
"Polygon("), std::string::npos);
507 EXPECT_NE(os.str().find(
"n=4"), std::string::npos);
508 EXPECT_NE(os.str().find(
"closed"), std::string::npos);
515 std::ostringstream os;
517 EXPECT_NE(os.str().find(
"Point3D("), std::string::npos);
520 std::ostringstream os;
522 EXPECT_NE(os.str().find(
"Segment3D("), std::string::npos);
525 std::ostringstream os;
527 EXPECT_NE(os.str().find(
"Triangle3D("), std::string::npos);
530 std::ostringstream os;
533 EXPECT_NE(os.str().find(
"Tetrahedron("), std::string::npos);
545 EXPECT_NE(wkt.find(
"POINT ("), std::string::npos);
546 EXPECT_NE(wkt.find(
"3"), std::string::npos);
547 EXPECT_NE(wkt.find(
"4"), std::string::npos);
554 EXPECT_NE(wkt.find(
"LINESTRING ("), std::string::npos);
561 EXPECT_NE(wkt.find(
"POLYGON (("), std::string::npos);
564 size_t pos = 0,
count = 0;
565 while ((pos = wkt.find(
"0 0", pos)) != std::string::npos)
567 EXPECT_GE(
count, 2u);
574 EXPECT_NE(wkt.find(
"POLYGON (("), std::string::npos);
588 EXPECT_NE(wkt.find(
"POLYGON (("), std::string::npos);
595 EXPECT_NE(wkt.find(
"POINT Z ("), std::string::npos);
602 EXPECT_NE(json.find(
"\"type\":\"Point\""), std::string::npos);
603 EXPECT_NE(json.find(
"\"coordinates\":["), std::string::npos);
610 EXPECT_NE(json.find(
"\"type\":\"LineString\""), std::string::npos);
618 EXPECT_NE(json.find(
"\"type\":\"Polygon\""), std::string::npos);
632 EXPECT_NE(json.find(
"\"type\":\"Polygon\""), std::string::npos);
633 EXPECT_NE(json.find(
"\"coordinates\":[["), std::string::npos);
640 EXPECT_NE(json.find(
"\"type\":\"Point\""), std::string::npos);
654 EXPECT_EQ(tree.
size(), 0u);
665 EXPECT_EQ(tree.
size(), 1u);
670 EXPECT_EQ(
r.size(), 1u);
671 EXPECT_EQ(
r(0), 42u);
675 EXPECT_EQ(
r.size(), 0u);
689 EXPECT_EQ(tree.
size(), 4u);
693 EXPECT_EQ(
r.size(), 2u);
697 EXPECT_EQ(
r.size(), 1u);
702 EXPECT_EQ(
r.size(), 0u);
717 EXPECT_EQ(
r.size(), 2u);
721 EXPECT_EQ(
r.size(), 3u);
725 EXPECT_EQ(
r.size(), 0u);
754 EXPECT_GT(snap.nodes.size(), 0u);
755 EXPECT_NE(snap.root, ~
static_cast<size_t>(0));
757 size_t leaf_count = 0;
758 for (
size_t i = 0; i < snap.nodes.size(); ++i)
759 if (snap.nodes(i).is_leaf)
761 EXPECT_EQ(leaf_count, tree.
size());
766 constexpr size_t num_entries = 128;
770 for (
size_t i = 0; i < num_entries; ++i)
772 const long x =
static_cast<long>(3 * i);
773 const long y =
static_cast<long>((41 * i) % 97);
779 EXPECT_EQ(snap.nodes.size(), 2 * num_entries - 1);
780 EXPECT_LT(snap.root, snap.nodes.size());
782 size_t leaf_count = 0;
783 for (
size_t i = 0; i < snap.nodes.size(); ++i)
784 if (snap.nodes(i).is_leaf)
788 EXPECT_LT(snap.nodes(i).left, snap.nodes.size());
789 EXPECT_LT(snap.nodes(i).right, snap.nodes.size());
792 EXPECT_EQ(leaf_count, num_entries);
800#if __cplusplus >= 202002L
805 EXPECT_TRUE((GeomNumberType<Geom_Number>));
806 EXPECT_TRUE((GeomNumberType<double>));
807 EXPECT_TRUE((GeomNumberType<long long>));
817#if __cplusplus >= 202002L && __has_include(<format>)
823# if defined(__cpp_lib_format) || \
824 (defined(_LIBCPP_VERSION) && _LIBCPP_VERSION >= 170000)
829 auto s = std::format(
"{}",
Point(3, 4));
830 EXPECT_NE(s.find(
"Point("), std::string::npos);
831 EXPECT_NE(s.find(
"3"), std::string::npos);
832 EXPECT_NE(s.find(
"4"), std::string::npos);
839 EXPECT_NE(s.find(
"Segment("), std::string::npos);
846 EXPECT_NE(s.find(
"Triangle("), std::string::npos);
852 auto s = std::format(
"{}",
Rectangle(0, 0, 5, 5));
853 EXPECT_NE(s.find(
"Rectangle("), std::string::npos);
859 auto s = std::format(
"{}",
Point3D(1, 2, 3));
860 EXPECT_NE(s.find(
"Point3D("), std::string::npos);
866 EXPECT_NE(s.find(
"PolarPoint("), std::string::npos);
872 EXPECT_NE(s.find(
"Ellipse("), std::string::npos);
878 EXPECT_NE(s.find(
"RotatedEllipse("), std::string::npos);
884 EXPECT_NE(s.find(
"Segment3D("), std::string::npos);
892 EXPECT_NE(s.find(
"Triangle3D("), std::string::npos);
901 EXPECT_NE(s.find(
"Tetrahedron("), std::string::npos);
909 GTEST_SKIP() <<
"<format> exists, but std::format is not usable: neither "
910 "__cpp_lib_format nor libc++ 17 or later.";
933 for (
const auto & pt : sq)
938 EXPECT_EQ(
count, 4u);
995 EXPECT_EQ(visited, 2u);
1009 return p.get_x() == 1 && p.get_y() == 1;
1013 return p.get_x() == 99;
1027 EXPECT_TRUE(sq.
all([](
const Point & p) {
1028 return p.get_x() >= 0 && p.get_y() >= 0;
1031 EXPECT_FALSE(sq.
all([](
const Point & p) {
1032 return p.get_x() > 0;
1046 EXPECT_EQ(xs.size(), 3u);
1060 EXPECT_EQ(filtered.size(), 2u);
1069 EXPECT_EQ(poly.
size(), 4u);
1083 EXPECT_TRUE(it.has_curr());
1084 EXPECT_EQ(it.get_curr(),
Point(0, 0));
1087 EXPECT_EQ(it2.get_curr(),
Point(2, 3));
1112 auto hull_gw = gift(pts);
1113 auto hull_gm = graham(pts);
1114 auto hull_qh = qh(pts);
1117 EXPECT_EQ(hull_gw.size(), 4u);
1118 EXPECT_EQ(hull_gm.size(), 4u);
1119 EXPECT_EQ(hull_qh.size(), 4u);
1138 EXPECT_EQ(tris.size(), 4u);
1158 EXPECT_EQ(tris.size(), 6u);
1167 for (
int i = 0; i <
N; ++i)
1217 Point p2(-big, -big);
1218 Point p3(big, -big);
1262 EXPECT_EQ(result, InCircleResult::ON_CIRCLE);
1444 EXPECT_GE(result.size(), 1u);
1447 for (
size_t i = 0; i < result.size(); ++i)
1456 <<
"Intersection area = " << total_area.
get_d()
1457 <<
", expected 12 (concave polygon intersection bug?)";
1488 EXPECT_GE(result.size(), 1u);
1491 for (
size_t i = 0; i < result.size(); ++i)
1500 if (result.size() == 1)
1501 EXPECT_GT(result(0).
size(), 4u)
1502 <<
"Union collapsed to convex hull — concave shape lost";
1529 EXPECT_GE(result.size(), 1u);
1533 for (
size_t i = 0; i < result.size(); ++i)
1561 EXPECT_EQ(result.size(), 0u);
1577 auto result = pd(sites);
1579 EXPECT_EQ(result.sites.size(), 4u);
1580 EXPECT_EQ(result.cells.size(), 4u);
1584 for (
size_t v = 0; v < result.vertices.size(); ++v)
1586 const Point & pc = result.vertices(v);
1588 for (
size_t s = 0; s < result.sites.size(); ++s)
1590 - result.sites(s).weight);
1592 bool found_triple =
false;
1593 for (
size_t a = 0; a < pds.
size()
and not found_triple; ++a)
1594 for (
size_t b = a + 1; b < pds.
size()
and not found_triple; ++b)
1595 for (
size_t c = b + 1; c < pds.
size()
and not found_triple; ++c)
1596 if (pds(a) == pds(b)
and pds(b) == pds(c))
1597 found_triple =
true;
1599 EXPECT_TRUE(found_triple)
1600 <<
"Power vertex " << v <<
" is not equi-power-distant to any triple";
1614 auto pr = pd(wsites);
1621 EXPECT_EQ(pr.sites.size(),
vr.sites.size());
1622 EXPECT_EQ(pr.vertices.size(),
vr.vertices.size());
1625 if (pr.vertices.size() >= 1
and vr.vertices.size() >= 1)
1627 const Point & pv = pr.vertices(0);
1628 const Point & vv =
vr.vertices(0);
1632 <<
"Power vertex and Voronoi vertex differ";
1656 EXPECT_GE(result.
size(), 3u);
1664 EXPECT_LT(offset_area, orig_area)
1665 <<
"Inward offset area (" << offset_area.
get_d()
1666 <<
") >= original area (" << orig_area.
get_d()
1667 <<
") — collinear vertex bug in ConvexPolygonOffset";
1687 EXPECT_LT(result.
size(), 3u)
1688 <<
"Inward offset of 6 on a 10x10 square should produce empty result, "
1689 <<
"but got " << result.
size() <<
" vertices";
Axis-aligned bounding box tree for spatial queries.
Rectangle root_bbox() const
Return the root bounding box (union of all entries).
size_t build(Array< size_t > &idx, const size_t lo, const size_t hi)
bool is_empty() const
Whether the tree is empty.
size_t size() const
Number of entries.
DebugSnapshot debug_snapshot() const
Return the full tree structure for visualization/debug.
Array< size_t > query(const Rectangle &query) const
Find all entries whose bounding box overlaps the query rectangle.
Array< size_t > query_point(const Point &p) const
Find all entries whose bounding box contains the query point.
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
void reserve(size_t cap)
Reserves cap cells into the array.
Boolean operations on simple polygons (union, intersection, difference) using the Greiner-Hormann alg...
Array< Polygon > difference(const Polygon &a, const Polygon &b) const
Convenience: difference (a minus b).
Array< Polygon > polygon_union(const Polygon &a, const Polygon &b) const
Convenience: union.
Array< Polygon > intersection(const Polygon &a, const Polygon &b) const
Convenience: intersection.
static Polygon inward(const Polygon &convex_poly, const Geom_Number &distance)
Inward offset (erosion) of a convex polygon.
Polygon triangulation using the ear-cutting algorithm.
Doubly-linked list (defined in tpl_dynList.H).
T & append(const T &item)
const Geom_Number & get_vradius() const
Gets the vertical radius.
bool intersects_with(const Segment &s) const
Checks if a segment intersects the ellipse.
const Geom_Number & get_hradius() const
Gets the horizontal radius.
bool contains(const Point &p) const
Checks if a point lies inside or on the boundary of this ellipse.
static std::string to_geojson(const Point &p)
Converts a Point to a GeoJSON geometry object.
static std::string to_wkt(const Point &p)
Converts a Point to WKT format: "POINT (x y)".
Gift wrapping (Jarvis march) convex hull algorithm.
Graham scan convex hull algorithm.
Number Theoretic Transform over Z / MOD Z.
Represents a point in 3D space with exact rational coordinates.
static Point3D from_2d(const Point &p)
Lifts a 2D point to 3D, setting its z-coordinate to 0.
Geom_Number distance_squared_to(const Point3D &p) const
Squared Euclidean distance to another point.
Point3D cross(const Point3D &p) const
Cross product.
Geom_Number norm_squared() const
Squared Euclidean norm (magnitude).
Point to_2d() const
Projects this 3D point to a 2D point by dropping the z-coordinate.
Geom_Number dot(const Point3D &p) const
Dot product.
Represents a point with rectangular coordinates in a 2D plane.
const Geom_Number & get_x() const noexcept
Gets the x-coordinate value.
const Geom_Number & get_y() const noexcept
Gets the y-coordinate value.
Geom_Number distance_squared_to(const Point &that) const
Calculates the squared Euclidean distance to another point.
bool is_colinear_with(const Point &p1, const Point &p2) const
Checks if this point is collinear with two other points.
Polar representation of a 2D point.
STL/Aleph-compatible iterator over polygon vertices as Points.
const Point & get_curr() const
bool has_curr() const noexcept
A general (irregular) 2D polygon defined by a sequence of vertices.
void add_vertex(const Point &point)
Add a vertex to the polygon.
void close()
Close the polygon.
const bool & is_closed() const
Check if the polygon is closed.
const size_t & size() const
Get the number of vertices.
bool contains(const Point &p) const
Check if a point is inside the polygon (or on its boundary).
Power diagram (weighted Voronoi diagram).
QuickHull convex hull algorithm.
An axis-aligned rectangle.
const Geom_Number & get_xmin() const
Gets the minimum x-coordinate.
const Geom_Number & get_ymax() const
Gets the maximum y-coordinate.
const Geom_Number & get_ymin() const
Gets the minimum y-coordinate.
const Geom_Number & get_xmax() const
Gets the maximum x-coordinate.
An ellipse with arbitrary rotation.
bool contains(const Point &p) const
Checks if a point lies inside or on the ellipse.
const Geom_Number & get_sin() const
Gets the sine of the rotation angle.
bool on_boundary(const Point &p) const
Checks if a point lies exactly on the ellipse boundary.
const Geom_Number & get_cos() const
Gets the cosine of the rotation angle.
Represents a line segment in 3D space.
Point3D midpoint() const
Calculates the midpoint of the segment.
bool contains(const Point3D &p) const
Checks if a point lies on the segment.
const Point3D & get_src() const noexcept
Gets the source point of the segment.
Geom_Number distance_to(const Point3D &p) const
Calculates the shortest distance from a point to this segment.
const Point3D & get_tgt() const noexcept
Gets the target point of the segment.
Point3D at(const Geom_Number &t) const
Evaluates a point on the segment via linear interpolation.
Geom_Number length_squared() const
Calculates the squared length of the segment.
Geom_Number length() const
Calculates the length of the segment.
Represents a line segment between two points.
bool intersects_properly_with(const Segment &s) const
Checks if this segment properly intersects another segment.
Point mid_point() const
Returns the midpoint of this segment.
bool intersects_with(const Segment &s) const
Checks if this segment intersects another one (including endpoints and collinear overlap).
void enlarge_src(const Geom_Number &dist)
Extends the segment by a given distance from the source endpoint.
void enlarge_tgt(const Geom_Number &dist)
Extends the segment by a given distance from the target endpoint.
bool contains(const Point &p) const
Checks if a point lies on this segment.
const Point & get_tgt_point() const noexcept
Gets the target point of the segment.
const Point & get_src_point() const noexcept
Gets the source point of the segment.
Geom_Number length() const
Returns the Euclidean length of the segment.
Represents a tetrahedron in 3D space defined by four points.
Point3D centroid() const
Computes the centroid (center of mass) of the tetrahedron.
Faces faces() const
Gets the four faces of the tetrahedron.
bool is_degenerate() const
Checks if the tetrahedron is degenerate (i.e., its vertices are coplanar).
Geom_Number volume() const
Calculates the unsigned volume of the tetrahedron.
bool contains(const Point3D &p) const
Checks if a point lies inside the tetrahedron.
Represents a triangle in 3D space defined by three points.
BaryCoords barycentric(const Point3D &p) const
Computes the barycentric coordinates of a point p with respect to this triangle.
Point3D centroid() const
Computes the centroid (center of mass) of the triangle.
Point3D normal() const
Computes the normal vector of the triangle's plane.
Geom_Number double_area_squared() const
Calculates twice the squared area of the triangle.
bool is_degenerate() const
Checks if the triangle is degenerate (i.e., its vertices are collinear).
A non-degenerate triangle defined by three points.
bool contains(const Point &p) const
Checks if a point lies strictly inside this triangle.
Voronoi diagram derived as the dual of a Delaunay triangulation.
Aleph::DynList< Aleph::dry_detail::map_result_t< R, Operation &, T > > maps(Operation &op) const
bool exists(Operation &op) const
Test for existence in the container of an element satisfying a criterion.
Aleph::DynList< T > filter(Operation &operation) const
Filter the elements of a container according to a matching criterion.
bool all(Operation &operation) const
Check if all the elements of the container satisfy a condition.
void for_each(Operation &operation) const
Traverse all the container and performs an operation on each element.
auto get_it()
Return a properly initialized iterator positioned at the first item on the container.
TEST_F(GeomAlgorithmsTest, BooleanIntersectionConcaveLShapes)
__gmp_expr< T, __gmp_binary_expr< __gmp_expr< T, U >, unsigned long int, __gmp_root_function > > root(const __gmp_expr< T, U > &expr, unsigned long int l)
Geom_Number scalar_triple_product(const Point3D &a, const Point3D &b, const Point3D &c)
Scalar triple product: a · (b × c).
bool completed() const noexcept
Return true if all underlying iterators are finished.
size_t size(Node *root) noexcept
See compute_cardinality_rec(Node * root).
InCircleResult in_circle(const Point &a, const Point &b, const Point &c, const Point &p)
Classify point p against circumcircle of triangle (a,b,c), exactly.
and
Check uniqueness with explicit hash + equality functors.
bool diff(const C1 &c1, const C2 &c2, Eq e=Eq())
Check if two containers differ.
mpq_class Geom_Number
Numeric type used by the geometry module.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
T sum(const Container &container, const T &init=T{})
Compute sum of all elements.
static Geom_Number polygon_area(const Polygon &poly)
bool traverse(Operation &operation) noexcept(traverse_is_noexcept< Operation, typename Aleph::concepts_detail::traverse_arg< Container, Operation >::type, Container & >())
Traverse the container via its iterator and performs a conditioned operation on each item.