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

This commit is contained in:
Benjamin Nauck
2025-03-27 18:59:58 +01:00
parent ae686942a7
commit 34bc1d45ea
33 changed files with 204 additions and 168 deletions

View File

@@ -23,7 +23,6 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <cfloat>
# ifdef FC_OS_WIN32
# include <windows.h>
# endif
@@ -3267,7 +3266,7 @@ void View3DInventorViewer::setCameraType(SoType type)
// heightAngle. Setting it to 45 deg also causes an issue with a too
// close camera but we don't have this other ugly effect.
static_cast<SoPerspectiveCamera*>(cam)->heightAngle = (float)(M_PI / 4.0); // NOLINT
static_cast<SoPerspectiveCamera*>(cam)->heightAngle = (float)(std::numbers::pi / 4.0); // NOLINT
}
lightRotation->rotation.connectFrom(&cam->orientation);
@@ -3426,7 +3425,7 @@ void View3DInventorViewer::viewAll()
SoCamera* cam = this->getSoRenderManager()->getCamera();
if (cam && cam->getTypeId().isDerivedFrom(SoPerspectiveCamera::getClassTypeId())) {
static_cast<SoPerspectiveCamera*>(cam)->heightAngle = (float)(M_PI / 4.0); // NOLINT
static_cast<SoPerspectiveCamera*>(cam)->heightAngle = (float)(std::numbers::pi / 4.0); // NOLINT
}
if (isAnimationEnabled()) {
@@ -3632,26 +3631,28 @@ void View3DInventorViewer::alignToSelection()
angle *= -1;
}
using std::numbers::pi;
// Make angle positive
if (angle < 0) {
angle += 2 * M_PI;
angle += 2 * pi;
}
// Find the angle to rotate to the nearest horizontal or vertical alignment with directionX.
// f is a small value used to get more deterministic behavior when the camera is at directionX +- 45 degrees.
const float f = 0.00001F;
if (angle <= M_PI_4 + f) {
if (angle <= pi/4 + f) {
angle = 0;
}
else if (angle <= 3 * M_PI_4 + f) {
angle = M_PI_2;
else if (angle <= 3 * pi/4 + f) {
angle = pi/2;
}
else if (angle < M_PI + M_PI_4 - f) {
angle = M_PI;
else if (angle < pi + pi/4 - f) {
angle = pi;
}
else if (angle < M_PI + 3 * M_PI_4 - f) {
angle = M_PI + M_PI_2;
else if (angle < pi + 3 * pi/4 - f) {
angle = pi + pi/2;
}
else {
angle = 0;
@@ -3960,7 +3961,7 @@ void View3DInventorViewer::drawAxisCross()
const float NEARVAL = 0.1F;
const float FARVAL = 10.0F;
const float dim = NEARVAL * float(tan(M_PI / 8.0)); // FOV is 45 deg (45/360 = 1/8)
const float dim = NEARVAL * float(tan(std::numbers::pi / 8.0)); // FOV is 45 deg (45/360 = 1/8)
glFrustum(-dim, dim, -dim, dim, NEARVAL, FARVAL);