Merge pull request #21528 from mosfet80/piDef

CAM: using std::numbers pi definition
This commit is contained in:
sliptonic
2025-05-28 13:53:00 -05:00
committed by GitHub
6 changed files with 36 additions and 34 deletions

View File

@@ -32,6 +32,7 @@
#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)

View File

@@ -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) \
{ \

View File

@@ -27,9 +27,11 @@
#include "GlUtils.h"
#include <iostream>
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;
}

View File

@@ -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);

View File

@@ -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;

View File

@@ -28,6 +28,7 @@
#include <vector>
using namespace MillSim;
using std::numbers::pi;
int Shape::lastNumSlices = 0;
std::vector<float> 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);