From b4739d3ca4bc31d8b4e12b0c8c0979201278c3ca Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 26 Aug 2023 18:22:45 +0200 Subject: [PATCH] Base: fix clang-tidy warnings in BoundBox.h --- src/Base/BoundBox.h | 916 ++++++++++++++------------ src/Mod/Mesh/App/Core/TrimByPlane.cpp | 2 +- src/Mod/Mesh/App/Mesh.cpp | 35 +- 3 files changed, 516 insertions(+), 437 deletions(-) diff --git a/src/Base/BoundBox.h b/src/Base/BoundBox.h index a503203278..e8db802395 100644 --- a/src/Base/BoundBox.h +++ b/src/Base/BoundBox.h @@ -24,6 +24,7 @@ #ifndef BASE_BOUNDBOX_H #define BASE_BOUNDBOX_H +#include #include #include "Matrix.h" #include "Tools2D.h" @@ -35,53 +36,55 @@ namespace Base { class ViewProjMethod; /** The 3D bounding box class. */ -template +template class BoundBox3 { // helper function - static bool isOnRayW(_Precision, _Precision, _Precision); - static bool isOnRayS(_Precision, _Precision, _Precision); + static bool isOnRayW(Precision min, Precision max, Precision val); + static bool isOnRayS(Precision min, Precision max, Precision val); public: - using num_type = _Precision; + using num_type = Precision; using traits_type = float_traits; /** Public attributes */ //@{ - _Precision MinX; - _Precision MinY; - _Precision MinZ; - _Precision MaxX; - _Precision MaxY; - _Precision MaxZ; + Precision MinX; + Precision MinY; + Precision MinZ; + Precision MaxX; + Precision MaxY; + Precision MaxZ; //@} /** Builds box from pairs of x,y,z values. */ - inline explicit BoundBox3 (_Precision fMinX = std::numeric_limits<_Precision>::max(), - _Precision fMinY = std::numeric_limits<_Precision>::max(), - _Precision fMinZ = std::numeric_limits<_Precision>::max(), - _Precision fMaxX = -std::numeric_limits<_Precision>::max(), - _Precision fMaxY = -std::numeric_limits<_Precision>::max(), - _Precision fMaxZ = -std::numeric_limits<_Precision>::max()); - BoundBox3 (const BoundBox3<_Precision> &rcBB) { *this = rcBB; } + inline explicit BoundBox3 (Precision fMinX = std::numeric_limits::max(), + Precision fMinY = std::numeric_limits::max(), + Precision fMinZ = std::numeric_limits::max(), + Precision fMaxX = -std::numeric_limits::max(), + Precision fMaxY = -std::numeric_limits::max(), + Precision fMaxZ = -std::numeric_limits::max()); + BoundBox3 (const BoundBox3 &rcBB) = default; + BoundBox3 (BoundBox3 &&rcBB) noexcept = default; /** Builds box from an array of points. */ - inline BoundBox3 (const Vector3<_Precision> *pclVect, std::size_t ulCt); + inline BoundBox3 (const Vector3 *pclVect, std::size_t ulCt); /** Defines a bounding box around the center \a rcCnt with the * distances \a fDistance in each coordinate. */ - BoundBox3 (const Vector3<_Precision> &rcCnt, _Precision fDistance); + BoundBox3 (const Vector3& point, Precision distance); ~BoundBox3 (); /// Assignment operator - inline BoundBox3<_Precision>& operator = (const BoundBox3<_Precision> &rcBound); + inline BoundBox3& operator = (const BoundBox3 &rcBound) = default; + inline BoundBox3& operator = (BoundBox3 &&rcBound) noexcept = default; /** Methods for intersection, cuttíng and union of bounding boxes */ //@{ /** Checks for intersection. */ - inline bool Intersect (const BoundBox3<_Precision> &rcBB) const; + inline bool Intersect (const BoundBox3 &rcBB) const; /** Checks for intersection. */ - inline bool operator && (const BoundBox3<_Precision> &rcBB) const; + inline bool operator && (const BoundBox3 &rcBB) const; /** Checks for intersection. */ inline bool Intersect (const BoundBox2d &rcBB) const; /** Checks for intersection. */ @@ -89,13 +92,13 @@ public: /** Computes the intersection between two bounding boxes. * The result is also a bounding box. */ - BoundBox3<_Precision> Intersected (const BoundBox3<_Precision> &rcBB) const; + BoundBox3 Intersected (const BoundBox3 &rcBB) const; /** The union of two bounding boxes. */ - BoundBox3<_Precision> United (const BoundBox3<_Precision> &rcBB) const; + BoundBox3 United (const BoundBox3 &rcBB) const; /** Appends the point to the box. The box can grow but not shrink. */ - inline void Add (const Vector3<_Precision> &rclVect); + inline void Add (const Vector3 &rclVect); /** Appends the bounding box to this box. The box can grow but not shrink. */ - inline void Add (const BoundBox3<_Precision> &rcBB); + inline void Add (const BoundBox3 &rcBB); //@} /** Test methods */ @@ -103,11 +106,11 @@ public: /** Checks if this point lies inside the box. * @note It's up to the client programmer to make sure that this bounding box is valid. */ - inline bool IsInBox (const Vector3<_Precision> &rcVct) const; + inline bool IsInBox (const Vector3 &rcVct) const; /** Checks if this 3D box lies inside the box. * @note It's up to the client programmer to make sure that both bounding boxes are valid. */ - inline bool IsInBox (const BoundBox3<_Precision> &rcBB) const; + inline bool IsInBox (const BoundBox3 &rcBB) const; /** Checks if this 2D box lies inside the box. * @note It's up to the client programmer to make sure that both bounding boxes are valid. */ @@ -118,312 +121,354 @@ public: enum OCTANT {OCT_LDB = 0, OCT_RDB, OCT_LUB, OCT_RUB, OCT_LDF, OCT_RDF, OCT_LUF, OCT_RUF}; - bool GetOctantFromVector (const Vector3<_Precision> &rclVct, OCTANT &rclOctant) const; - BoundBox3<_Precision> CalcOctant (typename BoundBox3<_Precision>::OCTANT Octant) const; + bool GetOctantFromVector (const Vector3 &rclVct, OCTANT &rclOctant) const; + BoundBox3 CalcOctant (typename BoundBox3::OCTANT Octant) const; enum SIDE { LEFT =0, RIGHT=1, TOP=2, BOTTOM=3, FRONT=4, BACK=5, INVALID=255 }; + enum CORNER { + TLB = 0, // top-left-back + TLF = 1, // top-left-front + TRF = 2, // top-right-front + TRB = 3, // top-right-back + BLB = 4, // bottom-left-back + BLF = 5, // bottom-left-front + BRF = 6, // bottom-right-front + BRB = 7, // bottom-right-back + }; + enum EDGE { + TLB_TLF = 0, + TLF_TRF = 1, + TRF_TRB = 2, + TRB_TLB = 3, + BLB_BLF = 4, + BLF_BRF = 5, + BRF_BRB = 6, + BRB_BLB = 7, + TLB_BLB = 8, + TLF_BLF = 9, + TRF_BRF = 10, + TRB_BRB = 11 + }; /** * Returns the corner point \a usPoint. - * 0: front,bottom,left 1: front,bottom,right - * 2: front,top,right 3: front,top,left - * 4: back,bottom,left 5: back,bottom,right - * 6: back,top,right 7: back,top,left */ - inline Vector3<_Precision> CalcPoint (unsigned short usPoint) const; + inline Vector3 CalcPoint (unsigned short usPoint) const; /** Returns the plane of the given side. */ - void CalcPlane (unsigned short usPlane, Vector3<_Precision>& rBase, Vector3<_Precision>& rNormal ) const; + void CalcPlane (unsigned short usPlane, Vector3& rBase, + Vector3& rNormal) const; /** Calculates the two points of an edge. - * 0. edge P0-P1 1. edge P1-P2 2. edge P2-P3 - * 3. edge P3-P0 4. edge P4-P5 5. edge P5-P6 - * 6. edge P6-P7 7. edge P7-P4 8. edge P0-P4 - * 9. edge P1-P5 10. edge P2-P6 11. edge P3-P7 */ - bool CalcEdge (unsigned short usEdge, Vector3<_Precision>& rcP0, Vector3<_Precision>& rcP1) const; + bool CalcEdge (unsigned short usEdge, Vector3& rcP0, Vector3& rcP1) const; /** Intersection point of an inner search ray with the bounding box, built of * the base \a rcVct and the direction \a rcVctDir. \a rcVct must lie inside the * bounding box. */ - bool IntersectionPoint (const Vector3<_Precision> &rcVct, const Vector3<_Precision> &rcVctDir, Vector3<_Precision>& cVctRes, _Precision epsilon) const; + bool IntersectionPoint (const Vector3 &rcVct, + const Vector3 &rcVctDir, + Vector3& cVctRes, + Precision epsilon) const; /** Checks for intersection with line incl. search tolerance. */ - bool IsCutLine ( const Vector3<_Precision>& rcBase, const Vector3<_Precision>& rcDir, _Precision fTolerance = 0.0f) const; + bool IsCutLine (const Vector3& rcBase, + const Vector3& rcDir, + Precision fTolerance = 0.0F) const; /** Checks if this plane specified by (point,normal) cuts this box. * @note It's up to the client programmer to make sure that this bounding box is valid. */ - inline bool IsCutPlane (const Vector3<_Precision> &rclBase, const Vector3<_Precision> &rclNormal) const; + inline bool IsCutPlane (const Vector3 &rclBase, + const Vector3 &rclNormal) const; /** Computes the intersection points of line and bounding box. */ - bool IntersectWithLine (const Vector3<_Precision>& rcBase, const Vector3<_Precision>& rcDir, Vector3<_Precision>& rcP0, Vector3<_Precision>& rcP1) const; + bool IntersectWithLine (const Vector3& rcBase, + const Vector3& rcDir, + Vector3& rcP0, + Vector3& rcP1) const; /** Computes the intersection point of line and a plane of the bounding box. */ - bool IntersectPlaneWithLine (unsigned short usSide, const Vector3<_Precision>& rcBase, const Vector3<_Precision>& rcDir, - Vector3<_Precision>& rcP0) const; + bool IntersectPlaneWithLine (unsigned short usSide, + const Vector3& rcBase, + const Vector3& rcDir, + Vector3& rcP0) const; /** Returns the side of the bounding box the ray exits. */ - typename BoundBox3<_Precision>::SIDE GetSideFromRay (const Vector3<_Precision> &rclPt, const Vector3<_Precision> &rclDir) const; + typename BoundBox3::SIDE GetSideFromRay (const Vector3 &rclPt, + const Vector3 &rclDir) const; /** Returns the side of the bounding box the ray exits. */ - typename BoundBox3<_Precision>::SIDE GetSideFromRay (const Vector3<_Precision> &rclPt, const Vector3<_Precision> &rclDir, Vector3<_Precision>& rcInt) const; + typename BoundBox3::SIDE GetSideFromRay (const Vector3 &rclPt, + const Vector3 &rclDir, + Vector3& rcInt) const; /** * Searches for the closest point of the bounding box. */ - Vector3<_Precision> ClosestPoint (const Vector3<_Precision> &rclPt) const; + Vector3 ClosestPoint (const Vector3 &rclPt) const; /** Projects the box onto a plane and returns a 2D box. */ - BoundBox2d ProjectBox(const ViewProjMethod *rclP) const; + BoundBox2d ProjectBox(const ViewProjMethod* proj) const; /** Transform the corners of this box with the given matrix and create a new bounding box. * @note It's up to the client programmer to make sure that this bounding box is valid. */ - BoundBox3<_Precision> Transformed(const Matrix4D& mat) const; + BoundBox3 Transformed(const Matrix4D& mat) const; /** Returns the center of the box. */ - inline Vector3<_Precision> GetCenter () const; + inline Vector3 GetCenter () const; /** Compute the diagonal length of this bounding box. * @note It's up to the client programmer to make sure that this bounding box is valid. */ - inline _Precision CalcDiagonalLength () const; + inline Precision CalcDiagonalLength () const; void SetVoid (); /** Enlarges the box with \a fLen. */ - inline void Enlarge (_Precision fLen); + inline void Enlarge (Precision fLen); /** Shrinks the box with \a fLen. */ - inline void Shrink (_Precision fLen); + inline void Shrink (Precision fLen); /** Calculates expansion in x-direction. */ - inline _Precision LengthX () const; + inline Precision LengthX () const; /** Calculates expansion in y-direction. */ - inline _Precision LengthY () const; + inline Precision LengthY () const; /** Calculates expansion in z-direction. */ - inline _Precision LengthZ () const; + inline Precision LengthZ () const; /** Moves in x-direction. */ - inline void MoveX (_Precision f); + inline void MoveX (Precision value); /** Moves in y-direction. */ - inline void MoveY (_Precision f); + inline void MoveY (Precision value); /** Moves in z-direction. */ - inline void MoveZ (_Precision f); + inline void MoveZ (Precision value); /** Scales in x-direction. */ - inline void ScaleX (_Precision f); + inline void ScaleX (Precision value); /** Scales in y-direction. */ - inline void ScaleY (_Precision f); + inline void ScaleY (Precision value); /** Scales in z-direction. */ - inline void ScaleZ (_Precision f); + inline void ScaleZ (Precision value); /** Prints the values to stream. */ void Print (std::ostream&) const; }; -template -bool BoundBox3<_Precision>::isOnRayW(_Precision A, _Precision B, _Precision K) +template +bool BoundBox3::isOnRayW(Precision min, Precision max, Precision val) { - // Checks if point K lies on the ray [A,B] - return ((A <= K) && (K <= B)); + // Checks if point val lies on the ray [min,max] + return ((min <= val) && (val <= max)); } -template -bool BoundBox3<_Precision>::isOnRayS(_Precision A, _Precision B, _Precision K) +template +bool BoundBox3::isOnRayS(Precision min, Precision max, Precision val) { - // Checks if point K lies on the ray [A,B[ - return ((A <= K) && (K < B)); + // Checks if point val lies on the ray [min,max[ + return ((min <= val) && (val < max)); } -template -inline BoundBox3<_Precision>::BoundBox3 (_Precision fMinX, _Precision fMinY, _Precision fMinZ, - _Precision fMaxX, _Precision fMaxY, _Precision fMaxZ) +// NOLINTBEGIN(bugprone-easily-swappable-parameters) +template +inline BoundBox3::BoundBox3 (Precision fMinX, Precision fMinY, Precision fMinZ, + Precision fMaxX, Precision fMaxY, Precision fMaxZ) : MinX(fMinX), MinY(fMinY), MinZ(fMinZ), MaxX(fMaxX), MaxY(fMaxY), MaxZ(fMaxZ) { } +// NOLINTEND(bugprone-easily-swappable-parameters) -template -inline BoundBox3<_Precision>::BoundBox3 (const Vector3<_Precision> *pclVect, std::size_t ulCt) - : MinX( std::numeric_limits<_Precision>::max()) - , MinY( std::numeric_limits<_Precision>::max()) - , MinZ( std::numeric_limits<_Precision>::max()) - , MaxX(-std::numeric_limits<_Precision>::max()) - , MaxY(-std::numeric_limits<_Precision>::max()) - , MaxZ(-std::numeric_limits<_Precision>::max()) +template +inline BoundBox3::BoundBox3 (const Vector3 *pclVect, std::size_t ulCt) + : MinX( std::numeric_limits::max()) + , MinY( std::numeric_limits::max()) + , MinZ( std::numeric_limits::max()) + , MaxX(-std::numeric_limits::max()) + , MaxY(-std::numeric_limits::max()) + , MaxZ(-std::numeric_limits::max()) { - const Vector3<_Precision> *pI = nullptr, *pEnd = pclVect + ulCt; + const Vector3 *pI = nullptr; + const Vector3 *pEnd = pclVect + ulCt; for (pI = pclVect; pI < pEnd; ++pI) { - MinX = std::min<_Precision>(MinX, pI->x); - MinY = std::min<_Precision>(MinY, pI->y); - MinZ = std::min<_Precision>(MinZ, pI->z); - MaxX = std::max<_Precision>(MaxX, pI->x); - MaxY = std::max<_Precision>(MaxY, pI->y); - MaxZ = std::max<_Precision>(MaxZ, pI->z); + MinX = std::min(MinX, pI->x); + MinY = std::min(MinY, pI->y); + MinZ = std::min(MinZ, pI->z); + MaxX = std::max(MaxX, pI->x); + MaxY = std::max(MaxY, pI->y); + MaxZ = std::max(MaxZ, pI->z); } } -template -inline BoundBox3<_Precision>::BoundBox3 (const Vector3<_Precision> &rcVector, _Precision fDistance) +template +inline BoundBox3::BoundBox3 (const Vector3& point, Precision distance) + : MinX(point.x - distance) + , MinY(point.y - distance) + , MinZ(point.z - distance) + , MaxX(point.x + distance) + , MaxY(point.y + distance) + , MaxZ(point.z + distance) { - MinX = rcVector.x - fDistance; - MaxX = rcVector.x + fDistance; - MinY = rcVector.y - fDistance; - MaxY = rcVector.y + fDistance; - MinZ = rcVector.z - fDistance; - MaxZ = rcVector.z + fDistance; } -template -inline BoundBox3<_Precision>::~BoundBox3 () = default; +template +inline BoundBox3::~BoundBox3 () = default; -template -inline BoundBox3<_Precision>& BoundBox3<_Precision>::operator = (const BoundBox3<_Precision> &rcBound) +template +inline bool BoundBox3::Intersect (const BoundBox3 &rcBB) const { - MinX = rcBound.MinX; - MinY = rcBound.MinY; - MinZ = rcBound.MinZ; - MaxX = rcBound.MaxX; - MaxY = rcBound.MaxY; - MaxZ = rcBound.MaxZ; - return *this; -} - -template -inline bool BoundBox3<_Precision>::Intersect (const BoundBox3<_Precision> &rcBB) const -{ - if (rcBB.MaxX < this->MinX || rcBB.MinX > this->MaxX) + if (rcBB.MaxX < this->MinX || rcBB.MinX > this->MaxX) { return false; - if (rcBB.MaxY < this->MinY || rcBB.MinY > this->MaxY) + } + if (rcBB.MaxY < this->MinY || rcBB.MinY > this->MaxY) { return false; - if (rcBB.MaxZ < this->MinZ || rcBB.MinZ > this->MaxZ) + } + if (rcBB.MaxZ < this->MinZ || rcBB.MinZ > this->MaxZ) { return false; + } return true; } -template -bool BoundBox3<_Precision>::operator && (const BoundBox3<_Precision> &rcBB) const +template +bool BoundBox3::operator && (const BoundBox3 &rcBB) const { return Intersect(rcBB); } -template -inline bool BoundBox3<_Precision>::Intersect (const BoundBox2d &rcBB) const +template +inline bool BoundBox3::Intersect (const BoundBox2d &rcBB) const { - if (rcBB.MaxX < this->MinX || rcBB.MinX > this->MaxX) + if (rcBB.MaxX < this->MinX || rcBB.MinX > this->MaxX) { return false; - if (rcBB.MaxY < this->MinY || rcBB.MinY > this->MaxY) + } + if (rcBB.MaxY < this->MinY || rcBB.MinY > this->MaxY) { return false; + } return true; } -template -inline bool BoundBox3<_Precision>::operator && (const BoundBox2d &rcBB) const +template +inline bool BoundBox3::operator && (const BoundBox2d &rcBB) const { return Intersect(rcBB); } -template -inline BoundBox3<_Precision> BoundBox3<_Precision>::Intersected(const BoundBox3<_Precision> &rcBB) const +template +inline BoundBox3 +BoundBox3::Intersected(const BoundBox3 &rcBB) const { - BoundBox3<_Precision> cBBRes; + BoundBox3 cBBRes; - cBBRes.MinX = std::max<_Precision> (MinX, rcBB.MinX); - cBBRes.MaxX = std::min<_Precision> (MaxX, rcBB.MaxX); - cBBRes.MinY = std::max<_Precision> (MinY, rcBB.MinY); - cBBRes.MaxY = std::min<_Precision> (MaxY, rcBB.MaxY); - cBBRes.MinZ = std::max<_Precision> (MinZ, rcBB.MinZ); - cBBRes.MaxZ = std::min<_Precision> (MaxZ, rcBB.MaxZ); + cBBRes.MinX = std::max (MinX, rcBB.MinX); + cBBRes.MaxX = std::min (MaxX, rcBB.MaxX); + cBBRes.MinY = std::max (MinY, rcBB.MinY); + cBBRes.MaxY = std::min (MaxY, rcBB.MaxY); + cBBRes.MinZ = std::max (MinZ, rcBB.MinZ); + cBBRes.MaxZ = std::min (MaxZ, rcBB.MaxZ); return cBBRes; } -template -inline BoundBox3<_Precision> BoundBox3<_Precision>::United(const BoundBox3<_Precision> &rcBB) const +template +inline BoundBox3 BoundBox3::United(const BoundBox3 &rcBB) const { - BoundBox3<_Precision> cBBRes; + BoundBox3 cBBRes; - cBBRes.MinX = std::min<_Precision> (MinX, rcBB.MinX); - cBBRes.MaxX = std::max<_Precision> (MaxX, rcBB.MaxX); - cBBRes.MinY = std::min<_Precision> (MinY, rcBB.MinY); - cBBRes.MaxY = std::max<_Precision> (MaxY, rcBB.MaxY); - cBBRes.MinZ = std::min<_Precision> (MinZ, rcBB.MinZ); - cBBRes.MaxZ = std::max<_Precision> (MaxZ, rcBB.MaxZ); + cBBRes.MinX = std::min (MinX, rcBB.MinX); + cBBRes.MaxX = std::max (MaxX, rcBB.MaxX); + cBBRes.MinY = std::min (MinY, rcBB.MinY); + cBBRes.MaxY = std::max (MaxY, rcBB.MaxY); + cBBRes.MinZ = std::min (MinZ, rcBB.MinZ); + cBBRes.MaxZ = std::max (MaxZ, rcBB.MaxZ); return cBBRes; } -template -inline void BoundBox3<_Precision>::Add (const Vector3<_Precision> &rclVect) +template +inline void BoundBox3::Add (const Vector3 &rclVect) { - this->MinX = std::min<_Precision>(this->MinX, rclVect.x); - this->MinY = std::min<_Precision>(this->MinY, rclVect.y); - this->MinZ = std::min<_Precision>(this->MinZ, rclVect.z); - this->MaxX = std::max<_Precision>(this->MaxX, rclVect.x); - this->MaxY = std::max<_Precision>(this->MaxY, rclVect.y); - this->MaxZ = std::max<_Precision>(this->MaxZ, rclVect.z); + this->MinX = std::min(this->MinX, rclVect.x); + this->MinY = std::min(this->MinY, rclVect.y); + this->MinZ = std::min(this->MinZ, rclVect.z); + this->MaxX = std::max(this->MaxX, rclVect.x); + this->MaxY = std::max(this->MaxY, rclVect.y); + this->MaxZ = std::max(this->MaxZ, rclVect.z); } -template -inline void BoundBox3<_Precision>::Add (const BoundBox3<_Precision> &rcBB) +template +inline void BoundBox3::Add (const BoundBox3 &rcBB) { - this->MinX = std::min<_Precision> (this->MinX, rcBB.MinX); - this->MaxX = std::max<_Precision> (this->MaxX, rcBB.MaxX); - this->MinY = std::min<_Precision> (this->MinY, rcBB.MinY); - this->MaxY = std::max<_Precision> (this->MaxY, rcBB.MaxY); - this->MinZ = std::min<_Precision> (this->MinZ, rcBB.MinZ); - this->MaxZ = std::max<_Precision> (this->MaxZ, rcBB.MaxZ); + this->MinX = std::min (this->MinX, rcBB.MinX); + this->MaxX = std::max (this->MaxX, rcBB.MaxX); + this->MinY = std::min (this->MinY, rcBB.MinY); + this->MaxY = std::max (this->MaxY, rcBB.MaxY); + this->MinZ = std::min (this->MinZ, rcBB.MinZ); + this->MaxZ = std::max (this->MaxZ, rcBB.MaxZ); } -template -inline bool BoundBox3<_Precision>::IsInBox (const Vector3<_Precision> &rcVct) const +template +inline bool BoundBox3::IsInBox (const Vector3 &rcVct) const { - if (rcVct.x < this->MinX || rcVct.x > this->MaxX) + if (rcVct.x < this->MinX || rcVct.x > this->MaxX) { return false; - if (rcVct.y < this->MinY || rcVct.y > this->MaxY) + } + if (rcVct.y < this->MinY || rcVct.y > this->MaxY) { return false; - if (rcVct.z < this->MinZ || rcVct.z > this->MaxZ) + } + if (rcVct.z < this->MinZ || rcVct.z > this->MaxZ) { return false; + } return true; } -template -inline bool BoundBox3<_Precision>::IsInBox (const BoundBox3<_Precision> &rcBB) const +template +inline bool BoundBox3::IsInBox (const BoundBox3 &rcBB) const { - if (rcBB.MinX < this->MinX || rcBB.MaxX > this->MaxX) + if (rcBB.MinX < this->MinX || rcBB.MaxX > this->MaxX) { return false; - if (rcBB.MinY < this->MinY || rcBB.MaxY > this->MaxY) + } + if (rcBB.MinY < this->MinY || rcBB.MaxY > this->MaxY) { return false; - if (rcBB.MinZ < this->MinZ || rcBB.MaxZ > this->MaxZ) + } + if (rcBB.MinZ < this->MinZ || rcBB.MaxZ > this->MaxZ) { return false; + } return true; } -template -inline bool BoundBox3<_Precision>::IsInBox (const BoundBox2d &rcBB) const +template +inline bool BoundBox3::IsInBox (const BoundBox2d &rcBB) const { - if (rcBB.MinX < this->MinX || rcBB.MaxX > this->MaxX) + if (rcBB.MinX < this->MinX || rcBB.MaxX > this->MaxX) { return false; - if (rcBB.MinY < this->MinY || rcBB.MaxY > this->MaxY) + } + if (rcBB.MinY < this->MinY || rcBB.MaxY > this->MaxY) { return false; + } return true; } -template -inline bool BoundBox3<_Precision>::IsValid () const +template +inline bool BoundBox3::IsValid () const { return ((MinX <= MaxX) && (MinY <= MaxY) && (MinZ <= MaxZ)); } -template -inline bool BoundBox3<_Precision>::GetOctantFromVector (const Vector3<_Precision> &rclVct, OCTANT &rclOctant) const +template +inline bool BoundBox3::GetOctantFromVector (const Vector3 &rclVct, + OCTANT &rclOctant) const { - if (!IsInBox (rclVct)) + if (!IsInBox (rclVct)) { return false; + } unsigned short usNdx = 0; - if (isOnRayS ((MinX + MaxX)/2, MaxX, rclVct.x)) // left/RIGHT + if (isOnRayS ((MinX + MaxX)/2, MaxX, rclVct.x)) { // left/RIGHT usNdx |= 1; - if (isOnRayS ((MinY + MaxY)/2, MaxY, rclVct.y)) // down/UP + } + if (isOnRayS ((MinY + MaxY)/2, MaxY, rclVct.y)) { // down/UP usNdx |= 2; - if (isOnRayS ((MinZ + MaxZ)/2, MaxZ, rclVct.z)) // back/FRONT + } + if (isOnRayS ((MinZ + MaxZ)/2, MaxZ, rclVct.z)) { // back/FRONT usNdx |= 4; + } rclOctant = static_cast(usNdx); return true; } -template -inline BoundBox3<_Precision> BoundBox3<_Precision>::CalcOctant (typename BoundBox3< _Precision >::OCTANT Octant) const +template +inline BoundBox3 +BoundBox3::CalcOctant (typename BoundBox3< Precision >::OCTANT Octant) const { - BoundBox3<_Precision> cOct (*this); + BoundBox3 cOct (*this); switch (Octant) { case OCT_LDB: @@ -477,112 +522,117 @@ inline BoundBox3<_Precision> BoundBox3<_Precision>::CalcOctant (typename BoundBo return cOct; } -template -inline Vector3<_Precision> BoundBox3<_Precision>::CalcPoint (unsigned short usPoint) const +template +inline Vector3 BoundBox3::CalcPoint (unsigned short usPoint) const { switch (usPoint) { - case 0: return Vector3<_Precision>(MinX, MinY, MaxZ); - case 1: return Vector3<_Precision>(MaxX, MinY, MaxZ); - case 2: return Vector3<_Precision>(MaxX, MaxY, MaxZ); - case 3: return Vector3<_Precision>(MinX, MaxY, MaxZ); - case 4: return Vector3<_Precision>(MinX, MinY, MinZ); - case 5: return Vector3<_Precision>(MaxX, MinY, MinZ); - case 6: return Vector3<_Precision>(MaxX, MaxY, MinZ); - case 7: return Vector3<_Precision>(MinX, MaxY, MinZ); + case TLB: return Vector3(MinX, MinY, MaxZ); + case TLF: return Vector3(MaxX, MinY, MaxZ); + case TRF: return Vector3(MaxX, MaxY, MaxZ); + case TRB: return Vector3(MinX, MaxY, MaxZ); + case BLB: return Vector3(MinX, MinY, MinZ); + case BLF: return Vector3(MaxX, MinY, MinZ); + case BRF: return Vector3(MaxX, MaxY, MinZ); + case BRB: return Vector3(MinX, MaxY, MinZ); } - return Vector3<_Precision>(); + return Vector3(); } -template -inline void BoundBox3<_Precision>::CalcPlane (unsigned short usPlane, Vector3<_Precision>& rBase, Vector3<_Precision>& rNormal) const +// NOLINTBEGIN(bugprone-easily-swappable-parameters) +template +inline void BoundBox3::CalcPlane (unsigned short usPlane, + Vector3& rBase, + Vector3& rNormal) const +// NOLINTEND(bugprone-easily-swappable-parameters) { switch (usPlane) { case LEFT: rBase.Set(MinX, MinY, MaxZ); - rNormal.Set(1.0f, 0.0f, 0.0f); + rNormal.Set(1.0F, 0.0F, 0.0F); break; case RIGHT: rBase.Set(MaxX, MinY, MaxZ); - rNormal.Set(1.0f, 0.0f, 0.0f); + rNormal.Set(1.0F, 0.0F, 0.0F); break; case TOP: rBase.Set(MinX, MaxY, MaxZ); - rNormal.Set(0.0f, 1.0f, 0.0f); + rNormal.Set(0.0F, 1.0F, 0.0F); break; case BOTTOM: rBase.Set(MinX, MinY, MaxZ); - rNormal.Set(0.0f, 1.0f, 0.0f); + rNormal.Set(0.0F, 1.0F, 0.0F); break; case FRONT: rBase.Set(MinX, MinY, MaxZ); - rNormal.Set(0.0f, 0.0f, 1.0f); + rNormal.Set(0.0F, 0.0F, 1.0F); break; case BACK: rBase.Set(MinX, MinY, MinZ); - rNormal.Set(0.0f, 0.0f, 1.0f); + rNormal.Set(0.0F, 0.0F, 1.0F); break; default: break; } } -template -inline bool BoundBox3<_Precision>::CalcEdge (unsigned short usEdge, Vector3<_Precision>& rcP0, Vector3<_Precision>& rcP1) const +template +inline bool BoundBox3::CalcEdge (unsigned short usEdge, Vector3& rcP0, + Vector3& rcP1) const { switch (usEdge) { - case 0: - rcP0 = CalcPoint(0); - rcP1 = CalcPoint(1); + case TLB_TLF: + rcP0 = CalcPoint(TLB); + rcP1 = CalcPoint(TLF); break; - case 1: - rcP0 = CalcPoint(1); - rcP1 = CalcPoint(2); + case TLF_TRF: + rcP0 = CalcPoint(TLF); + rcP1 = CalcPoint(TRF); break; - case 2: - rcP0 = CalcPoint(2); - rcP1 = CalcPoint(3); + case TRF_TRB: + rcP0 = CalcPoint(TRF); + rcP1 = CalcPoint(TRB); break; - case 3: - rcP0 = CalcPoint(3); - rcP1 = CalcPoint(0); + case TRB_TLB: + rcP0 = CalcPoint(TRB); + rcP1 = CalcPoint(TLB); break; - case 4: - rcP0 = CalcPoint(4); - rcP1 = CalcPoint(5); + case BLB_BLF: + rcP0 = CalcPoint(BLB); + rcP1 = CalcPoint(BLF); break; - case 5: - rcP0 = CalcPoint(5); - rcP1 = CalcPoint(6); + case BLF_BRF: + rcP0 = CalcPoint(BLF); + rcP1 = CalcPoint(BRF); break; - case 6: - rcP0 = CalcPoint(6); - rcP1 = CalcPoint(7); + case BRF_BRB: + rcP0 = CalcPoint(BRF); + rcP1 = CalcPoint(BRB); break; - case 7: - rcP0 = CalcPoint(7); - rcP1 = CalcPoint(4); + case BRB_BLB: + rcP0 = CalcPoint(BRB); + rcP1 = CalcPoint(BLB); break; - case 8: - rcP0 = CalcPoint(0); - rcP1 = CalcPoint(4); + case TLB_BLB: + rcP0 = CalcPoint(TLB); + rcP1 = CalcPoint(BLB); break; - case 9: - rcP0 = CalcPoint(1); - rcP1 = CalcPoint(5); + case TLF_BLF: + rcP0 = CalcPoint(TLF); + rcP1 = CalcPoint(BLF); break; - case 10: - rcP0 = CalcPoint(2); - rcP1 = CalcPoint(6); + case TRF_BRF: + rcP0 = CalcPoint(TRF); + rcP1 = CalcPoint(BRF); break; - case 11: - rcP0 = CalcPoint(3); - rcP1 = CalcPoint(7); + case TRB_BRB: + rcP0 = CalcPoint(TRB); + rcP1 = CalcPoint(BRB); break; default: return false; // undefined @@ -591,12 +641,15 @@ inline bool BoundBox3<_Precision>::CalcEdge (unsigned short usEdge, Vector3<_Pre return true; } -template -inline bool BoundBox3<_Precision>::IntersectionPoint (const Vector3<_Precision> &rcVct, const Vector3<_Precision> &rcVctDir, Vector3<_Precision>& cVctRes, _Precision epsilon) const +template +inline bool BoundBox3::IntersectionPoint (const Vector3 &rcVct, + const Vector3 &rcVctDir, + Vector3& cVctRes, + Precision epsilon) const { + const unsigned short num = 6; bool rc=false; - BoundBox3<_Precision> cCmpBound(*this); - unsigned short i{}; + BoundBox3 cCmpBound(*this); // enlarge bounding box by epsilon cCmpBound.Enlarge(epsilon); @@ -604,10 +657,13 @@ inline bool BoundBox3<_Precision>::IntersectionPoint (const Vector3<_Precision> // Is point inside? if (cCmpBound.IsInBox (rcVct)) { // test sides - for (i = 0; (i < 6) && (!rc); i++) { + for (unsigned short i = 0; (i < num) && (!rc); i++) { rc = IntersectPlaneWithLine(i, rcVct, rcVctDir, cVctRes); - if (!cCmpBound.IsInBox(cVctRes)) + + if (!cCmpBound.IsInBox(cVctRes)) { rc = false; + } + if (rc) { // does intersection point lie in desired direction // or was found the opposing side? @@ -620,10 +676,13 @@ inline bool BoundBox3<_Precision>::IntersectionPoint (const Vector3<_Precision> return rc; } -template -inline bool BoundBox3<_Precision>::IsCutLine (const Vector3<_Precision>& rcBase, const Vector3<_Precision>& rcDir, _Precision fTolerance) const +template +inline bool BoundBox3::IsCutLine (const Vector3& rcBase, + const Vector3& rcDir, + Precision fTolerance) const { - _Precision fDist; + const unsigned short num = 6; + Precision fDist; // at first only a rough and quick test by the // Distance of the line to the center of the BB is calculated @@ -636,34 +695,36 @@ inline bool BoundBox3<_Precision>::IsCutLine (const Vector3<_Precision>& rcBase, if (fDist > (CalcDiagonalLength() + fTolerance)) { return false; } - else { // more detailed test here - unsigned char i{}; - Vector3<_Precision> clVectRes; - // intersect each face with the line - for (i = 0; i < 6; i++) { - if (IntersectPlaneWithLine(i, rcBase, rcDir, clVectRes)) { - // Check whether the intersection point is within BB limits + Tolerance - switch (i) { - case LEFT : // left and right plane - case RIGHT : - if ((isOnRayW (MinY - fTolerance, MaxY + fTolerance, clVectRes.y) && - isOnRayW (MinZ - fTolerance, MaxZ + fTolerance, clVectRes.z))) - return true; - break; - case TOP : // top and bottom plane - case BOTTOM : - if ((isOnRayW (MinX - fTolerance, MaxX + fTolerance, clVectRes.x) && - isOnRayW (MinZ - fTolerance, MaxZ + fTolerance, clVectRes.z))) - return true; - break; - case FRONT : // front and back plane - case BACK : - if ((isOnRayW (MinX - fTolerance, MaxX + fTolerance, clVectRes.x) && - isOnRayW (MinY - fTolerance, MaxY + fTolerance, clVectRes.y))) - return true; - break; - } + // more detailed test here + Vector3 clVectRes; + + // intersect each face with the line + for (unsigned short i = 0; i < num; i++) { + if (IntersectPlaneWithLine(i, rcBase, rcDir, clVectRes)) { + // Check whether the intersection point is within BB limits + Tolerance + switch (i) { + case LEFT : // left and right plane + case RIGHT : + if ((isOnRayW (MinY - fTolerance, MaxY + fTolerance, clVectRes.y) && + isOnRayW (MinZ - fTolerance, MaxZ + fTolerance, clVectRes.z))) { + return true; + } + break; + case TOP : // top and bottom plane + case BOTTOM : + if ((isOnRayW (MinX - fTolerance, MaxX + fTolerance, clVectRes.x) && + isOnRayW (MinZ - fTolerance, MaxZ + fTolerance, clVectRes.z))) { + return true; + } + break; + case FRONT : // front and back plane + case BACK : + if ((isOnRayW (MinX - fTolerance, MaxX + fTolerance, clVectRes.x) && + isOnRayW (MinY - fTolerance, MaxY + fTolerance, clVectRes.y))) { + return true; + } + break; } } } @@ -671,52 +732,63 @@ inline bool BoundBox3<_Precision>::IsCutLine (const Vector3<_Precision>& rcBase, return false; } -template -inline bool BoundBox3<_Precision>::IsCutPlane (const Vector3<_Precision> &rclBase, const Vector3<_Precision> &rclNormal) const +template +inline bool BoundBox3::IsCutPlane (const Vector3 &rclBase, + const Vector3 &rclNormal) const { + const unsigned short num = 8; if (fabs(GetCenter().DistanceToPlane(rclBase, rclNormal)) < CalcDiagonalLength()) { - _Precision fD = CalcPoint(0).DistanceToPlane(rclBase, rclNormal); - for (unsigned short i = 1; i < 8; i++) { - if ((CalcPoint(i).DistanceToPlane(rclBase, rclNormal) * fD) <= 0.0f) + Precision fD = CalcPoint(CORNER::TLB).DistanceToPlane(rclBase, rclNormal); + for (unsigned short i = 1; i < num; i++) { + if ((CalcPoint(i).DistanceToPlane(rclBase, rclNormal) * fD) <= 0.0F) { return true; + } } } return false; } -template -inline bool BoundBox3<_Precision>::IntersectWithLine (const Vector3<_Precision> & rcBase, const Vector3<_Precision>& rcDir, - Vector3<_Precision>& rcP0, Vector3<_Precision>& rcP1) const +// NOLINTBEGIN(bugprone-easily-swappable-parameters) +template +inline bool BoundBox3::IntersectWithLine (const Vector3 & rcBase, + const Vector3& rcDir, + Vector3& rcP0, + Vector3& rcP1) const +// NOLINTEND(bugprone-easily-swappable-parameters) { - Vector3<_Precision> clVectRes, clVect[6]; - + const unsigned short num = 6; + Vector3 clVectRes; + std::array, num> clVect; unsigned short numIntersect = 0; + + auto checkIntersect = [&](Base::Vector3 p1, + Base::Vector3 p2) { + if (isOnRayS(p1.x, p1.y, p1.z) && isOnRayS(p2.x, p2.y, p2.z)) { + clVect[numIntersect] = clVectRes; + numIntersect++; + } + }; + // cut each face with the line - for (unsigned short i = 0; i < 6; i++) { + for (unsigned short i = 0; i < num; i++) { if (IntersectPlaneWithLine(i, rcBase, rcDir, clVectRes)) { // check if intersection point is inside switch (i) { case LEFT : // left and right plane case RIGHT : - if ((isOnRayS(MinY, MaxY, clVectRes.y) && - isOnRayS(MinZ, MaxZ, clVectRes.z))) { - clVect[numIntersect] = clVectRes; - numIntersect++; - } break; + checkIntersect(Vector3{MinY, MaxY, clVectRes.y}, + Vector3{MinZ, MaxZ, clVectRes.z}); + break; case TOP : // top and bottom plane case BOTTOM : - if ((isOnRayS(MinX, MaxX, clVectRes.x) && - isOnRayS(MinZ, MaxZ, clVectRes.z))) { - clVect[numIntersect] = clVectRes; - numIntersect++; - } break; + checkIntersect(Vector3{MinX, MaxX, clVectRes.x}, + Vector3{MinZ, MaxZ, clVectRes.z}); + break; case FRONT : // front and back plane case BACK : - if ((isOnRayS(MinX, MaxX, clVectRes.x) && - isOnRayS(MinY, MaxY, clVectRes.y))) { - clVect[numIntersect] = clVectRes; - numIntersect++; - } break; + checkIntersect(Vector3{MinX, MaxX, clVectRes.x}, + Vector3{MinY, MaxY, clVectRes.y}); + break; } } } @@ -726,7 +798,8 @@ inline bool BoundBox3<_Precision>::IntersectWithLine (const Vector3<_Precision> rcP1 = clVect[1]; return true; } - else if (numIntersect > 2) { // search two different intersection points + + if (numIntersect > 2) { // search two different intersection points for (unsigned short i = 1; i < numIntersect; i++) { if (clVect[i] != clVect[0]) { rcP0 = clVect[0]; @@ -739,247 +812,252 @@ inline bool BoundBox3<_Precision>::IntersectWithLine (const Vector3<_Precision> return false; } -template -inline bool BoundBox3<_Precision>::IntersectPlaneWithLine (unsigned short usSide, const Vector3<_Precision>& rcBase, - const Vector3<_Precision>& rcDir, Vector3<_Precision>& rcP0) const +// NOLINTBEGIN(bugprone-easily-swappable-parameters) +template +inline bool BoundBox3::IntersectPlaneWithLine (unsigned short usSide, + const Vector3& rcBase, + const Vector3& rcDir, + Vector3& rcP0) const +// NOLINTEND(bugprone-easily-swappable-parameters) { - _Precision k; - Vector3<_Precision> cBase, cNormal; - Vector3<_Precision> cDir(rcDir); + Precision value; + Vector3 cBase; + Vector3 cNormal; + Vector3 cDir(rcDir); CalcPlane(usSide, cBase, cNormal); - if ((cNormal * cDir) == 0.0f) { + if ((cNormal * cDir) == 0.0F) { return false; // no point of intersection } - else { - k = (cNormal * (cBase - rcBase)) / (cNormal * cDir); - cDir.Scale(k, k, k); - rcP0 = rcBase + cDir; - return true; - } + + value = (cNormal * (cBase - rcBase)) / (cNormal * cDir); + cDir.Scale(value, value, value); + rcP0 = rcBase + cDir; + return true; } -template -inline typename BoundBox3<_Precision>::SIDE BoundBox3<_Precision>::GetSideFromRay (const Vector3<_Precision> &rclPt, const Vector3<_Precision> &rclDir) const +template +inline typename BoundBox3::SIDE +BoundBox3::GetSideFromRay (const Vector3 &rclPt, + const Vector3 &rclDir) const { - Vector3<_Precision> cIntersection; + Vector3 cIntersection; return GetSideFromRay( rclPt, rclDir, cIntersection); } -template -inline typename BoundBox3<_Precision>::SIDE BoundBox3<_Precision>::GetSideFromRay (const Vector3<_Precision> &rclPt, const Vector3<_Precision> &rclDir, - Vector3<_Precision>& rcInt) const +template +inline typename BoundBox3::SIDE +BoundBox3::GetSideFromRay (const Vector3 &rclPt, + const Vector3 &rclDir, + Vector3& rcInt) const { - Vector3<_Precision> cP0, cP1; - if (!IntersectWithLine(rclPt, rclDir, cP0, cP1)) + Vector3 cP0; + Vector3 cP1; + if (!IntersectWithLine(rclPt, rclDir, cP0, cP1)) { return INVALID; + } - Vector3<_Precision> cOut; + Vector3 cOut; // same orientation - if ((cP1-cP0)*rclDir > 0) + if ((cP1-cP0)*rclDir > 0) { cOut = cP1; - else + } + else { cOut = cP0; + } rcInt = cOut; - _Precision fMax = 1.0e-3f; + Precision fMax = 1.0e-3F; //NOLINT SIDE tSide = INVALID; if (fabs(cOut.x - MinX) < fMax) { // left plane - fMax = _Precision(fabs(cOut.x - MinX)); + fMax = Precision(fabs(cOut.x - MinX)); tSide = LEFT; } if (fabs(cOut.x - MaxX) < fMax) { // right plane - fMax = _Precision(fabs(cOut.x - MaxX)); + fMax = Precision(fabs(cOut.x - MaxX)); tSide = RIGHT; } if (fabs(cOut.y - MinY) < fMax) { // bottom plane - fMax = _Precision(fabs(cOut.y - MinY)); + fMax = Precision(fabs(cOut.y - MinY)); tSide = BOTTOM; } if (fabs(cOut.y - MaxY) < fMax) { // top plane - fMax = _Precision(fabs(cOut.y - MaxY)); + fMax = Precision(fabs(cOut.y - MaxY)); tSide = TOP; } if (fabs(cOut.z - MinZ) < fMax) { // front plane - fMax = _Precision(fabs(cOut.z - MinZ)); + fMax = Precision(fabs(cOut.z - MinZ)); tSide = FRONT; } if (fabs(cOut.z - MaxZ) < fMax) { // back plane - fMax = _Precision(fabs(cOut.z - MaxZ)); + fMax = Precision(fabs(cOut.z - MaxZ)); tSide = BACK; } return tSide; } -template -inline Vector3<_Precision> BoundBox3<_Precision>::ClosestPoint (const Vector3<_Precision> &rclPt) const +template +inline Vector3 BoundBox3::ClosestPoint (const Vector3 &rclPt) const { -#if 0 - // Get the nearest point of the bb, point MUST be inside the bb! - _Precision fMinDist = std::numeric_limits<_Precision>::max(); - Vector3<_Precision> cBase, cNormal, clRet; + Vector3 closest = rclPt; - for (int i = 0; i < 6; i++) { - Vector3<_Precision> clTemp = rclPt; - CalcPlane(i, cBase, cNormal); - clTemp.ProjectToPlane(cBase, cNormal); - _Precision fDist = (clTemp - rclPt).Length(); - if (fDist < fMinDist) { - fMinDist = fDist; - clRet = clTemp; - } - } + Vector3 center = GetCenter(); + Precision devx = closest.x - center.x; + Precision devy = closest.y - center.y; + Precision devz = closest.z - center.z; - return clRet; -#else - Vector3<_Precision> closest = rclPt; - - Vector3<_Precision> center = GetCenter(); - _Precision devx = closest.x - center.x; - _Precision devy = closest.y - center.y; - _Precision devz = closest.z - center.z; - - _Precision halfwidth = (MaxX - MinX) / 2; - _Precision halfheight = (MaxY - MinY) / 2; - _Precision halfdepth = (MaxZ - MinZ) / 2; + Precision halfwidth = (MaxX - MinX) / 2; + Precision halfheight = (MaxY - MinY) / 2; + Precision halfdepth = (MaxZ - MinZ) / 2; // Move point to be on the nearest plane of the box. - if ((fabs(devx) > fabs(devy)) && (fabs(devx) > fabs(devz))) + if ((fabs(devx) > fabs(devy)) && (fabs(devx) > fabs(devz))) { closest.x = center.x + halfwidth * ((devx < 0.0) ? -1.0 : 1.0); - else if (fabs(devy) > fabs(devz)) + } + else if (fabs(devy) > fabs(devz)) { closest.y = center.y + halfheight * ((devy < 0.0) ? -1.0 : 1.0); - else + } + else { closest.z = center.z + halfdepth * ((devz < 0.0) ? -1.0 : 1.0); + } // Clamp to be inside box. - closest.x = std::min<_Precision>(std::max<_Precision>(closest.x, MinX), MaxX); - closest.y = std::min<_Precision>(std::max<_Precision>(closest.y, MinY), MaxY); - closest.z = std::min<_Precision>(std::max<_Precision>(closest.z, MinZ), MaxZ); + closest.x = std::min(std::max(closest.x, MinX), MaxX); + closest.y = std::min(std::max(closest.y, MinY), MaxY); + closest.z = std::min(std::max(closest.z, MinZ), MaxZ); return closest; -#endif } -template -inline BoundBox2d BoundBox3<_Precision>::ProjectBox(const ViewProjMethod *pclP) const +template +inline BoundBox2d BoundBox3::ProjectBox(const ViewProjMethod* proj) const { + const int num = 8; BoundBox2d clBB2D; clBB2D.SetVoid(); - for (int i = 0; i < 8; i++) { - Vector3<_Precision> clTrsPt = (*pclP)(CalcPoint(i)); + for (int i = 0; i < num; i++) { + Vector3 clTrsPt = (*proj)(CalcPoint(i)); clBB2D.Add(Vector2d(clTrsPt.x, clTrsPt.y)); } return clBB2D; } -template -inline BoundBox3<_Precision> BoundBox3<_Precision>::Transformed(const Matrix4D& mat) const +template +inline BoundBox3 BoundBox3::Transformed(const Matrix4D& mat) const { - BoundBox3<_Precision> bbox; - for (int i=0; i<8; i++) + const int num = 8; + BoundBox3 bbox; + for (int i = 0; i < num; i++) { bbox.Add(mat * CalcPoint(i)); + } return bbox; } -template -inline Vector3<_Precision> BoundBox3<_Precision>::GetCenter () const +template +inline Vector3 BoundBox3::GetCenter () const { - return Vector3<_Precision>((MaxX + MinX) / 2, + return Vector3((MaxX + MinX) / 2, (MaxY + MinY) / 2, (MaxZ + MinZ) / 2); } -template -inline _Precision BoundBox3<_Precision>::CalcDiagonalLength () const +template +inline Precision BoundBox3::CalcDiagonalLength () const { - return static_cast<_Precision>(sqrt (((MaxX - MinX) * (MaxX - MinX)) + - ((MaxY - MinY) * (MaxY - MinY)) + - ((MaxZ - MinZ) * (MaxZ - MinZ)))); + return static_cast(sqrt (((MaxX - MinX) * (MaxX - MinX)) + + ((MaxY - MinY) * (MaxY - MinY)) + + ((MaxZ - MinZ) * (MaxZ - MinZ)))); } -template -inline void BoundBox3<_Precision>::SetVoid () +template +inline void BoundBox3::SetVoid () { - MinX = MinY = MinZ = std::numeric_limits<_Precision>::max(); - MaxX = MaxY = MaxZ = -std::numeric_limits<_Precision>::max(); + MinX = MinY = MinZ = std::numeric_limits::max(); + MaxX = MaxY = MaxZ = -std::numeric_limits::max(); } -template -inline void BoundBox3<_Precision>::Enlarge (_Precision fLen) +template +inline void BoundBox3::Enlarge (Precision fLen) { MinX -= fLen; MinY -= fLen; MinZ -= fLen; MaxX += fLen; MaxY += fLen; MaxZ += fLen; } -template -inline void BoundBox3<_Precision>::Shrink (_Precision fLen) +template +inline void BoundBox3::Shrink (Precision fLen) { MinX += fLen; MinY += fLen; MinZ += fLen; MaxX -= fLen; MaxY -= fLen; MaxZ -= fLen; } -template -inline _Precision BoundBox3<_Precision>::LengthX () const +template +inline Precision BoundBox3::LengthX () const { return MaxX - MinX; } -template -inline _Precision BoundBox3<_Precision>::LengthY () const +template +inline Precision BoundBox3::LengthY () const { return MaxY - MinY; } -template -inline _Precision BoundBox3<_Precision>::LengthZ () const +template +inline Precision BoundBox3::LengthZ () const { return MaxZ - MinZ; } -template -inline void BoundBox3<_Precision>::MoveX (_Precision f) +template +inline void BoundBox3::MoveX (Precision value) { - MinX += f; MaxX += f; + MinX += value; + MaxX += value; } -template -inline void BoundBox3<_Precision>::MoveY (_Precision f) +template +inline void BoundBox3::MoveY (Precision value) { - MinY += f; MaxY += f; + MinY += value; + MaxY += value; } -template -inline void BoundBox3<_Precision>::MoveZ (_Precision f) +template +inline void BoundBox3::MoveZ (Precision value) { - MinZ += f; MaxZ += f; + MinZ += value; + MaxZ += value; } -template -inline void BoundBox3<_Precision>::ScaleX (_Precision f) +template +inline void BoundBox3::ScaleX (Precision value) { - MinX *= f; MaxX *= f; + MinX *= value; + MaxX *= value; } -template -inline void BoundBox3<_Precision>::ScaleY (_Precision f) +template +inline void BoundBox3::ScaleY (Precision value) { - MinY *= f; MaxY *= f; + MinY *= value; + MaxY *= value; } -template -inline void BoundBox3<_Precision>::ScaleZ (_Precision f) +template +inline void BoundBox3::ScaleZ (Precision value) { - MinZ *= f; MaxZ *= f; + MinZ *= value; + MaxZ *= value; } using BoundBox3f = BoundBox3; diff --git a/src/Mod/Mesh/App/Core/TrimByPlane.cpp b/src/Mod/Mesh/App/Core/TrimByPlane.cpp index 8a404e656c..f69504a6b4 100644 --- a/src/Mod/Mesh/App/Core/TrimByPlane.cpp +++ b/src/Mod/Mesh/App/Core/TrimByPlane.cpp @@ -51,7 +51,7 @@ void MeshTrimByPlane::CheckFacets(const MeshFacetGrid& rclGrid, const Base::Vect // save all elements in checkElements clGridIter.GetElements(checkElements); } - else if (clBBox3d.CalcPoint(0).DistanceToPlane(base, normal) > 0.0f) { + else if (clBBox3d.CalcPoint(Base::BoundBox3f::TLB).DistanceToPlane(base, normal) > 0.0f) { // save all elements in removeFacets clGridIter.GetElements(removeFacets); } diff --git a/src/Mod/Mesh/App/Mesh.cpp b/src/Mod/Mesh/App/Mesh.cpp index a1f1cbb07c..ad39700a10 100644 --- a/src/Mod/Mesh/App/Mesh.cpp +++ b/src/Mod/Mesh/App/Mesh.cpp @@ -165,7 +165,7 @@ Base::BoundBox3d MeshObject::getBoundBox()const Base::BoundBox3d Bnd2; if (Bnd.IsValid()) { for (int i =0 ;i<=7;i++) - Bnd2.Add(transformPointToOutside(Bnd.CalcPoint(i))); + Bnd2.Add(transformPointToOutside(Bnd.CalcPoint(Base::BoundBox3f::CORNER(i)))); } return Bnd2; @@ -1882,28 +1882,29 @@ MeshObject* MeshObject::createCube(float length, float width, float height, floa MeshObject* MeshObject::createCube(const Base::BoundBox3d& bbox) { + using Corner = Base::BoundBox3d::CORNER; std::vector facets; - auto createFacet = [&bbox](int i, int j, int k) { + auto createFacet = [&bbox](Corner p1, Corner p2, Corner p3) { MeshCore::MeshGeomFacet facet; - facet._aclPoints[0] = Base::convertTo(bbox.CalcPoint(i)); - facet._aclPoints[1] = Base::convertTo(bbox.CalcPoint(j)); - facet._aclPoints[2] = Base::convertTo(bbox.CalcPoint(k)); + facet._aclPoints[0] = Base::convertTo(bbox.CalcPoint(p1)); + facet._aclPoints[1] = Base::convertTo(bbox.CalcPoint(p2)); + facet._aclPoints[2] = Base::convertTo(bbox.CalcPoint(p3)); facet.CalcNormal(); return facet; }; - facets.push_back(createFacet(0, 1, 2)); - facets.push_back(createFacet(0, 2, 3)); - facets.push_back(createFacet(0, 5, 1)); - facets.push_back(createFacet(0, 4, 5)); - facets.push_back(createFacet(0, 3, 7)); - facets.push_back(createFacet(0, 7, 4)); - facets.push_back(createFacet(4, 6, 5)); - facets.push_back(createFacet(4, 7, 6)); - facets.push_back(createFacet(1, 6, 2)); - facets.push_back(createFacet(1, 5, 6)); - facets.push_back(createFacet(2, 7, 3)); - facets.push_back(createFacet(2, 6, 7)); + facets.push_back(createFacet(Corner::TLB, Corner::TLF, Corner::TRF)); + facets.push_back(createFacet(Corner::TLB, Corner::TRF, Corner::TRB)); + facets.push_back(createFacet(Corner::TLB, Corner::BLF, Corner::TLF)); + facets.push_back(createFacet(Corner::TLB, Corner::BLB, Corner::BLF)); + facets.push_back(createFacet(Corner::TLB, Corner::TRB, Corner::BRB)); + facets.push_back(createFacet(Corner::TLB, Corner::BRB, Corner::BLB)); + facets.push_back(createFacet(Corner::BLB, Corner::BRF, Corner::BLF)); + facets.push_back(createFacet(Corner::BLB, Corner::BRB, Corner::BRF)); + facets.push_back(createFacet(Corner::TLF, Corner::BRF, Corner::TRF)); + facets.push_back(createFacet(Corner::TLF, Corner::BLF, Corner::BRF)); + facets.push_back(createFacet(Corner::TRF, Corner::BRB, Corner::TRB)); + facets.push_back(createFacet(Corner::TRF, Corner::BRF, Corner::BRB)); Base::EmptySequencer seq; std::unique_ptr mesh(new MeshObject);