]> OCCT Git - occt.git/commitdiff
Coding - Introduce compile-time sqrt constants and use them consistently (#789)
authorPasukhin Dmitry <dpasukhi@opencascade.com>
Sat, 1 Nov 2025 13:57:11 +0000 (13:57 +0000)
committerGitHub <noreply@github.com>
Sat, 1 Nov 2025 13:57:11 +0000 (13:57 +0000)
- 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

12 files changed:
src/DataExchange/TKDEIGES/IGESGraph/IGESGraph_Color.cxx
src/Draw/TKDraw/Draw/Draw_GraphicCommands.cxx
src/Draw/TKQADraw/QABugs/QABugs_13.cxx
src/FoundationClasses/TKMath/BSplSLib/BSplSLib.cxx
src/FoundationClasses/TKMath/Bnd/Bnd_OBB.cxx
src/FoundationClasses/TKMath/GTests/math_NewtonFunctionSetRoot_Test.cxx
src/FoundationClasses/TKMath/math/math_GlobOptMin.cxx
src/ModelingAlgorithms/TKBO/GTests/BRepAlgoAPI_Cut_Test.cxx
src/ModelingAlgorithms/TKBO/GTests/BRepAlgoAPI_Fuse_Test.cxx
src/ModelingData/TKGeomBase/Extrema/Extrema_GenExtCC.gxx
src/Visualization/TKOpenGl/OpenGl/OpenGl_BackgroundArray.cxx
src/Visualization/TKV3d/AIS/AIS_Manipulator.cxx

index d8f7fbe5e3ee6fa187737635f51322c0a836c8e8..f3ac88903b1f615b085f5da3a3055d8f7f53f21b 100644 (file)
 
 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)));
index 328971cb562fa2f60cef060058ac3405fe04c1e8..4203175aba64284bcbd92043f3ab9ec9dc7cfe77 100644 (file)
 #include <Standard_Stream.hxx>
 
 #include <stdio.h>
+
+#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"))
         {
index 82ccb9b3bed48d4cfe7954d3ba723980de69b9ea..abff26481eb6b2791d807ba319e0829db09b9b03 100644 (file)
 #include <GProp_GProps.hxx>
 #include <Standard_ErrorHandler.hxx>
 
+#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;
index be821ff61c855f1113edffb27cb35cde74b9ea29..7a2cf1086e6231d30b03e332cd3f58e245d6eecc 100644 (file)
 #include <TColStd_HArray1OfInteger.hxx>
 
 // 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,
index d3b5f28aa4bdcb0b5dc483103de9d1a26fa0622d..64bd9adb7395eeff06413a102f6403d17e40a19e 100644 (file)
 #include <Standard_Dump.hxx>
 #include <TColStd_Array1OfReal.hxx>
 
+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;
index 8bca08a4518158d64d65a8af37d5934c70c916ab..67c20c06e5d78d85c8e08e5297c7590d5fa806e8 100644 (file)
 #include <StdFail_NotDone.hxx>
 #include <Standard_DimensionError.hxx>
 
+#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
 }
 
index a90464bfc4019ee6bfec7ae94136611a64f07415..f317d16016c9a0f9c421037af4753117269b7bf2 100644 (file)
 #include <Standard_Real.hxx>
 #include <Precision.hxx>
 
+#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);
   }
 }
 
index f1ad0c81b63f8cb6a36a67fd2a1e2a4bbbbbd41a..947632b1c8e7a4a6713241c97767d6febbd10a11 100644 (file)
 
 #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)),
index 241865cb5f7350620e563bba794794240f267fc9..80fec7e4ffaf412f8ae8dd8f50d54b3483083a4e 100644 (file)
 
 #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);
 
index 08342743c3ff0599fe7e442d271348d05e0f4d61..c6bb44dc9847584d6c0416ce3a3d2bc4e99d9796 100644 (file)
 #include <NCollection_CellFilter.hxx>
 #include <GCPnts_AbscissaPoint.hxx>
 
+#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<Extrema_CCPointsInspector> aFilter(aCellSize);
index 79c932b72844cd0b123d2d8896700efc398189d5..33319a27c117913d10364f0d810e41d3ff5d248b 100644 (file)
 #include <OpenGl_Texture.hxx>
 #include <OpenGl_View.hxx>
 
+#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;
       }
index 0a31ad04c32cb16ebf47aa6ff974aeb7d1ea3b70..89e6ad4efa679bad7beee353411f554a7a2378c9 100644 (file)
 #include <TColgp_Array1OfPnt.hxx>
 #include <V3d_View.hxx>
 
+#ifndef M_SQRT2
+  #define M_SQRT2 1.41421356237309504880168872420969808
+#endif
+
 IMPLEMENT_STANDARD_HANDLE(AIS_Manipulator, AIS_InteractiveObject)
 IMPLEMENT_STANDARD_RTTIEXT(AIS_Manipulator, AIS_InteractiveObject)