From a7aeee4600f79f93ca67a38d9598cc93430b8c14 Mon Sep 17 00:00:00 2001 From: Efi Fogel Date: Mon, 7 Feb 2022 18:46:16 +0200 Subject: [PATCH] Fixed comapre_y_at_x_right of geodesic traits and added a corresponding test --- .../Arr_geodesic_arc_on_sphere_traits_2.h | 62 +++++++++---------- .../geodesic_arcs_on_sphere/test39.txt | 10 +++ ...t_construction.geodesic_arcs_on_sphere.cmd | 2 +- 3 files changed, 42 insertions(+), 32 deletions(-) create mode 100644 Arrangement_on_surface_2/test/Arrangement_on_surface_2/data/test_construction/geodesic_arcs_on_sphere/test39.txt diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_geodesic_arc_on_sphere_traits_2.h b/Arrangement_on_surface_2/include/CGAL/Arr_geodesic_arc_on_sphere_traits_2.h index e19fb8337c0..6afcb33c6a4 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_geodesic_arc_on_sphere_traits_2.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_geodesic_arc_on_sphere_traits_2.h @@ -1283,8 +1283,8 @@ public: const X_monotone_curve_2& xc2, const Point_2& p) const { - CGAL_precondition(!xc1.is_degenerate()); - CGAL_precondition(!xc2.is_degenerate()); + CGAL_precondition(! xc1.is_degenerate()); + CGAL_precondition(! xc2.is_degenerate()); // CGAL_precondition(p == xc1.left()); // CGAL_precondition(p == xc2.left()); @@ -1296,10 +1296,35 @@ public: // Non of the arcs is verticel. Thus, non of the endpoints coincide with // a pole. - // Compare the y-coord. at the x-coord of the most left right-endpoint. const Point_2& r1 = xc1.right(); const Point_2& r2 = xc2.right(); - if (!r1.is_no_boundary()) { + + // if p and r1 are antipodal, compare the plane normals + const Kernel& kernel = m_traits; + auto opposite_3 = kernel.construct_opposite_direction_3_object(); + // VC 10 does not like the following: + // if (!kernel.equal_3_object()(opposite_3(p), r1)) return EQUAL; + Direction_3 tmp1 = opposite_3(p); // pacify msvc 10 + if (kernel.equal_3_object()(tmp1, Direction_3(r1))) { + Sign xsign = Traits::x_sign(p); + Sign ysign = Traits::y_sign(p); + Project project = (xsign == ZERO) ? + ((ysign == POSITIVE) ? Traits::project_minus_xz : Traits::project_xz) : + ((xsign == POSITIVE) ? Traits::project_yz : Traits::project_minus_yz); + + Direction_2 n1 = project(xc1.normal()); + Direction_2 n2 = project(xc2.normal()); + auto opposite_2 = kernel.construct_opposite_direction_2_object(); + if (! xc1.is_directed_right()) n1 = opposite_2(n1); + if (! xc2.is_directed_right()) n2 = opposite_2(n2); + if (kernel.equal_2_object()(n1, n2)) return EQUAL; + const Direction_2 d(1, 0); + return (kernel.counterclockwise_in_between_2_object()(n1, d, n2)) ? + SMALLER : LARGER; + } + + // Compare the y-coord. at the x-coord of the most left right-endpoint. + if (! r1.is_no_boundary()) { // use r2 and xc1: Oriented_side os = m_traits.oriented_side(xc1.normal(), r2); return (os == ON_ORIENTED_BOUNDARY) ? EQUAL : @@ -1307,7 +1332,7 @@ public: ((os == ON_NEGATIVE_SIDE) ? LARGER : SMALLER) : ((os == ON_NEGATIVE_SIDE) ? SMALLER : LARGER); } - if (!r2.is_no_boundary()) { + if (! r2.is_no_boundary()) { // use r1 and xc2: Oriented_side os = m_traits.oriented_side(xc2.normal(), r1); return (os == ON_ORIENTED_BOUNDARY) ? EQUAL : @@ -1333,32 +1358,7 @@ public: ((os == ON_NEGATIVE_SIDE) ? LARGER : SMALLER); } // res == equal - // if p and r1 are antipodal, compare the plane normals - const Kernel& kernel = m_traits; - typename Kernel::Construct_opposite_direction_3 opposite_3 = - kernel.construct_opposite_direction_3_object(); - // VC 10 does not like the following: - // if (!kernel.equal_3_object()(opposite_3(p), r1)) return EQUAL; - Direction_3 tmp1 = opposite_3(p); // pacify msvc 10 - if (!kernel.equal_3_object()(tmp1, Direction_3(r1))) - return EQUAL; - - Sign xsign = Traits::x_sign(p); - Sign ysign = Traits::y_sign(p); - Project project = (xsign == ZERO) ? - ((ysign == POSITIVE) ? Traits::project_minus_xz : Traits::project_xz) : - ((xsign == POSITIVE) ? Traits::project_yz : Traits::project_minus_yz); - - Direction_2 n1 = project(xc1.normal()); - Direction_2 n2 = project(xc2.normal()); - typename Kernel::Construct_opposite_direction_2 opposite_2 = - kernel.construct_opposite_direction_2_object(); - if (!xc1.is_directed_right()) n1 = opposite_2(n1); - if (!xc2.is_directed_right()) n2 = opposite_2(n2); - if (kernel.equal_2_object()(n1, n2)) return EQUAL; - const Direction_2 d(1, 0); - return (kernel.counterclockwise_in_between_2_object()(n1, d, n2)) ? - SMALLER : LARGER; + return EQUAL; } }; diff --git a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/data/test_construction/geodesic_arcs_on_sphere/test39.txt b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/data/test_construction/geodesic_arcs_on_sphere/test39.txt new file mode 100644 index 00000000000..ac38fac01c7 --- /dev/null +++ b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/data/test_construction/geodesic_arcs_on_sphere/test39.txt @@ -0,0 +1,10 @@ +3 +1 2 0 0 -2 0 0 0 2 2 +1 2 0 0 -2 0 0 0 -2 2 +1 2 0 0 -2 0 0 0 2 2 +0 +2 2 2 +-2 0 0 +2 0 0 +1 2 0 0 -2 0 0 0 2 2 2 +1 2 0 0 -2 0 0 0 -2 2 1 diff --git a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/test_construction.geodesic_arcs_on_sphere.cmd b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/test_construction.geodesic_arcs_on_sphere.cmd index 7c0148e58a4..547aa518864 100644 --- a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/test_construction.geodesic_arcs_on_sphere.cmd +++ b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/test_construction.geodesic_arcs_on_sphere.cmd @@ -36,4 +36,4 @@ data/test_construction/geodesic_arcs_on_sphere/test35.txt data/test_construction/geodesic_arcs_on_sphere/test36.txt data/test_construction/geodesic_arcs_on_sphere/test37.txt data/test_construction/geodesic_arcs_on_sphere/test38.txt - +data/test_construction/geodesic_arcs_on_sphere/test39.txt