From 53b4878a94a96d09ccdd79d26f2d8a826c63249d Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Tue, 31 May 2022 18:09:00 +0200 Subject: [PATCH] Use exact FT instead of exact Kernel --- .../include/CGAL/Exact_kernel_selector_fwd.h | 25 ------- .../Intersections_2/Segment_2_Segment_2.h | 40 ++++++----- .../include/CGAL/Exact_kernel_selector.h | 4 +- .../CGAL/Constrained_triangulation_2.h | 68 +++++++++---------- 4 files changed, 52 insertions(+), 85 deletions(-) delete mode 100644 Installation/include/CGAL/Exact_kernel_selector_fwd.h diff --git a/Installation/include/CGAL/Exact_kernel_selector_fwd.h b/Installation/include/CGAL/Exact_kernel_selector_fwd.h deleted file mode 100644 index 8f0213606a7..00000000000 --- a/Installation/include/CGAL/Exact_kernel_selector_fwd.h +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) 2017 -// Utrecht University (The Netherlands), -// ETH Zurich (Switzerland), -// INRIA Sophia-Antipolis (France), -// Max-Planck-Institute Saarbruecken (Germany), -// and Tel-Aviv University (Israel). All rights reserved. -// -// This file is part of CGAL (www.cgal.org) -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial -// -// Author(s) : Sylvain Pion, -// Mael Rouxel-Labbé - -#ifndef CGAL_EXACT_KERNEL_SELECTOR_FWD_H -#define CGAL_EXACT_KERNEL_SELECTOR_FWD_H - -namespace CGAL { -template -struct Exact_kernel_selector; -} - -#endif // CGAL_EXACT_KERNEL_SELECTOR_FWD_H diff --git a/Intersections_2/include/CGAL/Intersections_2/Segment_2_Segment_2.h b/Intersections_2/include/CGAL/Intersections_2/Segment_2_Segment_2.h index e7725ea561c..59a07e1cea8 100644 --- a/Intersections_2/include/CGAL/Intersections_2/Segment_2_Segment_2.h +++ b/Intersections_2/include/CGAL/Intersections_2/Segment_2_Segment_2.h @@ -27,8 +27,8 @@ #include #include #include -#include -#include +#include +#include namespace CGAL { @@ -459,30 +459,30 @@ intersection(const typename K::Segment_2 &seg1, } template -boost::optional +typename K::Point_2 exact_intersection_point(const typename K::Point_2& pa, const typename K::Point_2& pb, const typename K::Point_2& pc, const typename K::Point_2& pd, const K&) { - using EK = typename Exact_kernel_selector::Exact_kernel; - using EK_Line_2 = typename EK::Line_2; - using EK_Point_2 = typename EK::Point_2; - Cartesian_converter to_exact; - Cartesian_converter from_exact; - typename EK::Intersect_2 exact_intersect; - const auto exact_intersection = - exact_intersect(EK_Line_2{to_exact(pa), to_exact(pb)}, - EK_Line_2{to_exact(pc), to_exact(pd)}); - if(!exact_intersection.has_value()) return {}; - using boost::get; - if (const auto *p = get(&*exact_intersection)) { - return { from_exact(*p) }; - } else { - return {}; - } + using FT = typename K::FT; + using Exact_FT = typename CGAL::internal::Exact_field_selector::Type; + NT_converter to_exact; + NT_converter from_exact; + Exact_FT s1_dx = to_exact(pa.x()) - to_exact(pb.x()); + Exact_FT s1_dy = to_exact(pa.y()) - to_exact(pb.y()); + Exact_FT s2_dx = to_exact(pd.x()) - to_exact(pc.x()); + Exact_FT s2_dy = to_exact(pd.y()) - to_exact(pc.y()); + Exact_FT lx = to_exact(pd.x()) - to_exact(pb.x()); + Exact_FT ly = to_exact(pd.y()) - to_exact(pb.y()); + + Exact_FT alpha = (lx*s2_dy-ly*s2_dx)/(s1_dx*s2_dy-s1_dy*s2_dx); + Exact_FT one_minus_alpha = Exact_FT(1) - alpha; + Exact_FT x = alpha * to_exact(pa.x()) + one_minus_alpha * to_exact(pb.x()); + Exact_FT y = alpha * to_exact(pa.y()) + one_minus_alpha * to_exact(pb.y()); + return { from_exact(x), from_exact(y) }; } } // namespace internal @@ -493,6 +493,4 @@ CGAL_DO_INTERSECT_FUNCTION_SELF(Segment_2, 2) } //namespace CGAL -#include - #endif diff --git a/Kernel_23/include/CGAL/Exact_kernel_selector.h b/Kernel_23/include/CGAL/Exact_kernel_selector.h index 23ed23d3afb..0bca055a640 100644 --- a/Kernel_23/include/CGAL/Exact_kernel_selector.h +++ b/Kernel_23/include/CGAL/Exact_kernel_selector.h @@ -29,11 +29,9 @@ #include #include -#include - namespace CGAL { -template +template struct Exact_kernel_selector { typedef typename internal::Exact_field_selector::Type Exact_nt; diff --git a/Triangulation_2/include/CGAL/Constrained_triangulation_2.h b/Triangulation_2/include/CGAL/Constrained_triangulation_2.h index 9f8f515eccd..04ef4a7fbe3 100644 --- a/Triangulation_2/include/CGAL/Constrained_triangulation_2.h +++ b/Triangulation_2/include/CGAL/Constrained_triangulation_2.h @@ -1137,9 +1137,8 @@ intersect(Face_handle f, int i, intersection_not_in_the_two_triangle(pi)) { // now compute the exact intersection point - const bool result = - almost_exact_intersection(geom_traits(), pa, pb, pc, pd, pi, itag); - if (!result || intersection_not_in_the_two_triangle(pi)) { + pi = almost_exact_intersection(geom_traits(), pa, pb, pc, pd, itag); + if (intersection_not_in_the_two_triangle(pi)) { // If the most-exact intersection point is not in the union of the two // triangles, then snap to `pc` or `pd`... if(compare_distance(pi, pc, pd) == SMALLER) { @@ -1865,57 +1864,54 @@ constexpr bool can_construct_almost_exact_intersection(const Gt&, Tag) { } template -bool almost_exact_intersection(const Gt&, - const typename Gt::Point_2&, - const typename Gt::Point_2&, - const typename Gt::Point_2&, - const typename Gt::Point_2&, - typename Gt::Point_2&, - Tag) +typename Gt::Point_2 +almost_exact_intersection(const Gt&, + const typename Gt::Point_2&, + const typename Gt::Point_2&, + const typename Gt::Point_2&, + const typename Gt::Point_2&, + Tag) { CGAL_error_msg("this function should be call only with Exact_predicates_tag"); } template -bool almost_exact_intersection(const Gt& gt, - const typename Gt::Point_2& pa, - const typename Gt::Point_2& pb, - const typename Gt::Point_2& pc, - const typename Gt::Point_2& pd, - typename Gt::Point_2& pi, - Exact_predicates_tag) +typename Gt::Point_2 +almost_exact_intersection(const Gt& gt, + const typename Gt::Point_2& pa, + const typename Gt::Point_2& pb, + const typename Gt::Point_2& pc, + const typename Gt::Point_2& pd, + Exact_predicates_tag) { Boolean_tag::value> tag; - return almost_exact_intersection(gt, pa, pb, pc, pd, pi, tag); + return almost_exact_intersection(gt, pa, pb, pc, pd, tag); } template -bool almost_exact_intersection(const Gt&, - const typename Gt::Point_2&, - const typename Gt::Point_2&, - const typename Gt::Point_2&, - const typename Gt::Point_2&, - typename Gt::Point_2&, - Tag_false) +typename Gt::Point_2 +almost_exact_intersection(const Gt&, + const typename Gt::Point_2&, + const typename Gt::Point_2&, + const typename Gt::Point_2&, + const typename Gt::Point_2&, + Tag_false) { CGAL_error_msg("this function should be call only with Exact_predicates_tag" " and with an appropriate traits class"); } template -bool almost_exact_intersection(const Gt& gt, - const typename Gt::Point_2& pa, - const typename Gt::Point_2& pb, - const typename Gt::Point_2& pc, - const typename Gt::Point_2& pd, - typename Gt::Point_2& pi, - Tag_true /* gt has Construct_exact_intersection_point_2 */) +typename Gt::Point_2 +almost_exact_intersection(const Gt& gt, + const typename Gt::Point_2& pa, + const typename Gt::Point_2& pb, + const typename Gt::Point_2& pc, + const typename Gt::Point_2& pd, + Tag_true /* gt has Construct_exact_intersection_point_2 */) { auto exact_intersect = gt.construct_exact_intersection_point_2_object(); - const auto exact_intersection = exact_intersect(pa, pb, pc, pd); - if(!exact_intersection.has_value()) return false; - pi = *exact_intersection; - return true; + return exact_intersect(pa, pb, pc, pd); } } //namespace CGAL