diff --git a/Kernel_23/doc/Kernel_23/CGAL/Bbox_2.h b/Kernel_23/doc/Kernel_23/CGAL/Bbox_2.h index bd65ee37b04..5dc0277c497 100644 --- a/Kernel_23/doc/Kernel_23/CGAL/Bbox_2.h +++ b/Kernel_23/doc/Kernel_23/CGAL/Bbox_2.h @@ -82,6 +82,11 @@ returns a bounding box of `b` and `c`. */ Bbox_2 operator+(const Bbox_2 &c) const; +/*! +updates `b` to be the bounding box of `b` and `c` and returns itself. +*/ +Bbox_2& operator+=(const Bbox_2 &c); + /// @} }; /* end Bbox_2 */ diff --git a/Kernel_23/doc/Kernel_23/CGAL/Bbox_3.h b/Kernel_23/doc/Kernel_23/CGAL/Bbox_3.h index cfa0ed6fa5b..2d763885de6 100644 --- a/Kernel_23/doc/Kernel_23/CGAL/Bbox_3.h +++ b/Kernel_23/doc/Kernel_23/CGAL/Bbox_3.h @@ -93,7 +93,12 @@ double max(int i) const; /*! returns a bounding box of `b` and `c`. */ -Bbox_3 operator+(const Bbox_3 &c) const; +Bbox_3 operator+(const Bbox_3 &c) const; + +/*! +updates `b` to be the bounding box of `b` and `c` and returns itself. +*/ +Bbox_3& operator+=(const Bbox_3 &c); /// @} diff --git a/Kernel_23/include/CGAL/Bbox_2.h b/Kernel_23/include/CGAL/Bbox_2.h index c5e187fb5f9..bedb38e7875 100644 --- a/Kernel_23/include/CGAL/Bbox_2.h +++ b/Kernel_23/include/CGAL/Bbox_2.h @@ -67,6 +67,7 @@ public: inline double min BOOST_PREVENT_MACRO_SUBSTITUTION (int i) const; inline Bbox_2 operator+(const Bbox_2 &b) const; + inline Bbox_2& operator+=(const Bbox_2 &b); }; @@ -138,6 +139,17 @@ Bbox_2::operator+(const Bbox_2 &b) const (std::max)(ymax(), b.ymax())); } +inline +Bbox_2& +Bbox_2::operator+=(const Bbox_2& b) +{ + rep[0] = (std::min)(xmin(), b.xmin()); + rep[1] = (std::min)(ymin(), b.ymin()); + rep[2] = (std::max)(xmax(), b.xmax()); + rep[3] = (std::max)(ymax(), b.ymax()); + return *this; +} + inline bool do_overlap(const Bbox_2 &bb1, const Bbox_2 &bb2) diff --git a/Kernel_23/include/CGAL/Bbox_3.h b/Kernel_23/include/CGAL/Bbox_3.h index fa1132c28f9..875bb79a1ac 100644 --- a/Kernel_23/include/CGAL/Bbox_3.h +++ b/Kernel_23/include/CGAL/Bbox_3.h @@ -66,6 +66,7 @@ public: inline double max BOOST_PREVENT_MACRO_SUBSTITUTION (int i) const; Bbox_3 operator+(const Bbox_3& b) const; + Bbox_3& operator+=(const Bbox_3& b); }; inline @@ -151,6 +152,19 @@ Bbox_3::operator+(const Bbox_3& b) const (std::max)(zmax(), b.zmax())); } +inline +Bbox_3& +Bbox_3::operator+=(const Bbox_3& b) +{ + rep[0] = (std::min)(xmin(), b.xmin()); + rep[1] = (std::min)(ymin(), b.ymin()); + rep[2] = (std::min)(zmin(), b.zmin()); + rep[3] = (std::max)(xmax(), b.xmax()); + rep[4] = (std::max)(ymax(), b.ymax()); + rep[5] = (std::max)(zmax(), b.zmax()); + return *this; +} + inline bool do_overlap(const Bbox_3& bb1, const Bbox_3& bb2) diff --git a/Kernel_23/test/Kernel_23/test_bbox.cpp b/Kernel_23/test/Kernel_23/test_bbox.cpp new file mode 100644 index 00000000000..28c63f89347 --- /dev/null +++ b/Kernel_23/test/Kernel_23/test_bbox.cpp @@ -0,0 +1,30 @@ +#include +#include +#include + +typedef CGAL::Simple_cartesian Kernel; +typedef Kernel::Point_3 Point_3; +typedef Kernel::Point_2 Point_2; + +int main() +{ + { + //Dimension 2 + Point_2 p1(0,0), p2(1,-1.3); + CGAL::Bbox_2 b1 = p1.bbox(), b2=p2.bbox(); + CGAL::Bbox_2 b3 = b1 + b2; + b1+=b2; + assert(b1==b3); + assert(CGAL::Bbox_2(0,-1.3,1,0) == b1); + } + + { + //Dimension 3 + Point_3 p1(0,0,0), p2(1,-1.3,1.5); + CGAL::Bbox_3 b1 = p1.bbox(), b2=p2.bbox(); + CGAL::Bbox_3 b3 = b1 + b2; + b1+=b2; + assert(b1==b3); + assert(CGAL::Bbox_3(0,-1.3,0,1,0,1.5) == b1); + } +}