Use Base::toDegrees() instead of manually converting

This commit is contained in:
Benjamin Nauck
2025-04-09 09:52:39 +02:00
parent 21fbf8e539
commit f22f3705db
17 changed files with 38 additions and 37 deletions

View File

@@ -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:

View File

@@ -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);
}

View File

@@ -48,6 +48,8 @@
# include <Inventor/misc/SoState.h>
#endif // _PreComp_
#include <Base/Tools.h>
#include <Gui/BitmapFactory.h>
#include <Gui/Tools.h>
@@ -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<GLfloat>(angle), 0,0,1);
glBegin(GL_QUADS);
glColor3f(1.F, 1.F, 1.F);

View File

@@ -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;

View File

@@ -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));
}
///////////////////////////////////////////////////////////////////////////////////////////////

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -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);

View File

@@ -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;

View File

@@ -33,6 +33,7 @@
# include <App/DocumentObject.h>
# include <Base/Console.h>
# include <Base/Type.h>
# include <Base/Tools.h>
# include <Gui/Action.h>
# include <Gui/Application.h>
# include <Gui/BitmapFactory.h>
@@ -2050,7 +2051,6 @@ void execCreateHorizChamferDimension(Gui::Command* cmd) {
std::vector<dimVertex> 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<dimVertex> 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 + "°";

View File

@@ -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) {

View File

@@ -31,6 +31,7 @@
#include <App/Application.h>
#include <Base/Console.h>
#include <Base/Parameter.h>
#include <Base/Tools.h>
#include <Mod/TechDraw/App/Preferences.h>
@@ -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;
}

View File

@@ -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) {

View File

@@ -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
{

View File

@@ -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();
}

View File

@@ -28,6 +28,7 @@
#endif // #ifndef _PreComp_
#include <App/Document.h>
#include <Base/Tools.h>
#include <Gui/BitmapFactory.h>
#include <Gui/Command.h>
#include <Gui/Document.h>
@@ -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<double, bool> 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<double, bool> result = getAngleFromSelection();
if (result.second) {
ui->dsbExtAngle->setValue(result.first * 180.0 / std::numbers::pi);
ui->dsbExtAngle->setValue(Base::toDegrees(result.first));
}
}

View File

@@ -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();