Sketcher: Use std::numeric_limits and std::numbers instead of defines

This commit is contained in:
Benjamin Nauck
2025-03-27 19:02:24 +01:00
parent 883d02756d
commit 3279a1dd8f
41 changed files with 355 additions and 225 deletions

View File

@@ -114,6 +114,8 @@ void EditModeConstraintCoinManager::updateVirtualSpace()
void EditModeConstraintCoinManager::processConstraints(const GeoListFacade& geolistfacade)
{
using std::numbers::pi;
const auto& constrlist = ViewProviderSketchCoinAttorney::getConstraints(viewProvider);
auto zConstrH = ViewProviderSketchCoinAttorney::getViewOrientationFactor(viewProvider)
@@ -262,7 +264,7 @@ Restart:
const Part::GeomCircle* circle =
static_cast<const Part::GeomCircle*>(geo);
ra = circle->getRadius();
angle = M_PI / 4;
angle = pi / 4;
midpos = circle->getCenter();
}
else if (geo->is<Part::GeomArcOfCircle>()) {
@@ -281,7 +283,7 @@ Restart:
rb = ellipse->getMinorRadius();
Base::Vector3d majdir = ellipse->getMajorAxisDir();
angle = atan2(majdir.y, majdir.x);
angleplus = M_PI / 4;
angleplus = pi / 4;
midpos = ellipse->getCenter();
}
else if (geo->is<Part::GeomArcOfEllipse>()) {
@@ -460,7 +462,7 @@ Restart:
norm1.Normalize();
dir1 = norm1;
dir1.RotateZ(-M_PI / 2.0);
dir1.RotateZ(-pi / 2.0);
}
else if (Constr->FirstPos == Sketcher::PointPos::none) {
@@ -485,7 +487,7 @@ Restart:
else if (geo1->is<Part::GeomCircle>()) {
const Part::GeomCircle* circle =
static_cast<const Part::GeomCircle*>(geo1);
norm1 = Base::Vector3d(cos(M_PI / 4), sin(M_PI / 4), 0);
norm1 = Base::Vector3d(cos(pi / 4), sin(pi / 4), 0);
dir1 = Base::Vector3d(-norm1.y, norm1.x, 0);
midpos1 = circle->getCenter() + circle->getRadius() * norm1;
}
@@ -514,7 +516,7 @@ Restart:
else if (geo2->is<Part::GeomCircle>()) {
const Part::GeomCircle* circle =
static_cast<const Part::GeomCircle*>(geo2);
norm2 = Base::Vector3d(cos(M_PI / 4), sin(M_PI / 4), 0);
norm2 = Base::Vector3d(cos(pi / 4), sin(pi / 4), 0);
dir2 = Base::Vector3d(-norm2.y, norm2.x, 0);
midpos2 = circle->getCenter() + circle->getRadius() * norm2;
}
@@ -576,7 +578,7 @@ Restart:
const Part::GeomCircle* circle =
static_cast<const Part::GeomCircle*>(geo1);
r1a = circle->getRadius();
angle1 = M_PI / 4;
angle1 = pi / 4;
midpos1 = circle->getCenter();
}
else if (geo1->is<Part::GeomArcOfCircle>()) {
@@ -595,7 +597,7 @@ Restart:
r1b = ellipse->getMinorRadius();
Base::Vector3d majdir = ellipse->getMajorAxisDir();
angle1 = atan2(majdir.y, majdir.x);
angle1plus = M_PI / 4;
angle1plus = pi / 4;
midpos1 = ellipse->getCenter();
}
else if (geo1->is<Part::GeomArcOfEllipse>()) {
@@ -641,7 +643,7 @@ Restart:
const Part::GeomCircle* circle =
static_cast<const Part::GeomCircle*>(geo2);
r2a = circle->getRadius();
angle2 = M_PI / 4;
angle2 = pi / 4;
midpos2 = circle->getCenter();
}
else if (geo2->is<Part::GeomArcOfCircle>()) {
@@ -660,7 +662,7 @@ Restart:
r2b = ellipse->getMinorRadius();
Base::Vector3d majdir = ellipse->getMajorAxisDir();
angle2 = atan2(majdir.y, majdir.x);
angle2plus = M_PI / 4;
angle2plus = pi / 4;
midpos2 = ellipse->getCenter();
}
else if (geo2->is<Part::GeomArcOfEllipse>()) {
@@ -968,7 +970,7 @@ Restart:
// otherwise We still use findHelperAngles before to find if helper
// is needed.
helperStartAngle1 = endAngle;
helperRange1 = 2 * M_PI - (endAngle - startAngle);
helperRange1 = 2 * pi - (endAngle - startAngle);
numPoints++;
}
@@ -991,7 +993,7 @@ Restart:
if (helperRange2 != 0.) {
helperStartAngle2 = endAngle;
helperRange2 = 2 * M_PI - (endAngle - startAngle);
helperRange2 = 2 * pi - (endAngle - startAngle);
numPoints++;
}
@@ -1089,7 +1091,7 @@ Restart:
// getSolvedSketch().calculateNormalAtPoint(Constr->Second, pos.x, pos.y);
norm.Normalize();
Base::Vector3d dir = norm;
dir.RotateZ(-M_PI / 2.0);
dir.RotateZ(-pi / 2.0);
relPos = seekConstraintPosition(
pos,
@@ -1340,7 +1342,7 @@ Restart:
p1[1] = line1->getEndPoint();
p2[0] = line2->getStartPoint();
p2[1] = line2->getEndPoint();
double length = DBL_MAX;
double length = std::numeric_limits<double>::max();
for (int i = 0; i <= 1; i++) {
for (int j = 0; j <= 1; j++) {
double tmp = (p2[j] - p1[i]).Length();
@@ -1385,12 +1387,12 @@ Restart:
// TODO: Check
// dir1 = getSolvedSketch().calculateNormalAtPoint(Constr->First,
// p.x, p.y);
dir1.RotateZ(-M_PI / 2); // convert to vector of tangency by rotating
dir1.RotateZ(-pi / 2); // convert to vector of tangency by rotating
dir2 = getNormal(geolistfacade, Constr->Second, p);
// TODO: Check
// dir2 = getSolvedSketch().calculateNormalAtPoint(Constr->Second,
// p.x, p.y);
dir2.RotateZ(-M_PI / 2);
dir2.RotateZ(-pi / 2);
startangle = atan2(dir1.y, dir1.x);
range = atan2(dir1.x * dir2.y - dir1.y * dir2.x,
@@ -1632,26 +1634,28 @@ void EditModeConstraintCoinManager::findHelperAngles(double& helperStartAngle,
double startAngle,
double endAngle)
{
using std::numbers::pi;
double margin = 0.2; // about 10deg
if (angle < 0) {
angle = angle + 2 * M_PI;
angle = angle + 2 * pi;
}
// endAngle can be more than 2*pi as its startAngle + arcAngle
if (endAngle > 2 * M_PI && angle < endAngle - 2 * M_PI) {
angle = angle + 2 * M_PI;
if (endAngle > 2 * pi && angle < endAngle - 2 * pi) {
angle = angle + 2 * pi;
}
if (!(angle > startAngle && angle < endAngle)) {
if ((angle < startAngle && startAngle - angle < angle + 2 * M_PI - endAngle)
|| (angle > endAngle && startAngle + 2 * M_PI - angle < angle - endAngle)) {
if ((angle < startAngle && startAngle - angle < angle + 2 * pi - endAngle)
|| (angle > endAngle && startAngle + 2 * pi - angle < angle - endAngle)) {
if (angle > startAngle) {
angle -= 2 * M_PI;
angle -= 2 * pi;
}
helperStartAngle = angle - margin;
helperRange = startAngle - angle + margin;
}
else {
if (angle < endAngle) {
angle += 2 * M_PI;
angle += 2 * pi;
}
helperStartAngle = endAngle;
helperRange = angle - endAngle + margin;