41#include <gtest/gtest.h>
49 Point a(0, 0), b(1, 0), c(0, 1);
55 Point a(0, 0), b(0, 1), c(1, 0);
61 Point a(0, 0), b(1, 1), c(2, 2);
62 EXPECT_EQ(
orientation(a, b, c), Orientation::COLLINEAR);
67 Point a(3, 5), b(3, 5), c(7, 2);
68 EXPECT_EQ(
orientation(a, b, c), Orientation::COLLINEAR);
75 Point a(0, 0), b(4, 0), c(0, 4);
77 EXPECT_EQ(
in_circle(a, b, c, p), InCircleResult::INSIDE);
82 Point a(0, 0), b(0, 4), c(4, 0);
84 EXPECT_EQ(
in_circle(a, b, c, p), InCircleResult::INSIDE);
89 Point a(0, 0), b(4, 0), c(0, 4);
101 "case_incircle_on_circle", scene,
102 "in_circle() / point on circumcircle");
104 EXPECT_EQ(
in_circle(a, b, c, p), InCircleResult::ON_CIRCLE);
109 Point a(0, 0), b(4, 0), c(0, 4);
111 EXPECT_EQ(
in_circle(a, b, c, p), InCircleResult::OUTSIDE);
114TEST(InCircle, DegenerateTriangleCollinear)
116 Point a(0, 0), b(1, 1), c(2, 2);
118 EXPECT_EQ(
in_circle(a, b, c, p), InCircleResult::DEGENERATE);
121TEST(InCircleDeterminant, SignDependsOnTriangleOrientation)
123 Point a(0, 0), b(4, 0), c(0, 4);
129 EXPECT_GT(det_ccw, 0);
130 EXPECT_LT(det_cw, 0);
162TEST(SegmentsIntersect, ProperCross)
169TEST(SegmentsIntersect, TShaped)
177TEST(SegmentsIntersect, SharedEndpoint)
184TEST(SegmentsIntersect, CollinearOverlap)
195 "case_segments_collinear_overlap", scene,
196 "segments_intersect() / collinear overlap");
201TEST(SegmentsIntersect, CollinearDisjoint)
208TEST(SegmentsIntersect, Parallel)
215TEST(SegmentsIntersect, Disjoint)
222TEST(SegmentsIntersect, FourPointOverload)
232TEST(IntersectionPoint, SimpleXCross)
237 EXPECT_EQ(p.
get_x(), 1);
238 EXPECT_EQ(p.
get_y(), 1);
241TEST(IntersectionPoint, ExactRational)
250 EXPECT_EQ(p.
get_y(), 0);
253TEST(IntersectionPoint, ExactRationalNonTrivial)
270 "case_intersection_exact_rational_non_trivial", scene,
271 "segment_intersection_point() exact rational");
277TEST(IntersectionPoint, VerticalSegment)
282 EXPECT_EQ(p.
get_x(), 2);
283 EXPECT_EQ(p.
get_y(), 2);
286TEST(IntersectionPoint, HorizontalSegment)
291 EXPECT_EQ(p.
get_x(), 3);
292 EXPECT_EQ(p.
get_y(), 3);
295TEST(IntersectionPoint, ParallelThrows)
302TEST(IntersectionPoint, DisjointNonParallelThrows)
310TEST(IntersectionPoint, CollinearOverlapThrows)
318TEST(IntersectionPoint, CollinearTouchingAtEndpointReturnsUniquePoint)
329 "case_intersection_collinear_touch_endpoint", scene,
330 "segment_intersection_point() / endpoint touching");
332 EXPECT_EQ(p.
get_x(), 2);
333 EXPECT_EQ(p.
get_y(), 0);
336TEST(IntersectionPoint, DegeneratePointOnSegmentReturnsThatPoint)
341 EXPECT_EQ(p.
get_x(), 2);
342 EXPECT_EQ(p.
get_y(), 2);
345TEST(IntersectionPoint, DegenerateIdenticalPointsReturnThatPoint)
350 EXPECT_EQ(p.
get_x(), 3);
351 EXPECT_EQ(p.
get_y(), -1);
384TEST(IsParallel, HorizontalPair)
396 Point a(0, 0), b(3, 0), c(0, 4);
402 Point a(0, 0), b(1, 1), c(2, 2);
406TEST(TriangleArea, ExactRational)
409 Point a(0, 0), b(1, 0), c(0, 1);
T & append(const T &data)
Append a copy of data
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.
Represents a line segment between two points.
bool is_parallel_with(const Segment &s) const
Checks if this segment is parallel to another one.
bool vertical
If true, use vertical layout (default).
std::filesystem::path emit_case_svg(const std::string &case_id, const SvgScene &scene, const std::string ¬e="")
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).
bool on_segment(const Segment &s, const Point &p)
Return true if p lies on segment s (exact).
bool segments_intersect(const Segment &s1, const Segment &s2)
Return true if segments s1 and s2 intersect (including endpoints).
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.
Point segment_intersection_point(const Segment &s1, const Segment &s2)
Compute the exact intersection point of segments s1 and s2.
Geom_Number area_of_triangle(const Point &a, const Point &b, const Point &c)
Return the (unsigned) area of triangle (a, b, c) as an exact rational.
Orientation orientation(const Point &a, const Point &b, const Point &c)
Return the orientation of the triple (a, b, c).
mpq_class Geom_Number
Numeric type used by the geometry module.
2D point and geometric utilities.
::Array<::Point > highlighted_points
::Array<::Segment > segments