24#ifndef JAU_AABBOX3F_HPP_
25#define JAU_AABBOX3F_HPP_
71 : m_lo( bl_ ), m_hi( tr_ ) {
80 void setHigh(const
float hx, const
float hy, const
float hz) noexcept {
84 void setLow(
const float lx,
const float ly,
const float lz)
noexcept {
88 void computeCenter() noexcept {
89 ( ( m_center = m_hi ) += m_lo ) *= 0.5f;
100 m_center.
set(0, 0, 0);
118 float size() const noexcept {
return m_lo.
dist(m_hi); }
120 float width() const noexcept {
return m_hi.
x - m_lo.
x; }
122 float height() const noexcept {
return m_hi.
y - m_lo.
y; }
124 float depth() const noexcept {
return m_hi.
z - m_lo.
z; }
163 const float hx,
const float hy,
const float hz)
noexcept {
164 m_lo.
set(lx, ly, lz);
165 m_hi.
set(hx, hy, hz);
198 m_hi.
x += deltaRight;
216 m_lo.
y -= deltaBottom;
236 if (o.m_lo.x < m_lo.
x) {
239 if (o.m_lo.y < m_lo.
y) {
242 if (o.m_lo.z < m_lo.
z) {
247 if (o.m_hi.x > m_hi.
x) {
250 if (o.m_hi.y > m_hi.
y) {
253 if (o.m_hi.z > m_hi.
z) {
276 if (newBL.
x < m_lo.
x) {
279 if (newBL.
y < m_lo.
y) {
282 if (newBL.
z < m_lo.
z) {
290 if (newTR.
x > m_hi.
x) {
293 if (newTR.
y > m_hi.
y) {
296 if (newTR.
z > m_hi.
z) {
345 return resize(xyz[0], xyz[1], xyz[2]);
355 return resize(p.x, p.y, p.z);
362 bool contains(
const float x,
const float y)
const noexcept {
363 return !( x<m_lo.
x || x>m_hi.
x ||
364 y<m_lo.
y || y>m_hi.
y );
377 bool contains(
const float x,
const float y,
const float z)
const noexcept {
378 return !( x<m_lo.
x || x>m_hi.
x ||
379 y<m_lo.
y || y>m_hi.
y ||
380 z<m_lo.
z || z>m_hi.
z );
391 return !( m_hi.
x < o.m_lo.x ||
401 return m_hi.
x >= o.m_hi.x &&
402 m_hi.
y >= o.m_hi.y &&
403 m_hi.
z >= o.m_hi.z &&
404 m_lo.
x <= o.m_lo.x &&
405 m_lo.
y <= o.m_lo.y &&
419 if (w <= 0 || h <= 0) {
422 const float _w =
width();
423 const float _h =
height();
424 if (_w <= 0 || _h <= 0) {
427 const float x0 = m_lo.
x;
428 const float y0 = m_lo.
y;
453 const float dirX = ray.dir.x;
454 const float diffX = ray.orig.x - m_center.
x;
455 const float extX = m_hi.
x - m_center.
x;
456 if(
std::abs(diffX) > extX && diffX*dirX >= 0.0f )
return false;
458 const float dirY = ray.dir.y;
459 const float diffY = ray.orig.y - m_center.
y;
460 const float extY = m_hi.
y - m_center.
y;
461 if(
std::abs(diffY) > extY && diffY*dirY >= 0.0f )
return false;
463 const float dirZ = ray.dir.z;
464 const float diffZ = ray.orig.z - m_center.
z;
465 const float extZ = m_hi.
z - m_center.
z;
466 if(
std::abs(diffZ) > extZ && diffZ*dirZ >= 0.0f )
return false;
468 const float absDirY =
std::abs(dirY);
469 const float absDirZ =
std::abs(dirZ);
471 float f = dirY * diffZ - dirZ * diffY;
472 if(
std::abs(f) > extY*absDirZ + extZ*absDirY )
return false;
474 const float absDirX =
std::abs(dirX);
476 f = dirZ * diffX - dirX * diffZ;
477 if(
std::abs(f) > extX*absDirZ + extZ*absDirX )
return false;
479 f = dirX * diffY - dirY * diffX;
480 if(
std::abs(f) > extX*absDirY + extY*absDirX )
return false;
518 const bool assumeIntersection) {
519 float maxT[] = { -1.0f, -1.0f, -1.0f };
556 if(origin.
x < m_lo.
x) {
562 maxT[0] = (m_lo.
x - origin.
x) / dir.x;
564 }
else if(origin.
x > m_hi.
x) {
570 maxT[0] = (m_hi.
x - origin.
x) / dir.x;
575 if(origin.
y < m_lo.
y) {
581 maxT[1] = (m_lo.
y - origin.
y) / dir.y;
583 }
else if(origin.
y > m_hi.
y) {
589 maxT[1] = (m_hi.
y - origin.
y) / dir.y;
594 if(origin.
z < m_lo.
z) {
600 maxT[2] = (m_lo.
z - origin.
z) / dir.z;
602 }
else if(origin.
z > m_hi.
z) {
608 maxT[2] = (m_hi.
z - origin.
z) / dir.z;
621 if(maxT[1] > maxT[whichPlane]) { whichPlane = 1; }
622 if(maxT[2] > maxT[whichPlane]) { whichPlane = 2; }
624 if( !assumeIntersection ) {
638 switch( whichPlane ) {
640 result.
y = origin.
y + maxT[whichPlane] * dir.y;
641 if(result.
y < m_lo.
y - epsilon || result.
y > m_hi.
y + epsilon) {
return false; }
642 result.
z = origin.
z + maxT[whichPlane] * dir.z;
643 if(result.
z < m_lo.
z - epsilon || result.
z > m_hi.
z + epsilon) {
return false; }
646 result.
x = origin.
x + maxT[whichPlane] * dir.x;
647 if(result.
x < m_lo.
x - epsilon || result.
x > m_hi.
x + epsilon) {
return false; }
648 result.
z = origin.
z + maxT[whichPlane] * dir.z;
649 if(result.
z < m_lo.
z - epsilon || result.
z > m_hi.
z + epsilon) {
return false; }
652 result.
x = origin.
x + maxT[whichPlane] * dir.x;
653 if(result.
x < m_lo.
x - epsilon || result.
x > m_hi.
x + epsilon) {
return false; }
654 result.
y = origin.
y + maxT[whichPlane] * dir.y;
655 if(result.
y < m_lo.
y - epsilon || result.
y > m_hi.
y + epsilon) {
return false; }
661 switch( whichPlane ) {
663 result.
y = origin.
y + maxT[whichPlane] * dir.y;
664 result.
z = origin.
z + maxT[whichPlane] * dir.z;
667 result.
x = origin.
x + maxT[whichPlane] * dir.x;
668 result.
z = origin.
z + maxT[whichPlane] * dir.z;
671 result.
x = origin.
x + maxT[whichPlane] * dir.x;
672 result.
y = origin.
y + maxT[whichPlane] * dir.y;
682 return "aabb[bl " + m_lo.
toString() +
Class template jau::function is a general-purpose static-polymorphic function wrapper.
constexpr Vector3F & set(const Vec2f &o, const value_type z_) noexcept
TODO constexpr bool operator<=>(const vec3f_t& rhs ) const noexcept { return ... }.
constexpr value_type dist(const Vector3F &o) const noexcept
Return the distance between this vector and the given one.
std::string toString() const noexcept
Axis Aligned Bounding Box.
bool contains(const float x, const float y) const noexcept
Check if the 2D point is bounded/contained by this aabbox3f.
AABBox3f & resizeWidth(const float deltaLeft, const float deltaRight) noexcept
Resize width of this aabbox3f with explicit left- and right delta values.
AABBox3f & setSize(const Vec3f &low, const Vec3f &high) noexcept
Set size of the aabbox3f specifying the coordinates of the low and high.
AABBox3f & resizeHeight(const float deltaBottom, const float deltaTop) noexcept
Resize height of this aabbox3f with explicit bottom- and top delta values.
AABBox3f & operator=(const AABBox3f &) noexcept=default
float depth() const noexcept
float width() const noexcept
float size() const noexcept
Get the size of this aabbox3f where the size is represented by the length of the vector between low a...
AABBox3f & setSize(const float low[], const float high[]) noexcept
Set size of the aabbox3f specifying the coordinates of the low and high.
float height() const noexcept
AABBox3f & resize(const AABBox3f &newBox, transform_vec3f_func &transform) noexcept
Resize the aabbox3f to encapsulate another AABox, which will be transformed on the fly first.
bool getRayIntersection(Vec3f &result, const Ray3f &ray, const float epsilon, const bool assumeIntersection)
Return intersection of a Ray with this bounding box, or false if none exist.
bool contains(const Point2f &p) const noexcept
Check if the 2D point is bounded/contained by this aabbox3f.
std::string toString() const noexcept
bool contains(const Point3f &p) const noexcept
Check if the 3D point is bounded/contained by this aabbox3f.
AABBox3f(const Point3f &bl_, const Point3f &tr_) noexcept
Create an aabbox3f with given bl (low) and tr (high)
bool hasZeroArea2D() const noexcept
Return true if get2DArea() is FloatUtil#isZero(float), considering epsilon.
float volume() const noexcept
Returns the volume, i.e.
AABBox3f & reset() noexcept
Reset this box to the inverse low/high, allowing the next resize(float, float, float) command to hit.
bool intersects2DRegion(const float x, const float y, const float w, const float h) const noexcept
Check if there is a common region between this AABBox and the passed 2D region irrespective of z rang...
float area2D() const noexcept
Returns the assumed 2D area, i.e.
constexpr AABBox3f(AABBox3f &&o) noexcept=default
bool intersectsRay(const Ray3f ray) const noexcept
Check if Ray intersects this bounding box.
AABBox3f & resize(const float xyz[]) noexcept
Resize the aabbox3f to encapsulate the passed xyz-coordinates.
AABBox3f() noexcept
Create an Axis Aligned bounding box (aabbox3f) where the low and and high MAX float Values.
const Point3f & high() const noexcept
Returns the maximum right-top-near (xyz) coordinate.
AABBox3f & setSize(const float lx, const float ly, const float lz, const float hx, const float hy, const float hz) noexcept
Set size of the aabbox3f specifying the coordinates of the low and high.
bool hasZeroVolume() const noexcept
Return true if getVolume() is FloatUtil#isZero(float), considering epsilon.
jau::function< jau::math::Vec3f(const jau::math::Vec3f &)> transform_vec3f_func
General purpose Vec3f transform function.
bool intersects(const AABBox3f &o) const noexcept
Returns whether this aabbox3f intersects (partially contains) given aabbox3f.
const Point3f & low() const noexcept
Returns the minimum left-bottom-far (xyz) coordinate.
constexpr AABBox3f(const AABBox3f &o) noexcept=default
const Point3f & center() const noexcept
Returns computed center of this aabbox3f of low() and high().
AABBox3f & resize(const float x, const float y, const float z) noexcept
Resize the aabbox3f to encapsulate the passed xyz-coordinates.
bool contains(const float x, const float y, const float z) const noexcept
Check if the 3D point is bounded/contained by this aabbox3f.
AABBox3f & resize(const AABBox3f &o) noexcept
Resize the aabbox3f to encapsulate another AABox.
AABBox3f & resize(const Point3f &p) noexcept
Resize the aabbox3f to encapsulate the passed xyz-coordinates.
bool contains(const AABBox3f &o) const noexcept
Returns whether this aabbox3f fully contains given aabbox3f.
AABBox3f & operator=(AABBox3f &&) noexcept=default
constexpr uint32_t bit_value(const float a) noexcept
Returns the unsigned integer representation according to IEEE 754 (IEC 559) single floating-point bit...
std::enable_if< std::is_floating_point_v< T >, bool >::type constexpr is_zero(const T &a, const T &epsilon=std::numeric_limits< T >::epsilon()) noexcept
Returns true if the given value is less than epsilon, w/ epsilon > 0.
constexpr uint32_t const float_iec559_sign_bit
Signed bit 31 of IEEE 754 (IEC 559) single float-point bit layout, i.e.
constexpr T max(const T x, const T y) noexcept
Returns the maximum of two integrals (w/ branching) in O(1)
constexpr T abs(const T x) noexcept
Returns the absolute value of an arithmetic number (w/ branching) in O(1)
Simple compound denoting a ray.
Point3F< T > orig
Origin of Ray.
Vector3F< T > dir
Normalized direction vector of ray.