From 3fc0831116f7005e4be51ca75b5b9d5cf90abb92 Mon Sep 17 00:00:00 2001 From: Benjamin Nauck Date: Thu, 27 Mar 2025 19:00:34 +0100 Subject: [PATCH] Drawing: Use std::numeric_limits and std::numbers instead of defines --- src/Mod/Drawing/App/DrawingExport.cpp | 14 +++++++++----- src/Mod/Drawing/Gui/TaskOrthoViews.cpp | 10 +++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/Mod/Drawing/App/DrawingExport.cpp b/src/Mod/Drawing/App/DrawingExport.cpp index 1f654caf60..516458e917 100644 --- a/src/Mod/Drawing/App/DrawingExport.cpp +++ b/src/Mod/Drawing/App/DrawingExport.cpp @@ -207,9 +207,10 @@ void SVGOutput::printCircle(const BRepAdaptor_Curve& c, std::ostream& out) } // arc of circle else { + using std::numbers::pi; // See also https://developer.mozilla.org/en/SVG/Tutorial/Paths - char xar = '0'; // x-axis-rotation - char las = (l - f > D_PI) ? '1' : '0'; // large-arc-flag + char xar = '0'; // x-axis-rotation + char las = (l - f > pi) ? '1' : '0'; // large-arc-flag char swp = (a < 0) ? '1' : '0'; // sweep-flag, i.e. clockwise (0) or counter-clockwise (1) out << ""; @@ -255,7 +256,8 @@ void SVGOutput::printEllipse(const BRepAdaptor_Curve& c, int id, std::ostream& o } // arc of ellipse else { - char las = (l - f > D_PI) ? '1' : '0'; // large-arc-flag + using std::numbers::pi; + char las = (l - f > pi) ? '1' : '0'; // large-arc-flag char swp = (a < 0) ? '1' : '0'; // sweep-flag, i.e. clockwise (0) or counter-clockwise (1) out << "" << std::endl; @@ -460,6 +462,8 @@ void DXFOutput::printHeader(std::ostream& out) void DXFOutput::printCircle(const BRepAdaptor_Curve& c, std::ostream& out) { + using std::numbers::pi; + gp_Circ circ = c.Circle(); const gp_Pnt& p = circ.Location(); double r = circ.Radius(); @@ -502,8 +506,8 @@ void DXFOutput::printCircle(const BRepAdaptor_Curve& c, std::ostream& out) double bx = e.X() - p.X(); double by = e.Y() - p.Y(); - double start_angle = atan2(ay, ax) * 180 / D_PI; - double end_angle = atan2(by, bx) * 180 / D_PI; + double start_angle = atan2(ay, ax) * 180 / pi; + double end_angle = atan2(by, bx) * 180 / pi; if (a > 0) { double temp = start_angle; diff --git a/src/Mod/Drawing/Gui/TaskOrthoViews.cpp b/src/Mod/Drawing/Gui/TaskOrthoViews.cpp index 98d8a2897f..319dbcb186 100644 --- a/src/Mod/Drawing/Gui/TaskOrthoViews.cpp +++ b/src/Mod/Drawing/Gui/TaskOrthoViews.cpp @@ -256,7 +256,7 @@ void orthoview::set_projection(const gp_Ax2& cs) // angle between desired projection and actual projection float rotation = X_dir.Angle(actual_X); - if (rotation != 0 && abs(M_PI - rotation) > 0.05) { + if (rotation != 0 && abs(std::numbers::pi - rotation) > 0.05) { if (!Z_dir.IsEqual(actual_X.Crossed(X_dir), 0.05)) { rotation = -rotation; } @@ -266,7 +266,7 @@ void orthoview::set_projection(const gp_Ax2& cs) // this_view->Direction.setValue(Z_dir.X(), Z_dir.Y(), Z_dir.Z()); this_view->Direction.setValue(x, y, z); - this_view->Rotation.setValue(180 * rotation / M_PI); + this_view->Rotation.setValue(180 * rotation / std::numbers::pi); } /////////////////////////////////////////////////////////////////////////////////////////////// @@ -613,8 +613,8 @@ void OrthoViews::set_orientation(int index) // set orientation of single view dir = primary.XDirection(); n = -views[index]->rel_y; } - - rotation = n * rotate_coeff * M_PI / 2; // rotate_coeff is -1 or 1 for 1st or 3rd angle + // rotate_coeff is -1 or 1 for 1st or 3rd angle + rotation = n * rotate_coeff * std::numbers::pi / 2; cs = primary.Rotated(gp_Ax1(gp_Pnt(0, 0, 0), dir), rotation); views[index]->set_projection(cs); } @@ -780,7 +780,7 @@ void OrthoViews::set_Axo(int rel_x, rotations[1] = -0.6156624905260762; } else { - rotations[0] = 1.3088876392502007 - M_PI / 2; + rotations[0] = 1.3088876392502007 - std::numbers::pi / 2; rotations[1] = -0.6156624905260762; }