From eeeb18926afbad9493950ab557bc05342807c77e Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 7 Apr 2014 15:04:32 +0000 Subject: [PATCH] Fixed build when using of double BoundingBox/BoundingSphere --- include/osg/BoundingBox | 21 ++++++++++++++++++++- include/osg/BoundingSphere | 23 +++++++++++++++-------- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/include/osg/BoundingBox b/include/osg/BoundingBox index 4201d4047..e6c5b4698 100644 --- a/include/osg/BoundingBox +++ b/include/osg/BoundingBox @@ -51,6 +51,12 @@ class BoundingBoxImpl -FLT_MAX) {} + template + inline BoundingBoxImpl(const BoundingBoxImpl& bb) : + _min(bb._min), + _max(bb._max) + {} + /** Creates a bounding box initialized to the given extents. */ inline BoundingBoxImpl(value_type xmin, value_type ymin, value_type zmin, value_type xmax, value_type ymax, value_type zmax) : @@ -73,6 +79,9 @@ class BoundingBoxImpl -FLT_MAX); } + inline bool operator == (const BoundingBoxImpl& rhs) const { return _min==rhs._min && _max==rhs._max; } + inline bool operator != (const BoundingBoxImpl& rhs) const { return _min!=rhs._min || _max!=rhs._max; } + /** Returns true if the bounding box extents are valid, false otherwise. */ inline bool valid() const { @@ -189,7 +198,8 @@ class BoundingBoxImpl /** Expands this bounding box to include the given sphere. * If this box is uninitialized, set it to include sh. */ - void expandBy(const BoundingSphereImpl& sh) + template + void expandBy(const BoundingSphereImpl& sh) { if (!sh.valid()) return; @@ -227,6 +237,15 @@ class BoundingBoxImpl (v.y()>=_min.y() && v.y()<=_max.y()) && (v.z()>=_min.z() && v.z()<=_max.z()); } + + /** Returns true if this bounding box contains the specified coordinate allowing for specific epsilon. */ + inline bool contains(const vec_type& v, value_type epsilon) const + { + return valid() && + ((v.x()+epsilon)>=_min.x() && (v.x()-epsilon)<=_max.x()) && + ((v.y()+epsilon)>=_min.y() && (v.y()-epsilon)<=_max.y()) && + ((v.z()+epsilon)>=_min.z() && (v.z()-epsilon)<=_max.z()); + } }; typedef BoundingBoxImpl BoundingBoxf; diff --git a/include/osg/BoundingSphere b/include/osg/BoundingSphere index 722899759..eb93ac277 100644 --- a/include/osg/BoundingSphere +++ b/include/osg/BoundingSphere @@ -63,6 +63,9 @@ class BoundingSphereImpl * otherwise. */ inline bool valid() const { return _radius>=0.0; } + inline bool operator == (const BoundingSphereImpl& rhs) const { return _center==rhs._center && _radius==rhs._radius; } + inline bool operator != (const BoundingSphereImpl& rhs) const { return _center!=rhs._center || _radius==rhs._radius; } + /** Set the bounding sphere to the given center/radius using floats. */ inline void set(const vec_type& center,value_type radius) { @@ -110,11 +113,13 @@ class BoundingSphereImpl /** Expands the sphere to encompass the given box. Repositions the * sphere center to minimize the radius increase. */ - void expandBy(const BoundingBoxImpl& bb); + template + void expandBy(const BoundingBoxImpl& bb); /** Expands the sphere to encompass the given box. Does not * repositions the sphere center. */ - void expandRadiusBy(const BoundingBoxImpl& bb); + template + void expandRadiusBy(const BoundingBoxImpl& bb); /** Returns true if v is within the sphere. */ inline bool contains(const vec_type& v) const @@ -135,12 +140,12 @@ class BoundingSphereImpl template - template +template void BoundingSphereImpl::expandBy(const vector_type& v) { if (valid()) { - vec_type dv = v-_center; + vec_type dv = vec_type(v)-_center; value_type r = dv.length(); if (r>_radius) { @@ -157,12 +162,12 @@ void BoundingSphereImpl::expandBy(const vector_type& v) } template - template +template void BoundingSphereImpl::expandRadiusBy(const vector_type& v) { if (valid()) { - value_type r = (v-_center).length(); + value_type r = (vec_type(v)-_center).length(); if (r>_radius) _radius = r; // else do nothing as vertex is within sphere. } @@ -244,7 +249,8 @@ void BoundingSphereImpl::expandRadiusBy(const BoundingSphereImpl& sh) } template -void BoundingSphereImpl::expandBy(const BoundingBoxImpl& bb) +template +void BoundingSphereImpl::expandBy(const BoundingBoxImpl& bb) { if (bb.valid()) { @@ -274,7 +280,8 @@ void BoundingSphereImpl::expandBy(const BoundingBoxImpl& bb) } template -void BoundingSphereImpl::expandRadiusBy(const BoundingBoxImpl& bb) +template +void BoundingSphereImpl::expandRadiusBy(const BoundingBoxImpl& bb) { if (bb.valid()) {