Skip to content

Commit

Permalink
Constructor from a range of pairs of numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
afabri committed Jun 20, 2024
1 parent 48d734c commit 4bc2770
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
21 changes: 17 additions & 4 deletions Kernel_23/include/CGAL/Bbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,29 +106,42 @@ class Bbox
max_values[i] = range;
}
}

template <typename I>
void init(int d, I b, I e) {
for(int i=0; i<d; ++i,++b)
{
min_values[i] = (*b).first;
max_values[i] = (*b).second;
}
}
};

}

// A D-dimensional axis aligned box
// A fixed D-dimensional axis aligned box
template<unsigned int N, typename T>
class Bbox : public Impl::Bbox<std::array<T, N>, Bbox<N,T>>
{
enum { D = N };
public:
inline constexpr int dimension() const { return D; }
Bbox(int d = 0 ) { assert(d==N || d==0); this->init(d ); }
Bbox(int d, double range) { assert(d==N || d==0); this->init(d, range); }
Bbox(int d, const T& range) { assert(d==N || d==0); this->init(d, range); }
template <typename I>
Bbox(int d, I b, I e) { assert(d==N || d==0); this->init(d, b, e); }
};

// A D-dimensional axis aligned box
// A dynamic D-dimensional axis aligned box
template<typename T>
class Bbox<0,T> : public Impl::Bbox<std::vector<T>, Bbox<0,T>>
{
public:
inline int dimension() const { return this->min_values.size(); }
Bbox(int d = 0 ) { init_values(d); this->init(d ); }
Bbox(int d, double range) { init_values(d); this->init(d, range); }
Bbox(int d, const T& 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, ); }

protected:
void init_values(int d) {
Expand Down
7 changes: 6 additions & 1 deletion Kernel_23/test/Kernel_23/test_bbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ int main()
assert(bb3 != bb3a);
bb3 = bb3a;
assert(bb3 == bb3a);
std::cout << bb3 << std::endl;

std::array<std::pair<double,double>,3> coord = { std::make_pair(0.0, 0.0), std::make_pair(1.0, 1.1), std::make_pair(1.0, 20.0)};

BBox3 bb3b(3,coord.begin(), coord.end());

std::cout << bb3b << std::endl;
}
}

0 comments on commit 4bc2770

Please sign in to comment.