From f22f3705db6028ac1a4ed43e356c1e77bad9a522 Mon Sep 17 00:00:00 2001 From: Benjamin Nauck Date: Wed, 9 Apr 2025 09:52:39 +0200 Subject: [PATCH] Use Base::toDegrees() instead of manually converting --- src/App/Expression.cpp | 2 +- src/Base/Rotation.cpp | 12 ++++++------ src/Gui/SoDatumLabel.cpp | 4 +++- src/Mod/Drawing/App/DrawingExport.cpp | 6 ++---- src/Mod/Drawing/Gui/TaskOrthoViews.cpp | 2 +- src/Mod/Sketcher/Gui/DrawSketchHandler.cpp | 2 +- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 2 +- src/Mod/TechDraw/App/DrawViewPart.cpp | 2 +- src/Mod/TechDraw/App/TechDrawExport.cpp | 4 ++-- src/Mod/TechDraw/Gui/CommandExtensionDims.cpp | 7 +++---- src/Mod/TechDraw/Gui/DrawGuiUtil.cpp | 2 +- src/Mod/TechDraw/Gui/QGISectionLine.cpp | 3 ++- src/Mod/TechDraw/Gui/QGIViewBalloon.cpp | 2 +- src/Mod/TechDraw/Gui/QGIViewDimension.cpp | 8 ++++---- src/Mod/TechDraw/Gui/TaskComplexSection.cpp | 4 ++-- src/Mod/TechDraw/Gui/TaskDimension.cpp | 9 +++++---- src/Mod/TechDraw/Gui/TaskSectionView.cpp | 4 ++-- 17 files changed, 38 insertions(+), 37 deletions(-) diff --git a/src/App/Expression.cpp b/src/App/Expression.cpp index 7b4a27623d..90ae19d2b0 100644 --- a/src/App/Expression.cpp +++ b/src/App/Expression.cpp @@ -2353,7 +2353,7 @@ Py::Object FunctionExpression::evaluate(const Expression *expr, int f, const std switch (f) { case VANGLE: - return Py::asObject(new QuantityPy(new Quantity(vector1.GetAngle(vector2) * 180 / pi, Unit::Angle))); + return Py::asObject(new QuantityPy(new Quantity(Base::toDegrees(vector1.GetAngle(vector2)), Unit::Angle))); case VCROSS: return Py::asObject(new Base::VectorPy(vector1.Cross(vector2))); case VDOT: diff --git a/src/Base/Rotation.cpp b/src/Base/Rotation.cpp index 2882d37c62..f77d91c34d 100644 --- a/src/Base/Rotation.cpp +++ b/src/Base/Rotation.cpp @@ -752,9 +752,9 @@ void Rotation::getYawPitchRoll(double& y, double& p, double& r) const } // convert to degree - y = (y / pi) * 180; - p = (p / pi) * 180; - r = (r / pi) * 180; + y = toDegrees(y); + p = toDegrees(p); + r = toDegrees(r); } bool Rotation::isSame(const Rotation& q) const @@ -1092,7 +1092,7 @@ void Rotation::getEulerAngles(EulerSequence theOrder, theGamma = aFirst; } - theAlpha *= 180.0 / std::numbers::pi; - theBeta *= 180.0 / std::numbers::pi; - theGamma *= 180.0 / std::numbers::pi; + theAlpha = Base::toDegrees(theAlpha); + theBeta = Base::toDegrees(theBeta); + theGamma = Base::toDegrees(theGamma); } diff --git a/src/Gui/SoDatumLabel.cpp b/src/Gui/SoDatumLabel.cpp index ba39d4f4e0..dfb6a63e48 100644 --- a/src/Gui/SoDatumLabel.cpp +++ b/src/Gui/SoDatumLabel.cpp @@ -48,6 +48,8 @@ # include #endif // _PreComp_ +#include + #include #include @@ -1691,7 +1693,7 @@ void SoDatumLabel::drawText(SoState *state, int srcw, int srch, float angle, con // Apply a rotation and translation matrix glTranslatef(textOffset[0], textOffset[1], textOffset[2]); - glRotatef((GLfloat) angle * 180 / std::numbers::pi, 0,0,1); + glRotatef(Base::toDegrees(angle), 0,0,1); glBegin(GL_QUADS); glColor3f(1.F, 1.F, 1.F); diff --git a/src/Mod/Drawing/App/DrawingExport.cpp b/src/Mod/Drawing/App/DrawingExport.cpp index 516458e917..6cf68f3c9e 100644 --- a/src/Mod/Drawing/App/DrawingExport.cpp +++ b/src/Mod/Drawing/App/DrawingExport.cpp @@ -462,8 +462,6 @@ 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(); @@ -506,8 +504,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 / pi; - double end_angle = atan2(by, bx) * 180 / pi; + double start_angle = Base::toDegrees(atan2(ay, ax)); + double end_angle = Base::toDegrees(atan2(by, bx)); if (a > 0) { double temp = start_angle; diff --git a/src/Mod/Drawing/Gui/TaskOrthoViews.cpp b/src/Mod/Drawing/Gui/TaskOrthoViews.cpp index 319dbcb186..0f272a72df 100644 --- a/src/Mod/Drawing/Gui/TaskOrthoViews.cpp +++ b/src/Mod/Drawing/Gui/TaskOrthoViews.cpp @@ -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 / std::numbers::pi); + this_view->Rotation.setValue(Base::toDegrees(rotation)); } /////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp b/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp index 7852e964f5..f04ea83ed5 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp +++ b/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp @@ -1009,7 +1009,7 @@ void DrawSketchHandler::drawDoubleAtCursor(const Base::Vector2d& position, SbString text; std::string doubleString = unit == Base::Unit::Length ? lengthToDisplayFormat(val, 1) - : angleToDisplayFormat(val * 180.0 / std::numbers::pi, 1); + : angleToDisplayFormat(Base::toDegrees(val), 1); text.sprintf(" (%s)", doubleString.c_str()); setPositionText(position, text); } diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index 3107c34e11..2a5f3f8ea1 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -3998,7 +3998,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 / std::numbers::pi; + return Base::toDegrees(-atan2((y1 - y0), (x1 - x0))); } catch (const Base::ZeroDivisionError&) { return 0; diff --git a/src/Mod/TechDraw/App/DrawViewPart.cpp b/src/Mod/TechDraw/App/DrawViewPart.cpp index 4b77dcff77..c479e98f21 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.cpp +++ b/src/Mod/TechDraw/App/DrawViewPart.cpp @@ -987,7 +987,7 @@ double DrawViewPart::getSizeAlongVector(Base::Vector3d alignmentVector) if (getEdgeCompound().IsNull()) { return 1.0; } - TopoDS_Shape rotatedShape = ShapeUtils::rotateShape(getEdgeCompound(), OXYZ, alignmentAngle * 180.0 / std::numbers::pi); + TopoDS_Shape rotatedShape = ShapeUtils::rotateShape(getEdgeCompound(), OXYZ, Base::toDegrees(alignmentAngle)); Bnd_Box shapeBox; shapeBox.SetGap(0.0); BRepBndLib::AddOptimal(rotatedShape, shapeBox); diff --git a/src/Mod/TechDraw/App/TechDrawExport.cpp b/src/Mod/TechDraw/App/TechDrawExport.cpp index eb97f04a0e..8484a66e1c 100644 --- a/src/Mod/TechDraw/App/TechDrawExport.cpp +++ b/src/Mod/TechDraw/App/TechDrawExport.cpp @@ -532,8 +532,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 / std::numbers::pi; - double end_angle = atan2(by, bx) * 180 / std::numbers::pi; + double start_angle = Base::toDegrees(atan2(ay, ax)); + double end_angle = Base::toDegrees(atan2(by, bx)); if (a > 0) { double temp = start_angle; diff --git a/src/Mod/TechDraw/Gui/CommandExtensionDims.cpp b/src/Mod/TechDraw/Gui/CommandExtensionDims.cpp index 7da9433ff9..ea1a86643e 100644 --- a/src/Mod/TechDraw/Gui/CommandExtensionDims.cpp +++ b/src/Mod/TechDraw/Gui/CommandExtensionDims.cpp @@ -33,6 +33,7 @@ # include # include # include +# include # include # include # include @@ -2050,7 +2051,6 @@ void execCreateHorizChamferDimension(Gui::Command* cmd) { std::vector allVertexes; allVertexes = _getVertexInfo(objFeat, subNames); if (!allVertexes.empty() && allVertexes.size() > 1) { - 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; @@ -2062,7 +2062,7 @@ void execCreateHorizChamferDimension(Gui::Command* cmd) { dim->Y.setValue(-yMax); float dx = allVertexes[0].point.x - allVertexes[1].point.x; float dy = allVertexes[0].point.y - allVertexes[1].point.y; - float alpha = round(abs(atan(dy / dx)) * Pi180); + float alpha = round(Base::toDegrees(abs(atan(dy / dx)))); std::string sAlpha = std::to_string((int)alpha); std::string formatSpec = dim->FormatSpec.getStrValue(); formatSpec = formatSpec + " x" + sAlpha + "°"; @@ -2119,7 +2119,6 @@ void execCreateVertChamferDimension(Gui::Command* cmd) { std::vector allVertexes; allVertexes = _getVertexInfo(objFeat, subNames); if (!allVertexes.empty() && allVertexes.size() > 1) { - 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; @@ -2131,7 +2130,7 @@ void execCreateVertChamferDimension(Gui::Command* cmd) { dim->Y.setValue(-mid.y); float dx = allVertexes[0].point.x - allVertexes[1].point.x; float dy = allVertexes[0].point.y - allVertexes[1].point.y; - float alpha = round(abs(atan(dx / dy)) * Pi180); + float alpha = round(Base::toDegrees(abs(atan(dx / dy)))); std::string sAlpha = std::to_string((int)alpha); std::string formatSpec = dim->FormatSpec.getStrValue(); formatSpec = formatSpec + " x" + sAlpha + "°"; diff --git a/src/Mod/TechDraw/Gui/DrawGuiUtil.cpp b/src/Mod/TechDraw/Gui/DrawGuiUtil.cpp index a6e9dce171..87ed5d4703 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 / std::numbers::pi; + toRotate = Base::toDegrees(toRotate); // Rotate least amount possible if(toRotate > 90) { diff --git a/src/Mod/TechDraw/Gui/QGISectionLine.cpp b/src/Mod/TechDraw/Gui/QGISectionLine.cpp index c5546e85ec..57c4b316af 100644 --- a/src/Mod/TechDraw/Gui/QGISectionLine.cpp +++ b/src/Mod/TechDraw/Gui/QGISectionLine.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include @@ -404,7 +405,7 @@ double QGISectionLine::getArrowRotation(Base::Vector3d arrowDir) if (angle < 0.0) { angle = 2 * std::numbers::pi + angle; } - double arrowRotation = 360.0 - angle * (180.0/std::numbers::pi); //convert to Qt rotation (clockwise degrees) + double arrowRotation = 360.0 - Base::toDegrees(angle); //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 042ac26537..97547baa29 100644 --- a/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp @@ -807,7 +807,7 @@ void QGIViewBalloon::drawBalloon(bool originDrag) dirballoonLinesLine = (arrowTipPosInParent - dLineStart).Normalize(); } - float arAngle = atan2(dirballoonLinesLine.y, dirballoonLinesLine.x) * 180 / pi; + float arAngle = Base::toDegrees(atan2(dirballoonLinesLine.y, dirballoonLinesLine.x)); if ((endType == ArrowType::FILLED_TRIANGLE) && (prefOrthoPyramid())) { if (arAngle < 0.0) { diff --git a/src/Mod/TechDraw/Gui/QGIViewDimension.cpp b/src/Mod/TechDraw/Gui/QGIViewDimension.cpp index 97cde6babf..8bd92d118e 100644 --- a/src/Mod/TechDraw/Gui/QGIViewDimension.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewDimension.cpp @@ -1001,8 +1001,8 @@ void QGIViewDimension::drawSingleArc(QPainterPath& painterPath, const Base::Vect arcCenter.x + arcRadius, arcCenter.y + arcRadius))); // In arc drawing are for some reason Qt's angles counterclockwise as in our computations... - painterPath.arcMoveTo(qtArcRectangle, toDeg(startAngle)); - painterPath.arcTo(qtArcRectangle, toDeg(startAngle), toDeg(endAngle - startAngle)); + painterPath.arcMoveTo(qtArcRectangle, Base::toDegrees(startAngle)); + painterPath.arcTo(qtArcRectangle, Base::toDegrees(startAngle), Base::toDegrees(endAngle - startAngle)); } void QGIViewDimension::drawMultiArc(QPainterPath& painterPath, const Base::Vector2d& arcCenter, @@ -2469,11 +2469,11 @@ void QGIViewDimension::setPens() aHead2->setWidth(m_lineWidth); } -double QGIViewDimension::toDeg(double angle) { return angle * 180 / std::numbers::pi; } +double QGIViewDimension::toDeg(double angle) { return Base::toDegrees(angle); } double QGIViewDimension::toQtRad(double angle) { return -angle; } -double QGIViewDimension::toQtDeg(double angle) { return -angle * 180.0 / std::numbers::pi; } +double QGIViewDimension::toQtDeg(double angle) { return Base::toDegrees(-angle); } void QGIViewDimension::makeMarkC(double xPos, double yPos, QColor color) const { diff --git a/src/Mod/TechDraw/Gui/TaskComplexSection.cpp b/src/Mod/TechDraw/Gui/TaskComplexSection.cpp index 5499eddefb..5312b8684b 100644 --- a/src/Mod/TechDraw/Gui/TaskComplexSection.cpp +++ b/src/Mod/TechDraw/Gui/TaskComplexSection.cpp @@ -195,7 +195,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 / std::numbers::pi); + m_compass->setDialAngle(Base::toDegrees(viewAngle)); m_viewDirectionWidget->setValueNoNotify(projectedViewDirection * -1.0); } else { @@ -310,7 +310,7 @@ void TaskComplexSection::slotViewDirectionChanged(Base::Vector3d newDirection) } projectedViewDirection.Normalize(); double viewAngle = atan2(projectedViewDirection.y, projectedViewDirection.x); - m_compass->setDialAngle(viewAngle * 180.0 / std::numbers::pi); + m_compass->setDialAngle(Base::toDegrees(viewAngle)); checkAll(false); applyAligned(); } diff --git a/src/Mod/TechDraw/Gui/TaskDimension.cpp b/src/Mod/TechDraw/Gui/TaskDimension.cpp index 6428a9e045..1b745307f7 100644 --- a/src/Mod/TechDraw/Gui/TaskDimension.cpp +++ b/src/Mod/TechDraw/Gui/TaskDimension.cpp @@ -28,6 +28,7 @@ #endif // #ifndef _PreComp_ #include +#include #include #include #include @@ -373,14 +374,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 / std::numbers::pi); + ui->dsbDimAngle->setValue(Base::toDegrees(lineAngle)); } void TaskDimension::onDimUseSelectionClicked() { std::pair result = getAngleFromSelection(); if (result.second) { - ui->dsbDimAngle->setValue(result.first * 180.0 / std::numbers::pi); + ui->dsbDimAngle->setValue(Base::toDegrees(result.first)); } } @@ -393,13 +394,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 / std::numbers::pi); + ui->dsbExtAngle->setValue(Base::toDegrees(extensionAngle)); } void TaskDimension::onExtUseSelectionClicked() { std::pair result = getAngleFromSelection(); if (result.second) { - ui->dsbExtAngle->setValue(result.first * 180.0 / std::numbers::pi); + ui->dsbExtAngle->setValue(Base::toDegrees(result.first)); } } diff --git a/src/Mod/TechDraw/Gui/TaskSectionView.cpp b/src/Mod/TechDraw/Gui/TaskSectionView.cpp index 6167723e30..7a98c2f53f 100644 --- a/src/Mod/TechDraw/Gui/TaskSectionView.cpp +++ b/src/Mod/TechDraw/Gui/TaskSectionView.cpp @@ -181,7 +181,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 / std::numbers::pi); + m_compass->setDialAngle(Base::toDegrees(viewAngle)); m_viewDirectionWidget->setValueNoNotify(sectionNormalVec * -1.0); } @@ -273,7 +273,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 / std::numbers::pi); + m_compass->setDialAngle(Base::toDegrees(viewAngle)); checkAll(false); directionChanged(true); applyAligned();