diff --git a/AABB_tree/include/CGAL/AABB_traits_2.h b/AABB_tree/include/CGAL/AABB_traits_2.h index b0214386bfb..690225c4a1d 100644 --- a/AABB_tree/include/CGAL/AABB_traits_2.h +++ b/AABB_tree/include/CGAL/AABB_traits_2.h @@ -26,6 +26,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -120,6 +123,256 @@ public: Intersection_distance intersection_distance_object() const { return Intersection_distance(); } }; +template +class Compare_distance { + typedef typename GeomTraits::Point_2 Point; + typedef typename GeomTraits::FT FT; + + /// Bounding box type. + typedef typename CGAL::Bbox_2 Bounding_box; +public: + CGAL::Comparison_result operator()(const Point& p, const Bounding_box& bb, const Point& bound) const + { + return do_intersect_circle_iso_rectangle_2 + (GeomTraits().construct_circle_2_object() + (p, GeomTraits().compute_squared_distance_2_object()(p, bound)), bb) ? + CGAL::SMALLER : CGAL::LARGER; + } + + template + CGAL::Comparison_result operator()(const Point& p, const Solid& pr, const Point& bound) const + { + return GeomTraits().do_intersect_2_object() + (GeomTraits().construct_circle_2_object() + (p, GeomTraits().compute_squared_distance_2_object()(p, bound)), pr) ? + CGAL::SMALLER : CGAL::LARGER; + } + + template + CGAL::Comparison_result operator()(const Point& p, const Solid& pr, const FT& sq_distance) const + { + return GeomTraits().do_intersect_2_object() + (GeomTraits().construct_circle_2_object()(p, sq_distance), + pr) ? + CGAL::SMALLER : + CGAL::LARGER; + } + + typename GeomTraits::Boolean do_intersect_circle_iso_rectangle_2(const typename GeomTraits::Circle_2& circle, + const typename GeomTraits::Iso_rectangle_2& rec) const + { + typedef typename GeomTraits::FT FT; + typedef typename GeomTraits::Point_2 Point; + + Point center = circle.center(); + + // Check that the minimum distance to the box is smaller than the radius, otherwise there is + // no intersection. `distance` stays at 0 if the center is inside or on `rec`. + FT distance = FT(0); + if (center.x() < rec.xmin()) + { + FT d = rec.xmin() - center.x(); + distance += d * d; + } + else if (center.x() > rec.xmax()) + { + FT d = center.x() - rec.xmax(); + distance += d * d; + } + + if (center.y() < rec.ymin()) + { + FT d = rec.ymin() - center.y(); + distance += d * d; + } + else if (center.y() > rec.ymax()) + { + FT d = center.y() - rec.ymax(); + distance += d * d; + } + + if (distance <= circle.squared_radius()) + return true; + + return false; + } +}; + +template ::value, bool Has_static_filters = internal::Has_static_filters::value> +class Compare_distance_getter_2 {}; + +template +class Compare_distance_getter_2 { + // this class is in charge of checking what K provides (i.e., can we use filtered predicates, can we use statically filtered predicates, etc.) + // depending on that it defines +public: + typedef Compare_distance type; + static Compare_distance compare_distance_object() { + return Compare_distance(); + } +}; + +template +class Compare_distance_getter_2 { + // this class is in charge of checking what K provides (i.e., can we use filtered predicates, can we use statically filtered predicates, etc.) + // depending on that it defines + + typedef GeomTraits Kernel; + + typedef typename Kernel::Exact_kernel EKernel; + typedef typename Kernel::Approximate_kernel AKernel; + typedef typename Kernel::C2E C2E; + typedef typename Kernel::C2F C2F; + + typedef Compare_distance Exact_functor; + typedef Compare_distance Filtered_functor; + +public: + typedef Filtered_predicate Compare_distance_pred; + typedef Compare_distance_pred type; + + static Compare_distance_pred compare_distance_object() { + return Compare_distance_pred(Exact_functor(), Filtered_functor()); + } +}; + +template +class Compare_distance_getter_2 { + // this class is in charge of checking what K provides (i.e., can we use filtered predicates, can we use statically filtered predicates, etc.) + // depending on that it defines + class Statically_filtered_compare_distance { + public: + typedef typename GeomTraits::Point_2 Point; + typedef typename GeomTraits::FT FT; + typedef typename GeomTraits::Circle_2 Circle_2; + + /// Bounding box type. + typedef CGAL::Bbox_2 Bounding_box; + + template + CGAL::Comparison_result operator()(const Point& p, const Solid& pr, const Point& bound) const { + return Compare_distance_getter_2::compare_distance_object()(p, pr, bound); + } + + template + CGAL::Comparison_result operator()(const Point& p, const Solid& pr, const FT& sq_distance) const { + return Compare_distance_getter_2::compare_distance_object()(p, pr, sq_distance); + } + + Comparison_result operator()(const Point& p, const Bounding_box& b, const Point& bound) const { + Circle_2 s = GeomTraits().construct_circle_2_object()(p, GeomTraits().compute_squared_distance_2_object()(p, bound)); + + CGAL_BRANCH_PROFILER_3(std::string("semi-static failures/attempts/calls to : ") + + std::string(CGAL_PRETTY_FUNCTION), tmp); + + internal::Static_filters_predicates::Get_approx get_approx; // Identity functor for all points + const Point& c = s.center(); + + double scx, scy, ssr; + double bxmin = b.xmin(), bymin = b.ymin(), + bxmax = b.xmax(), bymax = b.ymax(); + + if (internal::fit_in_double(get_approx(c).x(), scx) && + internal::fit_in_double(get_approx(c).y(), scy) && + internal::fit_in_double(s.squared_radius(), ssr)) + { + CGAL_BRANCH_PROFILER_BRANCH_1(tmp); + + if ((ssr < 1.11261183279326254436e-293) || (ssr > 2.80889552322236673473e+306)) { + CGAL_BRANCH_PROFILER_BRANCH_2(tmp); + return Compare_distance_getter_2::compare_distance_object()(p, b, bound); + } + double distance = 0; + double max1 = 0; + double double_tmp_result = 0; + double eps = 0; + if (scx < bxmin) + { + double bxmin_scx = bxmin - scx; + max1 = bxmin_scx; + + distance = square(bxmin_scx); + double_tmp_result = (distance - ssr); + + if ((max1 < 3.33558365626356687717e-147) || (max1 > 1.67597599124282407923e+153)) + return CGAL::SMALLER; + + eps = 1.99986535548615598560e-15 * (std::max)(ssr, square(max1)); + + if (double_tmp_result > eps) + return CGAL::LARGER; + } + else if (scx > bxmax) + { + double scx_bxmax = scx - bxmax; + max1 = scx_bxmax; + + distance = square(scx_bxmax); + double_tmp_result = (distance - ssr); + + if ((max1 < 3.33558365626356687717e-147) || (max1 > 1.67597599124282407923e+153)) + return CGAL::SMALLER; + + eps = 1.99986535548615598560e-15 * (std::max)(ssr, square(max1)); + + if (double_tmp_result > eps) + return CGAL::LARGER; + } + + if (scy < bymin) + { + double bymin_scy = bymin - scy; + if (max1 < bymin_scy) { + max1 = bymin_scy; + } + + distance += square(bymin_scy); + double_tmp_result = (distance - ssr); + + if ((max1 < 3.33558365626356687717e-147) || ((max1 > 1.67597599124282407923e+153))) + return CGAL::SMALLER; + + eps = 1.99986535548615598560e-15 * (std::max)(ssr, square(max1)); + + if (double_tmp_result > eps) { + return CGAL::LARGER; + } + } + else if (scy > bymax) + { + double scy_bymax = scy - bymax; + if (max1 < scy_bymax) { + max1 = scy_bymax; + } + distance += square(scy_bymax); + double_tmp_result = (distance - ssr); + + if (((max1 < 3.33558365626356687717e-147)) || ((max1 > 1.67597599124282407923e+153))) + return CGAL::SMALLER; + + eps = 1.99986535548615598560e-15 * (std::max)(ssr, square(max1)); + + if (double_tmp_result > eps) + return CGAL::LARGER; + } + + // double_tmp_result and eps were growing all the time + // no need to test for > eps as done earlier in at least one case + + return CGAL::SMALLER; + } + return Compare_distance_getter_2::compare_distance_object()(p, b, bound); + } + }; +public: + typedef Statically_filtered_compare_distance type; + + static Statically_filtered_compare_distance compare_distance_object() { + return Statically_filtered_compare_distance(); + } +}; + } } //end of namespace internal::AABB_tree /// \addtogroup PkgAABBTreeRef @@ -130,7 +383,7 @@ template< typename AABBTraits> class AABB_tree; template -class AABB_traits_base_2 +class AABB_traits_2 #ifndef DOXYGEN_RUNNING : public internal::AABB_tree::AABB_traits_base, public internal::AABB_tree::AABB_traits_intersection_base_2, @@ -141,7 +394,7 @@ class AABB_traits_base_2 typedef GeomTraits Geom_traits; public: - typedef AABB_traits_base_2 AT; + typedef AABB_traits_2 AT; // AABBTraits concept types typedef typename GeomTraits::FT FT; typedef AABBPrimitive Primitive; @@ -195,9 +448,9 @@ public: BboxMap bbm; /// Default constructor. - AABB_traits_base_2() { } + AABB_traits_2() { } - AABB_traits_base_2(BboxMap bbm) + AABB_traits_2(BboxMap bbm) : bbm(bbm) {} @@ -220,10 +473,10 @@ public: */ class Split_primitives { - typedef AABB_traits_base_2 Traits; + typedef AABB_traits_2 Traits; const Traits& m_traits; public: - Split_primitives(const AABB_traits_base_2& traits) + Split_primitives(const AABB_traits_2& traits) : m_traits(traits) {} typedef void result_type; @@ -257,9 +510,9 @@ public: * @return the bounding box of the primitives of the iterator range */ class Compute_bbox { - const AABB_traits_base_2& m_traits; + const AABB_traits_2& m_traits; public: - Compute_bbox(const AABB_traits_base_2& traits) + Compute_bbox(const AABB_traits_2& traits) :m_traits (traits) {} template @@ -282,9 +535,9 @@ public: /// In the case the query is a `CGAL::AABB_tree`, the `do_intersect()` /// function of this tree is used. class Do_intersect { - const AABB_traits_base_2& m_traits; + const AABB_traits_2& m_traits; public: - Do_intersect(const AABB_traits_base_2& traits) + Do_intersect(const AABB_traits_2& traits) :m_traits(traits) {} template @@ -317,9 +570,9 @@ public: class Intersection { - const AABB_traits_base_2& m_traits; + const AABB_traits_2& m_traits; public: - Intersection(const AABB_traits_base_2& traits) + Intersection(const AABB_traits_2& traits) :m_traits(traits) {} template std::optional< typename Intersection_and_primitive_id::Type > @@ -338,9 +591,9 @@ public: class Closest_point { typedef typename AT::Point Point; typedef typename AT::Primitive Primitive; - const AABB_traits_base_2& m_traits; + const AABB_traits_2& m_traits; public: - Closest_point(const AABB_traits_base_2& traits) + Closest_point(const AABB_traits_2& traits) : m_traits(traits) {} @@ -355,85 +608,10 @@ public: } }; - // This should go down to the GeomTraits, i.e. the kernel - // and the internal implementation should change its name from - // do_intersect to something like does_contain (this is what we compute, - // this is not the same do_intersect as the spherical kernel) - class Compare_distance { - typedef typename AT::Point Point; - typedef typename AT::FT FT; - typedef typename AT::Primitive Primitive; - public: - CGAL::Comparison_result operator()(const Point& p, const Bounding_box& bb, const Point& bound) const - { - return do_intersect_circle_iso_rectangle_2 - (GeomTraits().construct_circle_2_object() - (p, GeomTraits().compute_squared_distance_2_object()(p, bound)), bb) ? - CGAL::SMALLER : CGAL::LARGER; - } + typedef typename internal::AABB_tree::Compare_distance_getter_2::type Compare_distance; - // The following functions seem unused...? - template - CGAL::Comparison_result operator()(const Point& p, const Solid& pr, const Point& bound) const - { - return GeomTraits().do_intersect_2_object() - (GeomTraits().construct_circle_2_object() - (p, GeomTraits().compute_squared_distance_2_object()(p, bound)), pr)? - CGAL::SMALLER : CGAL::LARGER; - } - - template - CGAL::Comparison_result operator()(const Point& p, const Solid& pr, const FT& sq_distance) const - { - return GeomTraits().do_intersect_2_object() - (GeomTraits().construct_circle_2_object()(p, sq_distance), - pr) ? - CGAL::SMALLER : - CGAL::LARGER; - } - - typename GeomTraits::Boolean do_intersect_circle_iso_rectangle_2(const typename GeomTraits::Circle_2& circle, - const typename GeomTraits::Iso_rectangle_2& rec) const - { - typedef typename GeomTraits::FT FT; - typedef typename GeomTraits::Point_2 Point; - - Point center = circle.center(); - - // Check that the minimum distance to the box is smaller than the radius, otherwise there is - // no intersection. `distance` stays at 0 if the center is inside or on `rec`. - FT distance = FT(0); - if (center.x() < rec.xmin()) - { - FT d = rec.xmin() - center.x(); - distance += d * d; - } - else if (center.x() > rec.xmax()) - { - FT d = center.x() - rec.xmax(); - distance += d * d; - } - - if (center.y() < rec.ymin()) - { - FT d = rec.ymin() - center.y(); - distance += d * d; - } - else if (center.y() > rec.ymax()) - { - FT d = center.y() - rec.ymax(); - distance += d * d; - } - - if (distance <= circle.squared_radius()) - return true; - - return false; - } - }; - - Closest_point closest_point_object() const {return Closest_point(*this);} - Compare_distance compare_distance_object() const {return Compare_distance();} + Closest_point closest_point_object() const { return Closest_point(*this); } + Compare_distance compare_distance_object() const { return internal::AABB_tree::Compare_distance_getter_2::compare_distance_object(); } typedef enum { CGAL_AXIS_X = 0, CGAL_AXIS_Y = 1} Axis; @@ -458,26 +636,26 @@ private: } /// Comparison functions - static bool less_x(const Primitive& pr1, const Primitive& pr2,const AABB_traits_base_2& traits) + static bool less_x(const Primitive& pr1, const Primitive& pr2,const AABB_traits_2& traits) { return GeomTraits().less_x_2_object()( internal::Primitive_helper::get_reference_point(pr1,traits), internal::Primitive_helper::get_reference_point(pr2,traits) ); } - static bool less_y(const Primitive& pr1, const Primitive& pr2,const AABB_traits_base_2& traits) + static bool less_y(const Primitive& pr1, const Primitive& pr2,const AABB_traits_2& traits) { return GeomTraits().less_y_2_object()( internal::Primitive_helper::get_reference_point(pr1,traits), internal::Primitive_helper::get_reference_point(pr2,traits) ); } -}; // end class AABB_traits_base_2 +}; // end class AABB_traits_2 //------------------------------------------------------- // Private methods //------------------------------------------------------- template - typename AABB_traits_base_2::Axis - AABB_traits_base_2::longest_axis(const Bounding_box& bbox) + typename AABB_traits_2::Axis + AABB_traits_2::longest_axis(const Bounding_box& bbox) { const double dx = bbox.xmax() - bbox.xmin(); const double dy = bbox.ymax() - bbox.ymin(); @@ -491,67 +669,8 @@ private: return CGAL_AXIS_Y; } } -} -//------------------------------------------------------- -// Filtered traits -//------------------------------------------------------- - -#include - -namespace CGAL { - -/// This traits class handles any type of 2D geometric -/// primitives provided that the proper intersection tests and -/// constructions are implemented. It handles points, rays, lines and -/// segments as query types for intersection detection and -/// computations, and it handles points as query type for distance -/// queries. -/// -/// \cgalModels{AABBTraits,AABBRayIntersectionTraits} -/// -/// \tparam GeomTraits must be a model of the concept \ref AABBGeomTraits_2, -/// and provide the geometric types as well as the intersection tests and computations. -/// \tparam Primitive provide the type of primitives stored in the AABB_tree. -/// It is a model of the concept `AABBPrimitive` or `AABBPrimitiveWithSharedData`. -/// -/// \tparam BboxMap must be a model of `ReadablePropertyMap` that has as key type a primitive id, -/// and as value type a `Bounding_box`. -/// If the type is `Default` the `Datum` must have the -/// member function `bbox()` that returns the bounding box of the primitive. -/// -/// If the argument `GeomTraits` is a model of the concept \ref -/// AABBRayIntersectionGeomTraits_2, this class is also a model of \ref -/// AABBRayIntersectionTraits. -/// -/// \sa `AABBTraits` -/// \sa `AABB_tree` -/// \sa `AABBPrimitive` -/// \sa `AABBPrimitiveWithSharedData` - template::value> - class AABB_traits_2; - - template - class AABB_traits_2 : public AABB_traits_base_2 { - using Base = AABB_traits_base_2; - - public: - AABB_traits_2() : Base() {} - AABB_traits_2(BboxMap bbm) : Base(bbm) {} - }; - - template - class AABB_traits_2 : public AABB_filtered_traits_2 { - using Base = AABB_filtered_traits_2; - - public: - AABB_traits_2() : Base() {} - AABB_traits_2(BboxMap bbm) : Base(bbm) {} - }; - -/// @} - -} // end namespace CGAL +} // end namespace CGAL #include diff --git a/AABB_tree/include/CGAL/AABB_traits_3.h b/AABB_tree/include/CGAL/AABB_traits_3.h index 8835e81e062..62a14cf780f 100644 --- a/AABB_tree/include/CGAL/AABB_traits_3.h +++ b/AABB_tree/include/CGAL/AABB_traits_3.h @@ -251,10 +251,10 @@ public: }; template ::value, bool Has_static_filters = internal::Has_static_filters::value> -class Compare_distance_getter {}; +class Compare_distance_getter_3 {}; template -class Compare_distance_getter { +class Compare_distance_getter_3 { // this class is in charge of checking what K provides (i.e., can we use filtered predicates, can we use statically filtered predicates, etc.) // depending on that it defines public: @@ -265,7 +265,7 @@ public: }; template -class Compare_distance_getter { +class Compare_distance_getter_3 { // this class is in charge of checking what K provides (i.e., can we use filtered predicates, can we use statically filtered predicates, etc.) // depending on that it defines @@ -290,27 +290,26 @@ public: }; template -class Compare_distance_getter { +class Compare_distance_getter_3 { // this class is in charge of checking what K provides (i.e., can we use filtered predicates, can we use statically filtered predicates, etc.) // depending on that it defines class Statically_filtered_compare_distance { - + public: typedef typename GeomTraits::Point_3 Point; typedef typename GeomTraits::FT FT; typedef typename GeomTraits::Boolean Boolean; /// Bounding box type. - typedef typename CGAL::Bbox_3 Bounding_box; - public: + typedef CGAL::Bbox_3 Bounding_box; template CGAL::Comparison_result operator()(const Point& p, const Solid& pr, const Point& bound) const { - return Compare_distance_getter::compare_distance_object()(p, pr, bound); + return Compare_distance_getter_3::compare_distance_object()(p, pr, bound); } template CGAL::Comparison_result operator()(const Point& p, const Solid& pr, const FT& sq_distance) const { - return Compare_distance_getter::compare_distance_object()(p, pr, sq_distance); + return Compare_distance_getter_3::compare_distance_object()(p, pr, sq_distance); } Comparison_result operator()(const Point& p, const Bounding_box& b, const Point& bound) const { @@ -334,7 +333,7 @@ class Compare_distance_getter { if ((ssr < 1.11261183279326254436e-293) || (ssr > 2.80889552322236673473e+306)) { CGAL_BRANCH_PROFILER_BRANCH_2(tmp); - return Compare_distance_getter::compare_distance_object()(p, b, bound); + return Compare_distance_getter_3::compare_distance_object()(p, b, bound); } double distance = 0; double max1 = 0; @@ -453,7 +452,7 @@ class Compare_distance_getter { CGAL_BRANCH_PROFILER_BRANCH_2(tmp); } - return Compare_distance_getter::compare_distance_object()(p, b, bound); + return Compare_distance_getter_3::compare_distance_object()(p, b, bound); } }; public: @@ -730,10 +729,10 @@ public: } }; - typedef typename internal::AABB_tree::Compare_distance_getter::type Compare_distance; + typedef typename internal::AABB_tree::Compare_distance_getter_3::type Compare_distance; Closest_point closest_point_object() const {return Closest_point(*this);} - Compare_distance compare_distance_object() const {return internal::AABB_tree::Compare_distance_getter::compare_distance_object();} + Compare_distance compare_distance_object() const {return internal::AABB_tree::Compare_distance_getter_3::compare_distance_object();} typedef enum { CGAL_AXIS_X = 0, CGAL_AXIS_Y = 1, @@ -775,7 +774,7 @@ private: internal::Primitive_helper::get_reference_point(pr2,traits) ); } -}; // end class AABB_traits_base_3 +}; // end class AABB_traits_3 //------------------------------------------------------- @@ -813,8 +812,6 @@ private: } } -/// @} - } // end namespace CGAL #include diff --git a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_filtered_traits_2.h b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_filtered_traits_2.h deleted file mode 100644 index 21c2b903dbd..00000000000 --- a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_filtered_traits_2.h +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright (c) 2024 INRIA Sophia-Antipolis (France). -// All rights reserved. -// -// This file is part of CGAL (www.cgal.org). -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial -// -// -// Author(s) : Stéphane Tayeb, Pierre Alliez, Camille Wormser -// - -#ifndef CGAL_AABB_FILTERED_TRAITS_2_H -#define CGAL_AABB_FILTERED_TRAITS_2_H - -#include - -#include -#include - -namespace CGAL { - -template -class AABB_filtered_traits_base_2 : public AABB_traits_base_2 { - using Base = AABB_traits_base_2; -public: - typedef GeomTraits Kernel; - - typedef typename Kernel::Exact_kernel EKernel; - typedef typename Kernel::Approximate_kernel AKernel; - typedef typename Kernel::C2E C2E; - typedef typename Kernel::C2F C2F; - - // Exact traits is based on the exact kernel. - typedef AABB_traits_base_2 Exact_traits; - // Filtering traits is based on the filtering kernel. - typedef AABB_traits_base_2 Filtering_traits; - - typedef Filtered_predicate< - typename Exact_traits::Compare_distance, - typename Filtering_traits::Compare_distance, - C2E, C2F> Compare_distance; - - AABB_filtered_traits_base_2() : Base() {} - AABB_filtered_traits_base_2(BboxMap bbm) : Base(bbm) {} - - Compare_distance compare_distance_object() const - { - typename Exact_traits::Compare_distance pe = Exact_traits().compare_distance_object(); - typename Filtering_traits::Compare_distance pf = Filtering_traits().compare_distance_object(); - - return Compare_distance(pe, pf); - } -}; -} - -#include - -namespace CGAL { - -template::value> -class AABB_filtered_traits_2; - -template -class AABB_filtered_traits_2 : public AABB_filtered_traits_base_2 { - using Base = AABB_filtered_traits_base_2; - -public: - AABB_filtered_traits_2() : Base() {} - AABB_filtered_traits_2(BboxMap bbm) : Base(bbm) {} -}; - -template -class AABB_filtered_traits_2 : public AABB_statically_filtered_traits_2 { - using Base = AABB_statically_filtered_traits_2; - -public: - AABB_filtered_traits_2() : Base() {} - AABB_filtered_traits_2(BboxMap bbm) : Base(bbm) {} -}; - -} //namespace CGAL - -#endif diff --git a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_statically_filtered_traits_2.h b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_statically_filtered_traits_2.h deleted file mode 100644 index 645c8610ad5..00000000000 --- a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_statically_filtered_traits_2.h +++ /dev/null @@ -1,150 +0,0 @@ -// Copyright (c) 2024 INRIA Sophia-Antipolis (France). -// All rights reserved. -// -// This file is part of CGAL (www.cgal.org). -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial -// -// -// Author(s) : Stéphane Tayeb, Pierre Alliez, Camille Wormser -// - -#ifndef CGAL_AABB_STATICALLY_FILTERED_TRAITS_2_H -#define CGAL_AABB_STATICALLY_FILTERED_TRAITS_2_H - -#include - -#include -#include -#include - -namespace CGAL { - -template -class AABB_statically_filtered_traits_2 : public AABB_filtered_traits_base_2 { - using Base = AABB_filtered_traits_base_2; - -public: - class Compare_distance : public Base::Compare_distance { - public: - using Point = typename GeomTraits::Point_2; - using Bounding_box = Bbox_2; - using Circle_2 = typename GeomTraits::Circle_2; - - Comparison_result operator()(const Point& p, const Bounding_box& b, const Point& bound) const { - Circle_2 s = GeomTraits().construct_circle_2_object()(p, GeomTraits().compute_squared_distance_2_object()(p, bound)); - - CGAL_BRANCH_PROFILER_3(std::string("semi-static failures/attempts/calls to : ") + - std::string(CGAL_PRETTY_FUNCTION), tmp); - - internal::Static_filters_predicates::Get_approx get_approx; // Identity functor for all points - const Point& c = s.center(); - - double scx, scy, ssr; - double bxmin = b.xmin(), bymin = b.ymin(), - bxmax = b.xmax(), bymax = b.ymax(); - - if (internal::fit_in_double(get_approx(c).x(), scx) && - internal::fit_in_double(get_approx(c).y(), scy) && - internal::fit_in_double(s.squared_radius(), ssr)) - { - CGAL_BRANCH_PROFILER_BRANCH_1(tmp); - - if ((ssr < 1.11261183279326254436e-293) || (ssr > 2.80889552322236673473e+306)) { - CGAL_BRANCH_PROFILER_BRANCH_2(tmp); - return Base::Compare_distance::operator()(p, b, bound); - } - double distance = 0; - double max1 = 0; - double double_tmp_result = 0; - double eps = 0; - if (scx < bxmin) - { - double bxmin_scx = bxmin - scx; - max1 = bxmin_scx; - - distance = square(bxmin_scx); - double_tmp_result = (distance - ssr); - - if ((max1 < 3.33558365626356687717e-147) || (max1 > 1.67597599124282407923e+153)) - return CGAL::SMALLER; - - eps = 1.99986535548615598560e-15 * (std::max)(ssr, square(max1)); - - if (double_tmp_result > eps) - return CGAL::LARGER; - } - else if (scx > bxmax) - { - double scx_bxmax = scx - bxmax; - max1 = scx_bxmax; - - distance = square(scx_bxmax); - double_tmp_result = (distance - ssr); - - if ((max1 < 3.33558365626356687717e-147) || (max1 > 1.67597599124282407923e+153)) - return CGAL::SMALLER; - - eps = 1.99986535548615598560e-15 * (std::max)(ssr, square(max1)); - - if (double_tmp_result > eps) - return CGAL::LARGER; - } - - if (scy < bymin) - { - double bymin_scy = bymin - scy; - if (max1 < bymin_scy) { - max1 = bymin_scy; - } - - distance += square(bymin_scy); - double_tmp_result = (distance - ssr); - - if ((max1 < 3.33558365626356687717e-147) || ((max1 > 1.67597599124282407923e+153))) - return CGAL::SMALLER; - - eps = 1.99986535548615598560e-15 * (std::max)(ssr, square(max1)); - - if (double_tmp_result > eps) { - return CGAL::LARGER; - } - } - else if (scy > bymax) - { - double scy_bymax = scy - bymax; - if (max1 < scy_bymax) { - max1 = scy_bymax; - } - distance += square(scy_bymax); - double_tmp_result = (distance - ssr); - - if (((max1 < 3.33558365626356687717e-147)) || ((max1 > 1.67597599124282407923e+153))) - return CGAL::SMALLER; - - eps = 1.99986535548615598560e-15 * (std::max)(ssr, square(max1)); - - if (double_tmp_result > eps) - return CGAL::LARGER; - } - - // double_tmp_result and eps were growing all the time - // no need to test for > eps as done earlier in at least one case - - return CGAL::SMALLER; - } - return Base::Compare_distance::operator()(p, b, bound); - } - }; - - AABB_statically_filtered_traits_2() : Base() {} - AABB_statically_filtered_traits_2(BboxMap bbm) : Base(bbm) {} - - Compare_distance compare_distance_object() const { return Compare_distance(); } -}; - -} //namespace CGAL - -#endif