From af0287e17465b010b44191f61e973993d586d518 Mon Sep 17 00:00:00 2001 From: Andrea Date: Fri, 23 May 2025 01:11:37 +0200 Subject: [PATCH] CAM: use std::numbers pi definition se std::numbers pi definition --- src/Mod/CAM/PathSimulator/AppGL/GlUtils.h | 5 +--- .../PathSimulator/AppGL/MillPathSegment.cpp | 16 +++++++----- .../CAM/PathSimulator/AppGL/SimDisplay.cpp | 26 ++++++++++--------- src/Mod/CAM/PathSimulator/AppGL/SimDisplay.h | 6 +++-- src/Mod/CAM/PathSimulator/AppGL/SimShapes.cpp | 3 ++- 5 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/Mod/CAM/PathSimulator/AppGL/GlUtils.h b/src/Mod/CAM/PathSimulator/AppGL/GlUtils.h index d46eca829f..fad98ac5e2 100644 --- a/src/Mod/CAM/PathSimulator/AppGL/GlUtils.h +++ b/src/Mod/CAM/PathSimulator/AppGL/GlUtils.h @@ -25,9 +25,6 @@ #include "OpenGlWrapper.h" #include "linmath.h" -#define PI 3.14159265f -#define PI2 (PI * 2) - constexpr auto EPSILON = 0.00001f; #define EQ_FLOAT(x, y) (fabs((x) - (y)) < EPSILON) @@ -46,7 +43,7 @@ constexpr auto EPSILON = 0.00001f; if (GLLogError()) \ __debugbreak(); \ } -#define RadToDeg(x) (x * 180.0f / PI) + #define GLDELETE(type, x) \ { \ diff --git a/src/Mod/CAM/PathSimulator/AppGL/MillPathSegment.cpp b/src/Mod/CAM/PathSimulator/AppGL/MillPathSegment.cpp index 72ba80cf8d..bf2a518c8e 100644 --- a/src/Mod/CAM/PathSimulator/AppGL/MillPathSegment.cpp +++ b/src/Mod/CAM/PathSimulator/AppGL/MillPathSegment.cpp @@ -27,9 +27,11 @@ #include "GlUtils.h" #include +using std::numbers::pi; + #define N_MILL_SLICES 8 -#define MAX_SEG_DEG (PI / 2.0f) // 90 deg -#define NIN_SEG_DEG (PI / 90.0f) // 2 deg +#define MAX_SEG_DEG (pi/ 2.0f) // 90 deg +#define NIN_SEG_DEG (pi / 90.0f) // 2 deg #define SWEEP_ARC_PAD 1.05f #define PX 0 #define PY 1 @@ -53,7 +55,7 @@ bool IsArcMotion(MillMotion* m) } float MillPathSegment::mResolution = 1; -float MillPathSegment::mSmallRadStep = (PI / 8); +float MillPathSegment::mSmallRadStep = (pi / 8); MillPathSegment::MillPathSegment(EndMill* _endmill, MillMotion* from, MillMotion* to) { @@ -93,7 +95,7 @@ MillPathSegment::MillPathSegment(EndMill* _endmill, MillMotion* from, MillMotion float endAng = atan2f(mCenter[PX] - to->x, to->y - mCenter[PY]); mSweepAng = (mStartAngRad - endAng) * mArcDir; if (mSweepAng < EPSILON) { - mSweepAng += PI * 2; + mSweepAng += pi * 2; } numSimSteps = (int)(mSweepAng / mStepAngRad) + 1; mStepAngRad = mArcDir * mSweepAng / numSimSteps; @@ -240,12 +242,12 @@ float MillPathSegment::SetQuality(float quality, float maxStockDimension) if (mResolution < 0.5) { mResolution = 0.5; } - mSmallRadStep = PI / 8; + mSmallRadStep = pi / 8; if (quality < 4) { - mSmallRadStep = PI / 2; + mSmallRadStep = pi / 2; } else if (quality < 8) { - mSmallRadStep = PI / 4; + mSmallRadStep = pi / 4; } return mResolution; } diff --git a/src/Mod/CAM/PathSimulator/AppGL/SimDisplay.cpp b/src/Mod/CAM/PathSimulator/AppGL/SimDisplay.cpp index 145ea6a6e7..1806a9cea0 100644 --- a/src/Mod/CAM/PathSimulator/AppGL/SimDisplay.cpp +++ b/src/Mod/CAM/PathSimulator/AppGL/SimDisplay.cpp @@ -36,6 +36,8 @@ namespace MillSim { + using std::numbers::pi; + void SimDisplay::InitShaders() { // use shaders @@ -119,16 +121,16 @@ void SimDisplay::UniformHemisphere(vec3& randVec) float x1 = distr01(generator); float x2 = distr01(generator); float s = sqrt(1.0f - x1 * x1); - randVec[0] = cosf(PI2 * x2) * s; - randVec[1] = sinf(PI2 * x2) * s; + randVec[0] = cosf(pi*2 * x2) * s; + randVec[1] = sinf(pi*2 * x2) * s; randVec[2] = x1; } void SimDisplay::UniformCircle(vec3& randVec) { float x = distr01(generator); - randVec[0] = cosf(PI2 * x); - randVec[1] = sinf(PI2 * x); + randVec[0] = cosf(pi*2 * x); + randVec[1] = sinf(pi*2 * x); randVec[2] = 0; } @@ -484,22 +486,22 @@ void SimDisplay::SetupLinePathPass(int curSegment, bool isHidden) void SimDisplay::TiltEye(float tiltStep) { mEyeInclination += tiltStep; - if (mEyeInclination > PI / 2) { - mEyeInclination = PI / 2; + if (mEyeInclination > pi / 2) { + mEyeInclination = pi / 2; } - else if (mEyeInclination < -PI / 2) { - mEyeInclination = -PI / 2; + else if (mEyeInclination < -pi / 2) { + mEyeInclination = -pi / 2; } } void SimDisplay::RotateEye(float rotStep) { mEyeRoration += rotStep; - if (mEyeRoration > PI2) { - mEyeRoration -= PI2; + if (mEyeRoration > pi*2) { + mEyeRoration -= pi*2; } else if (mEyeRoration < 0) { - mEyeRoration += PI2; + mEyeRoration += pi*2; } updateDisplay = true; } @@ -535,7 +537,7 @@ void SimDisplay::MoveEye(float x, float z) void SimDisplay::MoveEyeCenter() { mEyeRoration = 0; - mEyeInclination = PI / 6; + mEyeInclination = pi / 6; mEyeX = 0; mEyeZ = 0; UpdateEyeFactor(0.1f); diff --git a/src/Mod/CAM/PathSimulator/AppGL/SimDisplay.h b/src/Mod/CAM/PathSimulator/AppGL/SimDisplay.h index 3213337d1a..6ae4f27a1b 100644 --- a/src/Mod/CAM/PathSimulator/AppGL/SimDisplay.h +++ b/src/Mod/CAM/PathSimulator/AppGL/SimDisplay.h @@ -34,6 +34,8 @@ namespace MillSim { + using std::numbers::pi; + struct Point3D { float x, y, z; @@ -113,8 +115,8 @@ protected: float mEyeDistance = 30; float mEyeRoration = 0; - float mEyeInclination = PI / 6; // 30 degree - float mEyeStep = PI / 36; // 5 degree + float mEyeInclination = pi / 6; // 30 degree + float mEyeStep = pi / 36; // 5 degree float mMaxStockDim = 100; float mEyeDistFactor = 0.0f; diff --git a/src/Mod/CAM/PathSimulator/AppGL/SimShapes.cpp b/src/Mod/CAM/PathSimulator/AppGL/SimShapes.cpp index 246ae24c3e..6819916e68 100644 --- a/src/Mod/CAM/PathSimulator/AppGL/SimShapes.cpp +++ b/src/Mod/CAM/PathSimulator/AppGL/SimShapes.cpp @@ -28,6 +28,7 @@ #include using namespace MillSim; +using std::numbers::pi; int Shape::lastNumSlices = 0; std::vector Shape::sinTable; @@ -39,7 +40,7 @@ void Shape::GenerateSinTable(int nSlices) return; } - float slice = (float)(2 * PI / nSlices); + float slice = (float)(2 * pi / nSlices); int nvals = nSlices + 1; sinTable.resize(nvals); cosTable.resize(nvals);