diff --git a/src/ApplicationFramework/TKCDF/LDOM/LDOMBasicString.cxx b/src/ApplicationFramework/TKCDF/LDOM/LDOMBasicString.cxx index 7fbc99579e..7bd0c08b35 100644 --- a/src/ApplicationFramework/TKCDF/LDOM/LDOMBasicString.cxx +++ b/src/ApplicationFramework/TKCDF/LDOM/LDOMBasicString.cxx @@ -144,6 +144,10 @@ LDOMBasicString& LDOMBasicString::operator=(const LDOM_NullPtr*) LDOMBasicString& LDOMBasicString::operator=(const LDOMBasicString& anOther) { + if (this == &anOther) + { + return *this; + } if (myType == LDOM_AsciiFree && myVal.ptr) delete[] (char*)myVal.ptr; myType = anOther.Type(); diff --git a/src/Draw/TKDraw/Draw/Draw.cxx b/src/Draw/TKDraw/Draw/Draw.cxx index 8d3e430927..5a302c29b6 100644 --- a/src/Draw/TKDraw/Draw/Draw.cxx +++ b/src/Draw/TKDraw/Draw/Draw.cxx @@ -746,8 +746,10 @@ void Draw::Load(Draw_Interpretor& theDI, theMapOfFunctions.Bind(theKey, aFunc); } - void (*fp)(Draw_Interpretor&) = NULL; - fp = (void (*)(Draw_Interpretor&))aFunc; + // Cast through void* to avoid -Wcast-function-type-mismatch warning. + // This is safe for dynamically loaded plugin symbols. + void (*fp)(Draw_Interpretor&) = + reinterpret_cast(reinterpret_cast(aFunc)); (*fp)(theDI); } diff --git a/src/Draw/TKViewerTest/ViewerTest/ViewerTest_ViewerCommands_1.mm b/src/Draw/TKViewerTest/ViewerTest/ViewerTest_ViewerCommands_1.mm index 6ba2c63ef2..ba145cbb9c 100644 --- a/src/Draw/TKViewerTest/ViewerTest/ViewerTest_ViewerCommands_1.mm +++ b/src/Draw/TKViewerTest/ViewerTest/ViewerTest_ViewerCommands_1.mm @@ -24,6 +24,8 @@ #include #include +#include + #if !defined(MAC_OS_X_VERSION_10_12) || (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_12) // replacements for macOS versions before 10.12 #define NSEventModifierFlagControl NSControlKeyMask @@ -279,7 +281,7 @@ static Aspect_VKeyFlags getMouseKeyFlags (NSEvent* theEvent) const Aspect_VKeyFlags aFlags = getMouseKeyFlags (theEvent); const Standard_Real aDelta = [theEvent deltaY]; - if (Abs (aDelta) < 0.001) + if (std::abs(aDelta) < 0.001) { // a lot of values near zero can be generated by touchpad return; diff --git a/src/FoundationClasses/TKMath/BSplSLib/BSplSLib.cxx b/src/FoundationClasses/TKMath/BSplSLib/BSplSLib.cxx index ddf377e492..b5c6d81022 100644 --- a/src/FoundationClasses/TKMath/BSplSLib/BSplSLib.cxx +++ b/src/FoundationClasses/TKMath/BSplSLib/BSplSLib.cxx @@ -2389,7 +2389,6 @@ void BSplSLib::BuildCache(const Standard_Real theU, Standard_Real* aCache = (Standard_Real*)&(theCacheArray(theCacheArray.LowerRow(), theCacheArray.LowerCol())); - Standard_Real* aPolyCoeffs = dc.poles; Standard_Real aFactors[2]; // aFactors[0] corresponds to variable with minimal degree @@ -2402,8 +2401,8 @@ void BSplSLib::BuildCache(const Standard_Real theU, aFactors[0] = 1.0; for (aCol = 0; aCol <= d1; aCol++) { - aPolyCoeffs = dc.poles + (aCol * d2p1 + aRow) * aDimension; - aCoeff = aFactors[0] * aFactors[1]; + Standard_Real* aPolyCoeffs = dc.poles + (aCol * d2p1 + aRow) * aDimension; + aCoeff = aFactors[0] * aFactors[1]; for (i = 0; i < aDimension; i++) aCache[i] = aPolyCoeffs[i] * aCoeff; aCache += aCacheShift; @@ -3076,9 +3075,9 @@ void BSplSLib::MovePoint(const Standard_Real U, ULastIndex = UIndex2; Standard_Real maxValue = 0.0; - Standard_Integer i, ukk1 = 0, ukk2; + Standard_Integer ukk1 = 0, ukk2; - for (i = UFirstIndex - UFirstNonZeroBsplineIndex + 1; + for (Standard_Integer i = UFirstIndex - UFirstNonZeroBsplineIndex + 1; i <= ULastIndex - UFirstNonZeroBsplineIndex + 1; i++) { @@ -3091,7 +3090,6 @@ void BSplSLib::MovePoint(const Standard_Real U, // find a ukk2 if symmetry ukk2 = ukk1; - i = ukk1 - UFirstNonZeroBsplineIndex + 2; if ((ukk1 + 1) <= ULastIndex) { if (std::abs(UBSplineBasis(1, ukk1 - UFirstNonZeroBsplineIndex + 2) - maxValue) < 1.e-10) @@ -3109,10 +3107,10 @@ void BSplSLib::MovePoint(const Standard_Real U, if (VLastIndex > VIndex2) VLastIndex = VIndex2; - maxValue = 0.0; - Standard_Integer j, vkk1 = 0, vkk2; + maxValue = 0.0; + Standard_Integer vkk1 = 0, vkk2; - for (j = VFirstIndex - VFirstNonZeroBsplineIndex + 1; + for (Standard_Integer j = VFirstIndex - VFirstNonZeroBsplineIndex + 1; j <= VLastIndex - VFirstNonZeroBsplineIndex + 1; j++) { @@ -3125,7 +3123,6 @@ void BSplSLib::MovePoint(const Standard_Real U, // find a vkk2 if symmetry vkk2 = vkk1; - j = vkk1 - VFirstNonZeroBsplineIndex + 2; if ((vkk1 + 1) <= VLastIndex) { if (std::abs(VBSplineBasis(1, vkk1 - VFirstNonZeroBsplineIndex + 2) - maxValue) < 1.e-10) @@ -3139,11 +3136,9 @@ void BSplSLib::MovePoint(const Standard_Real U, Standard_Real D2 = 0.0; Standard_Real hN, Coef, DvalU, DvalV; - Standard_Integer ii, jj; - - for (i = 1; i <= UDegree + 1; i++) + for (Standard_Integer i = 1; i <= UDegree + 1; i++) { - ii = i + UFirstNonZeroBsplineIndex - 1; + const Standard_Integer ii = i + UFirstNonZeroBsplineIndex - 1; if (ii < ukk1) { DvalU = ukk1 - ii; @@ -3157,9 +3152,9 @@ void BSplSLib::MovePoint(const Standard_Real U, DvalU = 0.0; } - for (j = 1; j <= VDegree + 1; j++) + for (Standard_Integer j = 1; j <= VDegree + 1; j++) { - jj = j + VFirstNonZeroBsplineIndex - 1; + const Standard_Integer jj = j + VFirstNonZeroBsplineIndex - 1; if (Rational) { hN = Weights(ii, jj) * UBSplineBasis(1, i) * VBSplineBasis(1, j); @@ -3199,7 +3194,7 @@ void BSplSLib::MovePoint(const Standard_Real U, // compute the new poles - for (i = Poles.LowerRow(); i <= Poles.UpperRow(); i++) + for (Standard_Integer i = Poles.LowerRow(); i <= Poles.UpperRow(); i++) { if (i < ukk1) { @@ -3214,7 +3209,7 @@ void BSplSLib::MovePoint(const Standard_Real U, DvalU = 0.0; } - for (j = Poles.LowerCol(); j <= Poles.UpperCol(); j++) + for (Standard_Integer j = Poles.LowerCol(); j <= Poles.UpperCol(); j++) { if (i >= UFirstIndex && i <= ULastIndex && j >= VFirstIndex && j <= VLastIndex) { diff --git a/src/FoundationClasses/TKMath/Bnd/Bnd_Box.hxx b/src/FoundationClasses/TKMath/Bnd/Bnd_Box.hxx index be530c5734..74afab11ba 100644 --- a/src/FoundationClasses/TKMath/Bnd/Bnd_Box.hxx +++ b/src/FoundationClasses/TKMath/Bnd/Bnd_Box.hxx @@ -162,7 +162,7 @@ public: //! intervals of definition, when they are finite, are reduced by //! the absolute value of Tol, while the maximum values are //! increased by the same amount. - void Enlarge(const Standard_Real Tol) noexcept { Gap = std::max(Gap, std::abs(Tol)); } + void Enlarge(const Standard_Real Tol) noexcept { Gap = (std::max)(Gap, std::abs(Tol)); } //! Returns the bounds of this bounding box. The gap is included. //! If this bounding box is infinite (i.e. "open"), returned values diff --git a/src/FoundationClasses/TKMath/Bnd/Bnd_Box2d.hxx b/src/FoundationClasses/TKMath/Bnd/Bnd_Box2d.hxx index 0bdf52534b..474fcb0862 100644 --- a/src/FoundationClasses/TKMath/Bnd/Bnd_Box2d.hxx +++ b/src/FoundationClasses/TKMath/Bnd/Bnd_Box2d.hxx @@ -139,7 +139,7 @@ public: //! intervals of definition, when they are finite, are reduced by //! the absolute value of Tol, while the maximum values are //! increased by the same amount. - void Enlarge(const Standard_Real theTol) noexcept { Gap = std::max(Gap, std::abs(theTol)); } + void Enlarge(const Standard_Real theTol) noexcept { Gap = (std::max)(Gap, std::abs(theTol)); } //! Returns the bounds of this 2D bounding box. //! The gap is included. If this bounding box is infinite (i.e. "open"), returned values diff --git a/src/FoundationClasses/TKMath/Poly/Poly_MergeNodesTool.cxx b/src/FoundationClasses/TKMath/Poly/Poly_MergeNodesTool.cxx index 96af784862..6ed9c0572e 100644 --- a/src/FoundationClasses/TKMath/Poly/Poly_MergeNodesTool.cxx +++ b/src/FoundationClasses/TKMath/Poly/Poly_MergeNodesTool.cxx @@ -139,30 +139,15 @@ inline bool Poly_MergeNodesTool::MergedNodesMap::vec3AreEqual( // const CellVec3i anIndex2 = vec3ToCell (theKey2); // return anIndex1.IsEqual (anIndex2); - float aVal = theKey1.x() - theKey2.x(); - if (aVal < 0) - { - aVal = -aVal; - } - if (aVal > myTolerance) + if (std::abs(theKey1.x() - theKey2.x()) > myTolerance) { return false; } - aVal = theKey1.y() - theKey2.y(); - if (aVal < 0) - { - aVal = -aVal; - } - if (aVal > myTolerance) + if (std::abs(theKey1.y() - theKey2.y()) > myTolerance) { return false; } - aVal = theKey1.z() - theKey2.z(); - if (aVal < 0) - { - aVal = -aVal; - } - if (aVal > myTolerance) + if (std::abs(theKey1.z() - theKey2.z()) > myTolerance) { return false; } diff --git a/src/FoundationClasses/TKMath/gp/gp_Ax2.cxx b/src/FoundationClasses/TKMath/gp/gp_Ax2.cxx index 196f1973fc..967c199b5b 100644 --- a/src/FoundationClasses/TKMath/gp/gp_Ax2.cxx +++ b/src/FoundationClasses/TKMath/gp/gp_Ax2.cxx @@ -31,19 +31,13 @@ gp_Ax2::gp_Ax2(const gp_Pnt& P, const gp_Dir& V) : axis(P, V) { - Standard_Real A = V.X(); - Standard_Real B = V.Y(); - Standard_Real C = V.Z(); - Standard_Real Aabs = A; - if (Aabs < 0) - Aabs = -Aabs; - Standard_Real Babs = B; - if (Babs < 0) - Babs = -Babs; - Standard_Real Cabs = C; - if (Cabs < 0) - Cabs = -Cabs; - gp_Dir D; + const Standard_Real A = V.X(); + const Standard_Real B = V.Y(); + const Standard_Real C = V.Z(); + const Standard_Real Aabs = std::abs(A); + const Standard_Real Babs = std::abs(B); + const Standard_Real Cabs = std::abs(C); + gp_Dir D; // pour determiner l axe X : // on dit que le produit scalaire Vx.V = 0. diff --git a/src/FoundationClasses/TKMath/gp/gp_Ax3.cxx b/src/FoundationClasses/TKMath/gp/gp_Ax3.cxx index ccbdbf4bfe..7e6fe820fc 100644 --- a/src/FoundationClasses/TKMath/gp/gp_Ax3.cxx +++ b/src/FoundationClasses/TKMath/gp/gp_Ax3.cxx @@ -29,19 +29,13 @@ gp_Ax3::gp_Ax3(const gp_Pnt& P, const gp_Dir& V) : axis(P, V) { - Standard_Real A = V.X(); - Standard_Real B = V.Y(); - Standard_Real C = V.Z(); - Standard_Real Aabs = A; - if (Aabs < 0) - Aabs = -Aabs; - Standard_Real Babs = B; - if (Babs < 0) - Babs = -Babs; - Standard_Real Cabs = C; - if (Cabs < 0) - Cabs = -Cabs; - gp_Dir D; + const Standard_Real A = V.X(); + const Standard_Real B = V.Y(); + const Standard_Real C = V.Z(); + const Standard_Real Aabs = std::abs(A); + const Standard_Real Babs = std::abs(B); + const Standard_Real Cabs = std::abs(C); + gp_Dir D; // pour determiner l axe X : // on dit que le produit scalaire Vx.V = 0. diff --git a/src/FoundationClasses/TKMath/gp/gp_Cone.hxx b/src/FoundationClasses/TKMath/gp/gp_Cone.hxx index 9bd890e4cf..24b188103f 100644 --- a/src/FoundationClasses/TKMath/gp/gp_Cone.hxx +++ b/src/FoundationClasses/TKMath/gp/gp_Cone.hxx @@ -240,13 +240,8 @@ inline gp_Cone::gp_Cone(const gp_Ax3& theA3, radius(theRadius), semiAngle(theAng) { - Standard_Real aVal = theAng; - if (aVal < 0) - { - aVal = -aVal; - } - Standard_ConstructionError_Raise_if(theRadius < 0. || aVal <= gp::Resolution() - || M_PI * 0.5 - aVal <= gp::Resolution(), + Standard_ConstructionError_Raise_if(theRadius < 0. || std::abs(theAng) <= gp::Resolution() + || M_PI * 0.5 - std::abs(theAng) <= gp::Resolution(), "gp_Cone() - invalid construction parameters"); } @@ -254,13 +249,8 @@ inline gp_Cone::gp_Cone(const gp_Ax3& theA3, inline void gp_Cone::SetSemiAngle(const Standard_Real theAng) { - Standard_Real aVal = theAng; - if (aVal < 0) - { - aVal = -aVal; - } - Standard_ConstructionError_Raise_if(aVal <= gp::Resolution() - || M_PI * 0.5 - aVal <= gp::Resolution(), + Standard_ConstructionError_Raise_if(std::abs(theAng) <= gp::Resolution() + || M_PI * 0.5 - std::abs(theAng) <= gp::Resolution(), "gp_Cone::SetSemiAngle() - invalid angle range"); semiAngle = theAng; } diff --git a/src/FoundationClasses/TKMath/gp/gp_GTrsf.cxx b/src/FoundationClasses/TKMath/gp/gp_GTrsf.cxx index 8e10a76f4d..425449e707 100644 --- a/src/FoundationClasses/TKMath/gp/gp_GTrsf.cxx +++ b/src/FoundationClasses/TKMath/gp/gp_GTrsf.cxx @@ -97,11 +97,8 @@ void gp_GTrsf::Power(const Standard_Integer N) { if (shape == gp_Other) { - Standard_Integer Npower = N; - if (Npower < 0) - Npower = -Npower; - Npower--; - gp_XYZ Temploc = loc; + Standard_Integer Npower = std::abs(N) - 1; + gp_XYZ Temploc = loc; // Standard_Real Tempscale = scale; gp_Mat Tempmatrix(matrix); for (;;) diff --git a/src/FoundationClasses/TKMath/gp/gp_GTrsf2d.cxx b/src/FoundationClasses/TKMath/gp/gp_GTrsf2d.cxx index bb50c6d565..4ade0e59d3 100644 --- a/src/FoundationClasses/TKMath/gp/gp_GTrsf2d.cxx +++ b/src/FoundationClasses/TKMath/gp/gp_GTrsf2d.cxx @@ -113,11 +113,8 @@ void gp_GTrsf2d::Power(const Standard_Integer N) } if (shape == gp_Other) { - Standard_Integer Npower = N; - if (Npower < 0) - Npower = -Npower; - Npower--; - gp_XY Temploc = loc; + Standard_Integer Npower = std::abs(N) - 1; + gp_XY Temploc = loc; // Standard_Real Tempscale = scale; gp_Mat2d Tempmatrix(matrix); for (;;) diff --git a/src/FoundationClasses/TKMath/gp/gp_Lin.cxx b/src/FoundationClasses/TKMath/gp/gp_Lin.cxx index 35b88ae065..77f5d0b066 100644 --- a/src/FoundationClasses/TKMath/gp/gp_Lin.cxx +++ b/src/FoundationClasses/TKMath/gp/gp_Lin.cxx @@ -33,11 +33,8 @@ Standard_Real gp_Lin::Distance(const gp_Lin& Other) const } else { - gp_Dir dir(pos.Direction().Crossed(Other.pos.Direction())); - Standard_Real D = gp_Vec(pos.Location(), Other.pos.Location()).Dot(gp_Vec(dir)); - if (D < 0) - D = -D; - return D; + const gp_Dir dir(pos.Direction().Crossed(Other.pos.Direction())); + return std::abs(gp_Vec(pos.Location(), Other.pos.Location()).Dot(gp_Vec(dir))); } } diff --git a/src/FoundationClasses/TKMath/gp/gp_Lin2d.hxx b/src/FoundationClasses/TKMath/gp/gp_Lin2d.hxx index a7c5c0978a..8eb85473f2 100644 --- a/src/FoundationClasses/TKMath/gp/gp_Lin2d.hxx +++ b/src/FoundationClasses/TKMath/gp/gp_Lin2d.hxx @@ -225,12 +225,7 @@ inline Standard_Real gp_Lin2d::Distance(const gp_Pnt2d& theP) const noexcept { gp_XY aCoord = theP.XY(); aCoord.Subtract((pos.Location()).XY()); - Standard_Real aVal = aCoord.Crossed(pos.Direction().XY()); - if (aVal < 0) - { - aVal = -aVal; - } - return aVal; + return std::abs(aCoord.Crossed(pos.Direction().XY())); } //================================================================================================= diff --git a/src/FoundationClasses/TKMath/gp/gp_Mat.hxx b/src/FoundationClasses/TKMath/gp/gp_Mat.hxx index cc1bf74a86..f7dec21427 100644 --- a/src/FoundationClasses/TKMath/gp/gp_Mat.hxx +++ b/src/FoundationClasses/TKMath/gp/gp_Mat.hxx @@ -192,12 +192,8 @@ public: constexpr Standard_Boolean IsSingular() const noexcept { // Pour etre sur que Gauss va fonctionner, il faut faire Gauss ... - Standard_Real aVal = Determinant(); - if (aVal < 0) - { - aVal = -aVal; - } - return aVal <= gp::Resolution(); + const Standard_Real aDet = Determinant(); + return (aDet < 0.0 ? -aDet : aDet) <= gp::Resolution(); } constexpr void Add(const gp_Mat& theOther) noexcept; @@ -363,12 +359,9 @@ inline constexpr gp_Mat gp_Mat::Added(const gp_Mat& theOther) const noexcept inline constexpr void gp_Mat::Divide(const Standard_Real theScalar) { - Standard_Real aVal = theScalar; - if (aVal < 0) - { - aVal = -aVal; - } - Standard_ConstructionError_Raise_if(aVal <= gp::Resolution(), "gp_Mat : Divide by 0"); + Standard_ConstructionError_Raise_if((theScalar < 0.0 ? -theScalar : theScalar) + <= gp::Resolution(), + "gp_Mat : Divide by 0"); const Standard_Real anUnSurScalar = 1.0 / theScalar; myMat[0][0] *= anUnSurScalar; myMat[0][1] *= anUnSurScalar; diff --git a/src/FoundationClasses/TKMath/gp/gp_Mat2d.cxx b/src/FoundationClasses/TKMath/gp/gp_Mat2d.cxx index 8d960ec214..eb7b2d29da 100644 --- a/src/FoundationClasses/TKMath/gp/gp_Mat2d.cxx +++ b/src/FoundationClasses/TKMath/gp/gp_Mat2d.cxx @@ -158,11 +158,8 @@ void gp_Mat2d::Power(const Standard_Integer theN) { if (theN < 0) Invert(); - Standard_Integer Npower = theN; - if (Npower < 0) - Npower = -Npower; - Npower--; - gp_Mat2d aTemp = *this; + Standard_Integer Npower = std::abs(theN) - 1; + gp_Mat2d aTemp = *this; for (;;) { if (IsOdd(Npower)) diff --git a/src/FoundationClasses/TKMath/gp/gp_Trsf.cxx b/src/FoundationClasses/TKMath/gp/gp_Trsf.cxx index b8c89f3548..081885b8e4 100644 --- a/src/FoundationClasses/TKMath/gp/gp_Trsf.cxx +++ b/src/FoundationClasses/TKMath/gp/gp_Trsf.cxx @@ -158,13 +158,11 @@ void gp_Trsf::SetRotationPart(const gp_Quaternion& theR) void gp_Trsf::SetScale(const gp_Pnt& P, const Standard_Real S) { - shape = gp_Scale; - scale = S; - loc = P.XYZ(); - Standard_Real As = scale; - if (As < 0) - As = -As; - Standard_ConstructionError_Raise_if(As <= gp::Resolution(), "gp_Trsf::SetScaleFactor"); + shape = gp_Scale; + scale = S; + loc = P.XYZ(); + Standard_ConstructionError_Raise_if(std::abs(scale) <= gp::Resolution(), + "gp_Trsf::SetScaleFactor"); matrix.SetIdentity(); loc.Multiply(1 - S); } @@ -281,19 +279,10 @@ void gp_Trsf::SetTranslationPart(const gp_Vec& V) noexcept void gp_Trsf::SetScaleFactor(const Standard_Real S) { - Standard_Real As = S; - if (As < 0) - As = -As; - Standard_ConstructionError_Raise_if(As <= gp::Resolution(), "gp_Trsf::SetScaleFactor"); - scale = S; - As = scale - 1.; - if (As < 0) - As = -As; - Standard_Boolean unit = As <= gp::Resolution(); // = (scale == 1) - As = scale + 1.; - if (As < 0) - As = -As; - Standard_Boolean munit = As <= gp::Resolution(); // = (scale == -1) + Standard_ConstructionError_Raise_if(std::abs(S) <= gp::Resolution(), "gp_Trsf::SetScaleFactor"); + scale = S; + const Standard_Boolean unit = std::abs(scale - 1.) <= gp::Resolution(); // = (scale == 1) + const Standard_Boolean munit = std::abs(scale + 1.) <= gp::Resolution(); // = (scale == -1) switch (shape) { @@ -355,11 +344,8 @@ void gp_Trsf::SetValues(const Standard_Real a11, gp_XYZ col4(a14, a24, a34); // compute the determinant gp_Mat M(col1, col2, col3); - Standard_Real s = M.Determinant(); - Standard_Real As = s; - if (As < 0) - As = -As; - Standard_ConstructionError_Raise_if(As < gp::Resolution(), + Standard_Real s = M.Determinant(); + Standard_ConstructionError_Raise_if(std::abs(s) < gp::Resolution(), "gp_Trsf::SetValues, null determinant"); if (s > 0) s = std::pow(s, 1. / 3.); @@ -594,11 +580,8 @@ void gp_Trsf::Power(const Standard_Integer N) } if (shape == gp_Translation) { - Standard_Integer Npower = N; - if (Npower < 0) - Npower = -Npower; - Npower--; - gp_XYZ Temploc = loc; + Standard_Integer Npower = std::abs(N) - 1; + gp_XYZ Temploc = loc; for (;;) { if (IsOdd(Npower)) @@ -611,12 +594,9 @@ void gp_Trsf::Power(const Standard_Integer N) } else if (shape == gp_Scale) { - Standard_Integer Npower = N; - if (Npower < 0) - Npower = -Npower; - Npower--; - gp_XYZ Temploc = loc; - Standard_Real Tempscale = scale; + Standard_Integer Npower = std::abs(N) - 1; + gp_XYZ Temploc = loc; + Standard_Real Tempscale = scale; for (;;) { if (IsOdd(Npower)) @@ -633,11 +613,8 @@ void gp_Trsf::Power(const Standard_Integer N) } else if (shape == gp_Rotation) { - Standard_Integer Npower = N; - if (Npower < 0) - Npower = -Npower; - Npower--; - gp_Mat Tempmatrix(matrix); + Standard_Integer Npower = std::abs(N) - 1; + gp_Mat Tempmatrix(matrix); if (loc.X() == 0.0 && loc.Y() == 0.0 && loc.Z() == 0.0) { for (;;) @@ -682,14 +659,11 @@ void gp_Trsf::Power(const Standard_Integer N) } else { - shape = gp_CompoundTrsf; - Standard_Integer Npower = N; - if (Npower < 0) - Npower = -Npower; - Npower--; - gp_XYZ Temploc = loc; - Standard_Real Tempscale = scale; - gp_Mat Tempmatrix(matrix); + shape = gp_CompoundTrsf; + Standard_Integer Npower = std::abs(N) - 1; + gp_XYZ Temploc = loc; + Standard_Real Tempscale = scale; + gp_Mat Tempmatrix(matrix); for (;;) { if (IsOdd(Npower)) diff --git a/src/FoundationClasses/TKMath/gp/gp_Trsf2d.cxx b/src/FoundationClasses/TKMath/gp/gp_Trsf2d.cxx index 0ad01da1a8..c2e4a60b4c 100644 --- a/src/FoundationClasses/TKMath/gp/gp_Trsf2d.cxx +++ b/src/FoundationClasses/TKMath/gp/gp_Trsf2d.cxx @@ -85,14 +85,8 @@ void gp_Trsf2d::SetTransformation(const gp_Ax2d& A) void gp_Trsf2d::SetTranslationPart(const gp_Vec2d& V) { - loc = V.XY(); - Standard_Real X = loc.X(); - if (X < 0) - X = -X; - Standard_Real Y = loc.Y(); - if (Y < 0) - Y = -Y; - if (X <= gp::Resolution() && Y <= gp::Resolution()) + loc = V.XY(); + if (std::abs(loc.X()) <= gp::Resolution() && std::abs(loc.Y()) <= gp::Resolution()) { if (shape == gp_Identity || shape == gp_PntMirror || shape == gp_Scale || shape == gp_Rotation || shape == gp_Ax1Mirror) @@ -230,20 +224,14 @@ void gp_Trsf2d::Invert() } else if (shape == gp_Scale) { - Standard_Real As = scale; - if (As < 0) - As = -As; - Standard_ConstructionError_Raise_if(As <= gp::Resolution(), + Standard_ConstructionError_Raise_if(std::abs(scale) <= gp::Resolution(), "gp_Trsf2d::Invert() - transformation has zero scale"); scale = 1.0 / scale; loc.Multiply(-scale); } else { - Standard_Real As = scale; - if (As < 0) - As = -As; - Standard_ConstructionError_Raise_if(As <= gp::Resolution(), + Standard_ConstructionError_Raise_if(std::abs(scale) <= gp::Resolution(), "gp_Trsf2d::Invert() - transformation has zero scale"); scale = 1.0 / scale; matrix.Transpose(); @@ -653,11 +641,8 @@ void gp_Trsf2d::SetValues(const Standard_Real a11, gp_XY col3(a13, a23); // compute the determinant gp_Mat2d M(col1, col2); - Standard_Real s = M.Determinant(); - Standard_Real As = s; - if (As < 0) - As = -As; - Standard_ConstructionError_Raise_if(As < gp::Resolution(), + Standard_Real s = M.Determinant(); + Standard_ConstructionError_Raise_if(std::abs(s) < gp::Resolution(), "gp_Trsf2d::SetValues, null determinant"); if (s > 0) diff --git a/src/FoundationClasses/TKernel/GTests/Quantity_ColorRGBA_Test.cxx b/src/FoundationClasses/TKernel/GTests/Quantity_ColorRGBA_Test.cxx index 78adb4bd0e..395111b28b 100644 --- a/src/FoundationClasses/TKernel/GTests/Quantity_ColorRGBA_Test.cxx +++ b/src/FoundationClasses/TKernel/GTests/Quantity_ColorRGBA_Test.cxx @@ -26,9 +26,9 @@ protected: void TearDown() override {} // Helper to compare floating point values - bool IsNear(Standard_ShortReal theValue1, - Standard_ShortReal theValue2, - Standard_ShortReal theTolerance = 0.001f) const + bool IsNear(Standard_Real theValue1, + Standard_Real theValue2, + Standard_Real theTolerance = 0.001) const { return std::abs(theValue1 - theValue2) < theTolerance; } diff --git a/src/FoundationClasses/TKernel/OSD/OSD_File.cxx b/src/FoundationClasses/TKernel/OSD/OSD_File.cxx index 197bd20ca7..02e73a2527 100644 --- a/src/FoundationClasses/TKernel/OSD/OSD_File.cxx +++ b/src/FoundationClasses/TKernel/OSD/OSD_File.cxx @@ -1264,15 +1264,14 @@ void OSD_File::Close() myFileHandle = INVALID_HANDLE_VALUE; #else // note: it probably should be single call to fclose()... - int status = close(myFileChannel); - if (status == -1) + if (close(myFileChannel) == -1) { myError.SetValue(errno, Iam, "Close"); } myFileChannel = -1; if (myFILE != NULL) { - status = fclose((FILE*)myFILE); + (void)fclose((FILE*)myFILE); myFILE = NULL; } #endif diff --git a/src/FoundationClasses/TKernel/OSD/OSD_OpenFile.cxx b/src/FoundationClasses/TKernel/OSD/OSD_OpenFile.cxx index 5cb4da7a86..1d7aa70ca8 100644 --- a/src/FoundationClasses/TKernel/OSD/OSD_OpenFile.cxx +++ b/src/FoundationClasses/TKernel/OSD/OSD_OpenFile.cxx @@ -70,7 +70,9 @@ int OSD_OpenFileDescriptor(const TCollection_ExtendedString& theName, } #else NCollection_Utf8String aString(theName.ToExtString()); - aFileDesc = open(aString.ToCString(), aFlags); + // Mode 0600 is used when O_CREAT is set + // (owner read+write only, similar to Windows _S_IREAD | _S_IWRITE) + aFileDesc = open(aString.ToCString(), aFlags, S_IRUSR | S_IWUSR); #endif return aFileDesc; } diff --git a/src/FoundationClasses/TKernel/Plugin/Plugin.cxx b/src/FoundationClasses/TKernel/Plugin/Plugin.cxx index b0502fcbe7..cfedc3468c 100644 --- a/src/FoundationClasses/TKernel/Plugin/Plugin.cxx +++ b/src/FoundationClasses/TKernel/Plugin/Plugin.cxx @@ -99,8 +99,10 @@ Handle(Standard_Transient) Plugin::Load(const Standard_GUID& aGUID, else f = theMapOfFunctions(pid); - Standard_Transient* (*fp)(const Standard_GUID&) = NULL; - fp = (Standard_Transient * (*)(const Standard_GUID&)) f; + // Cast through void* to avoid -Wcast-function-type-mismatch warning. + // This is safe for dynamically loaded plugin symbols. + Standard_Transient* (*fp)(const Standard_GUID&) = + reinterpret_cast(reinterpret_cast(f)); Handle(Standard_Transient) theServiceFactory = (*fp)(aGUID); return theServiceFactory; } diff --git a/src/FoundationClasses/TKernel/Standard/Standard_CStringHasher.hxx b/src/FoundationClasses/TKernel/Standard/Standard_CStringHasher.hxx index eb91316e2d..3532c6b1e5 100644 --- a/src/FoundationClasses/TKernel/Standard/Standard_CStringHasher.hxx +++ b/src/FoundationClasses/TKernel/Standard/Standard_CStringHasher.hxx @@ -18,8 +18,6 @@ #include #include -#include - class Standard_CStringHasher { public: diff --git a/src/ModelingData/TKG3d/Geom/Geom_BSplineCurve.cxx b/src/ModelingData/TKG3d/Geom/Geom_BSplineCurve.cxx index bde66ba29c..d117dc431e 100644 --- a/src/ModelingData/TKG3d/Geom/Geom_BSplineCurve.cxx +++ b/src/ModelingData/TKG3d/Geom/Geom_BSplineCurve.cxx @@ -881,7 +881,8 @@ void Geom_BSplineCurve::SetOrigin(const Standard_Real U, const Standard_Real Tol } UpdateKnots(); } - if (std::abs(U - uf) < Tol) + // For periodic curve, uf and ul represent the same point + if (std::abs(U - uf) < Tol || std::abs(U - ul) < Tol) return; TColStd_Array1OfReal& kn = knots->ChangeArray1(); diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_ExtElCS.cxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_ExtElCS.cxx index 06a7ebe330..1a38052932 100644 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_ExtElCS.cxx +++ b/src/ModelingData/TKGeomBase/Extrema/Extrema_ExtElCS.cxx @@ -90,7 +90,7 @@ void Extrema_ExtElCS::Perform(const gp_Lin& C, const gp_Cylinder& S) } else { - Standard_Integer i, aStartIdx = 0; + Standard_Integer i; Extrema_POnCurv myPOnC1, myPOnC2; Extrem.Points(1, myPOnC1, myPOnC2); @@ -108,8 +108,7 @@ void Extrema_ExtElCS::Perform(const gp_Lin& C, const gp_Cylinder& S) } else if (Inters.IsDone()) { - myNbExt = Inters.NbPoints(); - aStartIdx = myNbExt; + myNbExt = Inters.NbPoints(); if (myNbExt > 0) { // Not more than 2 additional points from perpendiculars. @@ -137,22 +136,16 @@ void Extrema_ExtElCS::Perform(const gp_Lin& C, const gp_Cylinder& S) Extrema_ExtPElS ExPS(PC, S, Precision::Confusion()); if (ExPS.IsDone()) { - if (aStartIdx == 0) - { - myNbExt = ExPS.NbExt(); - mySqDist = new TColStd_HArray1OfReal(1, myNbExt); - myPoint1 = new Extrema_HArray1OfPOnCurv(1, myNbExt); - myPoint2 = new Extrema_HArray1OfPOnSurf(1, myNbExt); - } - else - myNbExt += ExPS.NbExt(); + myNbExt = ExPS.NbExt(); + mySqDist = new TColStd_HArray1OfReal(1, myNbExt); + myPoint1 = new Extrema_HArray1OfPOnCurv(1, myNbExt); + myPoint2 = new Extrema_HArray1OfPOnSurf(1, myNbExt); - for (i = aStartIdx + 1; i <= myNbExt; i++) + for (i = 1; i <= myNbExt; i++) { myPoint1->SetValue(i, myPOnC2); - myPoint2->SetValue(i, ExPS.Point(i - aStartIdx)); - mySqDist->SetValue(i, - (myPOnC2.Value()).SquareDistance(ExPS.Point(i - aStartIdx).Value())); + myPoint2->SetValue(i, ExPS.Point(i)); + mySqDist->SetValue(i, (myPOnC2.Value()).SquareDistance(ExPS.Point(i).Value())); } } } diff --git a/src/ModelingData/TKGeomBase/GeomConvert/GeomConvert_1.cxx b/src/ModelingData/TKGeomBase/GeomConvert/GeomConvert_1.cxx index cf50aa040f..3e3d3b6115 100644 --- a/src/ModelingData/TKGeomBase/GeomConvert/GeomConvert_1.cxx +++ b/src/ModelingData/TKGeomBase/GeomConvert/GeomConvert_1.cxx @@ -566,12 +566,10 @@ Handle(Geom_BSplineSurface) GeomConvert::SurfaceToBSplineSurface(const Handle(Ge if (C->IsRational()) C->Weights(Weights); - Standard_Integer nbUSpans; - Standard_Real AlfaU; + Standard_Real AlfaU; if (Strim->IsUPeriodic()) { NbUKnots = 4; - nbUSpans = 3; AlfaU = M_PI / 3.; NbUPoles = 6; periodic = Standard_True; @@ -579,7 +577,8 @@ Handle(Geom_BSplineSurface) GeomConvert::SurfaceToBSplineSurface(const Handle(Ge else { // Nombre de spans : ouverture maximale = 150 degres ( = PI / 1.2 rds) - nbUSpans = (Standard_Integer)std::trunc(1.2 * (ULast - UFirst) / M_PI) + 1; + const Standard_Integer nbUSpans = + (Standard_Integer)std::trunc(1.2 * (ULast - UFirst) / M_PI) + 1; AlfaU = (ULast - UFirst) / (nbUSpans * 2); NbUPoles = 2 * nbUSpans + 1; NbUKnots = nbUSpans + 1; diff --git a/src/ModelingData/TKGeomBase/IntAna/IntAna_QuadQuadGeo.cxx b/src/ModelingData/TKGeomBase/IntAna/IntAna_QuadQuadGeo.cxx index 5346b5d904..8857b23783 100644 --- a/src/ModelingData/TKGeomBase/IntAna/IntAna_QuadQuadGeo.cxx +++ b/src/ModelingData/TKGeomBase/IntAna/IntAna_QuadQuadGeo.cxx @@ -1608,17 +1608,15 @@ void IntAna_QuadQuadGeo::Perform(const gp_Cone& Con1, const gp_Cone& Con2, const // 3.2 - one line when cone1 touches cone2 (iRet=1) // 3.3 - two lines when cone1 intersects cone2 (iRet=2) // - Standard_Integer iRet; - Standard_Real aGamma, aBeta1, aBeta2; - Standard_Real aD1, aR1, aTgBeta1, aTgBeta2, aHalfPI; - Standard_Real aCosGamma, aSinGamma, aDx, aR2, aRD2, aD2; - gp_Pnt2d aP0, aPA1, aP1, aPA2; - gp_Vec2d aVAx2; - gp_Ax1 aAx1, aAx2; + Standard_Real aGamma, aBeta1, aBeta2; + Standard_Real aD1, aR1, aTgBeta1, aTgBeta2, aHalfPI; + Standard_Real aCosGamma, aSinGamma, aDx, aR2, aRD2, aD2; + gp_Pnt2d aP0, aPA1, aP1, aPA2; + gp_Vec2d aVAx2; + gp_Ax1 aAx1, aAx2; // // Preliminary analysis. Determination of iRet // - iRet = 0; aHalfPI = 0.5 * M_PI; aD1 = 1.; aPA1.SetCoord(aD1, 0.); @@ -1663,12 +1661,11 @@ void IntAna_QuadQuadGeo::Perform(const gp_Cone& Con1, const gp_Cone& Con2, const // if (aRD2 > (aR2 + Tol)) { - iRet = 0; typeres = IntAna_Empty; // nothing return; } // - iRet = 1; // touch case => 1 line + Standard_Integer iRet = 1; // touch case => 1 line if (aRD2 < (aR2 - Tol)) { iRet = 2; // intersection => couple of lines @@ -1707,7 +1704,6 @@ void IntAna_QuadQuadGeo::Perform(const gp_Cone& Con1, const gp_Cone& Con2, const aIntr.Perform(aPln1, aPln2, Tol, Tol); if (!aIntr.IsDone() || 0 == aIntr.NbSolutions()) { - iRet = -1; // just in case. it must not be so typeres = IntAna_NoGeometricSolution; return; } diff --git a/src/Visualization/TKV3d/AIS/AIS_ViewCube.cxx b/src/Visualization/TKV3d/AIS/AIS_ViewCube.cxx index 612613da16..9837ac1078 100644 --- a/src/Visualization/TKV3d/AIS/AIS_ViewCube.cxx +++ b/src/Visualization/TKV3d/AIS/AIS_ViewCube.cxx @@ -1031,32 +1031,34 @@ void AIS_ViewCube::HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager return; } + const AIS_ViewCubeOwner* aCubeOwner = dynamic_cast(theOwner.get()); + if (aCubeOwner == nullptr) + { + return; + } + const Graphic3d_ZLayerId aLayer = theStyle->ZLayer() != Graphic3d_ZLayerId_UNKNOWN ? theStyle->ZLayer() : myDrawer->ZLayer(); - const AIS_ViewCubeOwner* aCubeOwner = dynamic_cast(theOwner.get()); - Handle(Prs3d_Presentation) aHiPrs = GetHilightPresentation(thePrsMgr); aHiPrs->Clear(); aHiPrs->CStructure()->ViewAffinity = myViewAffinity; aHiPrs->SetTransformPersistence(TransformPersistence()); aHiPrs->SetZLayer(aLayer); + Handle(Graphic3d_Group) aGroup = aHiPrs->NewGroup(); + aGroup->SetGroupPrimitivesAspect(theStyle->ShadingAspect()->Aspect()); + Standard_Integer aNbNodes = 0, aNbTris = 0; + createBoxPartTriangles(Handle(Graphic3d_ArrayOfTriangles)(), + aNbNodes, + aNbTris, + aCubeOwner->MainOrientation()); + if (aNbNodes > 0) { - Handle(Graphic3d_Group) aGroup = aHiPrs->NewGroup(); - aGroup->SetGroupPrimitivesAspect(theStyle->ShadingAspect()->Aspect()); - Standard_Integer aNbNodes = 0, aNbTris = 0; - createBoxPartTriangles(Handle(Graphic3d_ArrayOfTriangles)(), - aNbNodes, - aNbTris, - aCubeOwner->MainOrientation()); - if (aNbNodes > 0) - { - Handle(Graphic3d_ArrayOfTriangles) aTris = - new Graphic3d_ArrayOfTriangles(aNbNodes, aNbTris * 3, Graphic3d_ArrayFlags_None); - aNbNodes = aNbTris = 0; - createBoxPartTriangles(aTris, aNbNodes, aNbTris, aCubeOwner->MainOrientation()); - aGroup->AddPrimitiveArray(aTris); - } + Handle(Graphic3d_ArrayOfTriangles) aTris = + new Graphic3d_ArrayOfTriangles(aNbNodes, aNbTris * 3, Graphic3d_ArrayFlags_None); + aNbNodes = aNbTris = 0; + createBoxPartTriangles(aTris, aNbNodes, aNbTris, aCubeOwner->MainOrientation()); + aGroup->AddPrimitiveArray(aTris); } if (thePrsMgr->IsImmediateModeOn())