45#ifndef LASS_GUARDIAN_OF_INCLUSION_PRIM_AABB_3D_INL
46#define LASS_GUARDIAN_OF_INCLUSION_PRIM_AABB_3D_INL
62template <
typename T,
class MMP>
74template <
typename T,
class MMP>
79 MMP::checkMinMax(min_, max_);
87template <
typename T,
class MMP>
99template <
typename T,
class MMP>
111template <
typename T,
class MMP>
112const typename Aabb3D<T, MMP>::TPoint&
123template <
typename T,
class MMP>
124const typename Aabb3D<T, MMP>::TPoint&
135template <
typename T,
class MMP>
145 MMP::setMin(min_, max_,
min);
153template <
typename T,
class MMP>
163 MMP::setMax(min_, max_,
max);
171template <
typename T,
class MMP>
173typename Aabb3D<T, MMP>::TSelf&
185template <
typename T,
class MMP>
186typename Aabb3D<T, MMP>::TSelf&
190 min_ = pointwiseMin(min_, point);
191 max_ = pointwiseMax(max_, point);
199template <
typename T,
class MMP>
201typename Aabb3D<T, MMP>::TSelf&
205 min_ = pointwiseMin(min_, other.
min());
206 max_ = pointwiseMax(max_, other.
max());
214template <
typename T,
class MMP>
217 grow(TVector(iDistance, iDistance, iDistance));
224template <
typename T,
class MMP>
229 if (max_.x < min_.x || max_.y < min_.y || max_.z < min_.z)
241template <
typename T,
class MMP>
244 const TVector extra =
size() * ((
num::abs(iScale) - 1) / 2);
256template <
typename T,
class MMP>
257const typename Aabb3D<T, MMP>::TPointH
268template <
typename T,
class MMP>
269const typename Aabb3D<T, MMP>::TVector
284template <
typename T,
class MMP>
285const typename Aabb3D<T, MMP>::TValue
292 const TVector result =
size();
293 return 2 * (result.x * result.y + result.y * result.z + result.z * result.x);
300template <
typename T,
class MMP>
301const typename Aabb3D<T, MMP>::TValue
308 const TVector result =
size();
309 return result.x * result.y * result.z;
316template <
typename T,
class MMP>
321 if (point.x > min_.x && point.x < max_.x &&
322 point.y > min_.y && point.y < max_.y &&
323 point.z > min_.z && point.z < max_.z)
328 if (point.x < min_.x || point.x > max_.x ||
329 point.y < min_.y || point.y > max_.y ||
330 point.z < min_.z || point.z > max_.z)
343template <
typename T,
class MMP>
347 return point.x >= min_.x && point.x <= max_.x &&
348 point.y >= min_.y && point.y <= max_.y &&
349 point.z >= min_.z && point.z <= max_.z;
359template <
typename T,
class MMP>
364 return other.
min().x >= min_.x && other.
max().x <= max_.x
365 && other.
min().y >= min_.y && other.
max().y <= max_.y
366 && other.
min().z >= min_.z && other.
max().z <= max_.z;
390template <
typename T,
class MMP>
395 if (other.
max().x < min_.x || other.
min().x > max_.x)
return false;
396 if (other.
max().y < min_.y || other.
min().y > max_.y)
return false;
397 if (other.
max().z < min_.z || other.
min().z > max_.z)
return false;
422template <
typename T,
class MMP>
427 if (other.
max().x <= min_.x || other.
min().x >= max_.x)
return false;
428 if (other.
max().y <= min_.y || other.
min().y >= max_.y)
return false;
429 if (other.
max().z <= min_.z || other.
min().z >= max_.z)
return false;
440template <
typename T,
class MMP>
441template <
class RandomGenerator>
442const typename Aabb3D<T, MMP>::TPoint
446 std::uniform_real_distribution<TValue> uniform;
447 const TVector t(uniform(generator), uniform(generator), uniform(generator));
448 const TPoint result(min_ + t * (max_ - min_));
457template <
typename T,
class MMP>
460 min_ = TPoint(TNumTraits::max, TNumTraits::max, TNumTraits::max);
461 max_ = TPoint(TNumTraits::min, TNumTraits::min, TNumTraits::min);
471template <
typename T,
class MMP>
475 return min_.x > max_.x;
494template <
typename T,
class MMP>
497 return (min_.x <= max_.x && min_.y <= max_.y && min_.z <= max_.z) || (min_.x > max_.x);
504template <
typename T,
class MMP>
505template <
typename MMP2>
508 std::swap(min_, other.min_);
509 std::swap(max_, other.max_);
519template <
typename T,
class MMPa,
class MMPb>
inline
532template <
typename T,
class MMP>
inline
545template <
typename T,
class MMP>
inline
572template <
typename T,
class MMP>
inline
577 return pointwiseMax(pointwiseMax(a.
min() - b, b - a.
max()), TVector()).
norm();
589template <
typename T,
class MMPa,
class MMPb>
inline
594 return pointwiseMax(pointwiseMax(a.
min() - b.
max(), b.
min() - a.
max()), TVector()).
norm();
616template <
typename T,
class MMPa,
class MMPb,
class MMPr>
636template <
typename T,
class MMPa,
class MMPb>
inline
646template <
typename T,
typename MMP>
inline
647bool intersects(
const Aabb3D<T, MMP>& a,
const Point3D<T>& b)
649 return a.contains(b);
656template <
typename T,
typename MMP>
inline
657bool intersects(
const Point3D<T>& a,
const Aabb3D<T, MMP>& b)
659 return b.contains(a);
664template <
typename T,
class MMPa,
class MMPb>
inline
667 return a.collides(b);
674template <
typename T,
typename MMP>
inline
677 typedef typename Aabb3D<T, MMP>::TPoint TPoint;
678 const TPoint& min = a.min();
679 const TPoint& max = a.max();
680 return min.x < b.x && b.x < max.x &&
681 min.y < b.y && b.y < max.y &&
682 min.z < b.z && b.z < max.z;
689template <
typename T,
typename MMP>
inline
692 return collides(b, a);
699template <
typename T,
class MMP>
700std::ostream& operator<<(std::ostream& stream,
const Aabb3D<T, MMP>& aabb)
702 LASS_ENFORCE_STREAM(stream) <<
"{m=" << aabb.min() <<
", M=" << aabb.max() <<
"}";
710template<
typename T,
class MMP>
711io::XmlOStream& operator<<(io::XmlOStream& stream,
const Aabb3D<T, MMP>& aabb)
713 LASS_ENFORCE_STREAM(stream)
715 <<
"<min>" << aabb.min() <<
"</min>\n"
716 <<
"<max>" << aabb.max() <<
"</max>\n"
your momma's axis aligned bounding box.
const TVector size() const
Return size of bounding box per axis, max - min.
TSelf & operator+=(const TPoint &point)
Expand bounding box so it contains point.
const Aabb3D< T, MMP > operator+(const Point3D< T > &a, const Aabb3D< T, MMP > &b)
add a point to an AABB
const TValue volume() const
Returns volume of bounding box.
void clear()
set AABB to an empty box
const TPointH center() const
Return the center point of the bounding box.
bool intersects(const Aabb3D< T, MMP2 > &other) const
Check if two axis-aligned bounding boxes do intersect.
T distance(const Aabb3D< T, MMPa > &a, const Aabb3D< T, MMPb > &b)
distance between two AABBs
const TPoint random(RandomGenerator &random) const
Return a random point so that bounding box contains it.
const TPoint & min() const
return corner with smallest component values
void scale(TParam iScale)
Scale bounding box by scale iScale.
T distance(const Aabb3D< T, MMP > &a, const Point3D< T > &b)
distance between AABB and point
const TPoint & max() const
Return corner with largest component values.
Side classify(const TPoint &point) const
Classify if a point is in or outside the bounding box, or on its surface.
TSelf & operator=(const Aabb3D< T, MMP2 > &other)
assign one bounding box to another.
Result intersect(const Aabb3D< T, MMPa > &a, const Aabb3D< T, MMPb > &b, Aabb3D< T, MMPr > &result)
Calculate the intersection of two axis aligned bounding boxes.
const TValue area() const
Returns surface area of bounding box.
bool collides(const Aabb3D< T, MMP2 > &other) const
Check if two axis-aligned bounding boxes do dollide.
void grow(TParam iDistance)
Expand bounding box by distance iDistance.
void setMin(const TPoint &min)
set corner with smallest component values
const Aabb3D< T, MMPa > operator+(const Aabb3D< T, MMPa > &a, const Aabb3D< T, MMPb > &b)
join two AABBs
bool isEmpty() const
Return true if bounding box contains no points.
void setMax(const TPoint &max)
set corner with larges component values
bool isValid() const
internal check to see if AABB is valid.
const Aabb3D< T, MMP > operator+(const Aabb3D< T, MMP > &a, const Point3D< T > &b)
add a point to an AABB
bool contains(const TPoint &point) const
Returns true if point is inside bounding box or on its surface.
Aabb3D()
Construct an empty bounding box.
void swap(Aabb3D< T, MMP2 > &other)
swap two bounding boxes.
T abs(const T &x)
if x < 0 return -x, else return x.
set of geometrical primitives
Side
Different sides of a surface.
@ sOutside
outside the surface
@ sSurface
right on the surface
@ sInside
inside the surface
Result
meta information on the result you have from an operation like an intersection ...
@ rNone
operation has no answer, output arguments are meaningless
@ rOne
there's exactly one answer, 1 output argument contains the answer
Library for Assembled Shared Sources.
const TValue norm() const
Return norm of vector.