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