diff --git a/src/Mod/Sketcher/App/Sketch.cpp b/src/Mod/Sketcher/App/Sketch.cpp index fef264d601..24d350825d 100644 --- a/src/Mod/Sketcher/App/Sketch.cpp +++ b/src/Mod/Sketcher/App/Sketch.cpp @@ -3060,6 +3060,7 @@ int Sketch::addAngleAtPointConstraint(int geoId1, ConstraintType cTyp, bool driving) { + using std::numbers::pi; if (!(cTyp == Angle || cTyp == Tangent || cTyp == Perpendicular)) { // assert(0);//none of the three types. Why are we here?? return -1; @@ -3132,28 +3133,28 @@ int Sketch::addAngleAtPointConstraint(int geoId1, // the desired angle value (and we are to decide if 180* should be added to it) double angleDesire = 0.0; if (cTyp == Tangent) { - angleOffset = -M_PI / 2; + angleOffset = -pi / 2; angleDesire = 0.0; } if (cTyp == Perpendicular) { angleOffset = 0; - angleDesire = M_PI / 2; + angleDesire = pi / 2; } if (*value == 0.0) { // autodetect tangency internal/external (and same for perpendicularity) double angleErr = GCSsys.calculateAngleViaPoint(*crv1, *crv2, p) - angleDesire; // bring angleErr to -pi..pi - if (angleErr > M_PI) { - angleErr -= M_PI * 2; + if (angleErr > pi) { + angleErr -= pi * 2; } - if (angleErr < -M_PI) { - angleErr += M_PI * 2; + if (angleErr < -pi) { + angleErr += pi * 2; } // the autodetector - if (fabs(angleErr) > M_PI / 2) { - angleDesire += M_PI; + if (fabs(angleErr) > pi / 2) { + angleDesire += pi; } *angle = angleDesire; @@ -4542,7 +4543,7 @@ bool Sketch::updateNonDrivingConstraints() } else if ((*it).constr->Type == Angle) { - (*it).constr->setValue(std::fmod(*((*it).value), 2.0 * M_PI)); + (*it).constr->setValue(std::fmod(*((*it).value), 2.0 * std::numbers::pi)); } else if ((*it).constr->Type == Diameter && (*it).constr->First >= 0) { diff --git a/src/Mod/Sketcher/App/SketchAnalysis.cpp b/src/Mod/Sketcher/App/SketchAnalysis.cpp index e2e4751771..81d20781ef 100644 --- a/src/Mod/Sketcher/App/SketchAnalysis.cpp +++ b/src/Mod/Sketcher/App/SketchAnalysis.cpp @@ -591,7 +591,7 @@ void SketchAnalysis::analyseMissingPointOnPointCoincident(double angleprecision) if (fabs(tgv1 * tgv2) > fabs(cos(angleprecision))) { vc.Type = Sketcher::Tangent; } - else if (fabs(tgv1 * tgv2) < fabs(cos(M_PI / 2 - angleprecision))) { + else if (fabs(tgv1 * tgv2) < fabs(cos(std::numbers::pi / 2 - angleprecision))) { vc.Type = Sketcher::Perpendicular; } } @@ -726,7 +726,8 @@ void SketchAnalysis::makeMissingVerticalHorizontalOneByOne() bool SketchAnalysis::checkVertical(Base::Vector3d dir, double angleprecision) { - return (dir.x == 0. && dir.y != 0.) || (fabs(dir.y / dir.x) > tan(M_PI / 2 - angleprecision)); + return (dir.x == 0. && dir.y != 0.) + || (fabs(dir.y / dir.x) > tan(std::numbers::pi / 2 - angleprecision)); } bool SketchAnalysis::checkHorizontal(Base::Vector3d dir, double angleprecision) diff --git a/src/Mod/Sketcher/App/SketchAnalysis.h b/src/Mod/Sketcher/App/SketchAnalysis.h index 4695254d29..dc354b6d80 100644 --- a/src/Mod/Sketcher/App/SketchAnalysis.h +++ b/src/Mod/Sketcher/App/SketchAnalysis.h @@ -94,7 +94,7 @@ public: int detectMissingPointOnPointConstraints(double precision = Precision::Confusion() * 1000, bool includeconstruction = true); /// Point on Point constraint simple routine Analyse step (see constructor) - void analyseMissingPointOnPointCoincident(double angleprecision = M_PI / 8); + void analyseMissingPointOnPointCoincident(double angleprecision = std::numbers::pi / 8); /// Point on Point constraint simple routine Get step (see constructor) std::vector& getMissingPointOnPointConstraints() { @@ -113,7 +113,7 @@ public: void makeMissingPointOnPointCoincidentOneByOne(); /// Vertical/Horizontal constraints simple routine Detect step (see constructor) - int detectMissingVerticalHorizontalConstraints(double angleprecision = M_PI / 8); + int detectMissingVerticalHorizontalConstraints(double angleprecision = std::numbers::pi / 8); /// Vertical/Horizontal constraints simple routine Get step (see constructor) std::vector& getMissingVerticalHorizontalConstraints() { @@ -168,7 +168,7 @@ public: /// /// It applies coincidents - vertical/horizontal constraints and equality constraints. int autoconstraint(double precision = Precision::Confusion() * 1000, - double angleprecision = M_PI / 8, + double angleprecision = std::numbers::pi / 8, bool includeconstruction = true); // helper functions, which may be used by more complex methods, and/or called directly by user diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 64b717d48d..e7f62dfb41 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -1143,7 +1143,7 @@ void SketchObject::reverseAngleConstraintToSupplementary(Constraint* constr, int } else { double actAngle = constr->getValue(); - constr->setValue(M_PI - actAngle); + constr->setValue(std::numbers::pi - actAngle); } } @@ -3248,12 +3248,12 @@ int SketchObject::fillet(int GeoId1, int GeoId2, const Base::Vector3d& refPnt1, std::swap(startAngle, endAngle); } - if (endAngle > 2 * M_PI) { - endAngle -= 2 * M_PI; + if (endAngle > 2 * std::numbers::pi) { + endAngle -= 2 * std::numbers::pi; } if (startAngle < 0) { - endAngle += 2 * M_PI; + endAngle += 2 * std::numbers::pi; } // Create Arc Segment @@ -4905,6 +4905,8 @@ std::vector SketchObject::getSymmetric(const std::vector& int refGeoId, Sketcher::PointPos refPosId) { + using std::numbers::pi; + std::vector symmetricVals; bool refIsLine = refPosId == Sketcher::PointPos::none; int cgeoid = getHighestCurveIndex() + 1; @@ -4980,8 +4982,8 @@ std::vector SketchObject::getSymmetric(const std::vector& Base::Vector3d scp = cp + 2.0 * (cp.Perpendicular(refGeoLine->getStartPoint(), vectline) - cp); - double theta1 = Base::fmod(atan2(sep.y - scp.y, sep.x - scp.x), 2.f * M_PI); - double theta2 = Base::fmod(atan2(ssp.y - scp.y, ssp.x - scp.x), 2.f * M_PI); + double theta1 = Base::fmod(atan2(sep.y - scp.y, sep.x - scp.x), 2.f * std::numbers::pi); + double theta2 = Base::fmod(atan2(ssp.y - scp.y, ssp.x - scp.x), 2.f * std::numbers::pi); geoaoc->setCenter(scp); geoaoc->setRange(theta1, theta2, true); @@ -5028,12 +5030,12 @@ std::vector SketchObject::getSymmetric(const std::vector& double theta1, theta2; geosymaoe->getRange(theta1, theta2, true); - theta1 = 2.0 * M_PI - theta1; - theta2 = 2.0 * M_PI - theta2; + theta1 = 2.0 * pi - theta1; + theta2 = 2.0 * pi - theta2; std::swap(theta1, theta2); if (theta1 < 0) { - theta1 += 2.0 * M_PI; - theta2 += 2.0 * M_PI; + theta1 += 2.0 * pi; + theta2 += 2.0 * pi; } geosymaoe->setRange(theta1, theta2, true); @@ -5178,8 +5180,8 @@ std::vector SketchObject::getSymmetric(const std::vector& Base::Vector3d sep = ep + 2.0 * (refpoint - ep); Base::Vector3d scp = cp + 2.0 * (refpoint - cp); - double theta1 = Base::fmod(atan2(ssp.y - scp.y, ssp.x - scp.x), 2.f * M_PI); - double theta2 = Base::fmod(atan2(sep.y - scp.y, sep.x - scp.x), 2.f * M_PI); + double theta1 = Base::fmod(atan2(ssp.y - scp.y, ssp.x - scp.x), 2.f * pi); + double theta2 = Base::fmod(atan2(sep.y - scp.y, sep.x - scp.x), 2.f * pi); geoaoc->setCenter(scp); geoaoc->setRange(theta1, theta2, true); @@ -8568,6 +8570,8 @@ void processEdge(const TopoDS_Edge& edge, gp_Ax3& sketchAx3, TopoDS_Shape& aProjFace) { + using std::numbers::pi; + BRepAdaptor_Curve curve(edge); if (curve.GetType() == GeomAbs_Line) { geos.emplace_back(projectLine(curve, gPlane, invPlm)); @@ -8641,11 +8645,11 @@ void processEdge(const TopoDS_Edge& edge, int tours = 0; double startAngle = baseAngle + alpha; // bring startAngle back in [-pi/2 , 3pi/2[ - while (startAngle < -M_PI / 2.0 && tours < 10) { - startAngle = baseAngle + ++tours * 2.0 * M_PI + alpha; + while (startAngle < -pi / 2.0 && tours < 10) { + startAngle = baseAngle + ++tours * 2.0 * pi + alpha; } - while (startAngle >= 3.0 * M_PI / 2.0 && tours > -10) { - startAngle = baseAngle + --tours * 2.0 * M_PI + alpha; + while (startAngle >= 3.0 * pi / 2.0 && tours > -10) { + startAngle = baseAngle + --tours * 2.0 * pi + alpha; } // apply same offset to end angle @@ -8661,7 +8665,7 @@ void processEdge(const TopoDS_Edge& edge, // P2 = P2 already defined P1 = ProjPointOnPlane_XYZ(beg, sketchPlane); } - else if (endAngle < M_PI) { + else if (endAngle < pi) { // P2 = P2, already defined P1 = ProjPointOnPlane_XYZ(end, sketchPlane); } @@ -8671,16 +8675,16 @@ void processEdge(const TopoDS_Edge& edge, } } } - else if (startAngle < M_PI) { - if (endAngle < M_PI) { + else if (startAngle < pi) { + if (endAngle < pi) { P1 = ProjPointOnPlane_XYZ(beg, sketchPlane); P2 = ProjPointOnPlane_XYZ(end, sketchPlane); } - else if (endAngle < 2.0 * M_PI - startAngle) { + else if (endAngle < 2.0 * pi - startAngle) { P2 = ProjPointOnPlane_XYZ(beg, sketchPlane); // P1 = P1, already defined } - else if (endAngle < 2.0 * M_PI) { + else if (endAngle < 2.0 * pi) { P2 = ProjPointOnPlane_XYZ(end, sketchPlane); // P1 = P1, already defined } @@ -8690,15 +8694,15 @@ void processEdge(const TopoDS_Edge& edge, } } else { - if (endAngle < 2 * M_PI) { + if (endAngle < 2 * pi) { P1 = ProjPointOnPlane_XYZ(beg, sketchPlane); P2 = ProjPointOnPlane_XYZ(end, sketchPlane); } - else if (endAngle < 4 * M_PI - startAngle) { + else if (endAngle < 4 * pi - startAngle) { P1 = ProjPointOnPlane_XYZ(beg, sketchPlane); // P2 = P2, already defined } - else if (endAngle < 3 * M_PI) { + else if (endAngle < 3 * pi) { // P1 = P1, already defined P2 = ProjPointOnPlane_XYZ(end, sketchPlane); } @@ -8818,7 +8822,7 @@ void processEdge(const TopoDS_Edge& edge, gp_Vec2d PB = ProjVecOnPlane_UV(origAxisMinor, sketchPlane); double t_max = 2.0 * PA.Dot(PB) / (PA.SquareMagnitude() - PB.SquareMagnitude()); t_max = 0.5 * atan(t_max);// gives new major axis is most cases, but not all - double t_min = t_max + 0.5 * M_PI; + double t_min = t_max + 0.5 * pi; // ON_max = OM(t_max) gives the point, which projected on the sketch plane, // becomes the apoapse of the projected ellipse. @@ -9313,7 +9317,7 @@ void SketchObject::rebuildExternalGeometry(std::optional extToAdd processEdge(edge, geos, gPlane, invPlm, mov, sketchPlane, invRot, sketchAx3, aProjFace); } - if (fabs(dnormal.Angle(snormal) - M_PI_2) < Precision::Confusion()) { + if (fabs(dnormal.Angle(snormal) - std::numbers::pi/2) < Precision::Confusion()) { // The face is normal to the sketch plane // We don't want to keep the projection of all the edges of the face. // We need a single line that goes from min to max of all the projections. @@ -11310,6 +11314,8 @@ int SketchObject::port_reversedExternalArcs(bool justAnalyze) /// false - fail (this indicates an error, or that a constraint locking isn't supported). bool SketchObject::AutoLockTangencyAndPerpty(Constraint* cstr, bool bForce, bool bLock) { + using std::numbers::pi; + try { // assert ( cstr->Type == Tangent || cstr->Type == Perpendicular); /*tangency type already set. If not bForce - don't touch.*/ @@ -11359,25 +11365,25 @@ bool SketchObject::AutoLockTangencyAndPerpty(Constraint* cstr, bool bForce, bool // the desired angle value (and we are to decide if 180* should be added to it) double angleDesire = 0.0; if (cstr->Type == Tangent) { - angleOffset = -M_PI / 2; + angleOffset = -pi / 2; angleDesire = 0.0; } if (cstr->Type == Perpendicular) { angleOffset = 0; - angleDesire = M_PI / 2; + angleDesire = pi / 2; } double angleErr = calculateAngleViaPoint(geoId1, geoId2, p.x, p.y) - angleDesire; // bring angleErr to -pi..pi - if (angleErr > M_PI) - angleErr -= M_PI * 2; - if (angleErr < -M_PI) - angleErr += M_PI * 2; + if (angleErr > pi) + angleErr -= pi * 2; + if (angleErr < -pi) + angleErr += pi * 2; // the autodetector - if (fabs(angleErr) > M_PI / 2) - angleDesire += M_PI; + if (fabs(angleErr) > pi / 2) + angleDesire += pi; // external tangency. The angle stored is offset by Pi/2 so that a value of 0.0 is // invalid and treated as "undecided". diff --git a/src/Mod/Sketcher/App/SketchObject.h b/src/Mod/Sketcher/App/SketchObject.h index 05a484c7be..4d17218403 100644 --- a/src/Mod/Sketcher/App/SketchObject.h +++ b/src/Mod/Sketcher/App/SketchObject.h @@ -841,13 +841,13 @@ public: public: // Analyser functions int autoConstraint(double precision = Precision::Confusion() * 1000, - double angleprecision = M_PI / 20, + double angleprecision = std::numbers::pi / 20, bool includeconstruction = true); int detectMissingPointOnPointConstraints(double precision = Precision::Confusion() * 1000, bool includeconstruction = true); - void analyseMissingPointOnPointCoincident(double angleprecision = M_PI / 8); - int detectMissingVerticalHorizontalConstraints(double angleprecision = M_PI / 8); + void analyseMissingPointOnPointCoincident(double angleprecision = std::numbers::pi / 8); + int detectMissingVerticalHorizontalConstraints(double angleprecision = std::numbers::pi / 8); int detectMissingEqualityConstraints(double precision); std::vector& getMissingPointOnPointConstraints(); diff --git a/src/Mod/Sketcher/App/SketchObjectPyImp.cpp b/src/Mod/Sketcher/App/SketchObjectPyImp.cpp index eaf4156d1a..28cc485a3f 100644 --- a/src/Mod/Sketcher/App/SketchObjectPyImp.cpp +++ b/src/Mod/Sketcher/App/SketchObjectPyImp.cpp @@ -1918,7 +1918,7 @@ PyObject* SketchObjectPy::insertBSplineKnot(PyObject* args) PyObject* SketchObjectPy::autoconstraint(PyObject* args) { double precision = Precision::Confusion() * 1000; - double angleprecision = M_PI / 8; + double angleprecision = std::numbers::pi / 8; PyObject* includeconstruction = Py_True; @@ -1960,7 +1960,7 @@ PyObject* SketchObjectPy::detectMissingPointOnPointConstraints(PyObject* args) PyObject* SketchObjectPy::detectMissingVerticalHorizontalConstraints(PyObject* args) { - double angleprecision = M_PI / 8; + double angleprecision = std::numbers::pi / 8; if (!PyArg_ParseTuple(args, "|d", &angleprecision)) { return nullptr; @@ -1984,7 +1984,7 @@ PyObject* SketchObjectPy::detectMissingEqualityConstraints(PyObject* args) PyObject* SketchObjectPy::analyseMissingPointOnPointCoincident(PyObject* args) { - double angleprecision = M_PI / 8; + double angleprecision = std::numbers::pi / 8; if (!PyArg_ParseTuple(args, "|d", &angleprecision)) { return nullptr; diff --git a/src/Mod/Sketcher/App/planegcs/Constraints.cpp b/src/Mod/Sketcher/App/planegcs/Constraints.cpp index 539dfd9f95..336d20e3d2 100644 --- a/src/Mod/Sketcher/App/planegcs/Constraints.cpp +++ b/src/Mod/Sketcher/App/planegcs/Constraints.cpp @@ -24,8 +24,8 @@ #pragma warning(disable : 4251) #endif -#define _USE_MATH_DEFINES #include +#include #include #define DEBUG_DERIVS 0 @@ -864,6 +864,8 @@ double ConstraintP2PAngle::grad(double* param) double ConstraintP2PAngle::maxStep(MAP_pD_D& dir, double lim) { + constexpr double pi_18 = std::numbers::pi / 18; + MAP_pD_D::iterator it = dir.find(angle()); if (it != dir.end()) { double step = std::abs(it->second); @@ -1444,6 +1446,8 @@ double ConstraintL2LAngle::grad(double* param) double ConstraintL2LAngle::maxStep(MAP_pD_D& dir, double lim) { + constexpr double pi_18 = std::numbers::pi / 18; + MAP_pD_D::iterator it = dir.find(angle()); if (it != dir.end()) { double step = std::abs(it->second); @@ -3536,10 +3540,10 @@ void ConstraintArcLength::errorgrad(double* err, double* grad, double* param) double startA = *arc.startAngle; // Assume positive angles and CCW arc while (startA < 0.) { - startA += 2. * M_PI; + startA += 2. * std::numbers::pi; } while (endA < startA) { - endA += 2. * M_PI; + endA += 2. * std::numbers::pi; } if (err) { *err = rad * (endA - startA) - *distance(); diff --git a/src/Mod/Sketcher/App/planegcs/GCS.cpp b/src/Mod/Sketcher/App/planegcs/GCS.cpp index f397db6a10..bc63d84608 100644 --- a/src/Mod/Sketcher/App/planegcs/GCS.cpp +++ b/src/Mod/Sketcher/App/planegcs/GCS.cpp @@ -47,10 +47,10 @@ #endif #include -#include #include #include #include +#include #include "GCS.h" #include "qp_eq.h" @@ -1029,6 +1029,8 @@ int System::addConstraintPerpendicularLine2Arc(Point& p1, int tagId, bool driving) { + using std::numbers::pi; + addConstraintP2PCoincident(p2, a.start, tagId, driving); double dx = *(p2.x) - *(p1.x); double dy = *(p2.y) - *(p1.y); @@ -1046,6 +1048,8 @@ int System::addConstraintPerpendicularArc2Line(Arc& a, int tagId, bool driving) { + using std::numbers::pi; + addConstraintP2PCoincident(p1, a.end, tagId, driving); double dx = *(p2.x) - *(p1.x); double dy = *(p2.y) - *(p1.y); @@ -1063,8 +1067,10 @@ int System::addConstraintPerpendicularCircle2Arc(Point& center, int tagId, bool driving) { + using std::numbers::pi; + addConstraintP2PDistance(a.start, center, radius, tagId, driving); - double incrAngle = *(a.startAngle) < *(a.endAngle) ? pi_2 : -pi_2; + double incrAngle = *(a.startAngle) < *(a.endAngle) ? pi / 2 : -pi / 2; double tangAngle = *a.startAngle + incrAngle; double dx = *(a.start.x) - *(center.x); double dy = *(a.start.y) - *(center.y); @@ -1082,8 +1088,10 @@ int System::addConstraintPerpendicularArc2Circle(Arc& a, int tagId, bool driving) { + using std::numbers::pi; + addConstraintP2PDistance(a.end, center, radius, tagId, driving); - double incrAngle = *(a.startAngle) < *(a.endAngle) ? -pi_2 : pi_2; + double incrAngle = *(a.startAngle) < *(a.endAngle) ? -pi / 2 : pi / 2; double tangAngle = *a.endAngle + incrAngle; double dx = *(a.end.x) - *(center.x); double dy = *(a.end.y) - *(center.y); @@ -2270,12 +2278,13 @@ int System::solve_LM(SubSystem* subsys, bool isRedundantsolving) x_new = x + h; h_norm = h.squaredNorm(); + constexpr double epsilon = std::numeric_limits::epsilon(); if (h_norm <= eps1 * eps1 * x.norm()) { // relative change in p is small, stop stop = 3; break; } - else if (h_norm >= (x.norm() + eps1) / (DBL_EPSILON * DBL_EPSILON)) { + else if (h_norm >= (x.norm() + eps1) / (epsilon * epsilon)) { // almost singular stop = 4; break; diff --git a/src/Mod/Sketcher/App/planegcs/Geo.h b/src/Mod/Sketcher/App/planegcs/Geo.h index 4604c55b26..bbfdf39736 100644 --- a/src/Mod/Sketcher/App/planegcs/Geo.h +++ b/src/Mod/Sketcher/App/planegcs/Geo.h @@ -53,9 +53,6 @@ public: }; using VEC_P = std::vector; -static constexpr double pi = boost::math::constants::pi(); -static constexpr double pi_2 = pi / 2.0; -static constexpr double pi_18 = pi / 18.0; /// Class DeriVector2 holds a vector value and its derivative on the /// parameter that the derivatives are being calculated for now. x,y is the diff --git a/src/Mod/Sketcher/Gui/CommandConstraints.cpp b/src/Mod/Sketcher/Gui/CommandConstraints.cpp index d46109ce7f..8ed676bb93 100644 --- a/src/Mod/Sketcher/Gui/CommandConstraints.cpp +++ b/src/Mod/Sketcher/Gui/CommandConstraints.cpp @@ -24,7 +24,6 @@ #ifndef _PreComp_ #include #include -#include #endif #include @@ -114,10 +113,10 @@ void finishDatumConstraint(Gui::Command* cmd, if (lastConstraintType == Radius || lastConstraintType == Diameter) { labelPosition = hGrp->GetFloat("RadiusDiameterConstraintDisplayBaseAngle", 15.0) - * (M_PI / 180);// Get radius/diameter constraint display angle + * (std::numbers::pi / 180);// Get radius/diameter constraint display angle labelPositionRandomness = hGrp->GetFloat("RadiusDiameterConstraintDisplayAngleRandomness", 0.0) - * (M_PI / 180);// Get randomness + * (std::numbers::pi / 180);// Get randomness // Adds a random value around the base angle, so that possibly overlapping labels get likely // a different position. @@ -320,7 +319,7 @@ bool SketcherGui::calculateAngle(Sketcher::SketchObject* Obj, int& GeoId1, int& } else { // if all points are collinear - double length = DBL_MAX; + double length = std::numeric_limits::max(); for (int i = 0; i <= 1; i++) { for (int j = 0; j <= 1; j++) { double tmp = Base::DistanceP2(p2[j], p1[i]); diff --git a/src/Mod/Sketcher/Gui/CommandSketcherBSpline.cpp b/src/Mod/Sketcher/Gui/CommandSketcherBSpline.cpp index 3b6e6819d0..ee3f9b5381 100644 --- a/src/Mod/Sketcher/Gui/CommandSketcherBSpline.cpp +++ b/src/Mod/Sketcher/Gui/CommandSketcherBSpline.cpp @@ -24,7 +24,6 @@ #ifndef _PreComp_ #include #include -#include #endif #include diff --git a/src/Mod/Sketcher/Gui/CommandSketcherOverlay.cpp b/src/Mod/Sketcher/Gui/CommandSketcherOverlay.cpp index 4dc6673d96..0e0158f73e 100644 --- a/src/Mod/Sketcher/Gui/CommandSketcherOverlay.cpp +++ b/src/Mod/Sketcher/Gui/CommandSketcherOverlay.cpp @@ -24,7 +24,6 @@ #ifndef _PreComp_ #include #include -#include #endif #include diff --git a/src/Mod/Sketcher/Gui/CommandSketcherTools.cpp b/src/Mod/Sketcher/Gui/CommandSketcherTools.cpp index 1fbfc714cb..4058d4e827 100644 --- a/src/Mod/Sketcher/Gui/CommandSketcherTools.cpp +++ b/src/Mod/Sketcher/Gui/CommandSketcherTools.cpp @@ -22,7 +22,6 @@ #include "PreCompiled.h" #ifndef _PreComp_ -#include #include #include @@ -1205,6 +1204,8 @@ public: void mouseMove(Base::Vector2d onSketchPos) override { + using std::numbers::pi; + if (Mode == STATUS_SEEK_First) { if (QApplication::keyboardModifiers() == Qt::ControlModifier) @@ -1218,14 +1219,14 @@ public: Base::Vector2d endpoint = onSketchPos; if (snapMode == SnapMode::Snap5Degree) { - angle = round(angle / (M_PI / 36)) * M_PI / 36; + angle = round(angle / (pi / 36)) * pi / 36; endpoint = EditCurve[0] + length * Base::Vector2d(cos(angle), sin(angle)); } if (showCursorCoords()) { SbString text; std::string lengthString = lengthToDisplayFormat(length, 1); - std::string angleString = angleToDisplayFormat(angle * 180.0 / M_PI, 1); + std::string angleString = angleToDisplayFormat(angle * 180.0 / pi, 1); text.sprintf(" (%s, %s)", lengthString.c_str(), angleString.c_str()); setPositionText(endpoint, text); } @@ -1781,6 +1782,8 @@ public: void mouseMove(Base::Vector2d onSketchPos) override { + using std::numbers::pi; + if (Mode == STATUS_SEEK_First) { if (QApplication::keyboardModifiers() == Qt::ControlModifier) @@ -1794,14 +1797,14 @@ public: Base::Vector2d endpoint = onSketchPos; if (snapMode == SnapMode::Snap5Degree) { - angle = round(angle / (M_PI / 36)) * M_PI / 36; + angle = round(angle / (pi / 36)) * pi / 36; endpoint = EditCurve[0] + length * Base::Vector2d(cos(angle), sin(angle)); } if (showCursorCoords()) { SbString text; std::string lengthString = lengthToDisplayFormat(length, 1); - std::string angleString = angleToDisplayFormat(angle * 180.0 / M_PI, 1); + std::string angleString = angleToDisplayFormat(angle * 180.0 / pi, 1); text.sprintf(" (%s, %s)", lengthString.c_str(), angleString.c_str()); setPositionText(endpoint, text); } diff --git a/src/Mod/Sketcher/Gui/CommandSketcherVirtualSpace.cpp b/src/Mod/Sketcher/Gui/CommandSketcherVirtualSpace.cpp index 6fcfdbfdf9..4af8107eb2 100644 --- a/src/Mod/Sketcher/Gui/CommandSketcherVirtualSpace.cpp +++ b/src/Mod/Sketcher/Gui/CommandSketcherVirtualSpace.cpp @@ -22,7 +22,6 @@ #include "PreCompiled.h" #ifndef _PreComp_ -#include #endif #include diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp b/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp index e378625ac1..b6ff76dfd8 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp +++ b/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp @@ -425,6 +425,8 @@ int DrawSketchHandler::seekAutoConstraint(std::vector& suggested const Base::Vector2d& Dir, AutoConstraint::TargetType type) { + using std::numbers::pi; + suggestedConstraints.clear(); SketchObject* obj = sketchgui->getSketchObject(); @@ -550,18 +552,18 @@ int DrawSketchHandler::seekAutoConstraint(std::vector& suggested // Number of Degree of deviation from horizontal or vertical lines const double angleDev = 2; - const double angleDevRad = angleDev * M_PI / 180.; + const double angleDevRad = angleDev * pi / 180.; AutoConstraint constr; constr.Type = Sketcher::None; constr.GeoId = GeoEnum::GeoUndef; constr.PosId = PointPos::none; double angle = std::abs(atan2(Dir.y, Dir.x)); - if (angle < angleDevRad || (M_PI - angle) < angleDevRad) { + if (angle < angleDevRad || (pi - angle) < angleDevRad) { // Suggest horizontal constraint constr.Type = Sketcher::Horizontal; } - else if (std::abs(angle - M_PI_2) < angleDevRad) { + else if (std::abs(angle - pi / 2) < angleDevRad) { // Suggest vertical constraint constr.Type = Sketcher::Vertical; } @@ -665,7 +667,7 @@ int DrawSketchHandler::seekAutoConstraint(std::vector& suggested double angle = atan2(projPnt.y, projPnt.x); while (angle < startAngle) { - angle += 2 * D_PI; // Bring it to range of arc + angle += 2 * pi; // Bring it to range of arc } // if the point is on correct side of arc @@ -714,10 +716,10 @@ int DrawSketchHandler::seekAutoConstraint(std::vector& suggested aoe->getMinorRadius() * ((tmpPos.x - center.x) * majdir.x + (tmpPos.y - center.y) * majdir.y)) - startAngle, - 2.f * M_PI); + 2.f * pi); while (angle < startAngle) { - angle += 2 * D_PI; // Bring it to range of arc + angle += 2 * pi; // Bring it to range of arc } // if the point is on correct side of arc @@ -978,7 +980,7 @@ void DrawSketchHandler::drawDirectionAtCursor(const Base::Vector2d& position, SbString text; std::string lengthString = lengthToDisplayFormat(length, 1); - std::string angleString = angleToDisplayFormat(angle * 180.0 / M_PI, 1); + std::string angleString = angleToDisplayFormat(angle * 180.0 / std::numbers::pi, 1); text.sprintf(" (%s, %s)", lengthString.c_str(), angleString.c_str()); setPositionText(position, text); } @@ -1009,7 +1011,7 @@ void DrawSketchHandler::drawDoubleAtCursor(const Base::Vector2d& position, SbString text; std::string doubleString = unit == Base::Unit::Length ? lengthToDisplayFormat(val, 1) - : angleToDisplayFormat(val * 180.0 / M_PI, 1); + : angleToDisplayFormat(val * 180.0 / std::numbers::pi, 1); text.sprintf(" (%s)", doubleString.c_str()); setPositionText(position, text); } diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerArc.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerArc.h index af25729b50..54123fb115 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerArc.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerArc.h @@ -132,7 +132,7 @@ private: if (constructionMethod() == ConstructionMethod::Center) { secondPoint = onSketchPos; double angle1 = (onSketchPos - centerPoint).Angle() - startAngle; - double angle2 = angle1 + (angle1 < 0. ? 2 : -2) * M_PI; + double angle2 = angle1 + (angle1 < 0. ? 2 : -2) * std::numbers::pi; arcAngle = abs(angle1 - arcAngle) < abs(angle2 - arcAngle) ? angle1 : angle2; if (arcAngle > 0) { @@ -183,7 +183,7 @@ private: } startAngle = std::max(angle1, angle2); endAngle = std::min(angle1, angle2); - arcAngle = 2 * M_PI - (startAngle - endAngle); + arcAngle = 2 * std::numbers::pi - (startAngle - endAngle); } } @@ -562,7 +562,7 @@ void DSHArcControllerBase::doEnforceControlParameters(Base::Vector2d& onSketchPo if (onViewParameters[OnViewParameter::Fifth]->isSet) { double arcAngle = Base::toRadians(onViewParameters[OnViewParameter::Fifth]->getValue()); - if (fmod(fabs(arcAngle), 2 * M_PI) < Precision::Confusion()) { + if (fmod(fabs(arcAngle), 2 * std::numbers::pi) < Precision::Confusion()) { unsetOnViewParameter(onViewParameters[OnViewParameter::Fifth].get()); return; } diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfEllipse.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfEllipse.h index 5185010b1c..a4ebaad0f1 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfEllipse.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfEllipse.h @@ -68,6 +68,8 @@ public: void mouseMove(Base::Vector2d onSketchPos) override { + using std::numbers::pi; + if (Mode == STATUS_SEEK_First) { setPositionText(onSketchPos); seekAndRenderAutoConstraint(sugConstr1, @@ -78,7 +80,7 @@ public: double rx0 = onSketchPos.x - EditCurve[0].x; double ry0 = onSketchPos.y - EditCurve[0].y; for (int i = 0; i < 16; i++) { - double angle = i * M_PI / 16.0; + double angle = i * pi / 16.0; double rx1 = rx0 * cos(angle) + ry0 * sin(angle); double ry1 = -rx0 * sin(angle) + ry0 * cos(angle); EditCurve[1 + i] = Base::Vector2d(EditCurve[0].x + rx1, EditCurve[0].y + ry1); @@ -115,7 +117,7 @@ public: / (sin(angleatpoint) * cos(phi)); for (int i = 1; i < 16; i++) { - double angle = i * M_PI / 16.0; + double angle = i * pi / 16.0; double rx1 = a * cos(angle) * cos(phi) - b * sin(angle) * sin(phi); double ry1 = a * cos(angle) * sin(phi) + b * sin(angle) * cos(phi); EditCurve[1 + i] = Base::Vector2d(EditCurve[0].x + rx1, EditCurve[0].y + ry1); @@ -161,7 +163,7 @@ public: + (onSketchPos.y - centerPoint.y) * sin(phi))) - startAngle; - double angle2 = angle1 + (angle1 < 0. ? 2 : -2) * M_PI; + double angle2 = angle1 + (angle1 < 0. ? 2 : -2) * pi; arcAngle = abs(angle1 - arcAngle) < abs(angle2 - arcAngle) ? angle1 : angle2; for (int i = 0; i < 34; i++) { @@ -178,7 +180,7 @@ public: SbString text; std::string aString = lengthToDisplayFormat(a, 1); std::string bString = lengthToDisplayFormat(b, 1); - std::string angleString = angleToDisplayFormat(arcAngle * 180.0 / M_PI, 1); + std::string angleString = angleToDisplayFormat(arcAngle * 180.0 / pi, 1); text.sprintf(" (R%s, R%s, %s)", aString.c_str(), bString.c_str(), @@ -222,6 +224,9 @@ public: bool releaseButton(Base::Vector2d onSketchPos) override { Q_UNUSED(onSketchPos); + + using std::numbers::pi; + if (Mode == STATUS_Close) { unsetCursor(); resetPositionText(); @@ -245,7 +250,7 @@ public: + (endPoint.y - centerPoint.y) * sin(phi))) - startAngle; - double angle2 = angle1 + (angle1 < 0. ? 2 : -2) * M_PI; + double angle2 = angle1 + (angle1 < 0. ? 2 : -2) * pi; arcAngle = abs(angle1 - arcAngle) < abs(angle2 - arcAngle) ? angle1 : angle2; bool isOriginalArcCCW = true; @@ -281,8 +286,8 @@ public: perp.Scale(abs(b)); majAxisPoint = centerPoint + perp; minAxisPoint = centerPoint + minAxisDir; - endAngle += M_PI / 2; - startAngle += M_PI / 2; + endAngle += pi / 2; + startAngle += pi / 2; } int currentgeoid = getHighestCurveIndex(); diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfHyperbola.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfHyperbola.h index 620f1bc0a1..9f96e3f169 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfHyperbola.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfHyperbola.h @@ -103,7 +103,7 @@ public: if (!boost::math::isnan(b)) { for (int i = 15; i >= -15; i--) { // P(U) = O + MajRad*Cosh(U)*XDir + MinRad*Sinh(U)*YDir - // double angle = i*M_PI/16.0; + // double angle = i*std::numbers::pi/16.0; double angle = i * angleatpoint / 15; double rx = a * cosh(angle) * cos(phi) - b * sinh(angle) * sin(phi); double ry = a * cosh(angle) * sin(phi) + b * sinh(angle) * cos(phi); @@ -150,7 +150,7 @@ public: /*double angle1 = angleatpoint - startAngle; - double angle2 = angle1 + (angle1 < 0. ? 2 : -2) * M_PI ; + double angle2 = angle1 + (angle1 < 0. ? 2 : -2) * std::numbers::pi ; arcAngle = abs(angle1-arcAngle) < abs(angle2-arcAngle) ? angle1 : angle2;*/ arcAngle = angleatpoint - startAngle; @@ -290,8 +290,8 @@ public: perp.Scale(abs(b)); majAxisPoint = centerPoint + perp; minAxisPoint = centerPoint + minAxisDir; - endAngle += M_PI / 2; - startAngle += M_PI / 2; + endAngle += std::numbers::pi / 2; + startAngle += std::numbers::pi / 2; } int currentgeoid = getHighestCurveIndex(); diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerArcSlot.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerArcSlot.h index 354930156a..cbd996489a 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerArcSlot.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerArcSlot.h @@ -133,7 +133,7 @@ private: startAngle = startAngleBackup; double angle1 = (onSketchPos - centerPoint).Angle() - startAngle; - double angle2 = angle1 + (angle1 < 0. ? 2 : -2) * M_PI; + double angle2 = angle1 + (angle1 < 0. ? 2 : -2) * std::numbers::pi; arcAngle = abs(angle1 - arcAngle) < abs(angle2 - arcAngle) ? angle1 : angle2; reverseIfNecessary(); @@ -305,6 +305,8 @@ private: void createShape(bool onlyeditoutline) override { + using std::numbers::pi; + ShapeGeometry.clear(); if (radius < Precision::Confusion()) { @@ -331,14 +333,14 @@ private: isConstructionMode()); addArcToShapeGeometry(toVector3d(startPoint), - angleReversed ? endAngle : startAngle + M_PI, - angleReversed ? endAngle + M_PI : startAngle + 2 * M_PI, + angleReversed ? endAngle : startAngle + pi, + angleReversed ? endAngle + pi : startAngle + 2 * pi, r, isConstructionMode()); addArcToShapeGeometry(toVector3d(endPoint), - angleReversed ? startAngle + M_PI : endAngle, - angleReversed ? startAngle + 2 * M_PI : M_PI + endAngle, + angleReversed ? startAngle + pi : endAngle, + angleReversed ? startAngle + 2 * pi : pi + endAngle, r, isConstructionMode()); @@ -635,7 +637,7 @@ void DSHArcSlotControllerBase::doEnforceControlParameters(Base::Vector2d& onSket if (onViewParameters[OnViewParameter::Fifth]->isSet) { double arcAngle = Base::toRadians(onViewParameters[OnViewParameter::Fifth]->getValue()); - if (fmod(fabs(arcAngle), 2 * M_PI) < Precision::Confusion()) { + if (fmod(fabs(arcAngle), 2 * std::numbers::pi) < Precision::Confusion()) { unsetOnViewParameter(onViewParameters[OnViewParameter::Fifth].get()); } else { diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerExtend.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerExtend.h index f6561f017d..587db8d527 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerExtend.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerExtend.h @@ -110,6 +110,9 @@ public: void mouseMove(Base::Vector2d onSketchPos) override { Q_UNUSED(onSketchPos); + + using std::numbers::pi; + if (Mode == STATUS_SEEK_Second) { const Part::Geometry* geom = sketchgui->getSketchObject()->getGeometry(BaseGeoId); if (geom->is()) { @@ -142,7 +145,7 @@ public: */ bool inCurve = (projection.Length() < recenteredLine.Length() && projection.GetAngle(recenteredLine) - < 0.1); // Two possible values here, M_PI and 0, but 0.1 is to + < 0.1); // Two possible values here, pi and 0, but 0.1 is to // avoid floating point problems. if (inCurve) { Increment = SavedExtendFromStart @@ -185,8 +188,8 @@ public: bool isCCWFromStart = crossProduct(angle, startAngle) < 0; if (outOfArc) { if (isCCWFromStart) { - modStartAngle -= 2 * M_PI - angleToStartAngle; - modArcAngle += 2 * M_PI - angleToStartAngle; + modStartAngle -= 2 * pi - angleToStartAngle; + modArcAngle += 2 * pi - angleToStartAngle; } else { modStartAngle -= angleToStartAngle; @@ -199,8 +202,8 @@ public: modArcAngle -= angleToStartAngle; } else { - modStartAngle += 2 * M_PI - angleToStartAngle; - modArcAngle -= 2 * M_PI - angleToStartAngle; + modStartAngle += 2 * pi - angleToStartAngle; + modArcAngle -= 2 * pi - angleToStartAngle; } } } @@ -208,7 +211,7 @@ public: bool isCWFromEnd = crossProduct(angle, endAngle) >= 0; if (outOfArc) { if (isCWFromEnd) { - modArcAngle += 2 * M_PI - angleToEndAngle; + modArcAngle += 2 * pi - angleToEndAngle; } else { modArcAngle += angleToEndAngle; @@ -219,7 +222,7 @@ public: modArcAngle -= angleToEndAngle; } else { - modArcAngle -= 2 * M_PI - angleToEndAngle; + modArcAngle -= 2 * pi - angleToEndAngle; } } } diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerLine.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerLine.h index efbe278b5e..50f7ea7377 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerLine.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerLine.h @@ -646,16 +646,17 @@ void DSHLineController::addConstraints() }; auto constraintp4angle = [&]() { + using std::numbers::pi; + double angle = Base::toRadians(p4); - if (fabs(angle - M_PI) < Precision::Confusion() - || fabs(angle + M_PI) < Precision::Confusion() + if (fabs(angle - pi) < Precision::Confusion() || fabs(angle + pi) < Precision::Confusion() || fabs(angle) < Precision::Confusion()) { Gui::cmdAppObjectArgs(obj, "addConstraint(Sketcher.Constraint('Horizontal',%d)) ", firstCurve); } - else if (fabs(angle - M_PI / 2) < Precision::Confusion() - || fabs(angle + M_PI / 2) < Precision::Confusion()) { + else if (fabs(angle - pi / 2) < Precision::Confusion() + || fabs(angle + pi / 2) < Precision::Confusion()) { Gui::cmdAppObjectArgs(obj, "addConstraint(Sketcher.Constraint('Vertical',%d)) ", firstCurve); diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerLineSet.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerLineSet.h index 798f9f674b..37b0f6834e 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerLineSet.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerLineSet.h @@ -188,6 +188,8 @@ public: void mouseMove(Base::Vector2d onSketchPos) override { + using std::numbers::pi; + suppressTransition = false; if (Mode == STATUS_SEEK_First) { setPositionText(onSketchPos); @@ -222,7 +224,7 @@ public: if (showCursorCoords()) { SbString text; std::string lengthString = lengthToDisplayFormat(length, 1); - std::string angleString = angleToDisplayFormat(angle * 180.0 / M_PI, 1); + std::string angleString = angleToDisplayFormat(angle * 180.0 / pi, 1); text.sprintf(" (%s, %s)", lengthString.c_str(), angleString.c_str()); setPositionText(EditCurve[1], text); } @@ -289,14 +291,14 @@ public: arcAngle = 0.f; } if (arcRadius >= 0 && arcAngle > 0) { - arcAngle -= 2 * M_PI; + arcAngle -= 2 * pi; } if (arcRadius < 0 && arcAngle < 0) { - arcAngle += 2 * M_PI; + arcAngle += 2 * pi; } if (SnapMode == SNAP_MODE_45Degree) { - arcAngle = round(arcAngle / (M_PI / 4)) * M_PI / 4; + arcAngle = round(arcAngle / (pi / 4)) * pi / 4; } endAngle = startAngle + arcAngle; @@ -316,7 +318,7 @@ public: if (showCursorCoords()) { SbString text; std::string radiusString = lengthToDisplayFormat(std::abs(arcRadius), 1); - std::string angleString = angleToDisplayFormat(arcAngle * 180.0 / M_PI, 1); + std::string angleString = angleToDisplayFormat(arcAngle * 180.0 / pi, 1); text.sprintf(" (R%s, %s)", radiusString.c_str(), angleString.c_str()); setPositionText(onSketchPos, text); } @@ -536,8 +538,8 @@ public: // #3974: if in radians, the printf %f defaults to six decimals, which leads to // loss of precision - double arcAngle = - abs(round((endAngle - startAngle) / (M_PI / 4)) * 45); // in degrees + double arcAngle = abs(round((endAngle - startAngle) / (std::numbers::pi / 4)) + * 45); // in degrees Gui::cmdAppObjectArgs(sketchgui->getObject(), "addConstraint(Sketcher.Constraint('Angle',%i,App.Units." diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerOffset.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerOffset.h index 0bf9697039..509d347027 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerOffset.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerOffset.h @@ -932,7 +932,7 @@ private: void findOffsetLength() { - double newOffsetLength = DBL_MAX; + double newOffsetLength = std::numeric_limits::max(); BRepBuilderAPI_MakeVertex mkVertex({endpoint.x, endpoint.y, 0.0}); TopoDS_Vertex vertex = mkVertex.Vertex(); @@ -960,7 +960,7 @@ private: } } - if (newOffsetLength != DBL_MAX) { + if (newOffsetLength != std::numeric_limits::max()) { offsetLength = newOffsetLength; } } diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerPolygon.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerPolygon.h index 0a6a242da7..54ce11d364 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerPolygon.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerPolygon.h @@ -242,7 +242,8 @@ private: return; } - double angleOfSeparation = 2.0 * M_PI / static_cast(numberOfCorners); // NOLINT + double angleOfSeparation = + 2.0 * std::numbers::pi / static_cast(numberOfCorners); // NOLINT double cos_v = cos(angleOfSeparation); double sin_v = sin(angleOfSeparation); diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerRectangle.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerRectangle.h index 8070c64436..f3ba68f73f 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerRectangle.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerRectangle.h @@ -111,6 +111,8 @@ public: private: void updateDataAndDrawToPosition(Base::Vector2d onSketchPos) override { + using std::numbers::pi; + switch (state()) { case SelectMode::SeekFirst: { toolWidgetManager.drawPositionAtCursor(onSketchPos); @@ -144,8 +146,8 @@ private: corner2 = Base::Vector2d(corner1.x, onSketchPos.y); cornersReversed = true; } - angle123 = M_PI / 2; - angle412 = M_PI / 2; + angle123 = pi / 2; + angle412 = pi / 2; } else if (constructionMethod() == ConstructionMethod::CenterAndCorner) { toolWidgetManager.drawDirectionAtCursor(onSketchPos, center); @@ -162,8 +164,8 @@ private: corner2 = Base::Vector2d(corner1.x, onSketchPos.y); cornersReversed = true; } - angle123 = M_PI / 2; - angle412 = M_PI / 2; + angle123 = pi / 2; + angle412 = pi / 2; } else if (constructionMethod() == ConstructionMethod::ThreePoints) { toolWidgetManager.drawDirectionAtCursor(onSketchPos, corner1); @@ -174,8 +176,8 @@ private: perpendicular.y = (corner2 - corner1).x; corner3 = corner2 + perpendicular; corner4 = corner1 + perpendicular; - angle123 = M_PI / 2; - angle412 = M_PI / 2; + angle123 = pi / 2; + angle412 = pi / 2; corner2Initial = corner2; side = getPointSideOfVector(corner3, corner2 - corner1, corner1); } @@ -189,8 +191,8 @@ private: perpendicular.y = (onSketchPos - center).x; corner2 = center + perpendicular; corner4 = center - perpendicular; - angle123 = M_PI / 2; - angle412 = M_PI / 2; + angle123 = pi / 2; + angle412 = pi / 2; side = getPointSideOfVector(corner2, corner3 - corner1, corner1); } @@ -247,7 +249,7 @@ private: acos((a.x * b.x + a.y * b.y) / (sqrt(a.x * a.x + a.y * a.y) * sqrt(b.x * b.x + b.y * b.y))); } - angle412 = M_PI - angle123; + angle412 = pi - angle123; if (roundCorners) { radius = std::min(length, width) / 6 // NOLINT * std::min(sqrt(1 - cos(angle412) * cos(angle412)), @@ -276,7 +278,7 @@ private: acos((a.x * b.x + a.y * b.y) / (sqrt(a.x * a.x + a.y * a.y) * sqrt(b.x * b.x + b.y * b.y))); } - angle123 = M_PI - angle412; + angle123 = pi - angle412; if (roundCorners) { radius = std::min(length, width) / 6 // NOLINT * std::min(sqrt(1 - cos(angle412) * cos(angle412)), @@ -677,7 +679,7 @@ private: width = vecW.Length(); angle = vecL.Angle(); if (length < Precision::Confusion() || width < Precision::Confusion() - || fmod(fabs(angle123), M_PI) < Precision::Confusion()) { + || fmod(fabs(angle123), std::numbers::pi) < Precision::Confusion()) { return; } @@ -738,9 +740,11 @@ private: void createFirstRectangleFillets(Base::Vector2d vecL, Base::Vector2d vecW, double L1, double L2) { + using std::numbers::pi; + // center points required later for special case of round corner frame with // radiusFrame = 0. - double end = angle - M_PI / 2; + double end = angle - pi / 2; Base::Vector2d b1 = (vecL + vecW) / (vecL + vecW).Length(); Base::Vector2d b2 = (vecL - vecW) / (vecL - vecW).Length(); @@ -749,16 +753,18 @@ private: center3 = toVector3d(corner3 - b1 * L2); center4 = toVector3d(corner4 + b2 * L1); - addArcToShapeGeometry(center1, end - M_PI + angle412, end, radius, isConstructionMode()); - addArcToShapeGeometry(center2, end, end - M_PI - angle123, radius, isConstructionMode()); - addArcToShapeGeometry(center3, end + angle412, end - M_PI, radius, isConstructionMode()); - addArcToShapeGeometry(center4, end - M_PI, end - angle123, radius, isConstructionMode()); + addArcToShapeGeometry(center1, end - pi + angle412, end, radius, isConstructionMode()); + addArcToShapeGeometry(center2, end, end - pi - angle123, radius, isConstructionMode()); + addArcToShapeGeometry(center3, end + angle412, end - pi, radius, isConstructionMode()); + addArcToShapeGeometry(center4, end - pi, end - angle123, radius, isConstructionMode()); } void createSecondRectangleGeometries(Base::Vector2d vecL, Base::Vector2d vecW, double L1, double L2) { - double end = angle - M_PI / 2; + using std::numbers::pi; + + double end = angle - pi / 2; if (radius < Precision::Confusion()) { radiusFrame = 0.; @@ -800,22 +806,22 @@ private: Base::Vector2d b2 = (vecL - vecW) / (vecL - vecW).Length(); addArcToShapeGeometry(toVector3d(frameCorner1 + b1 * L2F), - end - M_PI + angle412, + end - pi + angle412, end, radiusFrame, isConstructionMode()); addArcToShapeGeometry(toVector3d(frameCorner2 - b2 * L1F), end, - end - M_PI - angle123, + end - pi - angle123, radiusFrame, isConstructionMode()); addArcToShapeGeometry(toVector3d(frameCorner3 - b1 * L2F), end + angle412, - end - M_PI, + end - pi, radiusFrame, isConstructionMode()); addArcToShapeGeometry(toVector3d(frameCorner4 + b2 * L1F), - end - M_PI, + end - pi, end - angle123, radiusFrame, isConstructionMode()); @@ -1313,7 +1319,7 @@ private: firstCurve + 1, Sketcher::PointPos::none, firstCurve + 3); - if (fabs(angle123 - M_PI / 2) < Precision::Confusion()) { + if (fabs(angle123 - std::numbers::pi / 2) < Precision::Confusion()) { addToShapeConstraints(Sketcher::Perpendicular, firstCurve, Sketcher::PointPos::none, @@ -1932,7 +1938,7 @@ void DSHRectangleControllerBase::doEnforceControlParameters(Base::Vector2d& onSk if (onViewParameters[OnViewParameter::Sixth]->isSet) { double angle = Base::toRadians(onViewParameters[OnViewParameter::Sixth]->getValue()); - if (fmod(angle, M_PI) < Precision::Confusion()) { + if (fmod(angle, std::numbers::pi) < Precision::Confusion()) { unsetOnViewParameter(onViewParameters[OnViewParameter::Sixth].get()); return; } @@ -1944,8 +1950,8 @@ void DSHRectangleControllerBase::doEnforceControlParameters(Base::Vector2d& onSk int sign = handler->side != sign1 ? 1 : -1; - double angle123 = - (handler->corner2Initial - handler->corner1).Angle() + M_PI + sign * angle; + double angle123 = (handler->corner2Initial - handler->corner1).Angle() + + std::numbers::pi + sign * angle; onSketchPos.x = handler->corner2Initial.x + cos(angle123) * width; onSketchPos.y = handler->corner2Initial.y + sin(angle123) * width; @@ -1969,12 +1975,12 @@ void DSHRectangleControllerBase::doEnforceControlParameters(Base::Vector2d& onSk if (onViewParameters[OnViewParameter::Sixth]->isSet) { double c = Base::toRadians(onViewParameters[OnViewParameter::Sixth]->getValue()); - if (fmod(c, M_PI) < Precision::Confusion()) { + if (fmod(c, std::numbers::pi) < Precision::Confusion()) { unsetOnViewParameter(onViewParameters[OnViewParameter::Sixth].get()); return; } - double a = asin(width * sin(M_PI - c) + double a = asin(width * sin(std::numbers::pi - c) / (handler->corner3 - handler->corner1).Length()); int sign1 = handler->getPointSideOfVector(onSketchPos, @@ -2399,6 +2405,8 @@ void DSHRectangleController::doChangeDrawSketchHandlerMode() template<> void DSHRectangleController::addConstraints() { + using std::numbers::pi; + App::DocumentObject* obj = handler->sketchgui->getObject(); int firstCurve = handler->firstCurve; @@ -2569,15 +2577,15 @@ void DSHRectangleController::addConstraints() if (handler->constructionMethod() == ConstructionMethod::ThreePoints) { if (angleSet) { - if (fabs(angle - M_PI) < Precision::Confusion() - || fabs(angle + M_PI) < Precision::Confusion() + if (fabs(angle - pi) < Precision::Confusion() + || fabs(angle + pi) < Precision::Confusion() || fabs(angle) < Precision::Confusion()) { Gui::cmdAppObjectArgs(obj, "addConstraint(Sketcher.Constraint('Horizontal',%d)) ", firstCurve); } - else if (fabs(angle - M_PI / 2) < Precision::Confusion() - || fabs(angle + M_PI / 2) < Precision::Confusion()) { + else if (fabs(angle - pi / 2) < Precision::Confusion() + || fabs(angle + pi / 2) < Precision::Confusion()) { Gui::cmdAppObjectArgs(obj, "addConstraint(Sketcher.Constraint('Vertical',%d)) ", firstCurve); @@ -2591,7 +2599,7 @@ void DSHRectangleController::addConstraints() } } if (innerAngleSet) { - if (fabs(innerAngle - M_PI / 2) > Precision::Confusion()) { + if (fabs(innerAngle - pi / 2) > Precision::Confusion()) { // if 90? then perpendicular already created. Gui::cmdAppObjectArgs(obj, "addConstraint(Sketcher.Constraint('Angle',%d,%d,%d,%d,%f)) ", @@ -2617,7 +2625,7 @@ void DSHRectangleController::addConstraints() obj); } if (innerAngleSet) { - if (fabs(innerAngle - M_PI / 2) > Precision::Confusion()) { + if (fabs(innerAngle - pi / 2) > Precision::Confusion()) { // if 90? then perpendicular already created. Gui::cmdAppObjectArgs(obj, "addConstraint(Sketcher.Constraint('Angle',%d,%d,%d,%d,%f)) ", diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerRotate.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerRotate.h index 32266e9d38..03be54ee61 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerRotate.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerRotate.h @@ -103,7 +103,7 @@ private: endpoint = centerPoint + length * Base::Vector2d(cos(endAngle), sin(endAngle)); double angle1 = endAngle - startAngle; - double angle2 = angle1 + (angle1 < 0. ? 2 : -2) * M_PI; + double angle2 = angle1 + (angle1 < 0. ? 2 : -2) * std::numbers::pi; totalAngle = abs(angle1 - totalAngle) < abs(angle2 - totalAngle) ? angle1 : angle2; CreateAndDrawShapeGeometry(); @@ -408,10 +408,11 @@ private: // the new geometry. /*if (cstr->Type == DistanceX || cstr->Type == DistanceY) { //DistanceX/Y can be applied only if the rotation if 90 or 180. - if (fabs(fmod(individualAngle, M_PI)) < Precision::Confusion()) { + if (fabs(fmod(individualAngle, std::numbers::pi)) < + Precision::Confusion()) { // ok and nothing to do actually } - else if (fabs(fmod(individualAngle, M_PI * 0.5)) < + else if (fabs(fmod(individualAngle, std::numbers::pi * 0.5)) < Precision::Confusion()) { cstr->Type = cstr->Type == DistanceX ? DistanceY : DistanceX; } @@ -567,7 +568,7 @@ void DSHRotateControllerBase::doEnforceControlParameters(Base::Vector2d& onSketc double arcAngle = Base::toRadians(onViewParameters[OnViewParameter::Third]->getValue()); - if (fmod(fabs(arcAngle), 2 * M_PI) < Precision::Confusion()) { + if (fmod(fabs(arcAngle), 2 * std::numbers::pi) < Precision::Confusion()) { unsetOnViewParameter(onViewParameters[OnViewParameter::Third].get()); return; } @@ -580,7 +581,7 @@ void DSHRotateControllerBase::doEnforceControlParameters(Base::Vector2d& onSketc double arcAngle = Base::toRadians(onViewParameters[OnViewParameter::Fourth]->getValue()); - if (fmod(fabs(arcAngle), 2 * M_PI) < Precision::Confusion()) { + if (fmod(fabs(arcAngle), 2 * std::numbers::pi) < Precision::Confusion()) { unsetOnViewParameter(onViewParameters[OnViewParameter::Fourth].get()); return; } diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerSlot.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerSlot.h index 1108aa244e..46b27d58b3 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerSlot.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerSlot.h @@ -241,6 +241,8 @@ private: void createShape(bool onlyeditoutline) override { + using std::numbers::pi; + ShapeGeometry.clear(); if (length < Precision::Confusion() || radius < Precision::Confusion()) { @@ -248,14 +250,14 @@ private: } Part::GeomArcOfCircle* arc1 = addArcToShapeGeometry(toVector3d(startPoint), - M_PI / 2 + angle, - 1.5 * M_PI + angle, + pi / 2 + angle, + 1.5 * pi + angle, radius, isConstructionMode()); Part::GeomArcOfCircle* arc2 = addArcToShapeGeometry(toVector3d(secondPoint), - 1.5 * M_PI + angle, - M_PI / 2 + angle, + 1.5 * pi + angle, + pi / 2 + angle, radius, isConstructionMode()); @@ -323,13 +325,15 @@ private: void checkHorizontalVertical() { + using std::numbers::pi; + isHorizontal = false; isVertical = false; - if (fmod(fabs(angle), M_PI) < Precision::Confusion()) { + if (fmod(fabs(angle), pi) < Precision::Confusion()) { isHorizontal = true; } - else if (fmod(fabs(angle + M_PI / 2), M_PI) < Precision::Confusion()) { + else if (fmod(fabs(angle + pi / 2), pi) < Precision::Confusion()) { isVertical = true; } } diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerTranslate.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerTranslate.h index bac2d51208..f1412f8d7c 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerTranslate.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerTranslate.h @@ -584,7 +584,8 @@ void DSHTranslateControllerBase::doEnforceControlParameters(Base::Vector2d& onSk } if (onViewParameters[OnViewParameter::Fourth]->isSet) { - double angle = onViewParameters[OnViewParameter::Fourth]->getValue() * M_PI / 180; + double angle = + onViewParameters[OnViewParameter::Fourth]->getValue() * std::numbers::pi / 180; onSketchPos.x = handler->referencePoint.x + cos(angle) * length; onSketchPos.y = handler->referencePoint.y + sin(angle) * length; } @@ -607,7 +608,8 @@ void DSHTranslateControllerBase::doEnforceControlParameters(Base::Vector2d& onSk } if (onViewParameters[OnViewParameter::Sixth]->isSet) { - double angle = onViewParameters[OnViewParameter::Sixth]->getValue() * M_PI / 180; + double angle = + onViewParameters[OnViewParameter::Sixth]->getValue() * std::numbers::pi / 180; onSketchPos.x = handler->referencePoint.x + cos(angle) * length; onSketchPos.y = handler->referencePoint.y + sin(angle) * length; } @@ -647,7 +649,7 @@ void DSHTranslateController::adaptParameters(Base::Vector2d onSketchPos) Base::Vector2d vec2d = Base::Vector2d(handler->firstTranslationVector.x, handler->firstTranslationVector.y); double angle = vec2d.Angle(); - double range = angle * 180 / M_PI; + double range = angle * 180 / std::numbers::pi; if (!onViewParameters[OnViewParameter::Fourth]->isSet) { setOnViewParameterValue(OnViewParameter::Fourth, range, Base::Unit::Angle); @@ -669,7 +671,7 @@ void DSHTranslateController::adaptParameters(Base::Vector2d onSketchPos) Base::Vector2d vec2d = Base::Vector2d(handler->secondTranslationVector.x, handler->secondTranslationVector.y); double angle = vec2d.Angle(); - double range = angle * 180 / M_PI; + double range = angle * 180 / std::numbers::pi; if (!onViewParameters[OnViewParameter::Sixth]->isSet) { setOnViewParameterValue(OnViewParameter::Sixth, range, Base::Unit::Angle); diff --git a/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.cpp b/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.cpp index e368a8d7de..f69d71d71e 100644 --- a/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.cpp +++ b/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.cpp @@ -114,6 +114,8 @@ void EditModeConstraintCoinManager::updateVirtualSpace() void EditModeConstraintCoinManager::processConstraints(const GeoListFacade& geolistfacade) { + using std::numbers::pi; + const auto& constrlist = ViewProviderSketchCoinAttorney::getConstraints(viewProvider); auto zConstrH = ViewProviderSketchCoinAttorney::getViewOrientationFactor(viewProvider) @@ -262,7 +264,7 @@ Restart: const Part::GeomCircle* circle = static_cast(geo); ra = circle->getRadius(); - angle = M_PI / 4; + angle = pi / 4; midpos = circle->getCenter(); } else if (geo->is()) { @@ -281,7 +283,7 @@ Restart: rb = ellipse->getMinorRadius(); Base::Vector3d majdir = ellipse->getMajorAxisDir(); angle = atan2(majdir.y, majdir.x); - angleplus = M_PI / 4; + angleplus = pi / 4; midpos = ellipse->getCenter(); } else if (geo->is()) { @@ -460,7 +462,7 @@ Restart: norm1.Normalize(); dir1 = norm1; - dir1.RotateZ(-M_PI / 2.0); + dir1.RotateZ(-pi / 2.0); } else if (Constr->FirstPos == Sketcher::PointPos::none) { @@ -485,7 +487,7 @@ Restart: else if (geo1->is()) { const Part::GeomCircle* circle = static_cast(geo1); - norm1 = Base::Vector3d(cos(M_PI / 4), sin(M_PI / 4), 0); + norm1 = Base::Vector3d(cos(pi / 4), sin(pi / 4), 0); dir1 = Base::Vector3d(-norm1.y, norm1.x, 0); midpos1 = circle->getCenter() + circle->getRadius() * norm1; } @@ -514,7 +516,7 @@ Restart: else if (geo2->is()) { const Part::GeomCircle* circle = static_cast(geo2); - norm2 = Base::Vector3d(cos(M_PI / 4), sin(M_PI / 4), 0); + norm2 = Base::Vector3d(cos(pi / 4), sin(pi / 4), 0); dir2 = Base::Vector3d(-norm2.y, norm2.x, 0); midpos2 = circle->getCenter() + circle->getRadius() * norm2; } @@ -576,7 +578,7 @@ Restart: const Part::GeomCircle* circle = static_cast(geo1); r1a = circle->getRadius(); - angle1 = M_PI / 4; + angle1 = pi / 4; midpos1 = circle->getCenter(); } else if (geo1->is()) { @@ -595,7 +597,7 @@ Restart: r1b = ellipse->getMinorRadius(); Base::Vector3d majdir = ellipse->getMajorAxisDir(); angle1 = atan2(majdir.y, majdir.x); - angle1plus = M_PI / 4; + angle1plus = pi / 4; midpos1 = ellipse->getCenter(); } else if (geo1->is()) { @@ -641,7 +643,7 @@ Restart: const Part::GeomCircle* circle = static_cast(geo2); r2a = circle->getRadius(); - angle2 = M_PI / 4; + angle2 = pi / 4; midpos2 = circle->getCenter(); } else if (geo2->is()) { @@ -660,7 +662,7 @@ Restart: r2b = ellipse->getMinorRadius(); Base::Vector3d majdir = ellipse->getMajorAxisDir(); angle2 = atan2(majdir.y, majdir.x); - angle2plus = M_PI / 4; + angle2plus = pi / 4; midpos2 = ellipse->getCenter(); } else if (geo2->is()) { @@ -968,7 +970,7 @@ Restart: // otherwise We still use findHelperAngles before to find if helper // is needed. helperStartAngle1 = endAngle; - helperRange1 = 2 * M_PI - (endAngle - startAngle); + helperRange1 = 2 * pi - (endAngle - startAngle); numPoints++; } @@ -991,7 +993,7 @@ Restart: if (helperRange2 != 0.) { helperStartAngle2 = endAngle; - helperRange2 = 2 * M_PI - (endAngle - startAngle); + helperRange2 = 2 * pi - (endAngle - startAngle); numPoints++; } @@ -1089,7 +1091,7 @@ Restart: // getSolvedSketch().calculateNormalAtPoint(Constr->Second, pos.x, pos.y); norm.Normalize(); Base::Vector3d dir = norm; - dir.RotateZ(-M_PI / 2.0); + dir.RotateZ(-pi / 2.0); relPos = seekConstraintPosition( pos, @@ -1340,7 +1342,7 @@ Restart: p1[1] = line1->getEndPoint(); p2[0] = line2->getStartPoint(); p2[1] = line2->getEndPoint(); - double length = DBL_MAX; + double length = std::numeric_limits::max(); for (int i = 0; i <= 1; i++) { for (int j = 0; j <= 1; j++) { double tmp = (p2[j] - p1[i]).Length(); @@ -1385,12 +1387,12 @@ Restart: // TODO: Check // dir1 = getSolvedSketch().calculateNormalAtPoint(Constr->First, // p.x, p.y); - dir1.RotateZ(-M_PI / 2); // convert to vector of tangency by rotating + dir1.RotateZ(-pi / 2); // convert to vector of tangency by rotating dir2 = getNormal(geolistfacade, Constr->Second, p); // TODO: Check // dir2 = getSolvedSketch().calculateNormalAtPoint(Constr->Second, // p.x, p.y); - dir2.RotateZ(-M_PI / 2); + dir2.RotateZ(-pi / 2); startangle = atan2(dir1.y, dir1.x); range = atan2(dir1.x * dir2.y - dir1.y * dir2.x, @@ -1632,26 +1634,28 @@ void EditModeConstraintCoinManager::findHelperAngles(double& helperStartAngle, double startAngle, double endAngle) { + using std::numbers::pi; + double margin = 0.2; // about 10deg if (angle < 0) { - angle = angle + 2 * M_PI; + angle = angle + 2 * pi; } // endAngle can be more than 2*pi as its startAngle + arcAngle - if (endAngle > 2 * M_PI && angle < endAngle - 2 * M_PI) { - angle = angle + 2 * M_PI; + if (endAngle > 2 * pi && angle < endAngle - 2 * pi) { + angle = angle + 2 * pi; } if (!(angle > startAngle && angle < endAngle)) { - if ((angle < startAngle && startAngle - angle < angle + 2 * M_PI - endAngle) - || (angle > endAngle && startAngle + 2 * M_PI - angle < angle - endAngle)) { + if ((angle < startAngle && startAngle - angle < angle + 2 * pi - endAngle) + || (angle > endAngle && startAngle + 2 * pi - angle < angle - endAngle)) { if (angle > startAngle) { - angle -= 2 * M_PI; + angle -= 2 * pi; } helperStartAngle = angle - margin; helperRange = startAngle - angle + margin; } else { if (angle < endAngle) { - angle += 2 * M_PI; + angle += 2 * pi; } helperStartAngle = endAngle; helperRange = angle - endAngle + margin; diff --git a/src/Mod/Sketcher/Gui/PreCompiled.h b/src/Mod/Sketcher/Gui/PreCompiled.h index 8d2c1892ce..d4a2ac5e7c 100644 --- a/src/Mod/Sketcher/Gui/PreCompiled.h +++ b/src/Mod/Sketcher/Gui/PreCompiled.h @@ -32,7 +32,6 @@ #ifdef _PreComp_ // standard -#include #include #include diff --git a/src/Mod/Sketcher/Gui/SnapManager.cpp b/src/Mod/Sketcher/Gui/SnapManager.cpp index 399688add4..fd34a6df0e 100644 --- a/src/Mod/Sketcher/Gui/SnapManager.cpp +++ b/src/Mod/Sketcher/Gui/SnapManager.cpp @@ -122,7 +122,8 @@ void SnapManager::ParameterObserver::updateSnapAngleParameter(const std::string& { ParameterGrp::handle hGrp = getParameterGrpHandle(); - client.snapAngle = fmod(hGrp->GetFloat(parametername.c_str(), 5.) * M_PI / 180, 2 * M_PI); + client.snapAngle = fmod(hGrp->GetFloat(parametername.c_str(), 5.) * std::numbers::pi / 180, + 2 * std::numbers::pi); } void SnapManager::ParameterObserver::subscribeToParameters() @@ -222,7 +223,7 @@ bool SnapManager::snapAtAngle(double& x, double& y) double length = (pointToOverride - referencePoint).Length(); double angle1 = (pointToOverride - referencePoint).Angle(); - double angle2 = angle1 + (angle1 < 0. ? 2 : -2) * M_PI; + double angle2 = angle1 + (angle1 < 0. ? 2 : -2) * std::numbers::pi; lastMouseAngle = abs(angle1 - lastMouseAngle) < abs(angle2 - lastMouseAngle) ? angle1 : angle2; double angle = round(lastMouseAngle / snapAngle) * snapAngle; @@ -368,10 +369,10 @@ bool SnapManager::snapToArcMiddle(Base::Vector3d& pointToOverride, const Part::G double u, v; arc->getRange(u, v, true); if (v < u) { - v += 2 * M_PI; + v += 2 * std::numbers::pi; } double angle = v - u; - int revert = angle < M_PI ? 1 : -1; + int revert = angle < std::numbers::pi ? 1 : -1; /*To know if we are close to the middle of the arc, we are going to compare the angle of the * (mouse cursor - center) to the angle of the middle of the arc. If it's less than 10% of the diff --git a/src/Mod/Sketcher/Gui/SoZoomTranslation.cpp b/src/Mod/Sketcher/Gui/SoZoomTranslation.cpp index c1981f7a68..e42a545aff 100644 --- a/src/Mod/Sketcher/Gui/SoZoomTranslation.cpp +++ b/src/Mod/Sketcher/Gui/SoZoomTranslation.cpp @@ -22,7 +22,6 @@ #include "PreCompiled.h" #ifndef _PreComp_ -#include #include #include diff --git a/src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp b/src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp index 5a6a4237e7..397d501703 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp +++ b/src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp @@ -720,8 +720,9 @@ ConstraintFilterList::ConstraintFilterList(QWidget* parent) { ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath( "User parameter:BaseApp/Preferences/Mod/Sketcher/General"); - int filterState = hGrp->GetInt("ConstraintFilterState", - INT_MAX);// INT_MAX = 1111111111111111111111111111111 in binary. + int filterState = hGrp->GetInt( + "ConstraintFilterState", + std::numeric_limits::max()); // INT_MAX = 01111111111111111111111111111111 in binary. normalFilterCount = filterItems.size() - 2;// All filter but selected and associated selectedFilterIndex = normalFilterCount; diff --git a/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp b/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp index e5df986f5d..551b9fa90f 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp +++ b/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp @@ -1124,8 +1124,9 @@ ElementFilterList::ElementFilterList(QWidget* parent) { ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath( "User parameter:BaseApp/Preferences/Mod/Sketcher/General"); - int filterState = hGrp->GetInt("ElementFilterState", - INT_MAX);// INT_MAX = 1111111111111111111111111111111 in binary. + int filterState = hGrp->GetInt( + "ElementFilterState", + std::numeric_limits::max());// INT_MAX = 01111111111111111111111111111111 in binary. for (auto const& filterItem : filterItems) { Q_UNUSED(filterItem); @@ -1320,7 +1321,7 @@ void TaskSketcherElements::onListMultiFilterItemChanged(QListWidgetItem* item) } // Save the state of the filter. - int filterState = INT_MIN;// INT_MIN = 000000000000000000000000000000 in binary. + int filterState = 0; // All bits are cleared. for (int i = filterList->count() - 1; i >= 0; i--) { bool isChecked = filterList->item(i)->checkState() == Qt::Checked; filterState = filterState << 1;// we shift left first, else the list is shifted at the end. diff --git a/src/Mod/Sketcher/Gui/TaskSketcherGeneral.ui.autosave b/src/Mod/Sketcher/Gui/TaskSketcherGeneral.ui.autosave new file mode 100644 index 0000000000..3b73e8be00 --- /dev/null +++ b/src/Mod/Sketcher/Gui/TaskSketcherGeneral.ui.autosave @@ -0,0 +1,77 @@ + + + TaskSketcherGeneral + + + + 0 + 0 + 253 + 61 + + + + + .AppleSystemUIFont + + + + Form + + + + + + + 0 + 0 + + + + Link + + + + + + + + 0 + 0 + + + + DOF + + + + + + + + 1 + 0 + + + + Auto Recompute + + + + + + + + Gui::StatefulLabel + QLabel +
Gui/Widgets.h
+
+ + Gui::UrlLabel + QLabel +
Gui/Widgets.h
+
+
+ + +
diff --git a/src/Mod/Sketcher/Gui/Utils.cpp b/src/Mod/Sketcher/Gui/Utils.cpp index 9a6f1ee223..6fc5562cf7 100644 --- a/src/Mod/Sketcher/Gui/Utils.cpp +++ b/src/Mod/Sketcher/Gui/Utils.cpp @@ -22,7 +22,6 @@ #include "PreCompiled.h" #ifndef _PreComp_ -#include #include #include @@ -432,7 +431,7 @@ double SketcherGui::GetPointAngle(const Base::Vector2d& p1, const Base::Vector2d { double dX = p2.x - p1.x; double dY = p2.y - p1.y; - return dY >= 0 ? atan2(dY, dX) : atan2(dY, dX) + 2 * M_PI; + return dY >= 0 ? atan2(dY, dX) : atan2(dY, dX) + 2 * std::numbers::pi; } // Set the two points on circles at minimal distance diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index 1bde48de8d..3c27a517df 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -861,7 +861,7 @@ void ViewProviderSketch::getCoordsOnSketchPlane(const SbVec3f& point, const SbVe // line Base::Vector3d R1(point[0], point[1], point[2]), RA(normal[0], normal[1], normal[2]); - if (fabs(RN * RA) < FLT_EPSILON) + if (fabs(RN * RA) < std::numeric_limits::epsilon()) throw Base::ZeroDivisionError("View direction is parallel to sketch plane"); // intersection point on plane Base::Vector3d S = R1 + ((RN * (R0 - R1)) / (RN * RA)) * RA; @@ -1930,9 +1930,9 @@ void ViewProviderSketch::moveConstraint(Sketcher::Constraint* Constr, int constN || Constr->Type == Weight) dir = (p2 - p1).Normalize(); else if (Constr->Type == DistanceX) - dir = Base::Vector3d((p2.x - p1.x >= FLT_EPSILON) ? 1 : -1, 0, 0); + dir = Base::Vector3d((p2.x - p1.x >= std::numeric_limits::epsilon()) ? 1 : -1, 0, 0); else if (Constr->Type == DistanceY) - dir = Base::Vector3d(0, (p2.y - p1.y >= FLT_EPSILON) ? 1 : -1, 0); + dir = Base::Vector3d(0, (p2.y - p1.y >= std::numeric_limits::epsilon()) ? 1 : -1, 0); if (Constr->Type == Radius || Constr->Type == Diameter || Constr->Type == Weight) { Constr->LabelDistance = vec.x * dir.x + vec.y * dir.y; @@ -2029,9 +2029,9 @@ void ViewProviderSketch::moveAngleConstraint(Sketcher::Constraint* constr, int c Base::Vector3d p = getSolvedSketch().getPoint(constr->Third, constr->ThirdPos); p0 = Base::Vector3d(p.x, p.y, 0); Base::Vector3d dir1 = getSolvedSketch().calculateNormalAtPoint(constr->First, p.x, p.y); - dir1.RotateZ(-M_PI / 2);// convert to vector of tangency by rotating + dir1.RotateZ(-std::numbers::pi / 2);// convert to vector of tangency by rotating Base::Vector3d dir2 = getSolvedSketch().calculateNormalAtPoint(constr->Second, p.x, p.y); - dir2.RotateZ(-M_PI / 2); + dir2.RotateZ(-std::numbers::pi / 2); Base::Vector3d vec = Base::Vector3d(toPos.x, toPos.y, 0) - p0; factor = factor * Base::sgn((dir1 + dir2) * vec); @@ -3996,7 +3996,7 @@ double ViewProviderSketch::getRotation(SbVec3f pos0, SbVec3f pos1) const getCoordsOnSketchPlane(pos0, vol.getProjectionDirection(), x0, y0); getCoordsOnSketchPlane(pos1, vol.getProjectionDirection(), x1, y1); - return -atan2((y1 - y0), (x1 - x0)) * 180 / M_PI; + return -atan2((y1 - y0), (x1 - x0)) * 180 / std::numbers::pi; } catch (const Base::ZeroDivisionError&) { return 0; diff --git a/tests/src/Mod/Sketcher/App/SketchObject.cpp b/tests/src/Mod/Sketcher/App/SketchObject.cpp index 954308353c..36c1db0f26 100644 --- a/tests/src/Mod/Sketcher/App/SketchObject.cpp +++ b/tests/src/Mod/Sketcher/App/SketchObject.cpp @@ -237,7 +237,7 @@ TEST_F(SketchObjectTest, testGetPointFromGeomArcOfCircle) { // Arrange Base::Vector3d coordsCenter(1.0, 2.0, 0.0); - double radius = 3.0, startParam = M_PI / 3, endParam = M_PI * 1.5; + double radius = 3.0, startParam = std::numbers::pi / 3, endParam = std::numbers::pi * 1.5; Part::GeomArcOfCircle arcOfCircle; arcOfCircle.setCenter(coordsCenter); arcOfCircle.setRadius(radius); @@ -267,7 +267,7 @@ TEST_F(SketchObjectTest, testGetPointFromGeomArcOfEllipse) Base::Vector3d coordsCenter(1.0, 2.0, 0.0); double majorRadius = 4.0; double minorRadius = 3.0; - double startParam = M_PI / 3, endParam = M_PI * 1.5; + double startParam = std::numbers::pi / 3, endParam = std::numbers::pi * 1.5; Part::GeomArcOfEllipse arcOfEllipse; arcOfEllipse.setCenter(coordsCenter); arcOfEllipse.setMajorRadius(majorRadius); @@ -298,7 +298,7 @@ TEST_F(SketchObjectTest, testGetPointFromGeomArcOfHyperbola) Base::Vector3d coordsCenter(1.0, 2.0, 0.0); double majorRadius = 4.0; double minorRadius = 3.0; - double startParam = M_PI / 3, endParam = M_PI * 1.5; + double startParam = std::numbers::pi / 3, endParam = std::numbers::pi * 1.5; Part::GeomArcOfHyperbola arcOfHyperbola; arcOfHyperbola.setCenter(coordsCenter); arcOfHyperbola.setMajorRadius(majorRadius); @@ -330,7 +330,7 @@ TEST_F(SketchObjectTest, testGetPointFromGeomArcOfParabola) // Arrange Base::Vector3d coordsCenter(1.0, 2.0, 0.0); double focal = 3.0; - double startParam = M_PI / 3, endParam = M_PI * 1.5; + double startParam = std::numbers::pi / 3, endParam = std::numbers::pi * 1.5; Part::GeomArcOfParabola arcOfParabola; arcOfParabola.setCenter(coordsCenter); arcOfParabola.setFocal(focal); diff --git a/tests/src/Mod/Sketcher/App/SketchObjectChanges.cpp b/tests/src/Mod/Sketcher/App/SketchObjectChanges.cpp index 2b0f69aa76..5d2519bea6 100644 --- a/tests/src/Mod/Sketcher/App/SketchObjectChanges.cpp +++ b/tests/src/Mod/Sketcher/App/SketchObjectChanges.cpp @@ -846,7 +846,7 @@ TEST_F(SketchObjectTest, testJoinCurves) // Arrange // Make two curves Base::Vector3d coordsCenter(0.0, 0.0, 0.0); - double radius = 3.0, startParam = M_PI / 2, endParam = M_PI; + double radius = 3.0, startParam = std::numbers::pi / 2, endParam = std::numbers::pi; Part::GeomArcOfCircle arcOfCircle; arcOfCircle.setCenter(coordsCenter); arcOfCircle.setRadius(radius); @@ -877,7 +877,7 @@ TEST_F(SketchObjectTest, testJoinCurvesWhenTangent) // Arrange // Make two curves Base::Vector3d coordsCenter(0.0, 0.0, 0.0); - double radius = 3.0, startParam = M_PI / 2, endParam = M_PI; + double radius = 3.0, startParam = std::numbers::pi / 2, endParam = std::numbers::pi; Part::GeomArcOfCircle arcOfCircle; arcOfCircle.setCenter(coordsCenter); arcOfCircle.setRadius(radius); diff --git a/tests/src/Mod/Sketcher/App/SketcherTestHelpers.cpp b/tests/src/Mod/Sketcher/App/SketcherTestHelpers.cpp index ae4fb2414e..51aade677f 100644 --- a/tests/src/Mod/Sketcher/App/SketcherTestHelpers.cpp +++ b/tests/src/Mod/Sketcher/App/SketcherTestHelpers.cpp @@ -56,7 +56,7 @@ void setupArcOfCircle(Part::GeomArcOfCircle& arcOfCircle) { Base::Vector3d coordsCenter(1.0, 2.0, 0.0); double radius = 3.0; - double startParam = M_PI / 3, endParam = M_PI * 1.5; + double startParam = std::numbers::pi / 3, endParam = std::numbers::pi * 1.5; arcOfCircle.setCenter(coordsCenter); arcOfCircle.setRadius(radius); arcOfCircle.setRange(startParam, endParam, true); @@ -77,7 +77,7 @@ void setupArcOfHyperbola(Part::GeomArcOfHyperbola& arcOfHyperbola) Base::Vector3d coordsCenter(1.0, 2.0, 0.0); double majorRadius = 4.0; double minorRadius = 3.0; - double startParam = M_PI / 3, endParam = M_PI * 1.5; + double startParam = std::numbers::pi / 3, endParam = std::numbers::pi * 1.5; arcOfHyperbola.setCenter(coordsCenter); arcOfHyperbola.setMajorRadius(majorRadius); arcOfHyperbola.setMinorRadius(minorRadius); @@ -88,7 +88,7 @@ void setupArcOfParabola(Part::GeomArcOfParabola& aop) { Base::Vector3d coordsCenter(1.0, 2.0, 0.0); double focal = 3.0; - double startParam = -M_PI * 1.5, endParam = M_PI * 1.5; + double startParam = -std::numbers::pi * 1.5, endParam = std::numbers::pi * 1.5; aop.setCenter(coordsCenter); aop.setFocal(focal); aop.setRange(startParam, endParam, true); diff --git a/tests/src/Mod/Sketcher/App/planegcs/Constraints.cpp b/tests/src/Mod/Sketcher/App/planegcs/Constraints.cpp index 4f0b90b997..89cb81dc12 100644 --- a/tests/src/Mod/Sketcher/App/planegcs/Constraints.cpp +++ b/tests/src/Mod/Sketcher/App/planegcs/Constraints.cpp @@ -1,6 +1,7 @@ // SPDX-License-Identifier: LGPL-2.1-or-later #include +#include #include @@ -54,8 +55,8 @@ TEST_F(ConstraintsTest, tangentBSplineAndArc) // NOLINT arcEnd.y = &arcEndY; arcCenter.x = &arcCenterX; arcCenter.y = &arcCenterY; - double arcRadius = 5.0, arcStartAngle = 0.0, arcEndAngle = M_PI / 2; - double desiredAngle = M_PI; + double arcRadius = 5.0, arcStartAngle = 0.0, arcEndAngle = std::numbers::pi / 2; + double desiredAngle = std::numbers::pi; double bSplineStartX = 0.0, bSplineEndX = 16.0; double bSplineStartY = 10.0, bSplineEndY = -10.0; GCS::Point bSplineStart, bSplineEnd;