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

@@ -425,6 +425,8 @@ int DrawSketchHandler::seekAutoConstraint(std::vector<AutoConstraint>& suggested
const Base::Vector2d& Dir,
AutoConstraint::TargetType type)
{
using std::numbers::pi;
suggestedConstraints.clear();
SketchObject* obj = sketchgui->getSketchObject();
@@ -550,18 +552,18 @@ int DrawSketchHandler::seekAutoConstraint(std::vector<AutoConstraint>& suggested
// Number of Degree of deviation from horizontal or vertical lines
const double angleDev = 2;
const double angleDevRad = angleDev * M_PI / 180.;
const double angleDevRad = angleDev * pi / 180.;
AutoConstraint constr;
constr.Type = Sketcher::None;
constr.GeoId = GeoEnum::GeoUndef;
constr.PosId = PointPos::none;
double angle = std::abs(atan2(Dir.y, Dir.x));
if (angle < angleDevRad || (M_PI - angle) < angleDevRad) {
if (angle < angleDevRad || (pi - angle) < angleDevRad) {
// Suggest horizontal constraint
constr.Type = Sketcher::Horizontal;
}
else if (std::abs(angle - M_PI_2) < angleDevRad) {
else if (std::abs(angle - pi / 2) < angleDevRad) {
// Suggest vertical constraint
constr.Type = Sketcher::Vertical;
}
@@ -665,7 +667,7 @@ int DrawSketchHandler::seekAutoConstraint(std::vector<AutoConstraint>& suggested
double angle = atan2(projPnt.y, projPnt.x);
while (angle < startAngle) {
angle += 2 * D_PI; // Bring it to range of arc
angle += 2 * pi; // Bring it to range of arc
}
// if the point is on correct side of arc
@@ -714,10 +716,10 @@ int DrawSketchHandler::seekAutoConstraint(std::vector<AutoConstraint>& suggested
aoe->getMinorRadius()
* ((tmpPos.x - center.x) * majdir.x + (tmpPos.y - center.y) * majdir.y))
- startAngle,
2.f * M_PI);
2.f * pi);
while (angle < startAngle) {
angle += 2 * D_PI; // Bring it to range of arc
angle += 2 * pi; // Bring it to range of arc
}
// if the point is on correct side of arc
@@ -978,7 +980,7 @@ void DrawSketchHandler::drawDirectionAtCursor(const Base::Vector2d& position,
SbString text;
std::string lengthString = lengthToDisplayFormat(length, 1);
std::string angleString = angleToDisplayFormat(angle * 180.0 / M_PI, 1);
std::string angleString = angleToDisplayFormat(angle * 180.0 / std::numbers::pi, 1);
text.sprintf(" (%s, %s)", lengthString.c_str(), angleString.c_str());
setPositionText(position, text);
}
@@ -1009,7 +1011,7 @@ void DrawSketchHandler::drawDoubleAtCursor(const Base::Vector2d& position,
SbString text;
std::string doubleString = unit == Base::Unit::Length
? lengthToDisplayFormat(val, 1)
: angleToDisplayFormat(val * 180.0 / M_PI, 1);
: angleToDisplayFormat(val * 180.0 / std::numbers::pi, 1);
text.sprintf(" (%s)", doubleString.c_str());
setPositionText(position, text);
}