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 3253f2c2de
commit b625e81a3e
33 changed files with 204 additions and 168 deletions

View File

@@ -23,7 +23,7 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <algorithm>
# include <cfloat>
# include <numbers>
# ifdef FC_OS_WIN32
# include <windows.h>
# endif
@@ -553,7 +553,7 @@ void NaviCubeImplementation::addButtonFace(PickId pickId, const SbVec3f& directi
case PickId::DotBackside: {
int steps = 16;
for (int i = 0; i < steps; i++) {
float angle = 2.0f * M_PI * ((float)i+0.5) / (float)steps;
float angle = 2.0f * std::numbers::pi_v<float> * ((float)i+0.5) / (float)steps;
pointData.emplace_back(10. * cos(angle) + 87.);
pointData.emplace_back(10. * sin(angle) - 87.);
}
@@ -659,8 +659,8 @@ void NaviCubeImplementation::setSize(int size)
void NaviCubeImplementation::prepare()
{
static const float pi = boost::math::constants::pi<float>();
static const float pi1_2 = boost::math::constants::half_pi<float>();
constexpr float pi = std::numbers::pi_v<float>;
constexpr float pi1_2 = pi / 2;
createCubeFaceTextures();
@@ -817,7 +817,7 @@ void NaviCubeImplementation::drawNaviCube(bool pickMode, float opacity)
glOrtho(-2.1, 2.1, -2.1, 2.1, NEARVAL, FARVAL);
}
else {
const float dim = NEARVAL * float(tan(M_PI / 8.0)) * 1.1;
const float dim = NEARVAL * float(tan(std::numbers::pi / 8.0)) * 1.1;
glFrustum(-dim, dim, -dim, dim, NEARVAL, FARVAL);
}
glMatrixMode(GL_MODELVIEW);
@@ -1010,15 +1010,11 @@ SbRotation NaviCubeImplementation::getNearestOrientation(PickId pickId) {
angle *= -1;
}
static const float pi = boost::math::constants::pi<float>();
static const float pi2 = boost::math::constants::two_pi<float>();
static const float pi1_2 = boost::math::constants::half_pi<float>();
static const float pi1_3 = boost::math::constants::third_pi<float>();
static const float pi2_3 = boost::math::constants::two_thirds_pi<float>();
constexpr float pi = std::numbers::pi_v<float>;
// Make angle positive
if (angle < 0) {
angle += pi2;
angle += 2 * pi;
}
// f is a small value used to control orientation priority when the camera is almost exactly between two
@@ -1030,23 +1026,23 @@ SbRotation NaviCubeImplementation::getNearestOrientation(PickId pickId) {
// Find the angle to rotate to the nearest orientation
if (m_Faces[pickId].type == ShapeId::Corner) {
// 6 possible orientations for the corners
if (angle <= (M_PI / 6 + f)) {
if (angle <= (pi / 6 + f)) {
angle = 0;
}
else if (angle <= (M_PI_2 + f)) {
angle = pi1_3;
else if (angle <= (pi / 2 + f)) {
angle = pi / 3;
}
else if (angle < (5 * M_PI / 6 - f)) {
angle = pi2_3;
else if (angle < (5 * pi / 6 - f)) {
angle = 2 * pi / 3;
}
else if (angle <= (M_PI + M_PI / 6 + f)) {
else if (angle <= (pi + pi / 6 + f)) {
angle = pi;
}
else if (angle < (M_PI + M_PI_2 - f)) {
angle = pi + pi1_3;
else if (angle < (pi + pi / 2 - f)) {
angle = pi + pi / 3;
}
else if (angle < (M_PI + 5 * M_PI / 6 - f)) {
angle = pi + pi2_3;
else if (angle < (pi + 5 * pi / 6 - f)) {
angle = pi + 2 * pi / 3;
}
else {
angle = 0;
@@ -1054,17 +1050,17 @@ SbRotation NaviCubeImplementation::getNearestOrientation(PickId pickId) {
}
else {
// 4 possible orientations for the main and edge faces
if (angle <= (M_PI_4 + f)) {
if (angle <= (pi / 4 + f)) {
angle = 0;
}
else if (angle <= (3 * M_PI_4 + f)) {
angle = pi1_2;
else if (angle <= (3 * pi / 4 + f)) {
angle = pi / 2;
}
else if (angle < (M_PI + M_PI_4 - f)) {
else if (angle < (pi + pi / 4 - f)) {
angle = pi;
}
else if (angle < (M_PI + 3 * M_PI_4 - f)) {
angle = pi + pi1_2;
else if (angle < (pi + 3 * pi / 4 - f)) {
angle = pi + pi / 2;
}
else {
angle = 0;
@@ -1089,7 +1085,7 @@ bool NaviCubeImplementation::mouseReleased(short x, short y)
} else {
PickId pickId = pickFace(x, y);
long step = Base::clamp(long(m_NaviStepByTurn), 4L, 36L);
float rotStepAngle = (2 * M_PI) / step;
float rotStepAngle = (2 * std::numbers::pi) / step;
if (m_Faces[pickId].type == ShapeId::Main || m_Faces[pickId].type == ShapeId::Edge || m_Faces[pickId].type == ShapeId::Corner) {
// Handle the cube faces