CAM: Use std::numeric_limits and std::numbers instead of defines

This commit is contained in:
Benjamin Nauck
2025-03-27 19:00:18 +01:00
parent d551ad8be5
commit 9e3c0d111e
12 changed files with 44 additions and 60 deletions

View File

@@ -26,7 +26,6 @@
#define BOOST_GEOMETRY_DISABLE_DEPRECATED_03_WARNING
#ifndef _PreComp_
#include <cfloat>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/register/point.hpp>
@@ -452,7 +451,7 @@ void Area::addWire(CArea& area,
if (reversed) {
type = -type;
}
if (fabs(first - last) > M_PI) {
if (fabs(first - last) > std::numbers::pi) {
// Split arc(circle) larger than half circle. Because gcode
// can't handle full circle?
gp_Pnt mid = curve.Value((last - first) * 0.5 + first);
@@ -1221,7 +1220,8 @@ struct WireJoiner
info.iEnd[i] = info.iStart[i] = (int)adjacentList.size();
// populate adjacent list
for (auto vit = vmap.qbegin(bgi::nearest(pt[i], INT_MAX)); vit != vmap.qend();
constexpr int intMax = std::numeric_limits<int>::max();
for (auto vit = vmap.qbegin(bgi::nearest(pt[i], intMax)); vit != vmap.qend();
++vit) {
++rcount;
if (vit->pt().SquareDistance(pt[i]) > tol) {
@@ -2631,7 +2631,7 @@ TopoDS_Shape Area::makePocket(int index, PARAM_ARGS(PARAM_FARG, AREA_PARAMS_POCK
for (int j = 0; j < steps; ++j, offset += stepover) {
Point p1(-r, offset), p2(r, offset);
if (a > Precision::Confusion()) {
double r = a * M_PI / 180.0;
double r = a * std::numbers::pi / 180.0;
p1.Rotate(r);
p2.Rotate(r);
}
@@ -3703,7 +3703,7 @@ std::list<TopoDS_Shape> Area::sortWires(const std::list<TopoDS_Shape>& shapes,
double max_dist = sort_mode == SortModeGreedy ? threshold * threshold : 0;
while (!shape_list.empty()) {
AREA_TRACE("sorting " << shape_list.size() << ' ' << AREA_XYZ(pstart));
double best_d = DBL_MAX;
double best_d = std::numeric_limits<double>::max();
auto best_it = shape_list.begin();
for (auto it = best_it; it != shape_list.end(); ++it) {
double d;
@@ -4155,7 +4155,7 @@ void Area::toPath(Toolpath& path,
}
}
if (fabs(first - last) > M_PI) {
if (fabs(first - last) > std::numbers::pi) {
// Split arc(circle) larger than half circle.
gp_Pnt mid = curve.Value((last - first) * 0.5 + first);
addGArc(verbose,

View File

@@ -31,14 +31,6 @@
#define ARC_MIN_SEGMENTS 20.0 // minimum # segments to interpolate an arc
#ifndef M_PI
#define M_PI 3.14159265358979323846 /* pi */
#endif
#ifndef M_PI_2
#define M_PI_2 1.57079632679489661923 /* pi/2 */
#endif
namespace Path
{
@@ -195,7 +187,7 @@ void PathSegmentWalker::walk(PathSegmentVisitor& cb, const Base::Vector3d& start
if (nrot != lrot) {
double amax = std::max(fmod(fabs(a - A), 360),
std::max(fmod(fabs(b - B), 360), fmod(fabs(c - C), 360)));
double angle = amax / 180 * M_PI;
double angle = amax / 180 * std::numbers::pi;
int segments = std::max(ARC_MIN_SEGMENTS, 3.0 / (deviation / angle));
double da = (a - A) / segments;
@@ -257,16 +249,16 @@ void PathSegmentWalker::walk(PathSegmentVisitor& cb, const Base::Vector3d& start
Base::Vector3d anorm = (last0 - center0) % (next0 - center0);
if (anorm.*pz < 0) {
if (name == "G3" || name == "G03") {
angle = M_PI * 2 - angle;
angle = std::numbers::pi * 2 - angle;
}
}
else if (anorm.*pz > 0) {
if (name == "G2" || name == "G02") {
angle = M_PI * 2 - angle;
angle = std::numbers::pi * 2 - angle;
}
}
else if (angle == 0) {
angle = M_PI * 2;
angle = std::numbers::pi * 2;
}
double amax = std::max(fmod(fabs(a - A), 360),
@@ -337,7 +329,7 @@ void PathSegmentWalker::walk(PathSegmentVisitor& cb, const Base::Vector3d& start
if (nrot != lrot) {
double amax = std::max(fmod(fabs(a - A), 360),
std::max(fmod(fabs(b - B), 360), fmod(fabs(c - C), 360)));
double angle = amax / 180 * M_PI;
double angle = amax / 180 * std::numbers::pi;
int segments = std::max(ARC_MIN_SEGMENTS, 3.0 / (deviation / angle));
double da = (a - A) / segments;

View File

@@ -22,8 +22,6 @@
#include "PreCompiled.h"
#ifndef _PreComp_
#define _USE_MATH_DEFINES
#include <math.h>
#endif
#include <Base/Vector3D.h>
@@ -260,10 +258,10 @@ double Voronoi::diagram_type::angleOfSegment(int i, Voronoi::diagram_type::angle
double ang = 0;
if (p0.x() == p1.x()) {
if (p0.y() < p1.y()) {
ang = M_PI_2;
ang = std::numbers::pi / 2;
}
else {
ang = -M_PI_2;
ang = -std::numbers::pi / 2;
}
}
else {
@@ -292,7 +290,8 @@ bool Voronoi::diagram_type::segmentsAreConnected(int i, int j) const
void Voronoi::colorColinear(Voronoi::color_type color, double degree)
{
double rad = degree * M_PI / 180;
using std::numbers::pi;
double rad = degree * pi / 180;
Voronoi::diagram_type::angle_map_t angle;
int psize = vd->points.size();
@@ -306,11 +305,11 @@ void Voronoi::colorColinear(Voronoi::color_type color, double degree)
double a0 = vd->angleOfSegment(i0, &angle);
double a1 = vd->angleOfSegment(i1, &angle);
double a = a0 - a1;
if (a > M_PI_2) {
a -= M_PI;
if (a > pi / 2) {
a -= pi;
}
else if (a < -M_PI_2) {
a += M_PI;
else if (a < -pi / 2) {
a += pi;
}
if (fabs(a) < rad) {
it->color(color);

View File

@@ -22,7 +22,6 @@
#ifndef PATH_VORONOI_H
#define PATH_VORONOI_H
#include <climits>
#include <map>
#include <vector>
#include <Base/BaseClass.h>
@@ -33,11 +32,6 @@
#include <boost/polygon/polygon.hpp>
#include <boost/polygon/voronoi.hpp>
#if (SIZE_MAX == UINT_MAX)
#define PATH_VORONOI_COLOR_MASK 0x07FFFFFFul
#else
#define PATH_VORONOI_COLOR_MASK 0x07FFFFFFFFFFFFFFul
#endif
namespace Path
{
@@ -51,8 +45,8 @@ public:
~Voronoi() override;
using color_type = std::size_t;
static const int InvalidIndex = INT_MAX;
static const color_type ColorMask = PATH_VORONOI_COLOR_MASK;
static const int InvalidIndex = std::numeric_limits<int>::max();
static const color_type ColorMask = std::numeric_limits<color_type>::max() >> 5;
// types
using coordinate_type = double;

View File

@@ -466,12 +466,12 @@ PyObject* VoronoiEdgePy::isBorderline(PyObject* args)
PyObject* VoronoiEdgePy::toShape(PyObject* args)
{
double z0 = 0.0;
double z1 = DBL_MAX;
double z1 = std::numeric_limits<double>::max();
int dbg = 0;
if (!PyArg_ParseTuple(args, "|ddp", &z0, &z1, &dbg)) {
throw Py::RuntimeError("no, one or two arguments of type double accepted");
}
if (z1 == DBL_MAX) {
if (z1 == std::numeric_limits<double>::max()) {
z1 = z0;
}
VoronoiEdge* e = getVoronoiEdgePtr();
@@ -688,6 +688,8 @@ PyObject* VoronoiEdgePy::getDistances(PyObject* args)
PyObject* VoronoiEdgePy::getSegmentAngle(PyObject* args)
{
using std::numbers::pi;
VoronoiEdge* e = getVoronoiEdgeFromPy(this, args);
if (e->ptr->cell()->contains_segment() && e->ptr->twin()->cell()->contains_segment()) {
@@ -697,11 +699,11 @@ PyObject* VoronoiEdgePy::getSegmentAngle(PyObject* args)
double a0 = e->dia->angleOfSegment(i0);
double a1 = e->dia->angleOfSegment(i1);
double a = a0 - a1;
if (a > M_PI_2) {
a -= M_PI;
if (a > pi / 2) {
a -= pi;
}
else if (a < -M_PI_2) {
a += M_PI;
else if (a < -pi / 2) {
a += pi;
}
return Py::new_reference_to(Py::Float(a));
}

View File

@@ -183,11 +183,11 @@ ViewProviderPath::ViewProviderPath()
ShowCountConstraints.LowerBound = 0;
ShowCountConstraints.UpperBound = INT_MAX;
ShowCountConstraints.UpperBound = std::numeric_limits<int>::max();
ShowCountConstraints.StepSize = 1;
ShowCount.setConstraints(&ShowCountConstraints);
StartIndexConstraints.LowerBound = 0;
StartIndexConstraints.UpperBound = INT_MAX;
StartIndexConstraints.UpperBound = std::numeric_limits<int>::max();
StartIndexConstraints.StepSize = 1;
StartIndex.setConstraints(&StartIndexConstraints);
ADD_PROPERTY_TYPE(StartPosition,

View File

@@ -5,7 +5,7 @@
#define LINMATH_H
#include <string.h>
#include <math.h>
#include <cmath>
#ifdef LINMATH_NO_INLINE
#define LINMATH_H_FUNC static

View File

@@ -26,6 +26,7 @@
#include <cstring>
#include <ctime>
#include <algorithm>
#include <numbers>
namespace ClipperLib
{
@@ -116,7 +117,7 @@ inline double Angle3Points(const DoublePoint& p1, const DoublePoint& p2, const D
double t1 = atan2(p2.Y - p1.Y, p2.X - p1.X);
double t2 = atan2(p3.Y - p2.Y, p3.X - p2.X);
double a = fabs(t2 - t1);
return min(a, 2 * M_PI - a);
return min(a, 2 * std::numbers::pi - a);
}
inline DoublePoint DirectionV(const IntPoint& pt1, const IntPoint& pt2)
@@ -1096,8 +1097,8 @@ private:
class Interpolation
{
public:
const double MIN_ANGLE = -M_PI / 4;
const double MAX_ANGLE = M_PI / 4;
const double MIN_ANGLE = -std::numbers::pi / 4;
const double MAX_ANGLE = std::numbers::pi / 4;
void clear()
{
@@ -1542,7 +1543,7 @@ double Adaptive2d::CalcCutArea(Clipper& clip,
double minFi = fi1;
double maxFi = fi2;
if (maxFi < minFi) {
maxFi += 2 * M_PI;
maxFi += 2 * std::numbers::pi;
}
if (preventConventional && interPathLen >= RESOLUTION_FACTOR) {
@@ -2359,7 +2360,7 @@ bool Adaptive2d::MakeLeadPath(bool leadIn,
IntPoint(currentPoint.X + nextDir.X * stepSize, currentPoint.Y + nextDir.Y * stepSize);
Path checkPath;
double adaptFactor = 0.4;
double alfa = M_PI / 64;
double alfa = std::numbers::pi / 64;
double pathLen = 0;
checkPath.push_back(nextPoint);
for (int i = 0; i < 10000; i++) {
@@ -2802,7 +2803,7 @@ void Adaptive2d::ProcessPolyNode(Paths boundPaths, Paths toolBoundPaths)
IntPoint clp; // to store closest point
vector<DoublePoint> gyro; // used to average tool direction
vector<double> angleHistory; // use to predict deflection angle
double angle = M_PI;
double angle = std::numbers::pi;
engagePoint = toolPos;
Interpolation interp; // interpolation instance
@@ -2846,7 +2847,7 @@ void Adaptive2d::ProcessPolyNode(Paths boundPaths, Paths toolBoundPaths)
}
}
angle = M_PI / 4; // initial pass angle
angle = std::numbers::pi / 4; // initial pass angle
bool recalcArea = false;
double cumulativeCutArea = 0;
// init gyro
@@ -2991,7 +2992,7 @@ void Adaptive2d::ProcessPolyNode(Paths boundPaths, Paths toolBoundPaths)
rotateStep++;
// if new tool pos. outside boundary rotate until back in
recalcArea = true;
newToolDir = rotate(newToolDir, M_PI / 90);
newToolDir = rotate(newToolDir, std::numbers::pi / 90);
newToolPos = IntPoint(long(toolPos.X + newToolDir.X * stepScaled),
long(toolPos.Y + newToolDir.Y * stepScaled));
}

View File

@@ -36,10 +36,6 @@
#define __LONG_MAX__ 2147483647
#endif
#ifndef M_PI
#define M_PI 3.141592653589793238
#endif
// #define DEV_MODE
#define NTOL 1.0e-7 // numeric tolerance

View File

@@ -29,7 +29,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include <string.h> // for memcpy() prototype
#include <math.h> // for sqrt() prototype
#include <cmath> // for sqrt() prototype
class CBox2D
{

View File

@@ -31,7 +31,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <vector>
#include <list>
#include <math.h>
#include <cmath>
#include "Point.h"
#include "Box2D.h"

View File

@@ -17,7 +17,7 @@
#endif
#endif
#include <math.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <list>