Use Base::toRadians() instead of manually converting

This commit is contained in:
Benjamin Nauck
2025-04-09 09:14:54 +02:00
parent 1f8c8043fc
commit 21fbf8e539
43 changed files with 129 additions and 106 deletions

View File

@@ -33,6 +33,7 @@
#include <Base/Console.h>
#include <Base/Converter.h>
#include <Base/Tools.h>
#include "CenterLine.h"
#include "DrawUtil.h"
@@ -392,7 +393,7 @@ std::pair<Base::Vector3d, Base::Vector3d> CenterLine::rotatePointsAroundMid(cons
const double angleDeg)
{
std::pair<Base::Vector3d, Base::Vector3d> result;
double angleRad = angleDeg * std::numbers::pi / 180.0;
double angleRad = Base::toRadians(angleDeg);
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;

View File

@@ -114,6 +114,7 @@
#include <Base/FileInfo.h>
#include <Base/Interpreter.h>
#include <Base/Parameter.h>
#include <Base/Tools.h>
#include <Mod/Part/App/PartFeature.h>
@@ -956,7 +957,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 * std::numbers::pi / 180.0; // 5 degrees
double angleThresholdRad = Base::toRadians(angleThresholdDeg); // 5 degrees
TopExp_Explorer explEdges(profile, TopAbs_EDGE);
for (; explEdges.More(); explEdges.Next()) {
std::pair<Base::Vector3d, Base::Vector3d> segmentEnds = getSegmentEnds(TopoDS::Edge(explEdges.Current()));

View File

@@ -53,6 +53,7 @@
#include <Base/Converter.h>
#include <Base/FileInfo.h>
#include <Base/Parameter.h>
#include <Base/Tools.h>
#include "DrawGeomHatch.h"
#include "DrawGeomHatchPy.h" // generated from DrawGeomHatchPy.xml
@@ -402,12 +403,13 @@ std::vector<TopoDS_Edge> DrawGeomHatch::makeEdgeOverlay(PATLineSpec hatchLine, B
double interval = hatchLine.getInterval() * scale;
double offset = hatchLine.getOffset() * scale;
double angle = hatchLine.getAngle() + rotation;
origin.RotateZ(rotation * pi / 180.);
origin.RotateZ(Base::toRadians(rotation));
if (scale == 0. || interval == 0.)
return {};
Base::Vector3d hatchDirection(cos(angle * pi / 180.), sin(angle * pi / 180.), 0.);
const double hatchAngle = Base::toRadians(angle);
Base::Vector3d hatchDirection(cos(hatchAngle), sin(hatchAngle), 0.);
Base::Vector3d hatchPerpendicular(-hatchDirection.y, hatchDirection.x, 0.);
Base::Vector3d hatchIntervalAndOffset = offset * hatchDirection + interval * hatchPerpendicular;

View File

@@ -63,6 +63,7 @@
#include <Base/FileInfo.h>
#include <Base/Parameter.h>
#include <Base/Stream.h>
#include <Base/Tools.h>
#include <Base/UnitsApi.h>
#include <Base/Vector3D.h>
@@ -1060,8 +1061,8 @@ 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 * std::numbers::pi / 180.0;
if (rotDeg != 0.0) {
double rotRad = Base::toRadians(rotDeg);
// we always rotate around the origin.
appPoint.RotateZ(-rotRad);
}

View File

@@ -71,6 +71,7 @@
#include <Base/Converter.h>
#include <Base/Exception.h>
#include <Base/Parameter.h>
#include <Base/Tools.h>
#include "Cosmetic.h"
#include "CenterLine.h"
@@ -1105,7 +1106,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<gp_Pnt>(basePoint), unrotated.Direction());
double angleRad = Rotation.getValue() * std::numbers::pi / 180.0;
double angleRad = Base::toRadians(Rotation.getValue());
gp_Ax2 rotated = unrotated.Rotated(rotationAxis, -angleRad);
return rotated;
}

View File

@@ -710,8 +710,6 @@ Circle::Circle()
Circle::Circle(Base::Vector3d c, double r)
{
using std::numbers::pi;
geomType = GeomType::CIRCLE;
radius = r;
center = c;
@@ -721,11 +719,9 @@ Circle::Circle(Base::Vector3d c, double r)
gp_Circ circle;
circle.SetAxis(axis);
circle.SetRadius(r);
double angle1 = 0.0;
double angle2 = 360.0;
Handle(Geom_Circle) hCircle = new Geom_Circle (circle);
BRepBuilderAPI_MakeEdge aMakeEdge(hCircle, angle1*(pi/180), angle2*(pi/180));
BRepBuilderAPI_MakeEdge aMakeEdge(hCircle, 0.0, 2.0 * std::numbers::pi);
TopoDS_Edge edge = aMakeEdge.Edge();
occEdge = edge;
}
@@ -826,7 +822,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*(std::numbers::pi/180), eAng*(std::numbers::pi/180));
BRepBuilderAPI_MakeEdge aMakeEdge(hCircle, Base::toRadians(sAng), Base::toRadians(eAng));
TopoDS_Edge edge = aMakeEdge.Edge();
occEdge = edge;

View File

@@ -35,6 +35,7 @@
#include <Base/Console.h>
#include <Base/Stream.h>
#include <Base/Tools.h>
#include <Base/Vector3D.h>
#include "HatchLine.h"
@@ -396,7 +397,7 @@ double PATLineSpec::getSlope()
} else if (angle < -90.0) {
angle = (180 + angle);
}
return tan(angle * std::numbers::pi/180.0);
return tan(Base::toRadians(angle));
}
bool PATLineSpec::isDashed()
@@ -413,7 +414,7 @@ double PATLineSpec::getIntervalX()
return getInterval();
} else {
double perpAngle = fabs(getAngle() - 90.0);
return fabs(getInterval() / cos(perpAngle * std::numbers::pi/180.0));
return fabs(getInterval() / cos(Base::toRadians(perpAngle)));
}
}
@@ -426,7 +427,7 @@ double PATLineSpec::getIntervalY()
return 0.0;
} else {
double perpAngle = fabs(getAngle() - 90.0);
return fabs(getInterval() * tan(perpAngle * std::numbers::pi/180.0));
return fabs(getInterval() * tan(Base::toRadians(perpAngle)));
}
}

View File

@@ -65,6 +65,7 @@
#endif// #ifndef _PreComp_
#include <Base/Console.h>
#include <Base/Tools.h>
#include "DrawUtil.h"
#include "ShapeUtils.h"
@@ -266,19 +267,17 @@ TopoDS_Shape ShapeUtils::mirrorShape(const TopoDS_Shape& input, const gp_Pnt& in
//!rotates a shape about a viewAxis
TopoDS_Shape ShapeUtils::rotateShape(const TopoDS_Shape& input, const gp_Ax2& viewAxis,
double rotAngle)
double rotAngle)
{
TopoDS_Shape transShape;
if (input.IsNull()) {
return transShape;
}
gp_Ax1 rotAxis = viewAxis.Axis();
double rotation = rotAngle * std::numbers::pi / 180.0;
try {
gp_Ax1 rotAxis = viewAxis.Axis();
gp_Trsf tempTransform;
tempTransform.SetRotation(rotAxis, rotation);
tempTransform.SetRotation(rotAxis, Base::toRadians(rotAngle));
BRepBuilderAPI_Transform mkTrf(input, tempTransform);
transShape = mkTrf.Shape();
}

View File

@@ -26,6 +26,7 @@
# include <QStyleOptionGraphicsItem>
#endif
#include <Base/Tools.h>
#include <Mod/TechDraw/App/DrawUtil.h>
#include "QGIHighlight.h"
@@ -125,7 +126,7 @@ void QGIHighlight::makeReference()
QRectF r(m_start, m_end);
double radius = r.width() / 2.0;
QPointF center = r.center();
double angleRad = m_referenceAngle * std::numbers::pi / 180.0;
double angleRad = Base::toRadians(m_referenceAngle);
double posX = center.x() + cos(angleRad) * radius + horizOffset;
double posY = center.y() - sin(angleRad) * radius - vertOffset;
m_reference->setPos(posX, posY);

View File

@@ -698,7 +698,7 @@ 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 * pi / 180) * radius);
offsetLR = tan(Base::toRadians(30.0)) * radius;
QPolygonF triangle;
double startAngle = -pi / 2;
double angle = startAngle;
@@ -826,7 +826,7 @@ void QGIViewBalloon::drawBalloon(bool originDrag)
else {
arAngle = 0;
}
double radAngle = arAngle * pi / 180.0;
double radAngle = Base::toRadians(arAngle);
double sinAngle = sin(radAngle);
double cosAngle = cos(radAngle);
xAdj = Rez::guiX(arrowAdj * cosAngle);

View File

@@ -39,6 +39,7 @@
#include <App/Application.h>
#include <Base/Console.h>
#include <Base/Parameter.h>
#include <Base/Tools.h>
#include <Base/UnitsApi.h>
#include <Gui/Command.h>
#include <Mod/TechDraw/App/DrawUtil.h>
@@ -1838,9 +1839,9 @@ void QGIViewDimension::drawDistance(TechDraw::DrawViewDimension* dimension,
if (dimension->AngleOverride.getValue()) {
drawDistanceOverride(fromQtApp(linePoints.first()), fromQtApp(linePoints.second()),
dimension->LineAngle.getValue() * std::numbers::pi / 180.0, labelRectangle,
Base::toRadians(dimension->LineAngle.getValue()), labelRectangle,
standardStyle, renderExtent, flipArrows,
dimension->ExtensionAngle.getValue() * std::numbers::pi / 180.0);
Base::toRadians(dimension->ExtensionAngle.getValue()));
}
else {
drawDistanceExecutive(fromQtApp(linePoints.extensionLineFirst()), fromQtApp(linePoints.extensionLineSecond()),

View File

@@ -32,6 +32,7 @@
#include <App/Document.h>
#include <Base/Console.h>
#include <Base/Parameter.h>
#include <Base/Tools.h>
#include <Base/Vector3D.h>
#include <Gui/Selection/Selection.h>
#include <Mod/TechDraw/App/CenterLine.h>
@@ -964,7 +965,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() * std::numbers::pi / 180.0;
double rotationRad = Base::toRadians(viewPart->Rotation.getValue());
center.RotateZ(rotationRad);
double radius = viewDetail->Radius.getValue() * viewPart->getScale();

View File

@@ -31,6 +31,7 @@
#include <App/Link.h>
#include <Base/Console.h>
#include <Base/Converter.h>
#include <Base/Tools.h>
#include <Gui/BitmapFactory.h>
#include <Gui/Command.h>
#include <Gui/Control.h>
@@ -319,7 +320,7 @@ void TaskComplexSection::slotViewDirectionChanged(Base::Vector3d newDirection)
void TaskComplexSection::slotChangeAngle(double newAngle)
{
// Base::Console().Message("TCS::slotAngleChanged(%.3f)\n", newAngle);
double angleRadians = newAngle * std::numbers::pi / 180.0;
double angleRadians = Base::toRadians(newAngle);
double unitX = cos(angleRadians);
double unitY = sin(angleRadians);
Base::Vector3d localUnit(unitX, unitY, 0.0);

View File

@@ -113,7 +113,7 @@ void TaskCosmeticLine::setUiPrimary()
setWindowTitle(QObject::tr("Create Cosmetic Line"));
// double rotDeg = m_partFeat->Rotation.getValue();
// double rotRad = rotDeg * std::numbers::pi / 180.0;
// double rotRad = Base::toRadians(rotDeg);
Base::Vector3d centroid = m_partFeat->getCurrentCentroid();
Base::Vector3d p1, p2;
if (m_is3d.front()) {

View File

@@ -31,6 +31,7 @@
#include <App/Document.h>
#include <App/DocumentObject.h>
#include <Base/Console.h>
#include <Base/Tools.h>
#include <Gui/BitmapFactory.h>
#include <Gui/Command.h>
#include <Gui/Control.h>
@@ -281,7 +282,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 * std::numbers::pi / 180.0;
double angleRadians = Base::toRadians(newAngle);
double unitX = cos(angleRadians);
double unitY = sin(angleRadians);
Base::Vector3d localUnit(unitX, unitY, 0.0);