mirror of https://github.com/CGAL/cgal
add operator+= in bbox classes
This commit is contained in:
parent
fa177d6db5
commit
43d4a00db0
|
|
@ -82,6 +82,11 @@ returns a bounding box of `b` and `c`.
|
||||||
*/
|
*/
|
||||||
Bbox_2 operator+(const Bbox_2 &c) const;
|
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 */
|
}; /* end Bbox_2 */
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,11 @@ 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);
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
||||||
}; /* end Bbox_3 */
|
}; /* end Bbox_3 */
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,7 @@ public:
|
||||||
inline double min BOOST_PREVENT_MACRO_SUBSTITUTION (int i) const;
|
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) 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()));
|
(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
|
inline
|
||||||
bool
|
bool
|
||||||
do_overlap(const Bbox_2 &bb1, const Bbox_2 &bb2)
|
do_overlap(const Bbox_2 &bb1, const Bbox_2 &bb2)
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,7 @@ public:
|
||||||
inline double max BOOST_PREVENT_MACRO_SUBSTITUTION (int i) const;
|
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) const;
|
||||||
|
Bbox_3& operator+=(const Bbox_3& b);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline
|
inline
|
||||||
|
|
@ -151,6 +152,19 @@ Bbox_3::operator+(const Bbox_3& b) const
|
||||||
(std::max)(zmax(), b.zmax()));
|
(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
|
inline
|
||||||
bool
|
bool
|
||||||
do_overlap(const Bbox_3& bb1, const Bbox_3& bb2)
|
do_overlap(const Bbox_3& bb1, const Bbox_3& bb2)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
#include <CGAL/Simple_cartesian.h>
|
||||||
|
#include <CGAL/Bbox_2.h>
|
||||||
|
#include <CGAL/Bbox_3.h>
|
||||||
|
|
||||||
|
typedef CGAL::Simple_cartesian<double> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue