From af0287e17465b010b44191f61e973993d586d518 Mon Sep 17 00:00:00 2001 From: Andrea Date: Fri, 23 May 2025 01:11:37 +0200 Subject: [PATCH 1/4] 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); From b9c7f385a2a11115c4460c28ad073e8935b7e931 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 22 May 2025 23:17:45 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../CAM/PathSimulator/AppGL/MillPathSegment.cpp | 2 +- src/Mod/CAM/PathSimulator/AppGL/SimDisplay.cpp | 16 ++++++++-------- src/Mod/CAM/PathSimulator/AppGL/SimDisplay.h | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Mod/CAM/PathSimulator/AppGL/MillPathSegment.cpp b/src/Mod/CAM/PathSimulator/AppGL/MillPathSegment.cpp index bf2a518c8e..53bef6acfd 100644 --- a/src/Mod/CAM/PathSimulator/AppGL/MillPathSegment.cpp +++ b/src/Mod/CAM/PathSimulator/AppGL/MillPathSegment.cpp @@ -30,7 +30,7 @@ using std::numbers::pi; #define N_MILL_SLICES 8 -#define MAX_SEG_DEG (pi/ 2.0f) // 90 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 diff --git a/src/Mod/CAM/PathSimulator/AppGL/SimDisplay.cpp b/src/Mod/CAM/PathSimulator/AppGL/SimDisplay.cpp index 1806a9cea0..58ce770fde 100644 --- a/src/Mod/CAM/PathSimulator/AppGL/SimDisplay.cpp +++ b/src/Mod/CAM/PathSimulator/AppGL/SimDisplay.cpp @@ -36,7 +36,7 @@ namespace MillSim { - using std::numbers::pi; +using std::numbers::pi; void SimDisplay::InitShaders() { @@ -121,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(pi*2 * x2) * s; - randVec[1] = sinf(pi*2 * 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(pi*2 * x); - randVec[1] = sinf(pi*2 * x); + randVec[0] = cosf(pi * 2 * x); + randVec[1] = sinf(pi * 2 * x); randVec[2] = 0; } @@ -497,11 +497,11 @@ void SimDisplay::TiltEye(float tiltStep) void SimDisplay::RotateEye(float rotStep) { mEyeRoration += rotStep; - if (mEyeRoration > pi*2) { - mEyeRoration -= pi*2; + if (mEyeRoration > pi * 2) { + mEyeRoration -= pi * 2; } else if (mEyeRoration < 0) { - mEyeRoration += pi*2; + mEyeRoration += pi * 2; } updateDisplay = true; } diff --git a/src/Mod/CAM/PathSimulator/AppGL/SimDisplay.h b/src/Mod/CAM/PathSimulator/AppGL/SimDisplay.h index 6ae4f27a1b..04ff704bc2 100644 --- a/src/Mod/CAM/PathSimulator/AppGL/SimDisplay.h +++ b/src/Mod/CAM/PathSimulator/AppGL/SimDisplay.h @@ -34,7 +34,7 @@ namespace MillSim { - using std::numbers::pi; +using std::numbers::pi; struct Point3D { From 3d63b5d2821a39a55ef644f140ba2289ac9984d0 Mon Sep 17 00:00:00 2001 From: Andrea Date: Fri, 23 May 2025 01:18:58 +0200 Subject: [PATCH 3/4] . --- src/Mod/CAM/PathSimulator/App/VolSim.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Mod/CAM/PathSimulator/App/VolSim.cpp b/src/Mod/CAM/PathSimulator/App/VolSim.cpp index 7d45033b35..81fa2faef6 100644 --- a/src/Mod/CAM/PathSimulator/App/VolSim.cpp +++ b/src/Mod/CAM/PathSimulator/App/VolSim.cpp @@ -32,7 +32,8 @@ #include "VolSim.h" - +using std::numbers::pi; + //************************************************************************************************************ // stock //************************************************************************************************************ @@ -559,7 +560,7 @@ void cStock::ApplyLinearTool(Point3D& p1, Point3D& p2, cSimTool& tool) // end cup for (float r = 0.5f; r <= rad; r += (float)SIM_WALK_RES) { Point3D cupCirc(perpDirX * r, perpDirY * r, pi2.z); - float rotang = 180 * SIM_WALK_RES / (3.1415926535 * r); + float rotang = 180 * SIM_WALK_RES / (pi* r); cupCirc.SetRotationAngle(-rotang); float z = pi2.z + tool.GetToolProfileAt(r / rad); for (float a = 0; a < cupAngle; a += rotang) { @@ -588,9 +589,6 @@ void cStock::ApplyCircularTool(Point3D& p1, Point3D& p2, Point3D& cent, cSimTool Point3D xynorm = unit(Point3D(-cpx, -cpy, 0)); float crad = sqrt(cpx * cpx + cpy * cpy); - // bool shortRad = (crad - rad) < 0.0001; - // if (shortRad) - // rad = crad; float crad1 = std::max((float)0.5, crad - rad); float crad2 = crad + rad; @@ -602,10 +600,10 @@ void cStock::ApplyCircularTool(Point3D& p1, Point3D& p2, Point3D& cent, cSimTool double ang = eang - sang; if (!isCCW && ang > 0) { - ang -= 2 * 3.1415926; + ang -= 2 * pi; } if (isCCW && ang < 0) { - ang += 2 * 3.1415926; + ang += 2 * pi; } ang = fabs(ang); @@ -644,7 +642,7 @@ void cStock::ApplyCircularTool(Point3D& p1, Point3D& p2, Point3D& cent, cSimTool for (float r = 0.5f; r <= rad; r += (float)SIM_WALK_RES) { Point3D cupCirc(xynorm.x * r, xynorm.y * r, 0); float rotang = (float)SIM_WALK_RES / r; - int ndivs = (int)(3.1415926535 / rotang) + 1; + int ndivs = (int)(pi / rotang) + 1; if (!isCCW) { rotang = -rotang; } @@ -699,7 +697,7 @@ void Point3D::SetRotationAngleRad(float angle) void Point3D::SetRotationAngle(float angle) { - SetRotationAngleRad(angle * 2 * 3.1415926535 / 360); + SetRotationAngleRad(angle * 2 * pi / 360); } void Point3D::UpdateCmd(Path::Command& cmd) From f596e654f4ca38e737e40f770d60cb2f657f9d66 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 22 May 2025 23:23:16 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/Mod/CAM/PathSimulator/App/VolSim.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Mod/CAM/PathSimulator/App/VolSim.cpp b/src/Mod/CAM/PathSimulator/App/VolSim.cpp index 81fa2faef6..2a6164e8d9 100644 --- a/src/Mod/CAM/PathSimulator/App/VolSim.cpp +++ b/src/Mod/CAM/PathSimulator/App/VolSim.cpp @@ -33,7 +33,7 @@ #include "VolSim.h" using std::numbers::pi; - + //************************************************************************************************************ // stock //************************************************************************************************************ @@ -560,7 +560,7 @@ void cStock::ApplyLinearTool(Point3D& p1, Point3D& p2, cSimTool& tool) // end cup for (float r = 0.5f; r <= rad; r += (float)SIM_WALK_RES) { Point3D cupCirc(perpDirX * r, perpDirY * r, pi2.z); - float rotang = 180 * SIM_WALK_RES / (pi* r); + float rotang = 180 * SIM_WALK_RES / (pi * r); cupCirc.SetRotationAngle(-rotang); float z = pi2.z + tool.GetToolProfileAt(r / rad); for (float a = 0; a < cupAngle; a += rotang) {