From cf94011294f0861d98ad89d0eccb94a3d9311fa3 Mon Sep 17 00:00:00 2001 From: Benjamin Nauck Date: Thu, 27 Mar 2025 19:02:45 +0100 Subject: [PATCH] Techdraw: Use std::numeric_limits and std::numbers instead of defines --- src/Mod/TechDraw/App/CenterLine.cpp | 2 +- src/Mod/TechDraw/App/CosmeticVertex.cpp | 4 +- src/Mod/TechDraw/App/DrawBrokenView.cpp | 2 +- src/Mod/TechDraw/App/DrawComplexSection.cpp | 5 +- src/Mod/TechDraw/App/DrawGeomHatch.cpp | 6 +- src/Mod/TechDraw/App/DrawLeaderLine.cpp | 4 +- src/Mod/TechDraw/App/DrawPage.cpp | 2 +- src/Mod/TechDraw/App/DrawProjGroup.cpp | 6 +- src/Mod/TechDraw/App/DrawProjectSplit.cpp | 4 +- src/Mod/TechDraw/App/DrawUtil.cpp | 42 +++-- src/Mod/TechDraw/App/DrawUtil.h | 9 +- src/Mod/TechDraw/App/DrawView.cpp | 6 +- src/Mod/TechDraw/App/DrawViewDimension.cpp | 8 +- src/Mod/TechDraw/App/DrawViewPart.cpp | 10 +- src/Mod/TechDraw/App/EdgeWalker.cpp | 8 +- src/Mod/TechDraw/App/Geometry.cpp | 36 ++-- src/Mod/TechDraw/App/GeometryObject.cpp | 16 +- src/Mod/TechDraw/App/HatchLine.cpp | 6 +- src/Mod/TechDraw/App/ShapeUtils.cpp | 6 +- src/Mod/TechDraw/App/TechDrawExport.cpp | 12 +- src/Mod/TechDraw/Gui/CommandCreateDims.cpp | 8 +- src/Mod/TechDraw/Gui/CommandExtensionDims.cpp | 4 +- src/Mod/TechDraw/Gui/CommandExtensionPack.cpp | 2 +- src/Mod/TechDraw/Gui/DimensionValidators.cpp | 20 +-- src/Mod/TechDraw/Gui/DrawGuiUtil.cpp | 2 +- src/Mod/TechDraw/Gui/PathBuilder.cpp | 6 +- src/Mod/TechDraw/Gui/QGIHighlight.cpp | 2 +- src/Mod/TechDraw/Gui/QGILeaderLine.cpp | 2 +- src/Mod/TechDraw/Gui/QGISectionLine.cpp | 4 +- src/Mod/TechDraw/Gui/QGIViewBalloon.cpp | 16 +- src/Mod/TechDraw/Gui/QGIViewDimension.cpp | 157 ++++++++++-------- src/Mod/TechDraw/Gui/QGIViewPart.cpp | 2 +- src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp | 2 +- src/Mod/TechDraw/Gui/QGTracker.cpp | 7 +- src/Mod/TechDraw/Gui/TaskComplexSection.cpp | 7 +- src/Mod/TechDraw/Gui/TaskCosmeticLine.cpp | 2 +- src/Mod/TechDraw/Gui/TaskDimension.cpp | 10 +- src/Mod/TechDraw/Gui/TaskSectionView.cpp | 6 +- .../Gui/ViewProviderCosmeticExtension.cpp | 5 +- .../TechDraw/Gui/ViewProviderDrawingView.cpp | 5 +- 40 files changed, 243 insertions(+), 220 deletions(-) diff --git a/src/Mod/TechDraw/App/CenterLine.cpp b/src/Mod/TechDraw/App/CenterLine.cpp index a61d4ad12a..3ca87f7832 100644 --- a/src/Mod/TechDraw/App/CenterLine.cpp +++ b/src/Mod/TechDraw/App/CenterLine.cpp @@ -392,7 +392,7 @@ std::pair CenterLine::rotatePointsAroundMid(cons const double angleDeg) { std::pair result; - double angleRad = angleDeg * M_PI / 180.0; + double angleRad = angleDeg * std::numbers::pi / 180.0; result.first.x = ((p1.x - mid.x) * cos(angleRad)) - ((p1.y - mid.y) * sin(angleRad)) + mid.x; result.first.y = ((p1.x - mid.x) * sin(angleRad)) + ((p1.y - mid.y) * cos(angleRad)) + mid.y; diff --git a/src/Mod/TechDraw/App/CosmeticVertex.cpp b/src/Mod/TechDraw/App/CosmeticVertex.cpp index a33e6c2dd8..35275c0546 100644 --- a/src/Mod/TechDraw/App/CosmeticVertex.cpp +++ b/src/Mod/TechDraw/App/CosmeticVertex.cpp @@ -166,7 +166,7 @@ Base::Vector3d CosmeticVertex::rotatedAndScaled(const double scale, const double // invert the Y coordinate so the rotation math works out // the stored point is inverted scaledPoint = DU::invertY(scaledPoint); - scaledPoint.RotateZ(rotDegrees * M_PI / DegreesHalfCircle); + scaledPoint.RotateZ(rotDegrees * std::numbers::pi / DegreesHalfCircle); scaledPoint = DU::invertY(scaledPoint); } return scaledPoint; @@ -182,7 +182,7 @@ Base::Vector3d CosmeticVertex::makeCanonicalPoint(DrawViewPart* dvp, Base::Vecto Base::Vector3d result = point; if (rotDeg != 0.0) { // unrotate the point - double rotRad = rotDeg * M_PI / DegreesHalfCircle; + double rotRad = rotDeg * std::numbers::pi / DegreesHalfCircle; // we always rotate around the origin. result.RotateZ(-rotRad); } diff --git a/src/Mod/TechDraw/App/DrawBrokenView.cpp b/src/Mod/TechDraw/App/DrawBrokenView.cpp index 4dd3a15a02..af7c91fc54 100644 --- a/src/Mod/TechDraw/App/DrawBrokenView.cpp +++ b/src/Mod/TechDraw/App/DrawBrokenView.cpp @@ -1113,7 +1113,7 @@ Base::Vector3d DrawBrokenView::makePerpendicular(Base::Vector3d inDir) const gp_Pnt origin(0.0, 0.0, 0.0); auto dir = getProjectionCS().Direction(); gp_Ax1 axis(origin, dir); - auto gRotated = gDir.Rotated(axis, M_PI_2); + auto gRotated = gDir.Rotated(axis, std::numbers::pi/2); return Base::convertTo(gRotated); } diff --git a/src/Mod/TechDraw/App/DrawComplexSection.cpp b/src/Mod/TechDraw/App/DrawComplexSection.cpp index eda78c83e3..198d5da1ec 100644 --- a/src/Mod/TechDraw/App/DrawComplexSection.cpp +++ b/src/Mod/TechDraw/App/DrawComplexSection.cpp @@ -100,7 +100,6 @@ #include #endif -#define _USE_MATH_DEFINES #include #include @@ -387,7 +386,7 @@ void DrawComplexSection::makeAlignedPieces(const TopoDS_Shape& rawShape) } //we only want to reverse the segment normal if it is not perpendicular to section normal if (segmentNormal.Dot(gProjectionUnit) != 0.0 - && segmentNormal.Angle(gProjectionUnit) <= M_PI_2) { + && segmentNormal.Angle(gProjectionUnit) <= std::numbers::pi/2) { segmentNormal.Reverse(); } @@ -957,7 +956,7 @@ gp_Vec DrawComplexSection::projectVector(const gp_Vec& vec) const // being slightly wrong. see https://forum.freecad.org/viewtopic.php?t=79017&sid=612a62a60f5db955ee071a7aaa362dbb bool DrawComplexSection::validateOffsetProfile(TopoDS_Wire profile, Base::Vector3d direction, double angleThresholdDeg) const { - double angleThresholdRad = angleThresholdDeg * M_PI / 180.0; // 5 degrees + double angleThresholdRad = angleThresholdDeg * std::numbers::pi / 180.0; // 5 degrees TopExp_Explorer explEdges(profile, TopAbs_EDGE); for (; explEdges.More(); explEdges.Next()) { std::pair segmentEnds = getSegmentEnds(TopoDS::Edge(explEdges.Current())); diff --git a/src/Mod/TechDraw/App/DrawGeomHatch.cpp b/src/Mod/TechDraw/App/DrawGeomHatch.cpp index 66366a000e..72412cf557 100644 --- a/src/Mod/TechDraw/App/DrawGeomHatch.cpp +++ b/src/Mod/TechDraw/App/DrawGeomHatch.cpp @@ -385,6 +385,8 @@ std::vector DrawGeomHatch::getTrimmedLines(DrawViewPart* source, /* static */ std::vector DrawGeomHatch::makeEdgeOverlay(PATLineSpec hatchLine, Bnd_Box bBox, double scale, double rotation) { + using std::numbers::pi; + const size_t MaxNumberOfEdges = Preferences::getPreferenceGroup("PAT")->GetInt("MaxSeg", 10000l); std::vector result; @@ -399,12 +401,12 @@ std::vector DrawGeomHatch::makeEdgeOverlay(PATLineSpec hatchLine, B double interval = hatchLine.getInterval() * scale; double offset = hatchLine.getOffset() * scale; double angle = hatchLine.getAngle() + rotation; - origin.RotateZ(rotation * M_PI / 180.); + origin.RotateZ(rotation * pi / 180.); if (scale == 0. || interval == 0.) return {}; - Base::Vector3d hatchDirection(cos(angle * M_PI / 180.), sin(angle * M_PI / 180.), 0.); + Base::Vector3d hatchDirection(cos(angle * pi / 180.), sin(angle * pi / 180.), 0.); Base::Vector3d hatchPerpendicular(-hatchDirection.y, hatchDirection.x, 0.); Base::Vector3d hatchIntervalAndOffset = offset * hatchDirection + interval * hatchPerpendicular; diff --git a/src/Mod/TechDraw/App/DrawLeaderLine.cpp b/src/Mod/TechDraw/App/DrawLeaderLine.cpp index 124b5164b2..bca5eea111 100644 --- a/src/Mod/TechDraw/App/DrawLeaderLine.cpp +++ b/src/Mod/TechDraw/App/DrawLeaderLine.cpp @@ -375,7 +375,7 @@ std::vector DrawLeaderLine::getScaledAndRotatedPoints(bool doSc double rotationRad{0.0}; if (doRotate) { - rotationRad = dvp->Rotation.getValue() * M_PI / DegreesHalfCircle; + rotationRad = dvp->Rotation.getValue() * std::numbers::pi / DegreesHalfCircle; } std::vector pointsAll = WayPoints.getValues(); @@ -409,7 +409,7 @@ DrawLeaderLine::makeCanonicalPoints(const std::vector& inPoints, double rotationRad{0.0}; if (doRotate) { - rotationRad = - dvp->Rotation.getValue() * M_PI / DegreesHalfCircle; + rotationRad = - dvp->Rotation.getValue() * std::numbers::pi / DegreesHalfCircle; } std::vector result; diff --git a/src/Mod/TechDraw/App/DrawPage.cpp b/src/Mod/TechDraw/App/DrawPage.cpp index 2ad8f2c926..bd5c908e68 100644 --- a/src/Mod/TechDraw/App/DrawPage.cpp +++ b/src/Mod/TechDraw/App/DrawPage.cpp @@ -118,7 +118,7 @@ void DrawPage::onChanged(const App::Property* prop) for (auto* obj : getViews()) { auto* view = dynamic_cast(obj); if (view && view->ScaleType.isValue("Page")) { - if (std::abs(view->Scale.getValue() - Scale.getValue()) > FLT_EPSILON) { + if (std::abs(view->Scale.getValue() - Scale.getValue()) > std::numeric_limits::epsilon()) { view->Scale.setValue(Scale.getValue()); } } diff --git a/src/Mod/TechDraw/App/DrawProjGroup.cpp b/src/Mod/TechDraw/App/DrawProjGroup.cpp index 2b491aff97..2b05d8ab60 100644 --- a/src/Mod/TechDraw/App/DrawProjGroup.cpp +++ b/src/Mod/TechDraw/App/DrawProjGroup.cpp @@ -142,7 +142,7 @@ void DrawProjGroup::onChanged(const App::Property* prop) if (prop == &ScaleType) { if (ScaleType.isValue("Page")) { double newScale = page->Scale.getValue(); - if (std::abs(getScale() - newScale) > FLT_EPSILON) { + if (std::abs(getScale() - newScale) > std::numeric_limits::epsilon()) { Scale.setValue(newScale); updateChildrenScale(); } @@ -1146,9 +1146,9 @@ void DrawProjGroup::spin(const SpinDirection& spindirection) { double angle; if (spindirection == SpinDirection::CW) - angle = M_PI / 2.0;// Top -> Right -> Bottom -> Left -> Top + angle = std::numbers::pi / 2.0;// Top -> Right -> Bottom -> Left -> Top if (spindirection == SpinDirection::CCW) - angle = -M_PI / 2.0;// Top -> Left -> Bottom -> Right -> Top + angle = -std::numbers::pi / 2.0;// Top -> Left -> Bottom -> Right -> Top spin(angle); } diff --git a/src/Mod/TechDraw/App/DrawProjectSplit.cpp b/src/Mod/TechDraw/App/DrawProjectSplit.cpp index dd4b1825a0..7853e729b6 100644 --- a/src/Mod/TechDraw/App/DrawProjectSplit.cpp +++ b/src/Mod/TechDraw/App/DrawProjectSplit.cpp @@ -345,10 +345,12 @@ std::vector DrawProjectSplit::sortEdges(std::vector& //************************* std::string edgeSortItem::dump() { + using std::numbers::pi; + std::string result; std::stringstream builder; builder << "edgeSortItem - s: " << DrawUtil::formatVector(start) << " e: " << DrawUtil::formatVector(end) << - " sa: " << startAngle * 180.0/M_PI << " ea: " << endAngle* 180.0/M_PI << " idx: " << idx; + " sa: " << startAngle * 180.0/pi << " ea: " << endAngle* 180.0/pi << " idx: " << idx; return builder.str(); } diff --git a/src/Mod/TechDraw/App/DrawUtil.cpp b/src/Mod/TechDraw/App/DrawUtil.cpp index bbe2edda84..5e0dfc7a1c 100644 --- a/src/Mod/TechDraw/App/DrawUtil.cpp +++ b/src/Mod/TechDraw/App/DrawUtil.cpp @@ -203,7 +203,7 @@ double DrawUtil::angleWithX(Base::Vector3d inVec) { double result = atan2(inVec.y, inVec.x); if (result < 0) { - result += 2.0 * M_PI; + result += 2.0 * std::numbers::pi; } return result; @@ -225,7 +225,7 @@ double DrawUtil::angleWithX(TopoDS_Edge e, bool reverse) } double result = atan2(u.y, u.x); if (result < 0) { - result += 2.0 * M_PI; + result += 2.0 * std::numbers::pi; } return result; @@ -251,7 +251,7 @@ double DrawUtil::angleWithX(TopoDS_Edge e, TopoDS_Vertex v, double tolerance) c->D1(param, paramPoint, derivative); double angle = atan2(derivative.Y(), derivative.X()); if (angle < 0) {//map from [-PI:PI] to [0:2PI] - angle += 2.0 * M_PI; + angle += 2.0 * std::numbers::pi; } return angle; } @@ -289,7 +289,7 @@ double DrawUtil::incidenceAngleAtVertex(TopoDS_Edge e, TopoDS_Vertex v, double t //map to [0:2PI] if (incidenceAngle < 0.0) { - incidenceAngle = M_2PI + incidenceAngle; + incidenceAngle = 2*std::numbers::pi + incidenceAngle; } return incidenceAngle; @@ -1059,7 +1059,7 @@ Base::Vector3d DrawUtil::toAppSpace(const DrawViewPart& dvp, const Base::Vector // remove the effect of the Rotation property double rotDeg = dvp.Rotation.getValue(); - double rotRad = rotDeg * M_PI / 180.0; + double rotRad = rotDeg * std::numbers::pi / 180.0; if (rotDeg != 0.0) { // we always rotate around the origin. appPoint.RotateZ(-rotRad); @@ -1396,11 +1396,13 @@ double DrawUtil::sqr(double x) void DrawUtil::angleNormalize(double& fi) { - while (fi <= -M_PI) { - fi += M_2PI; + using std::numbers::pi; + + while (fi <= -pi) { + fi += 2*pi; } - while (fi > M_PI) { - fi -= M_2PI; + while (fi > pi) { + fi -= 2*pi; } } @@ -1414,13 +1416,14 @@ double DrawUtil::angleComposition(double fi, double delta) double DrawUtil::angleDifference(double fi1, double fi2, bool reflex) { + using std::numbers::pi; angleNormalize(fi1); angleNormalize(fi2); fi1 -= fi2; - if ((fi1 > +M_PI || fi1 <= -M_PI) != reflex) { - fi1 += fi1 > 0.0 ? -M_2PI : +M_2PI; + if ((fi1 > +pi || fi1 <= -pi) != reflex) { + fi1 += fi1 > 0.0 ? -2*pi : +2*pi; } return fi1; @@ -1559,6 +1562,7 @@ void DrawUtil::intervalMarkLinear(std::vector>& marking, void DrawUtil::intervalMarkCircular(std::vector>& marking, double start, double length, bool value) { + using std::numbers::pi; if (length == 0.0) { return; } @@ -1566,15 +1570,15 @@ void DrawUtil::intervalMarkCircular(std::vector>& markin length = -length; start -= length; } - if (length > M_2PI) { - length = M_2PI; + if (length > 2*pi) { + length = 2*pi; } angleNormalize(start); double end = start + length; - if (end > M_PI) { - end -= M_2PI; + if (end > pi) { + end -= 2*pi; } // Just make sure the point is stored, its index is read last @@ -1785,13 +1789,15 @@ void DrawUtil::findCircularArcRectangleIntersections(const Base::Vector2d& circl const Base::BoundBox2d& rectangle, std::vector& intersections) { + using std::numbers::pi; + findCircleRectangleIntersections(circleCenter, circleRadius, rectangle, intersections); if (arcRotation < 0.0) { arcRotation = -arcRotation; arcBaseAngle -= arcRotation; - if (arcBaseAngle <= -M_PI) { - arcBaseAngle += M_2PI; + if (arcBaseAngle <= -pi) { + arcBaseAngle += 2*pi; } } @@ -1799,7 +1805,7 @@ void DrawUtil::findCircularArcRectangleIntersections(const Base::Vector2d& circl for (unsigned int i = 0; i < intersections.size();) { double pointAngle = (intersections[i] - circleCenter).Angle(); if (pointAngle < arcBaseAngle - Precision::Confusion()) { - pointAngle += M_2PI; + pointAngle += 2*pi; } if (pointAngle > arcBaseAngle + arcRotation + Precision::Confusion()) { diff --git a/src/Mod/TechDraw/App/DrawUtil.h b/src/Mod/TechDraw/App/DrawUtil.h index 5a4e10d9b8..7490e58622 100644 --- a/src/Mod/TechDraw/App/DrawUtil.h +++ b/src/Mod/TechDraw/App/DrawUtil.h @@ -50,10 +50,6 @@ #include -#ifndef M_2PI -#define M_2PI ((M_PI)*2.0) -#endif - constexpr double DegreesHalfCircle{180.0}; #define VERTEXTOLERANCE (2.0 * Precision::Confusion()) @@ -108,7 +104,8 @@ public: static bool isFirstVert(TopoDS_Edge e, TopoDS_Vertex v, double tolerance = VERTEXTOLERANCE); static bool isLastVert(TopoDS_Edge e, TopoDS_Vertex v, double tolerance = VERTEXTOLERANCE); - static bool fpCompare(const double& d1, const double& d2, double tolerance = FLT_EPSILON); + static bool fpCompare(const double& d1, const double& d2, + double tolerance = std::numeric_limits::epsilon()); static std::pair boxIntersect2d(Base::Vector3d point, Base::Vector3d dir, double xRange, double yRange); static bool apparentIntersection(const Handle(Geom_Curve) curve1, @@ -147,7 +144,7 @@ public: static Base::Vector3d toR3(const gp_Ax2& fromSystem, const Base::Vector3d& fromPoint); static bool checkParallel(const Base::Vector3d v1, const Base::Vector3d v2, - double tolerance = FLT_EPSILON); + double tolerance = std::numeric_limits::epsilon()); //! rotate vector by angle radians around axis through org static Base::Vector3d vecRotate(Base::Vector3d vec, double angle, Base::Vector3d axis, Base::Vector3d org = Base::Vector3d(0.0, 0.0, 0.0)); diff --git a/src/Mod/TechDraw/App/DrawView.cpp b/src/Mod/TechDraw/App/DrawView.cpp index d3b52a6e4b..4b01917bf6 100644 --- a/src/Mod/TechDraw/App/DrawView.cpp +++ b/src/Mod/TechDraw/App/DrawView.cpp @@ -130,7 +130,7 @@ void DrawView::checkScale() TechDraw::DrawPage *page = findParentPage(); if(page) { if (ScaleType.isValue("Page")) { - if(std::abs(page->Scale.getValue() - Scale.getValue()) > FLT_EPSILON) { + if(std::abs(page->Scale.getValue() - Scale.getValue()) > std::numeric_limits::epsilon()) { Scale.setValue(page->Scale.getValue()); Scale.purgeTouched(); } @@ -190,7 +190,7 @@ void DrawView::onChanged(const App::Property* prop) } if (ScaleType.isValue("Page")) { Scale.setStatus(App::Property::ReadOnly, true); - if(std::abs(page->Scale.getValue() - getScale()) > FLT_EPSILON) { + if(std::abs(page->Scale.getValue() - getScale()) > std::numeric_limits::epsilon()) { Scale.setValue(page->Scale.getValue()); } } else if ( ScaleType.isValue("Custom") ) { @@ -200,7 +200,7 @@ void DrawView::onChanged(const App::Property* prop) Scale.setStatus(App::Property::ReadOnly, true); if (!checkFit(page)) { double newScale = autoScale(page->getPageWidth(), page->getPageHeight()); - if(std::abs(newScale - getScale()) > FLT_EPSILON) { + if(std::abs(newScale - getScale()) > std::numeric_limits::epsilon()) { Scale.setValue(newScale); } } diff --git a/src/Mod/TechDraw/App/DrawViewDimension.cpp b/src/Mod/TechDraw/App/DrawViewDimension.cpp index 72a7af43a0..a16883c267 100644 --- a/src/Mod/TechDraw/App/DrawViewDimension.cpp +++ b/src/Mod/TechDraw/App/DrawViewDimension.cpp @@ -105,11 +105,11 @@ const char* DrawViewDimension::TypeEnums[] = {"Distance", const char* DrawViewDimension::MeasureTypeEnums[] = {"True", "Projected", nullptr}; // constraint to set the step size to 0.1 -static const App::PropertyQuantityConstraint::Constraints ToleranceConstraint = {-DBL_MAX, - DBL_MAX, - 0.1}; +static const App::PropertyQuantityConstraint::Constraints ToleranceConstraint = { + -std::numeric_limits::max(), std::numeric_limits::max(), 0.1}; // constraint to force positive values -static const App::PropertyQuantityConstraint::Constraints PositiveConstraint = {0.0, DBL_MAX, 0.1}; +static const App::PropertyQuantityConstraint::Constraints PositiveConstraint = { + 0.0, std::numeric_limits::max(), 0.1}; DrawViewDimension::DrawViewDimension() { diff --git a/src/Mod/TechDraw/App/DrawViewPart.cpp b/src/Mod/TechDraw/App/DrawViewPart.cpp index d0359df991..117001a094 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.cpp +++ b/src/Mod/TechDraw/App/DrawViewPart.cpp @@ -986,7 +986,7 @@ double DrawViewPart::getSizeAlongVector(Base::Vector3d alignmentVector) if (getEdgeCompound().IsNull()) { return 1.0; } - TopoDS_Shape rotatedShape = ShapeUtils::rotateShape(getEdgeCompound(), OXYZ, alignmentAngle * 180.0 / M_PI); + TopoDS_Shape rotatedShape = ShapeUtils::rotateShape(getEdgeCompound(), OXYZ, alignmentAngle * 180.0 / std::numbers::pi); Bnd_Box shapeBox; shapeBox.SetGap(0.0); BRepBndLib::AddOptimal(rotatedShape, shapeBox); @@ -1105,7 +1105,7 @@ gp_Ax2 DrawViewPart::getRotatedCS(const Base::Vector3d basePoint) const // Base::Console().Message("DVP::getRotatedCS() - %s - %s\n", getNameInDocument(), Label.getValue()); gp_Ax2 unrotated = getProjectionCS(basePoint); gp_Ax1 rotationAxis(Base::convertTo(basePoint), unrotated.Direction()); - double angleRad = Rotation.getValue() * M_PI / 180.0; + double angleRad = Rotation.getValue() * std::numbers::pi / 180.0; gp_Ax2 rotated = unrotated.Rotated(rotationAxis, -angleRad); return rotated; } @@ -1302,9 +1302,9 @@ void DrawViewPart::spin(const SpinDirection& spindirection) { double angle; if (spindirection == SpinDirection::CW) - angle = M_PI / 2.0;// Top -> Right -> Bottom -> Left -> Top + angle = std::numbers::pi / 2.0;// Top -> Right -> Bottom -> Left -> Top if (spindirection == SpinDirection::CCW) - angle = -M_PI / 2.0;// Top -> Left -> Bottom -> Right -> Top + angle = -std::numbers::pi / 2.0;// Top -> Left -> Bottom -> Right -> Top spin(angle); } @@ -1338,7 +1338,7 @@ std::pair DrawViewPart::getDirsFromFront(ProjDir gp_Dir gNewDir; gp_Dir gNewXDir; - double angle = M_PI / 2.0;//90* + double angle = std::numbers::pi / 2.0;//90* if (viewType == ProjDirection::Right) { newCS = anchorCS.Rotated(gUpAxis, angle); diff --git a/src/Mod/TechDraw/App/EdgeWalker.cpp b/src/Mod/TechDraw/App/EdgeWalker.cpp index ae3d5b0af7..d30f1d9607 100644 --- a/src/Mod/TechDraw/App/EdgeWalker.cpp +++ b/src/Mod/TechDraw/App/EdgeWalker.cpp @@ -307,11 +307,11 @@ std::vector EdgeWalker::makeWalkerEdges(std::vector edg TopoDS_Vertex edgeVertex1 = TopExp::FirstVertex(e); TopoDS_Vertex edgeVertex2 = TopExp::LastVertex(e); std::size_t vertex1Index = findUniqueVert(edgeVertex1, verts); - if (vertex1Index == SIZE_MAX) { + if (vertex1Index == std::numeric_limits::max()) { continue; } std::size_t vertex2Index = findUniqueVert(edgeVertex2, verts); - if (vertex2Index == SIZE_MAX) { + if (vertex2Index == std::numeric_limits::max()) { continue; } @@ -338,7 +338,7 @@ size_t EdgeWalker::findUniqueVert(TopoDS_Vertex vx, std::vector & } idx++; } - return SIZE_MAX; + return std::numeric_limits::max(); } std::vector EdgeWalker::sortStrip(std::vector fw, bool includeBiggest) @@ -556,7 +556,7 @@ std::string embedItem::dump() std::stringstream builder; builder << "embedItem - vertex: " << iVertex << " incidenceList: "; for (auto& ii : incidenceList) { - builder << " e:" << ii.iEdge << "/a:" << (ii.angle * (180.0/M_PI)) << "/ed:" << ii.eDesc; + builder << " e:" << ii.iEdge << "/a:" << (ii.angle * (180.0/std::numbers::pi)) << "/ed:" << ii.eDesc; } return builder.str(); } diff --git a/src/Mod/TechDraw/App/Geometry.cpp b/src/Mod/TechDraw/App/Geometry.cpp index 0cb09d530b..6011cbea15 100644 --- a/src/Mod/TechDraw/App/Geometry.cpp +++ b/src/Mod/TechDraw/App/Geometry.cpp @@ -657,7 +657,7 @@ Ellipse::Ellipse(Base::Vector3d c, double mnr, double mjr) Base::Console().Message("G:Ellipse - failed to make Ellipse\n"); } const Handle(Geom_Ellipse) gEllipse = me.Value(); - BRepBuilderAPI_MakeEdge mkEdge(gEllipse, 0.0, 2 * M_PI); + BRepBuilderAPI_MakeEdge mkEdge(gEllipse, 0.0, 2 * std::numbers::pi); if (mkEdge.IsDone()) { occEdge = mkEdge.Edge(); } @@ -686,10 +686,10 @@ AOE::AOE(const TopoDS_Edge &e) : Ellipse(e) e.GetMessageString()); } - startAngle = fmod(f, 2.0*M_PI); - endAngle = fmod(l, 2.0*M_PI); + startAngle = fmod(f, 2.0*std::numbers::pi); + endAngle = fmod(l, 2.0*std::numbers::pi); cw = (a < 0) ? true: false; - largeArc = (l-f > M_PI) ? true : false; + largeArc = (l-f > std::numbers::pi) ? true : false; startPnt = Base::Vector3d(s.X(), s.Y(), s.Z()); endPnt = Base::Vector3d(ePt.X(), ePt.Y(), ePt.Z()); @@ -709,6 +709,8 @@ Circle::Circle() Circle::Circle(Base::Vector3d c, double r) { + using std::numbers::pi; + geomType = GeomType::CIRCLE; radius = r; center = c; @@ -722,7 +724,7 @@ Circle::Circle(Base::Vector3d c, double r) double angle2 = 360.0; Handle(Geom_Circle) hCircle = new Geom_Circle (circle); - BRepBuilderAPI_MakeEdge aMakeEdge(hCircle, angle1*(M_PI/180), angle2*(M_PI/180)); + BRepBuilderAPI_MakeEdge aMakeEdge(hCircle, angle1*(pi/180), angle2*(pi/180)); TopoDS_Edge edge = aMakeEdge.Edge(); occEdge = edge; } @@ -794,12 +796,12 @@ AOC::AOC(const TopoDS_Edge &e) : Circle(e) // this is the wrong determination of cw/ccw. needs to be determined by edge. double a = v3.DotCross(v1, v2); //error if v1 = v2? - startAngle = fmod(f, 2.0*M_PI); - endAngle = fmod(l, 2.0*M_PI); + startAngle = fmod(f, 2.0*std::numbers::pi); + endAngle = fmod(l, 2.0*std::numbers::pi); cw = (a < 0) ? true: false; - largeArc = (fabs(l-f) > M_PI) ? true : false; + largeArc = (fabs(l-f) > std::numbers::pi) ? true : false; startPnt = Base::convertTo(s); endPnt = Base::convertTo(ePt); @@ -823,7 +825,7 @@ AOC::AOC(Base::Vector3d c, double r, double sAng, double eAng) : Circle() circle.SetRadius(r); Handle(Geom_Circle) hCircle = new Geom_Circle (circle); - BRepBuilderAPI_MakeEdge aMakeEdge(hCircle, sAng*(M_PI/180), eAng*(M_PI/180)); + BRepBuilderAPI_MakeEdge aMakeEdge(hCircle, sAng*(std::numbers::pi/180), eAng*(std::numbers::pi/180)); TopoDS_Edge edge = aMakeEdge.Edge(); occEdge = edge; @@ -844,10 +846,10 @@ AOC::AOC(Base::Vector3d c, double r, double sAng, double eAng) : Circle() // this cw flag is a problem. we should just declare that arcs are always ccw and flip the start and end angles. double a = v3.DotCross(v1, v2); //error if v1 = v2? - startAngle = fmod(f, 2.0*M_PI); - endAngle = fmod(l, 2.0*M_PI); + startAngle = fmod(f, 2.0*std::numbers::pi); + endAngle = fmod(l, 2.0*std::numbers::pi); cw = (a < 0) ? true: false; - largeArc = (fabs(l-f) > M_PI) ? true : false; + largeArc = (fabs(l-f) > std::numbers::pi) ? true : false; startPnt = Base::convertTo(s); endPnt = Base::convertTo(ePt); @@ -866,7 +868,7 @@ AOC::AOC() : Circle() endPnt = Base::Vector3d(0.0, 0.0, 0.0); midPnt = Base::Vector3d(0.0, 0.0, 0.0); startAngle = 0.0; - endAngle = 2.0 * M_PI; + endAngle = 2.0 * std::numbers::pi; cw = false; largeArc = false; @@ -1095,7 +1097,7 @@ double Generic::slope() { Base::Vector3d v = asVector(); if (v.x == 0.0) { - return DOUBLE_MAX; + return std::numeric_limits::max(); } else { return v.y/v.x; } @@ -1146,11 +1148,11 @@ BSpline::BSpline(const TopoDS_Edge &e) startAngle = atan2(startPnt.y, startPnt.x); if (startAngle < 0) { - startAngle += 2.0 * M_PI; + startAngle += 2.0 * std::numbers::pi; } endAngle = atan2(endPnt.y, endPnt.x); if (endAngle < 0) { - endAngle += 2.0 * M_PI; + endAngle += 2.0 * std::numbers::pi; } Standard_Real tol3D = 0.001; //1/1000 of a mm? screen can't resolve this @@ -1473,7 +1475,7 @@ TopoDS_Edge GeometryUtils::edgeFromCircle(TechDraw::CirclePtr c) circle.SetAxis(axis); circle.SetRadius(c->radius); Handle(Geom_Circle) hCircle = new Geom_Circle (circle); - BRepBuilderAPI_MakeEdge aMakeEdge(hCircle, 0.0, 2.0 * M_PI); + BRepBuilderAPI_MakeEdge aMakeEdge(hCircle, 0.0, 2.0 * std::numbers::pi); return aMakeEdge.Edge(); } diff --git a/src/Mod/TechDraw/App/GeometryObject.cpp b/src/Mod/TechDraw/App/GeometryObject.cpp index b56e54943f..021cb13534 100644 --- a/src/Mod/TechDraw/App/GeometryObject.cpp +++ b/src/Mod/TechDraw/App/GeometryObject.cpp @@ -759,24 +759,26 @@ TechDraw::DrawViewDetail* GeometryObject::isParentDetail() bool GeometryObject::isWithinArc(double theta, double first, double last, bool cw) const { - if (fabs(last - first) >= 2 * M_PI) { + using std::numbers::pi; + + if (fabs(last - first) >= 2 * pi) { return true; } // Put params within [0, 2*pi) - not totally sure this is necessary - theta = fmod(theta, 2 * M_PI); + theta = fmod(theta, 2 * pi); if (theta < 0) { - theta += 2 * M_PI; + theta += 2 * pi; } - first = fmod(first, 2 * M_PI); + first = fmod(first, 2 * pi); if (first < 0) { - first += 2 * M_PI; + first += 2 * pi; } - last = fmod(last, 2 * M_PI); + last = fmod(last, 2 * pi); if (last < 0) { - last += 2 * M_PI; + last += 2 * pi; } if (cw) { diff --git a/src/Mod/TechDraw/App/HatchLine.cpp b/src/Mod/TechDraw/App/HatchLine.cpp index 2c2814cac1..e37626a2d1 100644 --- a/src/Mod/TechDraw/App/HatchLine.cpp +++ b/src/Mod/TechDraw/App/HatchLine.cpp @@ -396,7 +396,7 @@ double PATLineSpec::getSlope() } else if (angle < -90.0) { angle = (180 + angle); } - return tan(angle * M_PI/180.0); + return tan(angle * std::numbers::pi/180.0); } bool PATLineSpec::isDashed() @@ -413,7 +413,7 @@ double PATLineSpec::getIntervalX() return getInterval(); } else { double perpAngle = fabs(getAngle() - 90.0); - return fabs(getInterval() / cos(perpAngle * M_PI/180.0)); + return fabs(getInterval() / cos(perpAngle * std::numbers::pi/180.0)); } } @@ -426,7 +426,7 @@ double PATLineSpec::getIntervalY() return 0.0; } else { double perpAngle = fabs(getAngle() - 90.0); - return fabs(getInterval() * tan(perpAngle * M_PI/180.0)); + return fabs(getInterval() * tan(perpAngle * std::numbers::pi/180.0)); } } diff --git a/src/Mod/TechDraw/App/ShapeUtils.cpp b/src/Mod/TechDraw/App/ShapeUtils.cpp index 88db95abc8..6e5c070fe5 100644 --- a/src/Mod/TechDraw/App/ShapeUtils.cpp +++ b/src/Mod/TechDraw/App/ShapeUtils.cpp @@ -96,7 +96,7 @@ gp_Ax2 ShapeUtils::getViewAxis(const Base::Vector3d origin, const Base::Vector3d cross = cross.Cross(stdZ); } - if (cross.IsEqual(stdOrg, FLT_EPSILON)) { + if (cross.IsEqual(stdOrg, std::numeric_limits::epsilon())) { viewAxis = gp_Ax2(inputCenter, gp_Dir(direction.x, direction.y, direction.z)); return viewAxis; } @@ -142,7 +142,7 @@ gp_Ax2 ShapeUtils::legacyViewAxis1(const Base::Vector3d origin, const Base::Vect cross = cross.Cross(stdZ); } - if (cross.IsEqual(stdOrg, FLT_EPSILON)) { + if (cross.IsEqual(stdOrg, std::numeric_limits::epsilon())) { return gp_Ax2(inputCenter, gp_Dir(flipDirection.x, flipDirection.y, flipDirection.z)); } @@ -273,7 +273,7 @@ TopoDS_Shape ShapeUtils::rotateShape(const TopoDS_Shape& input, const gp_Ax2& vi } gp_Ax1 rotAxis = viewAxis.Axis(); - double rotation = rotAngle * M_PI / 180.0; + double rotation = rotAngle * std::numbers::pi / 180.0; try { gp_Trsf tempTransform; diff --git a/src/Mod/TechDraw/App/TechDrawExport.cpp b/src/Mod/TechDraw/App/TechDrawExport.cpp index dd7391eac6..eb97f04a0e 100644 --- a/src/Mod/TechDraw/App/TechDrawExport.cpp +++ b/src/Mod/TechDraw/App/TechDrawExport.cpp @@ -220,7 +220,7 @@ void SVGOutput::printCircle(const BRepAdaptor_Curve& c, std::ostream& out) else { // See also https://developer.mozilla.org/en/SVG/Tutorial/Paths char xar = '0'; // x-axis-rotation - char las = (l-f > M_PI) ? '1' : '0'; // large-arc-flag + char las = (l-f > std::numbers::pi) ? '1' : '0'; // large-arc-flag char swp = (a < 0) ? '1' : '0'; // sweep-flag, i.e. clockwise (0) or counter-clockwise (1) out << " M_PI) ? '1' : '0'; // large-arc-flag + char las = (l-f > std::numbers::pi) ? '1' : '0'; // large-arc-flag char swp = (a < 0) ? '1' : '0'; // sweep-flag, i.e. clockwise (0) or counter-clockwise (1) out << " M_PI) ? '1' : '0'; // large-arc-flag + char las = (l-f > std::numbers::pi) ? '1' : '0'; // large-arc-flag char swp = (a < 0) ? '1' : '0'; // sweep-flag, i.e. clockwise (0) or counter-clockwise (1) out << " 0) { double temp = start_angle; @@ -583,7 +583,7 @@ void DXFOutput::printEllipse(const BRepAdaptor_Curve& c, int /*id*/, std::ostrea gp_Dir xaxis = ellp.XAxis().Direction(); Standard_Real angle = xaxis.Angle(gp_Dir(1, 0,0)); angle = Base::toDegrees(angle); - char las = (l-f > D_PI) ? '1' : '0'; // large-arc-flag + char las = (l-f > std::numbers::pi) ? '1' : '0'; // large-arc-flag char swp = (a < 0) ? '1' : '0'; // sweep-flag, i.e. clockwise (0) or counter-clockwise (1) out << "::max(); + double minY = std::numeric_limits::max(); + double maxX = -std::numeric_limits::max(); + double maxY = -std::numeric_limits::max(); for (auto dim : dims) { TechDraw::pointPair pp = dim->getLinearPoints(); Base::Vector3d pnt1 = Rez::guiX(pp.first()); diff --git a/src/Mod/TechDraw/Gui/CommandExtensionDims.cpp b/src/Mod/TechDraw/Gui/CommandExtensionDims.cpp index 64d16ae320..7da9433ff9 100644 --- a/src/Mod/TechDraw/Gui/CommandExtensionDims.cpp +++ b/src/Mod/TechDraw/Gui/CommandExtensionDims.cpp @@ -2050,7 +2050,7 @@ void execCreateHorizChamferDimension(Gui::Command* cmd) { std::vector allVertexes; allVertexes = _getVertexInfo(objFeat, subNames); if (!allVertexes.empty() && allVertexes.size() > 1) { - const auto Pi180 = 180.0 / M_PI; + const auto Pi180 = 180.0 / std::numbers::pi; TechDraw::DrawViewDimension* dim; dim = _createLinDimension(objFeat, allVertexes[0].name, allVertexes[1].name, "DistanceX"); float yMax = std::max(abs(allVertexes[0].point.y), abs(allVertexes[1].point.y)) + 7.0; @@ -2119,7 +2119,7 @@ void execCreateVertChamferDimension(Gui::Command* cmd) { std::vector allVertexes; allVertexes = _getVertexInfo(objFeat, subNames); if (!allVertexes.empty() && allVertexes.size() > 1) { - const auto Pi180 = 180.0 / M_PI; + const auto Pi180 = 180.0 / std::numbers::pi; TechDraw::DrawViewDimension* dim; dim = _createLinDimension(objFeat, allVertexes[0].name, allVertexes[1].name, "DistanceY"); float xMax = std::max(abs(allVertexes[0].point.x), abs(allVertexes[1].point.x)) + 7.0; diff --git a/src/Mod/TechDraw/Gui/CommandExtensionPack.cpp b/src/Mod/TechDraw/Gui/CommandExtensionPack.cpp index e37c3a7795..582bcfdd22 100644 --- a/src/Mod/TechDraw/Gui/CommandExtensionPack.cpp +++ b/src/Mod/TechDraw/Gui/CommandExtensionPack.cpp @@ -2099,7 +2099,7 @@ double _getAngle(Base::Vector3d center, Base::Vector3d point) { constexpr double DegreesHalfCircle{180.0}; Base::Vector3d vecCP = point - center; - double angle = DU::angleWithX(vecCP) * DegreesHalfCircle / M_PI; + double angle = DU::angleWithX(vecCP) * DegreesHalfCircle / std::numbers::pi; return angle; } diff --git a/src/Mod/TechDraw/Gui/DimensionValidators.cpp b/src/Mod/TechDraw/Gui/DimensionValidators.cpp index 2142161701..9f24fdf162 100644 --- a/src/Mod/TechDraw/Gui/DimensionValidators.cpp +++ b/src/Mod/TechDraw/Gui/DimensionValidators.cpp @@ -386,10 +386,10 @@ DimensionGeometry TechDraw::isValidSingleEdge(const ReferenceEntry& ref) return DimensionGeometry::isInvalid; } Base::Vector3d line = gen1->points.at(1) - gen1->points.at(0); - if (fabs(line.y) < FLT_EPSILON) { + if (fabs(line.y) < std::numeric_limits::epsilon()) { return DimensionGeometry::isVertical; } - if (fabs(line.x) < FLT_EPSILON) { + if (fabs(line.x) < std::numeric_limits::epsilon()) { return DimensionGeometry::isHorizontal; } return DimensionGeometry::isDiagonal; @@ -430,13 +430,13 @@ DimensionGeometry TechDraw::isValidSingleEdge3d(DrawViewPart* dvp, const Referen Base::Vector3d point1 = Base::convertTo(BRep_Tool::Pnt(TopExp::LastVertex(occEdge))); point1 = dvp->projectPoint(point1); Base::Vector3d line = point1 - point0; - if (fabs(line.y) < FLT_EPSILON) { + if (fabs(line.y) < std::numeric_limits::epsilon()) { return DimensionGeometry::isVertical; } - if (fabs(line.x) < FLT_EPSILON) { + if (fabs(line.x) < std::numeric_limits::epsilon()) { return DimensionGeometry::isHorizontal; } - // else if (fabs(line.z) < FLT_EPSILON) { + // else if (fabs(line.z) < std::numeric_limits::epsilon()) { // return TechDraw::isZLimited; // } else { @@ -632,9 +632,9 @@ DimensionGeometry TechDraw::isValidVertexes(const ReferenceVector& refs) TechDraw::VertexPtr v0 = dvp->getVertex(refs.at(0).getSubName()); TechDraw::VertexPtr v1 = dvp->getVertex(refs.at(1).getSubName()); Base::Vector3d line = v1->point() - v0->point(); - if (fabs(line.y) < FLT_EPSILON) { + if (fabs(line.y) < std::numeric_limits::epsilon()) { return DimensionGeometry::isHorizontal; - } else if (fabs(line.x) < FLT_EPSILON) { + } else if (fabs(line.x) < std::numeric_limits::epsilon()) { return DimensionGeometry::isHorizontal; } else { return DimensionGeometry::isDiagonal; @@ -670,12 +670,12 @@ DimensionGeometry TechDraw::isValidVertexes3d(DrawViewPart* dvp, const Reference Base::Vector3d point1 = Base::convertTo(BRep_Tool::Pnt(TopoDS::Vertex(geometry1))); point1 = dvp->projectPoint(point1); Base::Vector3d line = point1 - point0; - if (fabs(line.y) < FLT_EPSILON) { + if (fabs(line.y) < std::numeric_limits::epsilon()) { return DimensionGeometry::isVertical; } - if (fabs(line.x) < FLT_EPSILON) { + if (fabs(line.x) < std::numeric_limits::epsilon()) { return DimensionGeometry::isHorizontal; - // } else if(fabs(line.z) < FLT_EPSILON) { + // } else if(fabs(line.z) < std::numeric_limits::epsilon()) { // return isZLimited; } else { return DimensionGeometry::isDiagonal; diff --git a/src/Mod/TechDraw/Gui/DrawGuiUtil.cpp b/src/Mod/TechDraw/Gui/DrawGuiUtil.cpp index 3954090e30..a6e9dce171 100644 --- a/src/Mod/TechDraw/Gui/DrawGuiUtil.cpp +++ b/src/Mod/TechDraw/Gui/DrawGuiUtil.cpp @@ -832,7 +832,7 @@ void DrawGuiUtil::rotateToAlign(DrawViewPart* view, const Base::Vector2d& oldDir double toRotate = newDirection.GetAngle(oldDirection); // Radians to degrees - toRotate = toRotate * 180 / M_PI; + toRotate = toRotate * 180 / std::numbers::pi; // Rotate least amount possible if(toRotate > 90) { diff --git a/src/Mod/TechDraw/Gui/PathBuilder.cpp b/src/Mod/TechDraw/Gui/PathBuilder.cpp index 2d5240baab..11e26758b3 100644 --- a/src/Mod/TechDraw/Gui/PathBuilder.cpp +++ b/src/Mod/TechDraw/Gui/PathBuilder.cpp @@ -327,11 +327,11 @@ void PathBuilder::pathArc(QPainterPath& path, double rx, double ry, double x_axi th_arc = th1 - th0; if (th_arc < 0 && sweep_flag) - th_arc += 2 * M_PI; + th_arc += 2 * std::numbers::pi; else if (th_arc > 0 && !sweep_flag) - th_arc -= 2 * M_PI; + th_arc -= 2 * std::numbers::pi; - n_segs = qCeil(qAbs(th_arc / (M_PI * 0.5 + 0.001))); + n_segs = qCeil(qAbs(th_arc / (std::numbers::pi * 0.5 + 0.001))); path.moveTo(curx, cury); diff --git a/src/Mod/TechDraw/Gui/QGIHighlight.cpp b/src/Mod/TechDraw/Gui/QGIHighlight.cpp index 165a9156e6..85d58d9ffc 100644 --- a/src/Mod/TechDraw/Gui/QGIHighlight.cpp +++ b/src/Mod/TechDraw/Gui/QGIHighlight.cpp @@ -125,7 +125,7 @@ void QGIHighlight::makeReference() QRectF r(m_start, m_end); double radius = r.width() / 2.0; QPointF center = r.center(); - double angleRad = m_referenceAngle * M_PI / 180.0; + double angleRad = m_referenceAngle * std::numbers::pi / 180.0; double posX = center.x() + cos(angleRad) * radius + horizOffset; double posY = center.y() - sin(angleRad) * radius - vertOffset; m_reference->setPos(posX, posY); diff --git a/src/Mod/TechDraw/Gui/QGILeaderLine.cpp b/src/Mod/TechDraw/Gui/QGILeaderLine.cpp index 40c1e15ecd..b8e23aac6c 100644 --- a/src/Mod/TechDraw/Gui/QGILeaderLine.cpp +++ b/src/Mod/TechDraw/Gui/QGILeaderLine.cpp @@ -589,7 +589,7 @@ Base::Vector3d QGILeaderLine::getAttachPoint() double yPos = Rez::guiX(featLeader->Y.getValue()); Base::Vector3d vAttachPoint{xPos, yPos}; vAttachPoint = vAttachPoint * baseScale; - double rotationRad = parent->Rotation.getValue() * M_PI / DegreesHalfCircle; + double rotationRad = parent->Rotation.getValue() * std::numbers::pi / DegreesHalfCircle; if (rotationRad != 0.0) { vAttachPoint.RotateZ(rotationRad); } diff --git a/src/Mod/TechDraw/Gui/QGISectionLine.cpp b/src/Mod/TechDraw/Gui/QGISectionLine.cpp index 37415d4df5..c5546e85ec 100644 --- a/src/Mod/TechDraw/Gui/QGISectionLine.cpp +++ b/src/Mod/TechDraw/Gui/QGISectionLine.cpp @@ -402,9 +402,9 @@ double QGISectionLine::getArrowRotation(Base::Vector3d arrowDir) arrowDir.Normalize(); double angle = atan2f(arrowDir.y, arrowDir.x); if (angle < 0.0) { - angle = 2 * M_PI + angle; + angle = 2 * std::numbers::pi + angle; } - double arrowRotation = 360.0 - angle * (180.0/M_PI); //convert to Qt rotation (clockwise degrees) + double arrowRotation = 360.0 - angle * (180.0/std::numbers::pi); //convert to Qt rotation (clockwise degrees) return arrowRotation; } diff --git a/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp b/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp index c63e7c5cdc..b1d4258814 100644 --- a/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp @@ -606,6 +606,8 @@ void QGIViewBalloon::draw() void QGIViewBalloon::drawBalloon(bool originDrag) { + using std::numbers::pi; + if ((!originDrag) && m_dragInProgress) { // TODO there are 2 drag status variables. m_draggingInProgress appears to be the one to use? // dragged shows false while drag is still in progress. @@ -696,14 +698,14 @@ void QGIViewBalloon::drawBalloon(bool originDrag) double radius = sqrt(pow((textHeight / 2.0), 2) + pow((textWidth / 2.0), 2)); radius = radius * scale; radius += Rez::guiX(3.0); - offsetLR = (tan(30 * M_PI / 180) * radius); + offsetLR = (tan(30 * pi / 180) * radius); QPolygonF triangle; - double startAngle = -M_PI / 2; + double startAngle = -pi / 2; double angle = startAngle; for (int i = 0; i < 4; i++) { triangle += QPointF(lblCenter.x + (radius * cos(angle)), lblCenter.y + (radius * sin(angle))); - angle += (2 * M_PI / 3); + angle += (2 * pi / 3); } balloonPath.moveTo(lblCenter.x + (radius * cos(startAngle)), lblCenter.y + (radius * sin(startAngle))); @@ -737,12 +739,12 @@ void QGIViewBalloon::drawBalloon(bool originDrag) radius += Rez::guiX(1.0); offsetLR = radius; QPolygonF triangle; - double startAngle = -2 * M_PI / 3; + double startAngle = -2 * pi / 3; double angle = startAngle; for (int i = 0; i < 7; i++) { triangle += QPointF(lblCenter.x + (radius * cos(angle)), lblCenter.y + (radius * sin(angle))); - angle += (2 * M_PI / 6); + angle += (2 * pi / 6); } balloonPath.moveTo(lblCenter.x + (radius * cos(startAngle)), lblCenter.y + (radius * sin(startAngle))); @@ -805,7 +807,7 @@ void QGIViewBalloon::drawBalloon(bool originDrag) dirballoonLinesLine = (arrowTipPosInParent - dLineStart).Normalize(); } - float arAngle = atan2(dirballoonLinesLine.y, dirballoonLinesLine.x) * 180 / M_PI; + float arAngle = atan2(dirballoonLinesLine.y, dirballoonLinesLine.x) * 180 / pi; if ((endType == ArrowType::FILLED_TRIANGLE) && (prefOrthoPyramid())) { if (arAngle < 0.0) { @@ -824,7 +826,7 @@ void QGIViewBalloon::drawBalloon(bool originDrag) else { arAngle = 0; } - double radAngle = arAngle * M_PI / 180.0; + double radAngle = arAngle * pi / 180.0; double sinAngle = sin(radAngle); double cosAngle = cos(radAngle); xAdj = Rez::guiX(arrowAdj * cosAngle); diff --git a/src/Mod/TechDraw/Gui/QGIViewDimension.cpp b/src/Mod/TechDraw/Gui/QGIViewDimension.cpp index 60040fbbba..27fdc744ed 100644 --- a/src/Mod/TechDraw/Gui/QGIViewDimension.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewDimension.cpp @@ -22,10 +22,6 @@ #include "PreCompiled.h" -#ifdef FC_OS_WIN32 -# define _USE_MATH_DEFINES //resolves Windows & M_PI issues -#endif - #ifndef _PreComp_ # include @@ -440,25 +436,27 @@ void QGIViewDimension::draw() double QGIViewDimension::getAnglePlacementFactor(double testAngle, double endAngle, double startRotation) { + using std::numbers::pi; + if (startRotation > 0.0) { startRotation = -startRotation; endAngle -= startRotation; - if (endAngle > M_PI) { - endAngle -= M_2PI; + if (endAngle > pi) { + endAngle -= 2 * pi; } } if (testAngle > endAngle) { - testAngle -= M_2PI; + testAngle -= 2 * pi; } if (testAngle >= endAngle + startRotation) { return +1.0; } - testAngle += M_PI; + testAngle += pi; if (testAngle > endAngle) { - testAngle -= M_2PI; + testAngle -= 2 * pi; } if (testAngle >= endAngle + startRotation) { @@ -472,7 +470,7 @@ int QGIViewDimension::compareAngleStraightness(double straightAngle, double left double rightAngle, double leftStrikeFactor, double rightStrikeFactor) { - double leftDelta = DrawUtil::angleComposition(M_PI, straightAngle - leftAngle); + double leftDelta = DrawUtil::angleComposition(std::numbers::pi, straightAngle - leftAngle); double rightDelta = DrawUtil::angleComposition(rightAngle, -straightAngle); if (fabs(leftDelta - rightDelta) <= Precision::Confusion()) { @@ -492,7 +490,7 @@ int QGIViewDimension::compareAngleStraightness(double straightAngle, double left double QGIViewDimension::getIsoStandardLinePlacement(double labelAngle) { // According to ISO 129-1 Standard Figure 23, the bordering angle is 1/2 PI, resp. -1/2 PI - return labelAngle < -M_PI / 2.0 || labelAngle > +M_PI / 2.0 ? +1.0 : -1.0; + return labelAngle < -std::numbers::pi / 2.0 || labelAngle > +std::numbers::pi / 2.0 ? +1.0 : -1.0; } Base::Vector2d QGIViewDimension::getIsoRefOutsetPoint(const Base::BoundBox2d& labelRectangle, @@ -599,7 +597,7 @@ double QGIViewDimension::computeLineAndLabelAngles(const Base::Vector2d& rotatio double devAngle = getIsoStandardLinePlacement(rawAngle) * asin(lineLabelDistance / rawDistance); lineAngle = DrawUtil::angleComposition(lineAngle, devAngle); - labelAngle = devAngle < 0.0 ? lineAngle : DrawUtil::angleComposition(lineAngle, M_PI); + labelAngle = devAngle < 0.0 ? lineAngle : DrawUtil::angleComposition(lineAngle, std::numbers::pi); return devAngle; } @@ -669,7 +667,7 @@ QGIViewDimension::computeArcStrikeFactor(const Base::BoundBox2d& labelRectangle, double arcAngle = drawMarking[startIndex].first; double arcRotation = drawMarking[currentIndex].first - arcAngle; if (arcRotation < 0.0) { - arcRotation += M_2PI; + arcRotation += 2 * std::numbers::pi; } DrawUtil::findCircularArcRectangleIntersections(arcCenter, arcRadius, arcAngle, @@ -689,7 +687,7 @@ double QGIViewDimension::normalizeStartPosition(double& startPosition, double& l { if (startPosition > 0.0) { startPosition = -startPosition; - lineAngle += M_PI; + lineAngle += std::numbers::pi; return -1.0; } @@ -872,7 +870,7 @@ bool QGIViewDimension::constructDimensionArc( // Add the arrow tails - these are drawn always double tailDelta = - arcRadius >= Precision::Confusion() ? getDefaultArrowTailLength() / arcRadius : M_PI_4; + arcRadius >= Precision::Confusion() ? getDefaultArrowTailLength() / arcRadius : std::numbers::pi / 4.0; double placementFactor = flipArrows ? +1.0 : -1.0; DrawUtil::intervalMarkCircular(outputMarking, endAngle, @@ -993,7 +991,7 @@ void QGIViewDimension::drawSingleArc(QPainterPath& painterPath, const Base::Vect return; } if (endAngle < startAngle) { - endAngle += M_2PI; + endAngle += 2 * std::numbers::pi; } QRectF qtArcRectangle( @@ -1019,7 +1017,7 @@ void QGIViewDimension::drawMultiArc(QPainterPath& painterPath, const Base::Vecto } if (entryIndex >= drawMarking.size()) { - drawSingleArc(painterPath, arcCenter, arcRadius, 0, M_2PI); + drawSingleArc(painterPath, arcCenter, arcRadius, 0, 2 * std::numbers::pi); return; } @@ -1067,7 +1065,7 @@ void QGIViewDimension::drawDimensionLine(QPainterPath& painterPath, double arrowAngles[2]; arrowAngles[0] = lineAngle; - arrowAngles[1] = lineAngle + M_PI; + arrowAngles[1] = lineAngle + std::numbers::pi; drawArrows(arrowCount, arrowPositions, arrowAngles, flipArrows, forcePointStyle); } @@ -1077,13 +1075,15 @@ void QGIViewDimension::drawDimensionArc(QPainterPath& painterPath, const Base::V double jointAngle, const Base::BoundBox2d& labelRectangle, int arrowCount, int standardStyle, bool flipArrows) const { + using std::numbers::pi; + // Keep the convention start rotation <= 0 double handednessFactor = normalizeStartRotation(startRotation); // Split the rest of 2PI minus the angle and assign joint offset so > 0 is closer to end arc side double jointRotation = handednessFactor * (jointAngle - endAngle); - if (fabs(jointRotation - startRotation * 0.5) > M_PI) { - jointRotation += jointRotation < 0.0 ? +M_2PI : -M_2PI; + if (fabs(jointRotation - startRotation * 0.5) > pi) { + jointRotation += jointRotation < 0.0 ? +2*pi : -2*pi; } std::vector> drawMarks; @@ -1099,8 +1099,8 @@ void QGIViewDimension::drawDimensionArc(QPainterPath& painterPath, const Base::V + Base::Vector2d::FromPolar(arcRadius, endAngle + handednessFactor * startRotation); double arrowAngles[2]; - arrowAngles[0] = endAngle + handednessFactor * M_PI_2; - arrowAngles[1] = endAngle + handednessFactor * (startRotation - M_PI_2); + arrowAngles[0] = endAngle + handednessFactor * std::numbers::pi/2; + arrowAngles[1] = endAngle + handednessFactor * (startRotation - std::numbers::pi/2); drawArrows(arrowCount, arrowPositions, arrowAngles, flipArrows); } @@ -1119,6 +1119,8 @@ void QGIViewDimension::drawDistanceExecutive(const Base::Vector2d& startPoint, int standardStyle, int renderExtent, bool flipArrows) const { + using std::numbers::pi; + QPainterPath distancePath; Base::Vector2d labelCenter(labelRectangle.GetCenter()); @@ -1170,9 +1172,9 @@ void QGIViewDimension::drawDistanceExecutive(const Base::Vector2d& startPoint, // Orient the leader line angle correctly towards the target point double angles[2]; angles[0] = - jointPositions[0] > 0.0 ? DrawUtil::angleComposition(lineAngle, M_PI) : lineAngle; + jointPositions[0] > 0.0 ? DrawUtil::angleComposition(lineAngle, pi) : lineAngle; angles[1] = - jointPositions[1] > 0.0 ? DrawUtil::angleComposition(lineAngle, M_PI) : lineAngle; + jointPositions[1] > 0.0 ? DrawUtil::angleComposition(lineAngle, pi) : lineAngle; // Select the placement, where the label is not obscured by the leader line // or (if both behave the same) the one that bends the reference line less @@ -1226,7 +1228,7 @@ void QGIViewDimension::drawDistanceExecutive(const Base::Vector2d& startPoint, // We may rotate the label so no leader and reference lines are needed double placementFactor = getIsoStandardLinePlacement(lineAngle); labelAngle = - placementFactor > 0.0 ? DrawUtil::angleComposition(lineAngle, M_PI) : lineAngle; + placementFactor > 0.0 ? DrawUtil::angleComposition(lineAngle, pi) : lineAngle; // Find out the projection of label center on the line with given angle Base::Vector2d labelProjection( @@ -1234,7 +1236,7 @@ void QGIViewDimension::drawDistanceExecutive(const Base::Vector2d& startPoint, + Base::Vector2d::FromPolar( placementFactor * (labelRectangle.Height() * 0.5 + getIsoDimensionLineSpacing()), - lineAngle + M_PI_2)); + lineAngle + pi/2)); // Compute the dimensional line start and end crossings with (virtual) extension lines //check for isometric direction and if iso compute non-perpendicular intersection of dim line and ext lines @@ -1288,14 +1290,14 @@ void QGIViewDimension::drawDistanceExecutive(const Base::Vector2d& startPoint, Base::Vector2d extensionOrigin; Base::Vector2d extensionTarget(computeExtensionLinePoints( - endPoint, endCross, lineAngle + M_PI_2, getDefaultExtensionLineOverhang(), gapSize, + endPoint, endCross, lineAngle + std::numbers::pi/2, getDefaultExtensionLineOverhang(), gapSize, extensionOrigin)); //draw 1st extension line distancePath.moveTo(toQtGui(extensionOrigin)); distancePath.lineTo(toQtGui(extensionTarget)); if (arrowCount > 1) { - extensionTarget = computeExtensionLinePoints(startPoint, startCross, lineAngle + M_PI_2, + extensionTarget = computeExtensionLinePoints(startPoint, startCross, lineAngle + std::numbers::pi/2, getDefaultExtensionLineOverhang(), gapSize, extensionOrigin); //draw second extension line @@ -1320,6 +1322,8 @@ void QGIViewDimension::drawDistanceOverride(const Base::Vector2d& startPoint, int standardStyle, int renderExtent, bool flipArrows, double extensionAngle) const { + using std::numbers::pi; + QPainterPath distancePath; Base::Vector2d labelCenter(labelRectangle.GetCenter()); @@ -1377,9 +1381,9 @@ void QGIViewDimension::drawDistanceOverride(const Base::Vector2d& startPoint, // Orient the leader line angle correctly towards the target point double angles[2]; angles[0] = - jointPositions[0] > 0.0 ? DrawUtil::angleComposition(lineAngle, M_PI) : lineAngle; + jointPositions[0] > 0.0 ? DrawUtil::angleComposition(lineAngle, pi) : lineAngle; angles[1] = - jointPositions[1] > 0.0 ? DrawUtil::angleComposition(lineAngle, M_PI) : lineAngle; + jointPositions[1] > 0.0 ? DrawUtil::angleComposition(lineAngle, pi) : lineAngle; // Select the placement, where the label is not obscured by the leader line // or (if both behave the same) the one that bends the reference line less @@ -1436,7 +1440,7 @@ void QGIViewDimension::drawDistanceOverride(const Base::Vector2d& startPoint, // We may rotate the label so no leader and reference lines are needed double placementFactor = getIsoStandardLinePlacement(lineAngle); labelAngle = - placementFactor > 0.0 ? DrawUtil::angleComposition(lineAngle, M_PI) : lineAngle; + placementFactor > 0.0 ? DrawUtil::angleComposition(lineAngle, pi) : lineAngle; // Find out the projection of label center on the line with given angle Base::Vector2d labelProjection( @@ -1444,7 +1448,7 @@ void QGIViewDimension::drawDistanceOverride(const Base::Vector2d& startPoint, + Base::Vector2d::FromPolar( placementFactor * (labelRectangle.Height() * 0.5 + getIsoDimensionLineSpacing()), - lineAngle + M_PI_2)); + lineAngle + std::numbers::pi/2)); // Compute the dimensional line start and end crossings with (virtual) extension lines startCross = @@ -1499,14 +1503,14 @@ void QGIViewDimension::drawDistanceOverride(const Base::Vector2d& startPoint, Base::Vector2d extensionOrigin; Base::Vector2d extensionTarget(computeExtensionLinePoints( - endPoint, endCross, lineAngle + M_PI_2, getDefaultExtensionLineOverhang(), gapSize, + endPoint, endCross, lineAngle + std::numbers::pi/2, getDefaultExtensionLineOverhang(), gapSize, extensionOrigin)); //draw 1st extension line distancePath.moveTo(toQtGui(extensionOrigin)); distancePath.lineTo(toQtGui(extensionTarget)); if (arrowCount > 1) { - extensionTarget = computeExtensionLinePoints(startPoint, startCross, lineAngle + M_PI_2, + extensionTarget = computeExtensionLinePoints(startPoint, startCross, lineAngle + std::numbers::pi/2, getDefaultExtensionLineOverhang(), gapSize, extensionOrigin); //draw second extension line @@ -1528,6 +1532,8 @@ void QGIViewDimension::drawRadiusExecutive(const Base::Vector2d& centerPoint, double centerOverhang, int standardStyle, int renderExtent, bool flipArrow) const { + using std::numbers::pi; + QPainterPath radiusPath; Base::Vector2d labelCenter(labelRectangle.GetCenter()); @@ -1558,10 +1564,10 @@ void QGIViewDimension::drawRadiusExecutive(const Base::Vector2d& centerPoint, // Orient the leader line angle correctly towards the point on arc if (angleFactors[0] < 0.0) { - lineAngles[0] = DrawUtil::angleComposition(lineAngles[0], M_PI); + lineAngles[0] = DrawUtil::angleComposition(lineAngles[0], pi); } if (angleFactors[1] < 0.0) { - lineAngles[1] = DrawUtil::angleComposition(lineAngles[1], M_PI); + lineAngles[1] = DrawUtil::angleComposition(lineAngles[1], pi); } // Find the positions where the reference line attaches to the dimension line @@ -1600,9 +1606,9 @@ void QGIViewDimension::drawRadiusExecutive(const Base::Vector2d& centerPoint, if (compareAngleStraightness( 0.0, - jointPositions[0] > 0.0 ? DrawUtil::angleComposition(lineAngles[0], M_PI) + jointPositions[0] > 0.0 ? DrawUtil::angleComposition(lineAngles[0], pi) : lineAngles[0], - jointPositions[1] > 0.0 ? DrawUtil::angleComposition(lineAngles[1], M_PI) + jointPositions[1] > 0.0 ? DrawUtil::angleComposition(lineAngles[1], pi) : lineAngles[1], strikeFactors[0], strikeFactors[1]) > 0) { @@ -1653,7 +1659,7 @@ void QGIViewDimension::drawRadiusExecutive(const Base::Vector2d& centerPoint, // Is there point on the arc, where line from center intersects it perpendicularly? double angleFactor = getAnglePlacementFactor(lineAngle, endAngle, startRotation); if (angleFactor < 0.0) { - lineAngle = DrawUtil::angleComposition(lineAngle, M_PI); + lineAngle = DrawUtil::angleComposition(lineAngle, pi); } Base::Vector2d arcPoint; @@ -1673,7 +1679,7 @@ void QGIViewDimension::drawRadiusExecutive(const Base::Vector2d& centerPoint, labelRectangle.Height() * 0.5 + getIsoDimensionLineSpacing(), lineAngle, labelAngle); - lineAngle = DrawUtil::angleComposition(lineAngle, M_PI); + lineAngle = DrawUtil::angleComposition(lineAngle, pi); labelPosition = -cos(devAngle) * ((labelCenter - arcPoint).Length()); } @@ -1693,7 +1699,7 @@ void QGIViewDimension::drawRadiusExecutive(const Base::Vector2d& centerPoint, // Is there point on the arc, where line from center intersects it perpendicularly? double angleFactor = getAnglePlacementFactor(lineAngle, endAngle, startRotation); if (angleFactor < 0) { - lineAngle = DrawUtil::angleComposition(lineAngle, M_PI); + lineAngle = DrawUtil::angleComposition(lineAngle, pi); } Base::Vector2d arcPoint; @@ -1779,7 +1785,7 @@ void QGIViewDimension::drawAreaExecutive(const Base::Vector2d& centerPoint, doub labelRectangle.Height() * 0.5 + getIsoDimensionLineSpacing(), lineAngle, labelAngle); - lineAngle = lineAngle - M_PI; + lineAngle = lineAngle - std::numbers::pi; double labelPosition = -cos(devAngle) * ((labelCenter - centerPoint).Length()); drawDimensionLine(areaPath, centerPoint, lineAngle, 0.0, labelPosition, labelRectangle, 1, standardStyle, flipArrow, forcePointStyle); @@ -1818,7 +1824,7 @@ void QGIViewDimension::drawDistance(TechDraw::DrawViewDimension* dimension, lineAngle = 0.0; } else if (strcmp(dimensionType, "DistanceY") == 0) { - lineAngle = M_PI_2; + lineAngle = std::numbers::pi/2; } else { lineAngle = (fromQtApp(linePoints.second()) - fromQtApp(linePoints.first())).Angle(); @@ -1831,9 +1837,9 @@ void QGIViewDimension::drawDistance(TechDraw::DrawViewDimension* dimension, if (dimension->AngleOverride.getValue()) { drawDistanceOverride(fromQtApp(linePoints.first()), fromQtApp(linePoints.second()), - dimension->LineAngle.getValue() * M_PI / 180.0, labelRectangle, + dimension->LineAngle.getValue() * std::numbers::pi / 180.0, labelRectangle, standardStyle, renderExtent, flipArrows, - dimension->ExtensionAngle.getValue() * M_PI / 180.0); + dimension->ExtensionAngle.getValue() * std::numbers::pi / 180.0); } else { drawDistanceExecutive(fromQtApp(linePoints.extensionLineFirst()), fromQtApp(linePoints.extensionLineSecond()), @@ -1844,6 +1850,8 @@ void QGIViewDimension::drawDistance(TechDraw::DrawViewDimension* dimension, void QGIViewDimension::drawRadius(TechDraw::DrawViewDimension* dimension, ViewProviderDimension* viewProvider) const { + using std::numbers::pi; + Base::BoundBox2d labelRectangle( fromQtGui(mapRectFromItem(datumLabel, datumLabel->tightBoundingRect()))); arcPoints curvePoints = dimension->getArcPoints(); @@ -1858,12 +1866,12 @@ void QGIViewDimension::drawRadius(TechDraw::DrawViewDimension* dimension, - endAngle; if (startRotation != 0.0 && ((startRotation > 0.0) != curvePoints.arcCW)) { - startRotation += curvePoints.arcCW ? +M_2PI : -M_2PI; + startRotation += curvePoints.arcCW ? +2*pi : -2*pi; } } else {// A circle arc covers the whole plane - endAngle = M_PI; - startRotation = -M_2PI; + endAngle = pi; + startRotation = -2*pi; } drawRadiusExecutive( @@ -1875,6 +1883,8 @@ void QGIViewDimension::drawRadius(TechDraw::DrawViewDimension* dimension, void QGIViewDimension::drawDiameter(TechDraw::DrawViewDimension* dimension, ViewProviderDimension* viewProvider) const { + using std::numbers::pi; + Base::BoundBox2d labelRectangle( fromQtGui(mapRectFromItem(datumLabel, datumLabel->tightBoundingRect()))); Base::Vector2d labelCenter(labelRectangle.GetCenter()); @@ -1941,9 +1951,9 @@ void QGIViewDimension::drawDiameter(TechDraw::DrawViewDimension* dimension, int selected = 0; if (compareAngleStraightness( 0.0, - jointPositions[0] > 0.0 ? DrawUtil::angleComposition(lineAngles[0], M_PI) + jointPositions[0] > 0.0 ? DrawUtil::angleComposition(lineAngles[0], pi) : lineAngles[0], - jointPositions[1] > 0.0 ? DrawUtil::angleComposition(lineAngles[1], M_PI) + jointPositions[1] > 0.0 ? DrawUtil::angleComposition(lineAngles[1], pi) : lineAngles[1], strikeFactors[0], strikeFactors[1]) > 0) { @@ -2006,8 +2016,8 @@ void QGIViewDimension::drawDiameter(TechDraw::DrawViewDimension* dimension, Base::Vector2d startPoint(curveCenter); Base::Vector2d endPoint(curveCenter); - if ((lineAngle >= M_PI_4 && lineAngle <= 3.0 * M_PI_4) - || (lineAngle <= -M_PI_4 && lineAngle >= -3.0 * M_PI_4)) { + if ((lineAngle >= pi/4 && lineAngle <= 3.0 * pi/4) + || (lineAngle <= -pi/4 && lineAngle >= -3.0 * pi/4)) { // Horizontal dimension line startPoint.x -= curveRadius; endPoint.x += curveRadius; @@ -2016,10 +2026,10 @@ void QGIViewDimension::drawDiameter(TechDraw::DrawViewDimension* dimension, else {// Vertical dimension line startPoint.y -= curveRadius; endPoint.y += curveRadius; - lineAngle = M_PI_2; + lineAngle = pi/2; } - // lineAngle = DrawUtil::angleComposition((labelCenter - curveCenter).Angle(), +M_PI_2); + // lineAngle = DrawUtil::angleComposition((labelCenter - curveCenter).Angle(), +pi/2); // startPoint = curveCenter - Base::Vector2d::FromPolar(curveRadius, lineAngle); // endPoint = curveCenter + Base::Vector2d::FromPolar(curveRadius, lineAngle); @@ -2031,8 +2041,8 @@ void QGIViewDimension::drawDiameter(TechDraw::DrawViewDimension* dimension, ? ViewProviderDimension::REND_EXTENT_REDUCED : ViewProviderDimension::REND_EXTENT_NORMAL; - drawRadiusExecutive(curveCenter, Rez::guiX(curvePoints.midArc, true), curveRadius, M_PI, - -M_2PI, labelRectangle, getDefaultExtensionLineOverhang(), + drawRadiusExecutive(curveCenter, Rez::guiX(curvePoints.midArc, true), curveRadius, pi, + -2*pi, labelRectangle, getDefaultExtensionLineOverhang(), standardStyle, renderExtent, flipArrows); } } @@ -2040,6 +2050,8 @@ void QGIViewDimension::drawDiameter(TechDraw::DrawViewDimension* dimension, void QGIViewDimension::drawAngle(TechDraw::DrawViewDimension* dimension, ViewProviderDimension* viewProvider) const { + using std::numbers::pi; + QPainterPath anglePath; Base::BoundBox2d labelRectangle( @@ -2105,11 +2117,11 @@ void QGIViewDimension::drawAngle(TechDraw::DrawViewDimension* dimension, jointRotations[1] = handednessFactor * (jointAngles[1] - endAngle); // Compare the offset with half of the rest of 2PI minus the angle and eventually fix the values - if (fabs(jointRotations[0] - startRotation * 0.5) > M_PI) { - jointRotations[0] += jointRotations[0] < 0.0 ? +M_2PI : -M_2PI; + if (fabs(jointRotations[0] - startRotation * 0.5) > pi) { + jointRotations[0] += jointRotations[0] < 0.0 ? +2*pi : -2*pi; } - if (fabs(jointRotations[1] - startRotation * 0.5) > M_PI) { - jointRotations[1] += jointRotations[1] < 0.0 ? +M_2PI : -M_2PI; + if (fabs(jointRotations[1] - startRotation * 0.5) > pi) { + jointRotations[1] += jointRotations[1] < 0.0 ? +2*pi : -2*pi; } // Compute the strike factors so we can choose the placement where value is not obscured by dimensional arc @@ -2133,9 +2145,9 @@ void QGIViewDimension::drawAngle(TechDraw::DrawViewDimension* dimension, if (compareAngleStraightness( 0.0, DrawUtil::angleComposition( - jointAngles[0], handednessFactor * jointRotations[0] > 0.0 ? -M_PI_2 : +M_PI_2), + jointAngles[0], handednessFactor * jointRotations[0] > 0.0 ? -pi/2 : +pi/2), DrawUtil::angleComposition( - jointAngles[1], handednessFactor * jointRotations[1] > 0.0 ? -M_PI_2 : +M_PI_2), + jointAngles[1], handednessFactor * jointRotations[1] > 0.0 ? -pi/2 : +pi/2), strikeFactors[0], strikeFactors[1]) > 0) { selected = 1; @@ -2160,10 +2172,10 @@ void QGIViewDimension::drawAngle(TechDraw::DrawViewDimension* dimension, Base::Vector2d labelDirection(labelCenter - angleVertex); double radiusAngle = labelDirection.Angle(); - labelAngle = DrawUtil::angleComposition(radiusAngle, M_PI_2); + labelAngle = DrawUtil::angleComposition(radiusAngle, pi/2); double placementFactor = getIsoStandardLinePlacement(labelAngle); labelAngle = - placementFactor > 0.0 ? DrawUtil::angleComposition(labelAngle, M_PI) : labelAngle; + placementFactor > 0.0 ? DrawUtil::angleComposition(labelAngle, pi) : labelAngle; arcRadius = labelDirection.Length() - placementFactor @@ -2290,22 +2302,23 @@ Base::Vector3d QGIViewDimension::findIsoExt(Base::Vector3d dir) const Base::Vector3d isoYr(0.866, -0.5, 0.0); //iso +Y? Base::Vector3d isoZ(0.0, 1.0, 0.0); //iso Z Base::Vector3d isoZr(0.0, -1.0, 0.0); //iso -Z - if (dir.IsEqual(isoX, FLT_EPSILON)) { + constexpr float floatEpsilon = std::numeric_limits::epsilon(); + if (dir.IsEqual(isoX, floatEpsilon)) { return isoY; } - else if (dir.IsEqual(-isoX, FLT_EPSILON)) { + else if (dir.IsEqual(-isoX, floatEpsilon)) { return -isoY; } - else if (dir.IsEqual(isoY, FLT_EPSILON)) { + else if (dir.IsEqual(isoY, floatEpsilon)) { return isoZ; } - else if (dir.IsEqual(-isoY, FLT_EPSILON)) { + else if (dir.IsEqual(-isoY, floatEpsilon)) { return -isoZ; } - else if (dir.IsEqual(isoZ, FLT_EPSILON)) { + else if (dir.IsEqual(isoZ, floatEpsilon)) { return isoX; } - else if (dir.IsEqual(-isoZ, FLT_EPSILON)) { + else if (dir.IsEqual(-isoZ, floatEpsilon)) { return -isoX; } @@ -2454,11 +2467,11 @@ void QGIViewDimension::setPens() aHead2->setWidth(m_lineWidth); } -double QGIViewDimension::toDeg(double angle) { return angle * 180 / M_PI; } +double QGIViewDimension::toDeg(double angle) { return angle * 180 / std::numbers::pi; } double QGIViewDimension::toQtRad(double angle) { return -angle; } -double QGIViewDimension::toQtDeg(double angle) { return -angle * 180.0 / M_PI; } +double QGIViewDimension::toQtDeg(double angle) { return -angle * 180.0 / std::numbers::pi; } void QGIViewDimension::makeMarkC(double xPos, double yPos, QColor color) const { diff --git a/src/Mod/TechDraw/Gui/QGIViewPart.cpp b/src/Mod/TechDraw/Gui/QGIViewPart.cpp index d0259a66bb..30d395be52 100644 --- a/src/Mod/TechDraw/Gui/QGIViewPart.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewPart.cpp @@ -964,7 +964,7 @@ void QGIViewPart::drawHighlight(TechDraw::DrawViewDetail* viewDetail, bool b) highlight->setPos(0.0, 0.0);//sb setPos(center.x, center.y)? Base::Vector3d center = viewDetail->AnchorPoint.getValue() * viewPart->getScale(); - double rotationRad = viewPart->Rotation.getValue() * M_PI / 180.0; + double rotationRad = viewPart->Rotation.getValue() * std::numbers::pi / 180.0; center.RotateZ(rotationRad); double radius = viewDetail->Radius.getValue() * viewPart->getScale(); diff --git a/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp b/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp index 436fcfac3e..51e785053c 100644 --- a/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp +++ b/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp @@ -549,7 +549,7 @@ std::pair QGIWeldSymbol::getLocalAxes() { auto localX = getLeader()->lastSegmentDirection(); auto localY = DU::invertY(localX); - localY.RotateZ(M_PI_2); + localY.RotateZ(std::numbers::pi/2); localY.Normalize(); localY = DU::invertY(localY); return {localX, localY}; diff --git a/src/Mod/TechDraw/Gui/QGTracker.cpp b/src/Mod/TechDraw/Gui/QGTracker.cpp index 8f796a33c9..c1313ded2b 100644 --- a/src/Mod/TechDraw/Gui/QGTracker.cpp +++ b/src/Mod/TechDraw/Gui/QGTracker.cpp @@ -54,7 +54,8 @@ using namespace TechDrawGui; QGTracker::QGTracker(QGSPage* inScene, TrackerMode m): m_sleep(false), m_qgParent(nullptr), - m_lastClick(QPointF(FLT_MAX, FLT_MAX)) + m_lastClick(QPointF(std::numeric_limits::max(), + std::numeric_limits::max())) { setTrackerMode(m); if (inScene) { @@ -183,7 +184,7 @@ QPointF QGTracker::snapToAngle(QPointF dumbPt) return dumbPt; QPointF result(dumbPt); - double angleIncr = M_PI / 8.0; //15* + double angleIncr = std::numbers::pi / 8.0; //15* //mirror last clicked point and event point to get sensible coords QPointF last(m_points.back().x(), -m_points.back().y()); QPointF pt(dumbPt.x(), -dumbPt.y()); @@ -192,7 +193,7 @@ QPointF QGTracker::snapToAngle(QPointF dumbPt) QPointF qVec = last - pt; //vec from end of track to end of tail double actual = atan2(-qVec.y(), qVec.x()); if (actual < 0.0) { - actual = (2 * M_PI) + actual; //map to +ve angle + actual = (2 * std::numbers::pi) + actual; //map to +ve angle } double intPart; diff --git a/src/Mod/TechDraw/Gui/TaskComplexSection.cpp b/src/Mod/TechDraw/Gui/TaskComplexSection.cpp index 30eab5653a..c19a4a500d 100644 --- a/src/Mod/TechDraw/Gui/TaskComplexSection.cpp +++ b/src/Mod/TechDraw/Gui/TaskComplexSection.cpp @@ -24,6 +24,7 @@ #ifndef _PreComp_ #include #include +#include #endif// #ifndef _PreComp_ #include @@ -193,7 +194,7 @@ void TaskComplexSection::setUiEdit() ui->leBaseView->setText(QString::fromStdString(m_baseView->getNameInDocument())); Base::Vector3d projectedViewDirection = m_baseView->projectPoint(sectionNormalVec, false); double viewAngle = atan2(-projectedViewDirection.y, -projectedViewDirection.x); - m_compass->setDialAngle(viewAngle * 180.0 / M_PI); + m_compass->setDialAngle(viewAngle * 180.0 / std::numbers::pi); m_viewDirectionWidget->setValueNoNotify(projectedViewDirection * -1.0); } else { @@ -308,7 +309,7 @@ void TaskComplexSection::slotViewDirectionChanged(Base::Vector3d newDirection) } projectedViewDirection.Normalize(); double viewAngle = atan2(projectedViewDirection.y, projectedViewDirection.x); - m_compass->setDialAngle(viewAngle * 180.0 / M_PI); + m_compass->setDialAngle(viewAngle * 180.0 / std::numbers::pi); checkAll(false); applyAligned(); } @@ -318,7 +319,7 @@ void TaskComplexSection::slotViewDirectionChanged(Base::Vector3d newDirection) void TaskComplexSection::slotChangeAngle(double newAngle) { // Base::Console().Message("TCS::slotAngleChanged(%.3f)\n", newAngle); - double angleRadians = newAngle * M_PI / 180.0; + double angleRadians = newAngle * std::numbers::pi / 180.0; double unitX = cos(angleRadians); double unitY = sin(angleRadians); Base::Vector3d localUnit(unitX, unitY, 0.0); diff --git a/src/Mod/TechDraw/Gui/TaskCosmeticLine.cpp b/src/Mod/TechDraw/Gui/TaskCosmeticLine.cpp index 5b83340515..11cea7d77a 100644 --- a/src/Mod/TechDraw/Gui/TaskCosmeticLine.cpp +++ b/src/Mod/TechDraw/Gui/TaskCosmeticLine.cpp @@ -113,7 +113,7 @@ void TaskCosmeticLine::setUiPrimary() setWindowTitle(QObject::tr("Create Cosmetic Line")); // double rotDeg = m_partFeat->Rotation.getValue(); - // double rotRad = rotDeg * M_PI / 180.0; + // double rotRad = rotDeg * std::numbers::pi / 180.0; Base::Vector3d centroid = m_partFeat->getCurrentCentroid(); Base::Vector3d p1, p2; if (m_is3d.front()) { diff --git a/src/Mod/TechDraw/Gui/TaskDimension.cpp b/src/Mod/TechDraw/Gui/TaskDimension.cpp index 4da35c5c67..f3794c9c9c 100644 --- a/src/Mod/TechDraw/Gui/TaskDimension.cpp +++ b/src/Mod/TechDraw/Gui/TaskDimension.cpp @@ -227,7 +227,7 @@ void TaskDimension::onEqualToleranceChanged() ui->leFormatSpecifierUnderTolerance->setDisabled(true); } else { - ui->qsbOvertolerance->setMinimum(-DBL_MAX); + ui->qsbOvertolerance->setMinimum(-std::numeric_limits::max()); if (!ui->cbTheoreticallyExact->isChecked()) { ui->qsbUndertolerance->setDisabled(false); ui->leFormatSpecifierUnderTolerance->setDisabled(false); @@ -372,14 +372,14 @@ void TaskDimension::onDimUseDefaultClicked() Base::Vector2d first2(points.first().x, -points.first().y); Base::Vector2d second2(points.second().x, -points.second().y); double lineAngle = (second2 - first2).Angle(); - ui->dsbDimAngle->setValue(lineAngle * 180.0 / M_PI); + ui->dsbDimAngle->setValue(lineAngle * 180.0 / std::numbers::pi); } void TaskDimension::onDimUseSelectionClicked() { std::pair result = getAngleFromSelection(); if (result.second) { - ui->dsbDimAngle->setValue(result.first * 180.0 / M_PI); + ui->dsbDimAngle->setValue(result.first * 180.0 / std::numbers::pi); } } @@ -392,13 +392,13 @@ void TaskDimension::onExtUseDefaultClicked() Base::Vector2d lineDirection = second2 - first2; Base::Vector2d extensionDirection(-lineDirection.y, lineDirection.x); double extensionAngle = extensionDirection.Angle(); - ui->dsbExtAngle->setValue(extensionAngle * 180.0 / M_PI); + ui->dsbExtAngle->setValue(extensionAngle * 180.0 / std::numbers::pi); } void TaskDimension::onExtUseSelectionClicked() { std::pair result = getAngleFromSelection(); if (result.second) { - ui->dsbExtAngle->setValue(result.first * 180.0 / M_PI); + ui->dsbExtAngle->setValue(result.first * 180.0 / std::numbers::pi); } } diff --git a/src/Mod/TechDraw/Gui/TaskSectionView.cpp b/src/Mod/TechDraw/Gui/TaskSectionView.cpp index 8cceb4eea7..3169ff543e 100644 --- a/src/Mod/TechDraw/Gui/TaskSectionView.cpp +++ b/src/Mod/TechDraw/Gui/TaskSectionView.cpp @@ -180,7 +180,7 @@ void TaskSectionView::setUiEdit() Base::Vector3d projectedViewDirection = m_base->projectPoint(sectionNormalVec, false); projectedViewDirection.Normalize(); double viewAngle = atan2(-projectedViewDirection.y, -projectedViewDirection.x); - m_compass->setDialAngle(viewAngle * 180.0 / M_PI); + m_compass->setDialAngle(viewAngle * 180.0 / std::numbers::pi); m_viewDirectionWidget->setValueNoNotify(sectionNormalVec * -1.0); } @@ -272,7 +272,7 @@ void TaskSectionView::slotViewDirectionChanged(Base::Vector3d newDirection) Base::Vector3d projectedViewDirection = m_base->projectPoint(newDirection, false); projectedViewDirection.Normalize(); double viewAngle = atan2(projectedViewDirection.y, projectedViewDirection.x); - m_compass->setDialAngle(viewAngle * 180.0 / M_PI); + m_compass->setDialAngle(viewAngle * 180.0 / std::numbers::pi); checkAll(false); directionChanged(true); applyAligned(); @@ -281,7 +281,7 @@ void TaskSectionView::slotViewDirectionChanged(Base::Vector3d newDirection) //the CompassWidget reports that the view direction angle has changed void TaskSectionView::slotChangeAngle(double newAngle) { - double angleRadians = newAngle * M_PI / 180.0; + double angleRadians = newAngle * std::numbers::pi / 180.0; double unitX = cos(angleRadians); double unitY = sin(angleRadians); Base::Vector3d localUnit(unitX, unitY, 0.0); diff --git a/src/Mod/TechDraw/Gui/ViewProviderCosmeticExtension.cpp b/src/Mod/TechDraw/Gui/ViewProviderCosmeticExtension.cpp index 8359f8a490..6a18181eb5 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderCosmeticExtension.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderCosmeticExtension.cpp @@ -24,10 +24,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# ifdef _MSC_VER -# define _USE_MATH_DEFINES -# include -# endif //_MSC_VER +# include #endif #include diff --git a/src/Mod/TechDraw/Gui/ViewProviderDrawingView.cpp b/src/Mod/TechDraw/Gui/ViewProviderDrawingView.cpp index c186079a6c..311e885f5d 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderDrawingView.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderDrawingView.cpp @@ -28,7 +28,6 @@ #include #endif -#include #include #include @@ -404,7 +403,7 @@ void ViewProviderDrawingView::stackTop() //no view, nothing to stack return; } - int maxZ = INT_MIN; + int maxZ = std::numeric_limits::min(); auto parent = qView->parentItem(); if (parent) { //if we have a parentItem, we have to stack within the parentItem, not within the page @@ -439,7 +438,7 @@ void ViewProviderDrawingView::stackBottom() //no view, nothing to stack return; } - int minZ = INT_MAX; + int minZ = std::numeric_limits::max(); auto parent = qView->parentItem(); if (parent) { //if we have a parentItem, we have to stack within the parentItem, not within the page