From c88c05399f38f0a9e5892e97ed4a6976fe999612 Mon Sep 17 00:00:00 2001 From: Pasukhin Dmitry Date: Sat, 1 Nov 2025 13:57:11 +0000 Subject: [PATCH] Coding - Introduce compile-time sqrt constants and use them consistently (#789) - Add M_SQRT2 macro in multiple sources and replace runtime sqrt/Sqrt(2) calls with the macro - Add SQRT_3 constexpr in IGESGraph_Color and Bnd_OBB and replace Sqrt(3) usages - Make BSplSLib_zero a constexpr array - Replace a few computed sqrt literals with compile-time constants for clarity and consistency --- .../TKDEIGES/IGESGraph/IGESGraph_Color.cxx | 8 ++++- src/Draw/TKDraw/Draw/Draw_GraphicCommands.cxx | 29 ++++++++------- src/Draw/TKQADraw/QABugs/QABugs_13.cxx | 8 +++-- .../TKMath/BSplSLib/BSplSLib.cxx | 18 ++++++---- src/FoundationClasses/TKMath/Bnd/Bnd_OBB.cxx | 21 ++++++----- .../math_NewtonFunctionSetRoot_Test.cxx | 8 +++-- .../TKMath/math/math_GlobOptMin.cxx | 6 +++- .../TKBO/GTests/BRepAlgoAPI_Cut_Test.cxx | 36 ++++++++++--------- .../TKBO/GTests/BRepAlgoAPI_Fuse_Test.cxx | 16 +++++---- .../TKGeomBase/Extrema/Extrema_GenExtCC.gxx | 8 +++-- .../OpenGl/OpenGl_BackgroundArray.cxx | 8 +++-- .../TKV3d/AIS/AIS_Manipulator.cxx | 4 +++ 12 files changed, 112 insertions(+), 58 deletions(-) diff --git a/src/DataExchange/TKDEIGES/IGESGraph/IGESGraph_Color.cxx b/src/DataExchange/TKDEIGES/IGESGraph/IGESGraph_Color.cxx index d8f7fbe5e3..f3ac88903b 100644 --- a/src/DataExchange/TKDEIGES/IGESGraph/IGESGraph_Color.cxx +++ b/src/DataExchange/TKDEIGES/IGESGraph/IGESGraph_Color.cxx @@ -22,6 +22,12 @@ IMPLEMENT_STANDARD_RTTIEXT(IGESGraph_Color, IGESData_ColorEntity) +namespace +{ +// Precomputed sqrt(3) +constexpr Standard_Real SQRT_3 = 1.7320508075688772935; +} // namespace + IGESGraph_Color::IGESGraph_Color() {} // This class inherits from IGESData_ColorEntity @@ -61,7 +67,7 @@ void IGESGraph_Color::HLSPercentage(Standard_Real& Hue, Standard_Real& Saturation) const { Hue = ((1.0 / (2.0 * M_PI)) - * (ATan(((2 * theRed) - theGreen - theBlue) / (Sqrt(3) * (theGreen - theBlue))))); + * (ATan(((2 * theRed) - theGreen - theBlue) / (SQRT_3 * (theGreen - theBlue))))); Lightness = ((1.0 / 3.0) * (theRed + theGreen + theBlue)); Saturation = (Sqrt((theRed * theRed) + (theGreen * theGreen) + (theBlue * theBlue) - (theRed * theGreen) - (theRed * theBlue) - (theBlue * theGreen))); diff --git a/src/Draw/TKDraw/Draw/Draw_GraphicCommands.cxx b/src/Draw/TKDraw/Draw/Draw_GraphicCommands.cxx index 328971cb56..4203175aba 100644 --- a/src/Draw/TKDraw/Draw/Draw_GraphicCommands.cxx +++ b/src/Draw/TKDraw/Draw/Draw_GraphicCommands.cxx @@ -29,6 +29,11 @@ #include #include + +#ifndef M_SQRT2 + #define M_SQRT2 1.41421356237309504880168872420969808 +#endif + #ifdef _WIN32 extern Draw_Viewer dout; extern Standard_Boolean Draw_Batch; @@ -722,9 +727,9 @@ static Standard_Integer hardcopy(Draw_Interpretor&, Standard_Integer n, const ch { if (!strcmp(a[3], "a7")) { - cad = cad / (2 * Sqrt(2)); - dx = dx / (2 * Sqrt(2)); - dy = dy / (2 * Sqrt(2)); + cad = cad / (2 * M_SQRT2); + dx = dx / (2 * M_SQRT2); + dy = dy / (2 * M_SQRT2); } else if (!strcmp(a[3], "a6")) { @@ -734,9 +739,9 @@ static Standard_Integer hardcopy(Draw_Interpretor&, Standard_Integer n, const ch } else if (!strcmp(a[3], "a5")) { - cad = cad / Sqrt(2); - dx = dx / Sqrt(2); - dy = dy / Sqrt(2); + cad = cad / M_SQRT2; + dx = dx / M_SQRT2; + dy = dy / M_SQRT2; } else if (!strcmp(a[3], "a4")) { @@ -747,9 +752,9 @@ static Standard_Integer hardcopy(Draw_Interpretor&, Standard_Integer n, const ch } else if (!strcmp(a[3], "a3")) { - cad = cad * Sqrt(2); - dx = dx * Sqrt(2); - dy = dy * Sqrt(2); + cad = cad * M_SQRT2; + dx = dx * M_SQRT2; + dy = dy * M_SQRT2; } else if (!strcmp(a[3], "a2")) { @@ -759,9 +764,9 @@ static Standard_Integer hardcopy(Draw_Interpretor&, Standard_Integer n, const ch } else if (!strcmp(a[3], "a1")) { - cad = cad * 2 * Sqrt(2); - dx = dx * 2 * Sqrt(2); - dy = dy * 2 * Sqrt(2); + cad = cad * 2 * M_SQRT2; + dx = dx * 2 * M_SQRT2; + dy = dy * 2 * M_SQRT2; } else if (!strcmp(a[3], "a0")) { diff --git a/src/Draw/TKQADraw/QABugs/QABugs_13.cxx b/src/Draw/TKQADraw/QABugs/QABugs_13.cxx index 82ccb9b3be..abff26481e 100644 --- a/src/Draw/TKQADraw/QABugs/QABugs_13.cxx +++ b/src/Draw/TKQADraw/QABugs/QABugs_13.cxx @@ -44,6 +44,10 @@ #include #include +#ifndef M_SQRT2 + #define M_SQRT2 1.41421356237309504880168872420969808 +#endif + //================================================================================================= static Standard_Integer OCC332bug(Draw_Interpretor& di, Standard_Integer argc, const char** argv) @@ -86,7 +90,7 @@ static Standard_Integer OCC332bug(Draw_Interpretor& di, Standard_Integer argc, c // SUPPORT: // 1. There is no need to normalize the direction - it's done automatically // gp_Ax2 origin(gp_Pnt(5000.0,-300.0, 1000.0), - // gp_Dir(0.0, -1.0/sqrt(2.0), -1.0/sqrt(2.0))); + // gp_Dir(0.0, -1.0/M_SQRT2, -1.0/M_SQRT2)); gp_Ax2 origin(gp_Pnt(5000.0, -300.0, 1000.0), gp_Dir(0.0, -1.0, -1.0)); TopoDS_Face myFace; @@ -441,7 +445,7 @@ static Standard_Integer OCC544(Draw_Interpretor& di, Standard_Integer argc, cons } di << "creating the shape for a bent tube\n"; - gp_Ax2 origin(gp_Pnt(500.0, -300.0, 100.0), gp_Dir(0.0, -1.0 / sqrt(2.0), -1.0 / sqrt(2.0))); + gp_Ax2 origin(gp_Pnt(500.0, -300.0, 100.0), gp_Dir(0.0, -1.0 / M_SQRT2, -1.0 / M_SQRT2)); TopoDS_Face firstFace, lastFace; TopoDS_Solid wallSolid, myShape; diff --git a/src/FoundationClasses/TKMath/BSplSLib/BSplSLib.cxx b/src/FoundationClasses/TKMath/BSplSLib/BSplSLib.cxx index be821ff61c..7a2cf1086e 100644 --- a/src/FoundationClasses/TKMath/BSplSLib/BSplSLib.cxx +++ b/src/FoundationClasses/TKMath/BSplSLib/BSplSLib.cxx @@ -35,7 +35,11 @@ #include // for null derivatives -static Standard_Real BSplSLib_zero[3] = {0.0, 0.0, 0.0}; +static constexpr Standard_Real BSplSLib_zero[3] = {0.0, 0.0, 0.0}; + +#ifndef M_SQRT2 + #define M_SQRT2 1.41421356237309504880168872420969808 +#endif //======================================================================= // struct : BSplCLib_DataContainer @@ -978,7 +982,8 @@ void BSplSLib::D2(const Standard_Real U, Standard_Integer dim, dim2; Standard_Real u1, u2; Standard_Integer d1, d2; - Standard_Real * result, *resVu, *resVv, *resVuu, *resVvv, *resVuv; + Standard_Real* result; + const Standard_Real * resVu, *resVv, *resVuu, *resVvv, *resVuv; BSplSLib_DataContainer dc(UDegree, VDegree); if (PrepareEval(U, V, @@ -1141,10 +1146,11 @@ void BSplSLib::D3(const Standard_Real U, { Standard_Boolean rational; // Standard_Integer k,dim,dim2; - Standard_Integer dim, dim2; - Standard_Real u1, u2; - Standard_Integer d1, d2; - Standard_Real * result, *resVu, *resVv, *resVuu, *resVvv, *resVuv, *resVuuu, *resVvvv, *resVuuv, + Standard_Integer dim, dim2; + Standard_Real u1, u2; + Standard_Integer d1, d2; + Standard_Real* result; + const Standard_Real *resVu, *resVv, *resVuu, *resVvv, *resVuv, *resVuuu, *resVvvv, *resVuuv, *resVuvv; BSplSLib_DataContainer dc(UDegree, VDegree); if (PrepareEval(U, diff --git a/src/FoundationClasses/TKMath/Bnd/Bnd_OBB.cxx b/src/FoundationClasses/TKMath/Bnd/Bnd_OBB.cxx index d3b5f28aa4..64bd9adb73 100644 --- a/src/FoundationClasses/TKMath/Bnd/Bnd_OBB.cxx +++ b/src/FoundationClasses/TKMath/Bnd/Bnd_OBB.cxx @@ -27,6 +27,12 @@ #include #include +namespace +{ +// Precomputed sqrt(3) +constexpr Standard_Real SQRT_3 = 1.7320508075688772935; +} // namespace + //! Auxiliary class to select from the points stored in //! BVH tree the two points giving the extreme projection //! parameters on the axis @@ -446,14 +452,13 @@ void OBBTool::ComputeExtremePoints() // gp_XYZ (1, -a, 0), // gp_XYZ (a, 0, 1), // gp_XYZ (a, 0, -1) }; - const Standard_Real aSqrt3 = Sqrt(3); - const gp_XYZ anInitialAxes7[myNbInitAxes] = {gp_XYZ(1.0, 0.0, 0.0), - gp_XYZ(0.0, 1.0, 0.0), - gp_XYZ(0.0, 0.0, 1.0), - gp_XYZ(1.0, 1.0, 1.0) / aSqrt3, - gp_XYZ(1.0, 1.0, -1.0) / aSqrt3, - gp_XYZ(1.0, -1.0, 1.0) / aSqrt3, - gp_XYZ(1.0, -1.0, -1.0) / aSqrt3}; + const gp_XYZ anInitialAxes7[myNbInitAxes] = {gp_XYZ(1.0, 0.0, 0.0), + gp_XYZ(0.0, 1.0, 0.0), + gp_XYZ(0.0, 0.0, 1.0), + gp_XYZ(1.0, 1.0, 1.0) / SQRT_3, + gp_XYZ(1.0, 1.0, -1.0) / SQRT_3, + gp_XYZ(1.0, -1.0, 1.0) / SQRT_3, + gp_XYZ(1.0, -1.0, -1.0) / SQRT_3}; // Set of initial axes const gp_XYZ* anInitialAxesArray = anInitialAxes7; diff --git a/src/FoundationClasses/TKMath/GTests/math_NewtonFunctionSetRoot_Test.cxx b/src/FoundationClasses/TKMath/GTests/math_NewtonFunctionSetRoot_Test.cxx index 8bca08a451..67c20c06e5 100644 --- a/src/FoundationClasses/TKMath/GTests/math_NewtonFunctionSetRoot_Test.cxx +++ b/src/FoundationClasses/TKMath/GTests/math_NewtonFunctionSetRoot_Test.cxx @@ -19,6 +19,10 @@ #include #include +#ifndef M_SQRT1_2 + #define M_SQRT1_2 0.707106781186547524400844362104849039 +#endif + namespace { const Standard_Real TOLERANCE = 1.0e-6; @@ -221,8 +225,8 @@ TEST(math_NewtonFunctionSetRoot, CircleLineIntersection) EXPECT_TRUE(solver.IsDone()); const math_Vector& root = solver.Root(); - EXPECT_NEAR(fabs(root(1)), 1.0 / sqrt(2.0), 1.0e-5); - EXPECT_NEAR(fabs(root(2)), 1.0 / sqrt(2.0), 1.0e-5); + EXPECT_NEAR(fabs(root(1)), M_SQRT1_2, 1.0e-5); + EXPECT_NEAR(fabs(root(2)), M_SQRT1_2, 1.0e-5); EXPECT_NEAR(root(1), root(2), TOLERANCE); // x = y constraint } diff --git a/src/FoundationClasses/TKMath/math/math_GlobOptMin.cxx b/src/FoundationClasses/TKMath/math/math_GlobOptMin.cxx index a90464bfc4..f317d16016 100644 --- a/src/FoundationClasses/TKMath/math/math_GlobOptMin.cxx +++ b/src/FoundationClasses/TKMath/math/math_GlobOptMin.cxx @@ -23,6 +23,10 @@ #include #include +#ifndef M_SQRT2 + #define M_SQRT2 1.41421356237309504880168872420969808 +#endif + //================================================================================================= static Standard_Real DistanceToBorder(const math_Vector& theX, @@ -554,7 +558,7 @@ void math_GlobOptMin::initCellSize() for (Standard_Integer anIdx = 1; anIdx <= myN; anIdx++) { myCellSize(anIdx - 1) = - (myGlobB(anIdx) - myGlobA(anIdx)) * Precision::PConfusion() / (2.0 * Sqrt(2.0)); + (myGlobB(anIdx) - myGlobA(anIdx)) * Precision::PConfusion() / (2.0 * M_SQRT2); } } diff --git a/src/ModelingAlgorithms/TKBO/GTests/BRepAlgoAPI_Cut_Test.cxx b/src/ModelingAlgorithms/TKBO/GTests/BRepAlgoAPI_Cut_Test.cxx index f1ad0c81b6..947632b1c8 100644 --- a/src/ModelingAlgorithms/TKBO/GTests/BRepAlgoAPI_Cut_Test.cxx +++ b/src/ModelingAlgorithms/TKBO/GTests/BRepAlgoAPI_Cut_Test.cxx @@ -13,6 +13,10 @@ #include "BOPTest_Utilities.pxx" +#ifndef M_SQRT2 + #define M_SQRT2 1.41421356237309504880168872420969808 +#endif + //================================================================================================== // BCut Simple Tests - migrating from /tests/boolean/bcut_simple/ //================================================================================================== @@ -622,7 +626,7 @@ TEST_F(BCutSimpleTest, NurbsBoxMinusRotatedRectangularBox_F1) { TopoDS_Shape aNurbsBox = BOPTest_Utilities::CreateBox(gp_Pnt(0, 0, 0), 1.0, 1.0, 1.0); aNurbsBox = BOPTest_Utilities::ConvertToNurbs(aNurbsBox); - const Standard_Real r = sqrt(2.0); + constexpr Standard_Real r = M_SQRT2; TopoDS_Shape aRectangularBox = BOPTest_Utilities::CreateBox(gp_Pnt(0, 0, 0), r, r / 2.0, 1.0); aRectangularBox = BOPTest_Utilities::RotateShape(aRectangularBox, gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)), @@ -636,7 +640,7 @@ TEST_F(BCutSimpleTest, RotatedRectangularBoxMinusNurbsBox_F2) { TopoDS_Shape aNurbsBox = BOPTest_Utilities::CreateBox(gp_Pnt(0, 0, 0), 1.0, 1.0, 1.0); aNurbsBox = BOPTest_Utilities::ConvertToNurbs(aNurbsBox); - const Standard_Real r = sqrt(2.0); + constexpr Standard_Real r = M_SQRT2; TopoDS_Shape aRectangularBox = BOPTest_Utilities::CreateBox(gp_Pnt(0, 0, 0), r, r / 2.0, 1.0); aRectangularBox = BOPTest_Utilities::RotateShape(aRectangularBox, gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)), @@ -676,28 +680,28 @@ TEST_F(BCutSimpleTest, RotatedSquareBoxMinusNurbsBox_F4) // Test bcut_simple/F5: NURBS box - rotated thin box (sqrt(2) x 0.25 x 1, 45deg) TEST_F(BCutSimpleTest, NurbsBoxMinusRotatedThinBox_F5) { - TopoDS_Shape aNurbsBox = BOPTest_Utilities::CreateBox(gp_Pnt(0, 0, 0), 1.0, 1.0, 1.0); - aNurbsBox = BOPTest_Utilities::ConvertToNurbs(aNurbsBox); - const Standard_Real r = sqrt(2.0); - TopoDS_Shape aThinBox = BOPTest_Utilities::CreateBox(gp_Pnt(0, 0, 0), r, 0.25, 1.0); - aThinBox = BOPTest_Utilities::RotateShape(aThinBox, + TopoDS_Shape aNurbsBox = BOPTest_Utilities::CreateBox(gp_Pnt(0, 0, 0), 1.0, 1.0, 1.0); + aNurbsBox = BOPTest_Utilities::ConvertToNurbs(aNurbsBox); + constexpr Standard_Real r = M_SQRT2; + TopoDS_Shape aThinBox = BOPTest_Utilities::CreateBox(gp_Pnt(0, 0, 0), r, 0.25, 1.0); + aThinBox = BOPTest_Utilities::RotateShape(aThinBox, gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)), 45.0 * M_PI / 180.0); - const TopoDS_Shape aResult = PerformCut(aNurbsBox, aThinBox); + const TopoDS_Shape aResult = PerformCut(aNurbsBox, aThinBox); ValidateResult(aResult, 7.03921); } // Test bcut_simple/F6: rotated thin box - NURBS box TEST_F(BCutSimpleTest, RotatedThinBoxMinusNurbsBox_F6) { - TopoDS_Shape aNurbsBox = BOPTest_Utilities::CreateBox(gp_Pnt(0, 0, 0), 1.0, 1.0, 1.0); - aNurbsBox = BOPTest_Utilities::ConvertToNurbs(aNurbsBox); - const Standard_Real r = sqrt(2.0); - TopoDS_Shape aThinBox = BOPTest_Utilities::CreateBox(gp_Pnt(0, 0, 0), r, 0.25, 1.0); - aThinBox = BOPTest_Utilities::RotateShape(aThinBox, + TopoDS_Shape aNurbsBox = BOPTest_Utilities::CreateBox(gp_Pnt(0, 0, 0), 1.0, 1.0, 1.0); + aNurbsBox = BOPTest_Utilities::ConvertToNurbs(aNurbsBox); + constexpr Standard_Real r = M_SQRT2; + TopoDS_Shape aThinBox = BOPTest_Utilities::CreateBox(gp_Pnt(0, 0, 0), r, 0.25, 1.0); + aThinBox = BOPTest_Utilities::RotateShape(aThinBox, gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)), 45.0 * M_PI / 180.0); - const TopoDS_Shape aResult = PerformCut(aThinBox, aNurbsBox); + const TopoDS_Shape aResult = PerformCut(aThinBox, aNurbsBox); ValidateResult(aResult, 1.83211); } @@ -706,7 +710,7 @@ TEST_F(BCutSimpleTest, NurbsBoxMinusRotatedNarrowBox_F7) { TopoDS_Shape aNurbsBox = BOPTest_Utilities::CreateBox(gp_Pnt(0, 0, 0), 1.0, 1.0, 1.0); aNurbsBox = BOPTest_Utilities::ConvertToNurbs(aNurbsBox); - const Standard_Real r = sqrt(31.0); + constexpr Standard_Real r = 5.5677643628300219; // sqrt(31.0) TopoDS_Shape aNarrowBox = BOPTest_Utilities::CreateBox(gp_Pnt(0, 0, 0), r / 4.0, 0.25, 1.0); aNarrowBox = BOPTest_Utilities::RotateShape(aNarrowBox, gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)), @@ -720,7 +724,7 @@ TEST_F(BCutSimpleTest, RotatedNarrowBoxMinusNurbsBox_F8) { TopoDS_Shape aNurbsBox = BOPTest_Utilities::CreateBox(gp_Pnt(0, 0, 0), 1.0, 1.0, 1.0); aNurbsBox = BOPTest_Utilities::ConvertToNurbs(aNurbsBox); - const Standard_Real r = sqrt(31.0); + constexpr Standard_Real r = 5.5677643628300219; TopoDS_Shape aNarrowBox = BOPTest_Utilities::CreateBox(gp_Pnt(0, 0, 0), r / 4.0, 0.25, 1.0); aNarrowBox = BOPTest_Utilities::RotateShape(aNarrowBox, gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)), diff --git a/src/ModelingAlgorithms/TKBO/GTests/BRepAlgoAPI_Fuse_Test.cxx b/src/ModelingAlgorithms/TKBO/GTests/BRepAlgoAPI_Fuse_Test.cxx index 241865cb5f..80fec7e4ff 100644 --- a/src/ModelingAlgorithms/TKBO/GTests/BRepAlgoAPI_Fuse_Test.cxx +++ b/src/ModelingAlgorithms/TKBO/GTests/BRepAlgoAPI_Fuse_Test.cxx @@ -13,6 +13,10 @@ #include "BOPTest_Utilities.pxx" +#ifndef M_SQRT2 + #define M_SQRT2 1.41421356237309504880168872420969808 +#endif + //================================================================================================== // BFuse Simple Tests - migrating from /tests/boolean/bfuse_simple/ //================================================================================================== @@ -380,9 +384,9 @@ TEST_F(BFuseSimpleTest, NurbsBoxPlusRotatedNarrowBox_D1) aBox1 = BOPTest_Utilities::ConvertToNurbs(aBox1); // Create rotated narrow box: r=sqrt(2), box(0,0,0,r,0.25,1), rotate 45 degrees around Z - const Standard_Real r = sqrt(2.0); - TopoDS_Shape aBox2 = BOPTest_Utilities::CreateBox(gp_Pnt(0, 0, 0), r, 0.25, 1.0); - gp_Trsf aTrsf; + constexpr Standard_Real r = M_SQRT2; + TopoDS_Shape aBox2 = BOPTest_Utilities::CreateBox(gp_Pnt(0, 0, 0), r, 0.25, 1.0); + gp_Trsf aTrsf; aTrsf.SetRotation(gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)), M_PI / 4.0); // 45 degrees aBox2.Move(aTrsf); @@ -397,9 +401,9 @@ TEST_F(BFuseSimpleTest, NurbsBoxPlusRotatedNarrowBoxVariation_D2) aBox1 = BOPTest_Utilities::ConvertToNurbs(aBox1); // Create rotated narrow box: r=sqrt(31), box(0,0,0,r/4,0.25,1), rotate 34.73 degrees around Z - const Standard_Real r = sqrt(31.0); - TopoDS_Shape aBox2 = BOPTest_Utilities::CreateBox(gp_Pnt(0, 0, 0), r / 4.0, 0.25, 1.0); - gp_Trsf aTrsf; + constexpr Standard_Real r = 5.5677643628300219; + TopoDS_Shape aBox2 = BOPTest_Utilities::CreateBox(gp_Pnt(0, 0, 0), r / 4.0, 0.25, 1.0); + gp_Trsf aTrsf; aTrsf.SetRotation(gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)), 34.73 * M_PI / 180.0); aBox2.Move(aTrsf); diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_GenExtCC.gxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_GenExtCC.gxx index 08342743c3..c6bb44dc98 100644 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_GenExtCC.gxx +++ b/src/ModelingData/TKGeomBase/Extrema/Extrema_GenExtCC.gxx @@ -28,6 +28,10 @@ #include #include +#ifndef M_SQRT2 + #define M_SQRT2 1.41421356237309504880168872420969808 +#endif + // Comparator, used in std::sort. static Standard_Boolean comp(const gp_XY& theA, const gp_XY& theB) { @@ -334,7 +338,7 @@ void Extrema_GenExtCC::Perform() Standard_Real aLC = 100.0; // Default value. const Standard_Real aMaxDer1 = 1.0 / C1.Resolution(1.0); const Standard_Real aMaxDer2 = 1.0 / C2.Resolution(1.0); - Standard_Real aMaxDer = Max(aMaxDer1, aMaxDer2) * Sqrt(2.0); + Standard_Real aMaxDer = Max(aMaxDer1, aMaxDer2) * M_SQRT2; if (aLC > aMaxDer) aLC = aMaxDer; @@ -420,7 +424,7 @@ void Extrema_GenExtCC::Perform() // Size computed to have cell index inside of int32 value. const Standard_Real aCellSize = Max( Max(anIntervals1->Last() - anIntervals1->First(), anIntervals2->Last() - anIntervals2->First()) - * Precision::PConfusion() / (2.0 * Sqrt(2.0)), + * Precision::PConfusion() / (2.0 * M_SQRT2), Precision::PConfusion()); Extrema_CCPointsInspector anInspector(aCellSize); NCollection_CellFilter aFilter(aCellSize); diff --git a/src/Visualization/TKOpenGl/OpenGl/OpenGl_BackgroundArray.cxx b/src/Visualization/TKOpenGl/OpenGl/OpenGl_BackgroundArray.cxx index 79c932b728..33319a27c1 100644 --- a/src/Visualization/TKOpenGl/OpenGl/OpenGl_BackgroundArray.cxx +++ b/src/Visualization/TKOpenGl/OpenGl/OpenGl_BackgroundArray.cxx @@ -19,6 +19,10 @@ #include #include +#ifndef M_SQRT2 + #define M_SQRT2 1.41421356237309504880168872420969808 +#endif + //================================================================================================= OpenGl_BackgroundArray::OpenGl_BackgroundArray(const Graphic3d_TypeOfBackground theType) @@ -287,8 +291,8 @@ Standard_Boolean OpenGl_BackgroundArray::createGradientArray( for (Standard_Integer anIt = 1; anIt < aSubdiv + 2; ++anIt) { anEllipVerts[anIt] = - OpenGl_Vec2(float(Cos(aParam) * Sqrt(2.0) * myViewWidth / 2.0 + myViewWidth / 2.0f), - float(Sin(aParam) * Sqrt(2.0) * myViewHeight / 2.0 + myViewHeight / 2.0f)); + OpenGl_Vec2(float(Cos(aParam) * M_SQRT2 * myViewWidth / 2.0 + myViewWidth / 2.0f), + float(Sin(aParam) * M_SQRT2 * myViewHeight / 2.0 + myViewHeight / 2.0f)); aParam += aTetta; } diff --git a/src/Visualization/TKV3d/AIS/AIS_Manipulator.cxx b/src/Visualization/TKV3d/AIS/AIS_Manipulator.cxx index 0a31ad04c3..89e6ad4efa 100644 --- a/src/Visualization/TKV3d/AIS/AIS_Manipulator.cxx +++ b/src/Visualization/TKV3d/AIS/AIS_Manipulator.cxx @@ -35,6 +35,10 @@ #include #include +#ifndef M_SQRT2 + #define M_SQRT2 1.41421356237309504880168872420969808 +#endif + IMPLEMENT_STANDARD_HANDLE(AIS_Manipulator, AIS_InteractiveObject) IMPLEMENT_STANDARD_RTTIEXT(AIS_Manipulator, AIS_InteractiveObject) -- 2.39.5