// Copyright (c) 2022 Institut Géographique National - IGN (France) // 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) : Mathieu Brédif #ifndef CGAL_BBOX_H #define CGAL_BBOX_H #include // defines BOOST_PREVENT_MACRO_SUBSTITUTION #include #include #include #include #include #include #include namespace CGAL { namespace Impl { template class Bbox { protected: typedef typename Container::value_type T; Container min_values; Container max_values; public: Bbox& operator+=(const Bbox& bbox) { CGAL_assertion(min_values.size() == 0 || min_values.size() == bbox.min_values.size()); if(min_values.size() == 0){ *this = bbox; } int dim = bbox.min_values.size(); for(int i=0; i bbox.min_values[i]) min_values[i] = bbox.min_values[i]; if(max_values[i] < bbox.max_values[i]) max_values[i] = bbox.max_values[i]; } return *this; } inline int dimension() const { return static_cast(this)->dimension(); } inline T min BOOST_PREVENT_MACRO_SUBSTITUTION (int i) const { return min_values[i]; } inline T max BOOST_PREVENT_MACRO_SUBSTITUTION (int i) const { return max_values[i]; } inline T& min BOOST_PREVENT_MACRO_SUBSTITUTION (int i) { return min_values[i]; } inline T& max BOOST_PREVENT_MACRO_SUBSTITUTION (int i) { return max_values[i]; } inline T measure() const { T result = max_values[0] - min_values[0]; if (result <= 0) return 0; for(int i=1; i::infinity()) { for(int i=0; i void init(int d, I b, I e) { CGAL_assertion(d == std::distance(b,e)); for(int i=0; i class Bbox; // A fixed D-dimensional axis aligned box template class Bbox, T> : public Impl::Bbox, Bbox,T>> { enum { D = N }; public: 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); } template Bbox(int d, I b, I e) { CGAL_assertion(d==N || d==0); this->init(d, b, e); } }; // A dynamic D-dimensional axis aligned box template class Bbox : public Impl::Bbox, Bbox> { 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); } template Bbox(int d, I b, I e) { init_values(d); this->init(d, b, e); } protected: void init_values(int d) { this->min_values.resize(d); this->max_values.resize(d); } }; template std::ostream& operator<<(std::ostream& out, const Impl::Bbox& bbox) { int d = bbox.dimension(); for(int i=0; i std::istream& operator>>(std::istream& in, Impl::Bbox& bbox) { int d = bbox.dimension(); for(int i=0; i> (bbox.min)(i) >> (bbox.max)(i); return in; } template Bbox, T> operator+(Bbox, T> bbox, const Bbox, T>& other) { bbox += other; return bbox; } } // namespace CGAL #endif // CGAL_DDT_BBOX_H