From be8f3b8e70025c8f743a2fbbedb0410268bc184a Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Fri, 10 Jan 2025 11:18:38 +0000 Subject: [PATCH] Add BBox_d --- Filtered_kernel/include/CGAL/Lazy.h | 8 +- .../internal/Frechet_distance_traits.h | 6 +- .../internal/Neighbor_search.h | 6 +- .../CGAL/Frechet_distance/internal/curve.h | 8 +- Kernel_d/doc/Kernel_d/CGAL/Bbox_d.h | 125 ++++++++++++++++++ Kernel_d/doc/Kernel_d/PackageDescription.txt | 1 + .../Bbox.h => Kernel_d/include/CGAL/Bbox_d.h | 44 +++--- .../NewKernel_d/function_objects_cartesian.h | 4 +- 8 files changed, 164 insertions(+), 38 deletions(-) create mode 100644 Kernel_d/doc/Kernel_d/CGAL/Bbox_d.h rename Kernel_23/include/CGAL/Bbox.h => Kernel_d/include/CGAL/Bbox_d.h (83%) diff --git a/Filtered_kernel/include/CGAL/Lazy.h b/Filtered_kernel/include/CGAL/Lazy.h index 3ccb1ff45963..d672b678bd31 100644 --- a/Filtered_kernel/include/CGAL/Lazy.h +++ b/Filtered_kernel/include/CGAL/Lazy.h @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include #include @@ -98,9 +98,9 @@ CGAL_LAZY_FORWARD(Bbox_2) CGAL_LAZY_FORWARD(Bbox_3) #undef CGAL_LAZY_FORWARD -template Bbox const& approx(Bbox const& d) { return d; } -template Bbox const& exact (Bbox const& d) { return d; } -template int depth (Bbox const& ) { return 0; } +template Bbox_d const& approx(Bbox_d const& d) { return d; } +template Bbox_d const& exact (Bbox_d const& d) { return d; } +template int depth (Bbox_d const& ) { return 0; } templateinline std::enable_if_t::value||std::is_enum::value, T> approx(T d){return d;} templateinline std::enable_if_t::value||std::is_enum::value, T> exact (T d){return d;} diff --git a/Frechet_distance/include/CGAL/Frechet_distance/internal/Frechet_distance_traits.h b/Frechet_distance/include/CGAL/Frechet_distance/internal/Frechet_distance_traits.h index 6105ea11bf07..2e098e85206c 100644 --- a/Frechet_distance/include/CGAL/Frechet_distance/internal/Frechet_distance_traits.h +++ b/Frechet_distance/include/CGAL/Frechet_distance/internal/Frechet_distance_traits.h @@ -17,7 +17,7 @@ #include -#include +#include #include namespace CGAL { @@ -36,9 +36,9 @@ class Frechet_distance_traits struct Construct_bbox_d { - Bbox operator()(const Point_d& p) const + Bbox_d operator()(const Point_d& p) const { - Bbox bb; + Bbox_d bb; for (int i=0;i #include #include -#include +#include #include #include #include @@ -53,7 +53,7 @@ class FrechetKdTree struct Point_d { - using BB = Bbox,FT>; + using BB = Bbox_d>; Point ends[2]; BB bbox; using PP = Concatenate_iterator; @@ -232,7 +232,7 @@ auto FrechetKdTree::to_kd_tree_point(const Polyline& curve) -> Point_d res.ends[0] = curve.front(); res.ends[1] = curve.back(); for (auto const& point : curve) { - Bbox,FT> bb = bbox(point); + Bbox_d> bb = bbox(point); res.bbox += bb; } return res; diff --git a/Frechet_distance/include/CGAL/Frechet_distance/internal/curve.h b/Frechet_distance/include/CGAL/Frechet_distance/internal/curve.h index 684566ec0d4e..156eb77249c1 100644 --- a/Frechet_distance/include/CGAL/Frechet_distance/internal/curve.h +++ b/Frechet_distance/include/CGAL/Frechet_distance/internal/curve.h @@ -18,7 +18,7 @@ #include #include -#include +#include #include #include #include @@ -46,8 +46,8 @@ double length_of_diagonal(const Bbox_3& bb) return sqrt(d).sup(); } -template -double length_of_diagonal(const Bbox,T>& bb) +template +double length_of_diagonal(const Bbox_d>& bb) { using I = Interval_nt; I d = square(I((bb.max)(0)) - I((bb.min)(0))); @@ -227,7 +227,7 @@ class Curve static constexpr int dimension = Traits::Dimension::value; using Bbox = std::conditional_t>>; + Bbox_3, ::CGAL::Bbox_d>>; using FT = typename Traits::FT; using IFT = std::conditional_t, FT, CGAL::Interval_nt>; diff --git a/Kernel_d/doc/Kernel_d/CGAL/Bbox_d.h b/Kernel_d/doc/Kernel_d/CGAL/Bbox_d.h new file mode 100644 index 000000000000..48fc24932ce2 --- /dev/null +++ b/Kernel_d/doc/Kernel_d/CGAL/Bbox_d.h @@ -0,0 +1,125 @@ + +namespace CGAL { + +/*! +\ingroup PkgKernelDKernelObjs + +An object `b` of the class `Bbox_d` is a bounding +box in the d-dimensional Euclidean plane \f$ \E^d\f$. This class is templated with a dimension tag. + +\cgalModels{Hashable} + +\sa `CGAL::Bbox_2` +\sa `CGAL::Bbox_3` + +*/ + +template +class Bbox_d { +public: + +/// \name Creation +/// @{ + +/*! +introduces an \em empty bounding box with lower left +corner coordinates at \f$ \infty \f$ +and with upper right corner coordinates at +\f$ -\infty \f$, \f$ \infty \f$ being +`std::numeric_limits::%infinity()`. +*/ + Bbox_d(); + +/*! +introduces a d-dimensional bounding box from a 2d bounding box. +\pre the dimension must be 2D +*/ +Bbox_d(const Bbox_2& b); + +/*! +introduces a d-dimensional bounding box from a range. +\pre the range must have the size of the dimension. +\tparam I an iterator model of `InputIterator` with value type double +*/ +template +Bbox_d(int d, I b, I e); + +/*! +introduces a d-dimensional bounding box from a 3d bounding box. +\pre the dimension must be 3D +*/ +Bbox_d(const Bbox_3& b); + +/// @} + +/// \name Operations +/// @{ + +/*! +ests for equality. +*/ +bool operator==(const Bbox_d &c) const; + +/*! +tests for inequality. +*/ +bool operator!=(const Bbox_d &q) const; + +/*! +returns the dimension. +*/ +int dimension() const; + + +/*! +returns an iterator for the %Cartesian coordinates of the lower left and the upper right corner. +*/ +Cartesian_const_iterator cartesian_begin() const; + + +/*! +returns the past-the-end iterator for the %Cartesian coordinates of the lower left and the upper right corner. +*/ +Cartesian_const_iterator cartesian_begin() const; + +/*! +returns a bounding box of `b` and `c`. +*/ +Bbox_d operator+(const Bbox_d &c) const; + +/*! +updates `b` to be the bounding box of `b` and `c` and returns itself. +*/ +Bbox_d& operator+=(const Bbox_d &c); + +/*! +dilates the bounding box by a specified number of ULP. +*/ +void dilate(int dist); + +/*! +scales the bounding box by `factor`, while keeping its center fixed. +\pre `factor > 0` +*/ +void scale(double factor); + +/// @} + +}; /* end Bbox_d */ + +/// \ingroup do_overlap_grp +/// @{ + +/*! +returns `true`, iff `bb1` and `bb2` overlap, i.e., iff their +intersection is non-empty. + +\relates Bbox_d +*/ +template +bool do_overlap(const Bbox_d &bb1, const Bbox_d &bb2); + +/// @} + + +} /* end namespace CGAL */ diff --git a/Kernel_d/doc/Kernel_d/PackageDescription.txt b/Kernel_d/doc/Kernel_d/PackageDescription.txt index f8c024183a2f..0d1bc81b7199 100644 --- a/Kernel_d/doc/Kernel_d/PackageDescription.txt +++ b/Kernel_d/doc/Kernel_d/PackageDescription.txt @@ -62,6 +62,7 @@ - `CGAL::Sphere_d` - `CGAL::Iso_box_d` - `CGAL::Aff_transformation_d` +- `CGAL::Bbox_d` \cgalCRPSection{Global %Kernel Functions} - `CGAL::affinely_independent()` diff --git a/Kernel_23/include/CGAL/Bbox.h b/Kernel_d/include/CGAL/Bbox_d.h similarity index 83% rename from Kernel_23/include/CGAL/Bbox.h rename to Kernel_d/include/CGAL/Bbox_d.h index 4bbcea7975fa..9c1c82f6a327 100644 --- a/Kernel_23/include/CGAL/Bbox.h +++ b/Kernel_d/include/CGAL/Bbox_d.h @@ -9,8 +9,8 @@ // // Author(s) : Mathieu Brédif -#ifndef CGAL_BBOX_H -#define CGAL_BBOX_H +#ifndef CGAL_BBOX_D_H +#define CGAL_BBOX_D_H #include // defines BOOST_PREVENT_MACRO_SUBSTITUTION #include @@ -175,26 +175,26 @@ class Bbox } -template -class Bbox; +template +class Bbox_d; // A fixed D-dimensional axis aligned box -template -class Bbox, T> : public Impl::Bbox, Bbox,T>> +template +class Bbox_d> : public Impl::Bbox, Bbox_d>> { enum { D = N }; - using array_const_iterator = typename std::array::const_iterator; + using array_const_iterator = typename std::array::const_iterator; public: using Cartesian_const_iterator = Concatenate_iterator; inline constexpr int dimension() const { return D; } - Bbox(int d = 0 ) { CGAL_assertion(d==N || d==0); this->init(d ); } - Bbox(int d, const T& range) { CGAL_assertion(d==N || d==0); this->init(d, range); } + Bbox_d(int d = 0 ) { CGAL_assertion(d==N || d==0); this->init(d ); } + Bbox_d(int d, double range) { CGAL_assertion(d==N || d==0); this->init(d, range); } template - Bbox(int d, I b, I e) { CGAL_assertion(d==N || d==0); this->init(d, b, e); } + Bbox_d(int d, I b, I e) { CGAL_assertion(d==N || d==0); this->init(d, b, e); } - Bbox(const Bbox_2& bb2){ this->init(bb2);} - Bbox(const Bbox_3& bb3){ this->init(bb3);} + Bbox_d(const Bbox_2& bb2){ this->init(bb2);} + Bbox_d(const Bbox_3& bb3){ this->init(bb3);} Cartesian_const_iterator cartesian_begin() const { @@ -208,15 +208,15 @@ class Bbox, T> : public Impl::Bbox, Bbox -class Bbox : public Impl::Bbox, Bbox> +template<> +class Bbox_d : public Impl::Bbox, Bbox_d> { public: inline int dimension() const { return this->min_values.size(); } - Bbox(int d = 0 ) { init_values(d); this->init(d ); } - Bbox(int d, const T& range) { init_values(d); this->init(d, range); } + Bbox_d(int d = 0 ) { init_values(d); this->init(d ); } + Bbox_d(int d, double range) { init_values(d); this->init(d, range); } template - Bbox(int d, I b, I e) { init_values(d); this->init(d, b, e); } + Bbox_d(int d, I b, I e) { init_values(d); this->init(d, b, e); } protected: void init_values(int d) { @@ -243,17 +243,17 @@ std::istream& operator>>(std::istream& in, Impl::Bbox& bbox) return in; } -template -Bbox, T> operator+(Bbox, T> bbox, const Bbox, T>& other) +template +Bbox_d> operator+(Bbox_d> bbox, const Bbox_d>& other) { bbox += other; return bbox; } -template +template inline bool -do_overlap(const Bbox& bb1, const Bbox& bb2) +do_overlap(const Bbox_d& bb1, const Bbox_d& bb2) { // check for emptiness ?? int d = bb1.dimension(); @@ -268,4 +268,4 @@ do_overlap(const Bbox& bb1, const Bbox& bb2) } // namespace CGAL -#endif // CGAL_DDT_BBOX_H +#endif // CGAL_BBOX_D_H diff --git a/NewKernel_d/include/CGAL/NewKernel_d/function_objects_cartesian.h b/NewKernel_d/include/CGAL/NewKernel_d/function_objects_cartesian.h index f1c0e6ed49c2..7429d3f879a1 100644 --- a/NewKernel_d/include/CGAL/NewKernel_d/function_objects_cartesian.h +++ b/NewKernel_d/include/CGAL/NewKernel_d/function_objects_cartesian.h @@ -14,7 +14,7 @@ #include #include -#include +#include #include #include #include @@ -1016,7 +1016,7 @@ template struct Construct_bbox : private Store_kernel { typedef typename Get_type::type Point; typedef typename Get_functor >::type CI; - typedef Bbox result_type; + typedef Bbox_d result_type; typedef Point argument_type; result_type operator()(Point const&a)const{ CI ci(this->kernel());