Skip to content

Commit

Permalink
Add BBox_d
Browse files Browse the repository at this point in the history
  • Loading branch information
afabri committed Jan 10, 2025
1 parent 0e0d81e commit be8f3b8
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 38 deletions.
8 changes: 4 additions & 4 deletions Filtered_kernel/include/CGAL/Lazy.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <CGAL/Origin.h>
#include <CGAL/Bbox_2.h>
#include <CGAL/Bbox_3.h>
#include <CGAL/Bbox.h>
#include <CGAL/Bbox_d.h>
#include <CGAL/Default.h>
#include <CGAL/tss.h>
#include <CGAL/type_traits/is_iterator.h>
Expand Down Expand Up @@ -98,9 +98,9 @@ CGAL_LAZY_FORWARD(Bbox_2)
CGAL_LAZY_FORWARD(Bbox_3)
#undef CGAL_LAZY_FORWARD

template<class A, class B> Bbox<A,B> const& approx(Bbox<A,B> const& d) { return d; }
template<class A, class B> Bbox<A,B> const& exact (Bbox<A,B> const& d) { return d; }
template<class A, class B> int depth (Bbox<A,B> const& ) { return 0; }
template<class A> Bbox_d<A> const& approx(Bbox_d<A> const& d) { return d; }
template<class A> Bbox_d<A> const& exact (Bbox_d<A> const& d) { return d; }
template<class A> int depth (Bbox_d<A> const& ) { return 0; }

template<class T>inline std::enable_if_t<std::is_arithmetic<T>::value||std::is_enum<T>::value, T> approx(T d){return d;}
template<class T>inline std::enable_if_t<std::is_arithmetic<T>::value||std::is_enum<T>::value, T> exact (T d){return d;}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include <CGAL/license/Frechet_distance.h>

#include <CGAL/Bbox.h>
#include <CGAL/Bbox_d.h>
#include <array>

namespace CGAL {
Expand All @@ -36,9 +36,9 @@ class Frechet_distance_traits

struct Construct_bbox_d
{
Bbox<Dimension, double> operator()(const Point_d& p) const
Bbox_d<Dimension> operator()(const Point_d& p) const
{
Bbox<Dimension, double> bb;
Bbox_d<Dimension> bb;
for (int i=0;i<dimension; ++i)
{
(bb.min)(i)=to_interval(p[i]).first;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <CGAL/Search_traits_d.h>
#include <CGAL/Search_traits.h>
#include <CGAL/number_utils.h>
#include <CGAL/Bbox.h>
#include <CGAL/Bbox_d.h>
#include <array>
#include <iterator>
#include <tuple>
Expand Down Expand Up @@ -53,7 +53,7 @@ class FrechetKdTree


struct Point_d {
using BB = Bbox<Dimension_tag<dim>,FT>;
using BB = Bbox_d<Dimension_tag<dim>>;
Point ends[2];
BB bbox;
using PP = Concatenate_iterator<typename Point::Cartesian_const_iterator, typename Point::Cartesian_const_iterator>;
Expand Down Expand Up @@ -232,7 +232,7 @@ auto FrechetKdTree<Traits>::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<Dimension_tag<dim>,FT> bb = bbox(point);
Bbox_d<Dimension_tag<dim>> bb = bbox(point);
res.bbox += bb;
}
return res;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <CGAL/Frechet_distance/internal/id.h>

#include <CGAL/Kernel/Type_mapper.h>
#include <CGAL/Bbox.h>
#include <CGAL/Bbox_d.h>
#include <CGAL/Bbox_2.h>
#include <CGAL/Bbox_3.h>
#include <CGAL/Cartesian_converter.h>
Expand Down Expand Up @@ -46,8 +46,8 @@ double length_of_diagonal(const Bbox_3& bb)
return sqrt(d).sup();
}

template<int N, typename T>
double length_of_diagonal(const Bbox<Dimension_tag<N>,T>& bb)
template<int N>
double length_of_diagonal(const Bbox_d<Dimension_tag<N>>& bb)
{
using I = Interval_nt<true>;
I d = square(I((bb.max)(0)) - I((bb.min)(0)));
Expand Down Expand Up @@ -227,7 +227,7 @@ class Curve<T, false>
static constexpr int dimension = Traits::Dimension::value;
using Bbox = std::conditional_t<dimension==2,
Bbox_2, std::conditional_t<dimension==3,
Bbox_3, ::CGAL::Bbox<typename Traits::Dimension, double>>>;
Bbox_3, ::CGAL::Bbox_d<typename Traits::Dimension>>>;

using FT = typename Traits::FT;
using IFT = std::conditional_t<std::is_floating_point_v<FT>, FT, CGAL::Interval_nt<false>>;
Expand Down
125 changes: 125 additions & 0 deletions Kernel_d/doc/Kernel_d/CGAL/Bbox_d.h
Original file line number Diff line number Diff line change
@@ -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 <typename DimensionTag>
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<double>::%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 <typename I>
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 <typename DimensionTag>
bool do_overlap(const Bbox_d &bb1, const Bbox_d &bb2);

/// @}


} /* end namespace CGAL */
1 change: 1 addition & 0 deletions Kernel_d/doc/Kernel_d/PackageDescription.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
- `CGAL::Sphere_d<Kernel>`
- `CGAL::Iso_box_d<Kernel>`
- `CGAL::Aff_transformation_d<Kernel>`
- `CGAL::Bbox_d<Dimension>`

\cgalCRPSection{Global %Kernel Functions}
- `CGAL::affinely_independent()`
Expand Down
44 changes: 22 additions & 22 deletions Kernel_23/include/CGAL/Bbox.h → Kernel_d/include/CGAL/Bbox_d.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <boost/config.hpp> // defines BOOST_PREVENT_MACRO_SUBSTITUTION
#include <stddef.h>
Expand Down Expand Up @@ -175,26 +175,26 @@ class Bbox

}

template <typename Di, typename T>
class Bbox;
template <typename Di>
class Bbox_d;

// A fixed D-dimensional axis aligned box
template<int N, typename T>
class Bbox<Dimension_tag<N>, T> : public Impl::Bbox<std::array<T, N>, Bbox<Dimension_tag<N>,T>>
template<int N>
class Bbox_d<Dimension_tag<N>> : public Impl::Bbox<std::array<double, N>, Bbox_d<Dimension_tag<N>>>
{
enum { D = N };
using array_const_iterator = typename std::array<T, N>::const_iterator;
using array_const_iterator = typename std::array<double, N>::const_iterator;
public:
using Cartesian_const_iterator = Concatenate_iterator<array_const_iterator,array_const_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 <typename I>
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
{
Expand All @@ -208,15 +208,15 @@ class Bbox<Dimension_tag<N>, T> : public Impl::Bbox<std::array<T, N>, Bbox<Dimen
};

// A dynamic D-dimensional axis aligned box
template<typename T>
class Bbox<Dynamic_dimension_tag,T> : public Impl::Bbox<std::vector<T>, Bbox<Dynamic_dimension_tag,T>>
template<>
class Bbox_d<Dynamic_dimension_tag> : public Impl::Bbox<std::vector<double>, Bbox_d<Dynamic_dimension_tag>>
{
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 <typename I>
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) {
Expand All @@ -243,17 +243,17 @@ std::istream& operator>>(std::istream& in, Impl::Bbox<Container, Derived>& bbox)
return in;
}

template<int N, typename T>
Bbox<Dimension_tag<N>, T> operator+(Bbox<Dimension_tag<N>, T> bbox, const Bbox<Dimension_tag<N>, T>& other)
template<int N>
Bbox_d<Dimension_tag<N>> operator+(Bbox_d<Dimension_tag<N>> bbox, const Bbox_d<Dimension_tag<N>>& other)
{
bbox += other;
return bbox;
}

template<typename Di, typename T>
template<typename Di>
inline
bool
do_overlap(const Bbox<Di,T>& bb1, const Bbox<Di,T>& bb2)
do_overlap(const Bbox_d<Di>& bb1, const Bbox_d<Di>& bb2)
{
// check for emptiness ??
int d = bb1.dimension();
Expand All @@ -268,4 +268,4 @@ do_overlap(const Bbox<Di,T>& bb1, const Bbox<Di,T>& bb2)

} // namespace CGAL

#endif // CGAL_DDT_BBOX_H
#endif // CGAL_BBOX_D_H
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include <CGAL/NewKernel_d/utils.h>
#include <CGAL/Dimension.h>
#include <CGAL/Bbox.h>
#include <CGAL/Bbox_d.h>
#include <CGAL/Uncertain.h>
#include <CGAL/NewKernel_d/store_kernel.h>
#include <CGAL/type_traits/is_iterator.h>
Expand Down Expand Up @@ -1016,7 +1016,7 @@ template<class R_> struct Construct_bbox : private Store_kernel<R_> {
typedef typename Get_type<R, Point_tag>::type Point;
typedef typename Get_functor<R, Construct_ttag<Point_cartesian_const_iterator_tag> >::type CI;

typedef Bbox<Dimension,double> result_type;
typedef Bbox_d<Dimension> result_type;
typedef Point argument_type;
result_type operator()(Point const&a)const{
CI ci(this->kernel());
Expand Down

0 comments on commit be8f3b8

Please sign in to comment.