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

This commit is contained in:
Benjamin Nauck
2025-03-27 19:00:34 +01:00
parent 9e3c0d111e
commit 3fc0831116
2 changed files with 14 additions and 10 deletions

View File

@@ -207,9 +207,10 @@ void SVGOutput::printCircle(const BRepAdaptor_Curve& c, std::ostream& out)
}
// arc of circle
else {
using std::numbers::pi;
// See also https://developer.mozilla.org/en/SVG/Tutorial/Paths
char xar = '0'; // x-axis-rotation
char las = (l - f > D_PI) ? '1' : '0'; // large-arc-flag
char xar = '0'; // x-axis-rotation
char las = (l - f > pi) ? '1' : '0'; // large-arc-flag
char swp = (a < 0) ? '1' : '0'; // sweep-flag, i.e. clockwise (0) or counter-clockwise (1)
out << "<path d=\"M" << s.X() << " " << s.Y() << " A" << r << " " << r << " " << xar << " "
<< las << " " << swp << " " << e.X() << " " << e.Y() << "\" />";
@@ -255,7 +256,8 @@ void SVGOutput::printEllipse(const BRepAdaptor_Curve& c, int id, std::ostream& o
}
// arc of ellipse
else {
char las = (l - f > D_PI) ? '1' : '0'; // large-arc-flag
using std::numbers::pi;
char las = (l - f > pi) ? '1' : '0'; // large-arc-flag
char swp = (a < 0) ? '1' : '0'; // sweep-flag, i.e. clockwise (0) or counter-clockwise (1)
out << "<path d=\"M" << s.X() << " " << s.Y() << " A" << r1 << " " << r2 << " " << angle
<< " " << las << " " << swp << " " << e.X() << " " << e.Y() << "\" />" << std::endl;
@@ -460,6 +462,8 @@ 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();
@@ -502,8 +506,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 / D_PI;
double end_angle = atan2(by, bx) * 180 / D_PI;
double start_angle = atan2(ay, ax) * 180 / pi;
double end_angle = atan2(by, bx) * 180 / pi;
if (a > 0) {
double temp = start_angle;

View File

@@ -256,7 +256,7 @@ void orthoview::set_projection(const gp_Ax2& cs)
// angle between desired projection and actual projection
float rotation = X_dir.Angle(actual_X);
if (rotation != 0 && abs(M_PI - rotation) > 0.05) {
if (rotation != 0 && abs(std::numbers::pi - rotation) > 0.05) {
if (!Z_dir.IsEqual(actual_X.Crossed(X_dir), 0.05)) {
rotation = -rotation;
}
@@ -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 / M_PI);
this_view->Rotation.setValue(180 * rotation / std::numbers::pi);
}
///////////////////////////////////////////////////////////////////////////////////////////////
@@ -613,8 +613,8 @@ void OrthoViews::set_orientation(int index) // set orientation of single view
dir = primary.XDirection();
n = -views[index]->rel_y;
}
rotation = n * rotate_coeff * M_PI / 2; // rotate_coeff is -1 or 1 for 1st or 3rd angle
// rotate_coeff is -1 or 1 for 1st or 3rd angle
rotation = n * rotate_coeff * std::numbers::pi / 2;
cs = primary.Rotated(gp_Ax1(gp_Pnt(0, 0, 0), dir), rotation);
views[index]->set_projection(cs);
}
@@ -780,7 +780,7 @@ void OrthoViews::set_Axo(int rel_x,
rotations[1] = -0.6156624905260762;
}
else {
rotations[0] = 1.3088876392502007 - M_PI / 2;
rotations[0] = 1.3088876392502007 - std::numbers::pi / 2;
rotations[1] = -0.6156624905260762;
}