From 2c1b967db15c3b43b04eb034d14ed938faaa0c6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 1 Feb 2021 11:19:30 +0100 Subject: [PATCH] add tests for intersection of segments --- ...t_cdt_2_projection_traits_special_case.cpp | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/Triangulation_2/test/Triangulation_2/test_cdt_2_projection_traits_special_case.cpp b/Triangulation_2/test/Triangulation_2/test_cdt_2_projection_traits_special_case.cpp index 26693b95a28..bf163771380 100644 --- a/Triangulation_2/test/Triangulation_2/test_cdt_2_projection_traits_special_case.cpp +++ b/Triangulation_2/test/Triangulation_2/test_cdt_2_projection_traits_special_case.cpp @@ -60,6 +60,67 @@ bool test(std::string test_name) return cdt.is_valid(); } + +template +bool test_segment_intersections(std::string test_name) +{ + std::cerr << "Testing " << test_name << std::endl; + + CDT_2_traits traits(typename K::Vector_3(0,0,1)); + typename CDT_2_traits::Intersect_2 intersect = traits.intersect_2_object(); + + typedef typename CDT_2_traits::Segment_2 Segment_2; + typedef typename CDT_2_traits::Point_2 Point_2; + + // test point intersection + Segment_2 s1( Point_2(0,0,0), Point_2(1,1,0) ), + s2( Point_2(0,1,0), Point_2(1,0,0) ); + + CGAL::Object o = intersect(s1,s2); + assert( o.is() ); + +// test segment overlap + Point_2 pts[4] = { Point_2(0,0,0), Point_2(1,0,1), Point_2(2,0,2), Point_2(4,0,3) }; + + o = intersect( Segment_2(pts[0], pts[1]), Segment_2(pts[2], pts[3]) ); + assert( o.empty() ); + + // pure overlap + o = intersect( Segment_2(pts[0], pts[2]), Segment_2(pts[1], pts[3]) ); + assert( o.is() ); + o = intersect( Segment_2(pts[0], pts[2]), Segment_2(pts[3], pts[1]) ); + assert( o.is() ); + o = intersect( Segment_2(pts[2], pts[0]), Segment_2(pts[1], pts[3]) ); + assert( o.is() ); + o = intersect( Segment_2(pts[2], pts[0]), Segment_2(pts[3], pts[1]) ); + assert( o.is() ); + // segment fully included + o = intersect( Segment_2(pts[0], pts[3]), Segment_2(pts[1], pts[2]) ); + assert( o.is() ); + assert( CGAL::object_cast(o) == Segment_2(pts[1], pts[2]) ); + // segment fully included with shared vertex + o = intersect( Segment_2(pts[0], pts[1]), Segment_2(pts[0], pts[2]) ); + assert( o.is() ); + assert( CGAL::object_cast(o) == Segment_2(pts[0], pts[1]) ); + // segment sharing a vertex + o = intersect( Segment_2(pts[0], pts[1]), Segment_2(pts[1], pts[2]) ); + assert( o.is() ); + assert( CGAL::object_cast(o) == pts[1]); + + // degenerate segment + Segment_2 sd(Point_2(1,0,6), Point_2(1,0,7)); + o = intersect( Segment_2(pts[0], pts[2]), sd ); + assert( o.is() ); + o = intersect( Segment_2(pts[0], pts[1]), sd ); + assert( o.is() ); + o = intersect( Segment_2(pts[1], pts[0]), sd ); + assert( o.is() ); + o = intersect( Segment_2(pts[2], pts[3]), sd ); + assert( o.empty() ); + + return true; +} + int main() { std::cerr.precision(17); @@ -75,5 +136,12 @@ int main() test > ("CDT_2 in a 3D plane, with Epeck"); + ok = ok && test_segment_intersections > + ("CDT_2 traits intersection with Epick"); + ok = ok && test_segment_intersections > + ("CDT_2 traits intersection with Epeck"); + return ok ? 0 : 1; }