From 69779ebf80ede5f4d8a2380c240e40d2b0a0aa78 Mon Sep 17 00:00:00 2001 From: Doug Roeper Date: Fri, 19 Mar 2021 09:36:30 -0400 Subject: [PATCH] Adds some helpers to calculate the span of a Bbox in each dimension. --- Kernel_23/include/CGAL/Bbox_2.h | 10 ++++++++++ Kernel_23/include/CGAL/Bbox_3.h | 27 ++++++++++++++++++++------ Kernel_23/test/Kernel_23/test_bbox.cpp | 7 +++++++ 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/Kernel_23/include/CGAL/Bbox_2.h b/Kernel_23/include/CGAL/Bbox_2.h index cb84444425a..827daa18028 100644 --- a/Kernel_23/include/CGAL/Bbox_2.h +++ b/Kernel_23/include/CGAL/Bbox_2.h @@ -61,6 +61,8 @@ public: inline double ymin() const; inline double xmax() const; inline double ymax() const; + inline double x_span() const; + inline double y_span() const; inline double max BOOST_PREVENT_MACRO_SUBSTITUTION (int i) const; inline double min BOOST_PREVENT_MACRO_SUBSTITUTION (int i) const; @@ -91,6 +93,14 @@ double Bbox_2::ymax() const { return rep[3]; } +inline double Bbox_2::x_span() const { + return xmax() - xmin(); +} + +inline double Bbox_2::y_span() const { + return ymax() - ymin(); +} + inline bool Bbox_2::operator==(const Bbox_2 &b) const diff --git a/Kernel_23/include/CGAL/Bbox_3.h b/Kernel_23/include/CGAL/Bbox_3.h index 1e5bb0d8eb9..684fe63ba39 100644 --- a/Kernel_23/include/CGAL/Bbox_3.h +++ b/Kernel_23/include/CGAL/Bbox_3.h @@ -58,12 +58,15 @@ public: inline bool operator!=(const Bbox_3 &b) const; inline int dimension() const; - double xmin() const; - double ymin() const; - double zmin() const; - double xmax() const; - double ymax() const; - double zmax() const; + double xmin() const; + double ymin() const; + double zmin() const; + double xmax() const; + double ymax() const; + double zmax() const; + double x_span() const; + double y_span() const; + double z_span() const; inline double min BOOST_PREVENT_MACRO_SUBSTITUTION (int i) const; inline double max BOOST_PREVENT_MACRO_SUBSTITUTION (int i) const; @@ -107,6 +110,18 @@ double Bbox_3::zmax() const { return rep[5]; } +inline double Bbox_3::x_span() const { + return xmax() - xmin(); +} + +inline double Bbox_3::y_span() const { + return ymax() - ymin(); +} + +inline double Bbox_3::z_span() const { + return zmax() - zmin(); +} + inline bool Bbox_3::operator==(const Bbox_3 &b) const diff --git a/Kernel_23/test/Kernel_23/test_bbox.cpp b/Kernel_23/test/Kernel_23/test_bbox.cpp index 7594e37934e..2fbc37f71a2 100644 --- a/Kernel_23/test/Kernel_23/test_bbox.cpp +++ b/Kernel_23/test/Kernel_23/test_bbox.cpp @@ -39,6 +39,9 @@ int main() -3000000000000001., 5000000.0000000019, 7.0000000000000026e+20) ); + CGAL::Bbox_2 span{1,2,5,8}; + assert( span.x_span() == 4); + assert( span.y_span() == 6); } { @@ -70,5 +73,9 @@ int main() 5000000.000000014, 7.0000000000000197e+20, 15.000000000000027) ); + CGAL::Bbox_3 span{1,2,3,5,8,11}; + assert( span.x_span() == 4); + assert( span.y_span() == 6); + assert( span.z_span() == 8); } }