From ec56c6608d2f514a27e5a679dc8527a7113f6716 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Wed, 5 Jun 2024 09:44:37 +0100 Subject: [PATCH] Kernel: Add a BBox class with dimension as parameter --- Kernel_23/include/CGAL/Bbox.h | 159 ++++++++++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 Kernel_23/include/CGAL/Bbox.h diff --git a/Kernel_23/include/CGAL/Bbox.h b/Kernel_23/include/CGAL/Bbox.h new file mode 100644 index 000000000000..be2c5cff4bd6 --- /dev/null +++ b/Kernel_23/include/CGAL/Bbox.h @@ -0,0 +1,159 @@ +// 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 + +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()); + 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 +class Bbox : public Impl::Bbox, Bbox> +{ + 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); } +}; + +// A D-dimensional axis aligned box +template +class Bbox<0,T> : public Impl::Bbox, 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); } + +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; +} + + +} // namespace CGAL + +#endif // CGAL_DDT_BBOX_H +