- 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
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
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)));
#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;
{
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"))
{
}
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"))
{
}
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"))
{
}
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"))
{
#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)
// 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;
}
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;
#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
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,
{
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,
#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
// 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;
#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;
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
}
#include <Standard_Real.hxx>
#include <Precision.hxx>
+#ifndef M_SQRT2
+ #define M_SQRT2 1.41421356237309504880168872420969808
+#endif
+
//=================================================================================================
static Standard_Real DistanceToBorder(const math_Vector& theX,
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);
}
}
#include "BOPTest_Utilities.pxx"
+#ifndef M_SQRT2
+ #define M_SQRT2 1.41421356237309504880168872420969808
+#endif
+
//==================================================================================================
// BCut Simple Tests - migrating from /tests/boolean/bcut_simple/
//==================================================================================================
{
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)),
{
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)),
// 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);
}
{
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)),
{
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)),
#include "BOPTest_Utilities.pxx"
+#ifndef M_SQRT2
+ #define M_SQRT2 1.41421356237309504880168872420969808
+#endif
+
//==================================================================================================
// BFuse Simple Tests - migrating from /tests/boolean/bfuse_simple/
//==================================================================================================
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);
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);
#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)
{
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;
// 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);
#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)
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;
}
#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)