From 34bc1d45ea7b20fd8fff2cd6a796002cbe835b82 Mon Sep 17 00:00:00 2001 From: Benjamin Nauck Date: Thu, 27 Mar 2025 18:59:58 +0100 Subject: [PATCH] Gui: Use std::numeric_limits and std::numbers instead of defines --- src/Gui/CallTips.cpp | 4 +- src/Gui/Clipping.cpp | 15 ++-- src/Gui/DemoMode.cpp | 2 +- src/Gui/Dialogs/DlgParameterImp.cpp | 4 +- src/Gui/EditableDatumLabel.cpp | 4 +- src/Gui/InputField.cpp | 4 +- src/Gui/Inventor/SoFCBackgroundGradient.cpp | 22 +++-- src/Gui/NaviCube.cpp | 52 +++++------ src/Gui/Navigation/NavigationAnimation.cpp | 10 ++- src/Gui/Navigation/NavigationStyle.cpp | 6 +- src/Gui/OverlayManager.cpp | 2 +- src/Gui/PreCompiled.h | 3 +- .../DlgSettingsCacheDirectory.cpp | 2 +- .../DlgSettingsDocumentImp.cpp | 2 +- src/Gui/QuantitySpinBox.cpp | 4 +- src/Gui/Quarter/SoQTQuarterAdaptor.cpp | 8 +- src/Gui/Selection/SelectionFilter.h | 5 +- src/Gui/Selection/SoFCSelectionContext.h | 5 +- src/Gui/ShortcutManager.cpp | 2 +- src/Gui/SoDatumLabel.cpp | 90 +++++++++++-------- src/Gui/SoFCCSysDragger.cpp | 16 ++-- src/Gui/SoTextLabel.cpp | 1 - src/Gui/SoTouchEvents.cpp | 10 ++- src/Gui/SpinBox.cpp | 28 +++--- src/Gui/Transform.cpp | 3 +- src/Gui/VectorListEditor.cpp | 13 +-- src/Gui/View3DInventorRiftViewer.cpp | 4 +- src/Gui/View3DInventorViewer.cpp | 25 +++--- src/Gui/View3DPy.cpp | 4 +- src/Gui/ViewProviderAnnotation.cpp | 2 +- src/Gui/propertyeditor/PropertyItem.cpp | 6 +- src/Gui/propertyeditor/PropertyItem.h | 12 +-- src/Gui/propertyeditor/PropertyModel.cpp | 2 +- 33 files changed, 204 insertions(+), 168 deletions(-) diff --git a/src/Gui/CallTips.cpp b/src/Gui/CallTips.cpp index 93221d7366..e3712f9c22 100644 --- a/src/Gui/CallTips.cpp +++ b/src/Gui/CallTips.cpp @@ -748,7 +748,7 @@ QString CallTipsList::stripWhiteSpace(const QString& str) const { QString stripped = str; QStringList lines = str.split(QLatin1String("\n")); - int minspace=INT_MAX; + int minspace=std::numeric_limits::max(); int line=0; for (QStringList::iterator it = lines.begin(); it != lines.end(); ++it, ++line) { if (it->size() > 0 && line > 0) { @@ -766,7 +766,7 @@ QString CallTipsList::stripWhiteSpace(const QString& str) const } // remove all leading tabs from each line - if (minspace > 0 && minspace < INT_MAX) { + if (minspace > 0 && minspace < std::numeric_limits::max()) { int line=0; QStringList strippedlines; for (QStringList::iterator it = lines.begin(); it != lines.end(); ++it, ++line) { diff --git a/src/Gui/Clipping.cpp b/src/Gui/Clipping.cpp index e56eb2997b..d2495c3720 100644 --- a/src/Gui/Clipping.cpp +++ b/src/Gui/Clipping.cpp @@ -109,20 +109,21 @@ Clipping::Clipping(Gui::View3DInventor* view, QWidget* parent) d->ui.setupUi(this); setupConnections(); - d->ui.clipView->setRange(-INT_MAX, INT_MAX); + constexpr int max = std::numeric_limits::max(); + d->ui.clipView->setRange(-max, max); d->ui.clipView->setSingleStep(0.1f); - d->ui.clipX->setRange(-INT_MAX, INT_MAX); + d->ui.clipX->setRange(-max, max); d->ui.clipX->setSingleStep(0.1f); - d->ui.clipY->setRange(-INT_MAX, INT_MAX); + d->ui.clipY->setRange(-max, max); d->ui.clipY->setSingleStep(0.1f); - d->ui.clipZ->setRange(-INT_MAX, INT_MAX); + d->ui.clipZ->setRange(-max, max); d->ui.clipZ->setSingleStep(0.1f); - d->ui.dirX->setRange(-INT_MAX, INT_MAX); + d->ui.dirX->setRange(-max, max); d->ui.dirX->setSingleStep(0.1f); - d->ui.dirY->setRange(-INT_MAX, INT_MAX); + d->ui.dirY->setRange(-max, max); d->ui.dirY->setSingleStep(0.1f); - d->ui.dirZ->setRange(-INT_MAX, INT_MAX); + d->ui.dirZ->setRange(-max, max); d->ui.dirZ->setSingleStep(0.1f); d->ui.dirZ->setValue(1.0f); diff --git a/src/Gui/DemoMode.cpp b/src/Gui/DemoMode.cpp index e253246b3d..d69224d891 100644 --- a/src/Gui/DemoMode.cpp +++ b/src/Gui/DemoMode.cpp @@ -166,7 +166,7 @@ SbVec3f DemoMode::getDirection(Gui::View3DInventor* view) const SbRotation inv = rot.inverse(); SbVec3f vec(this->viewAxis); inv.multVec(vec, vec); - if (vec.length() < FLT_EPSILON) { + if (vec.length() < std::numeric_limits::epsilon()) { vec = this->viewAxis; } vec.normalize(); diff --git a/src/Gui/Dialogs/DlgParameterImp.cpp b/src/Gui/Dialogs/DlgParameterImp.cpp index 2036e65ee4..8139e994ba 100644 --- a/src/Gui/Dialogs/DlgParameterImp.cpp +++ b/src/Gui/Dialogs/DlgParameterImp.cpp @@ -905,7 +905,7 @@ void ParameterValue::onCreateUIntItem() DlgInputDialogImp::UIntBox); dlg.setWindowTitle(QObject::tr("New unsigned item")); UIntSpinBox* edit = dlg.getUIntBox(); - edit->setRange(0, UINT_MAX); + edit->setRange(0, std::numeric_limits::max()); if (dlg.exec() == QDialog::Accepted) { QString value = edit->text(); unsigned long val = value.toULong(&ok); @@ -1249,7 +1249,7 @@ void ParameterUInt::changeValue() DlgInputDialogImp::UIntBox); dlg.setWindowTitle(QObject::tr("Change value")); UIntSpinBox* edit = dlg.getUIntBox(); - edit->setRange(0, UINT_MAX); + edit->setRange(0, std::numeric_limits::max()); edit->setValue(text(2).toULong()); if (dlg.exec() == QDialog::Accepted) { QString value = edit->text(); diff --git a/src/Gui/EditableDatumLabel.cpp b/src/Gui/EditableDatumLabel.cpp index 5fa800935e..0604bc0a2d 100644 --- a/src/Gui/EditableDatumLabel.cpp +++ b/src/Gui/EditableDatumLabel.cpp @@ -152,8 +152,8 @@ void EditableDatumLabel::startEdit(double val, QObject* eventFilteringObj, bool spinBox = new QuantitySpinBox(mdi); spinBox->setUnit(Base::Unit::Length); - spinBox->setMinimum(-INT_MAX); - spinBox->setMaximum(INT_MAX); + spinBox->setMinimum(-std::numeric_limits::max()); + spinBox->setMaximum(std::numeric_limits::max()); spinBox->setButtonSymbols(QAbstractSpinBox::NoButtons); spinBox->setKeyboardTracking(false); spinBox->setFocusPolicy(Qt::ClickFocus); // prevent passing focus with tab. diff --git a/src/Gui/InputField.cpp b/src/Gui/InputField.cpp index 0d432566a9..e53fc5d1c4 100644 --- a/src/Gui/InputField.cpp +++ b/src/Gui/InputField.cpp @@ -71,8 +71,8 @@ InputField::InputField(QWidget * parent) ExpressionWidget(), validInput(true), actUnitValue(0), - Maximum(DOUBLE_MAX), - Minimum(-DOUBLE_MAX), + Maximum(std::numeric_limits::max()), + Minimum(-std::numeric_limits::max()), StepSize(1.0), HistorySize(5), SaveSize(5) diff --git a/src/Gui/Inventor/SoFCBackgroundGradient.cpp b/src/Gui/Inventor/SoFCBackgroundGradient.cpp index 37eb809127..323c18a91e 100644 --- a/src/Gui/Inventor/SoFCBackgroundGradient.cpp +++ b/src/Gui/Inventor/SoFCBackgroundGradient.cpp @@ -25,10 +25,8 @@ #ifndef _PreComp_ #include #include -#ifdef FC_OS_WIN32 - #define _USE_MATH_DEFINES -#endif #include +#include #ifdef FC_OS_MACOSX #include #else @@ -39,17 +37,23 @@ #include "SoFCBackgroundGradient.h" static const std::array big_circle = []{ - static const float pi2 = boost::math::constants::two_pi(); + constexpr float pi = std::numbers::pi_v; + constexpr float sqrt2 = std::numbers::sqrt2_v; std::array result; int c = 0; - for (GLfloat i = 0; i < pi2; i += pi2 / 32, c++) { - result[c][0] = M_SQRT2*cosf(i); result[c][1] = M_SQRT2*sinf(i); + for (GLfloat i = 0; i < 2 * pi; i += 2 * pi / 32, c++) { + result[c][0] = sqrt2 * cosf(i); + result[c][1] = sqrt2 * sinf(i); } return result; }(); static const std::array small_oval = []{ - static const float pi2 = boost::math::constants::two_pi(); + constexpr float pi = std::numbers::pi_v; + constexpr float sqrt2 = std::numbers::sqrt2_v; + static const float sqrt1_2 = std::sqrt(1 / 2.F); + std::array result; int c = 0; - for (GLfloat i = 0; i < pi2; i += pi2 / 32, c++) { - result[c][0] = 0.3*M_SQRT2*cosf(i); result[c][1] = M_SQRT1_2*sinf(i); + for (GLfloat i = 0; i < 2 * pi; i += 2 * pi / 32, c++) { + result[c][0] = 0.3 * sqrt2 * cosf(i); + result[c][1] = sqrt1_2 * sinf(i); } return result; }(); diff --git a/src/Gui/NaviCube.cpp b/src/Gui/NaviCube.cpp index 2780fdc703..5cff61a54d 100644 --- a/src/Gui/NaviCube.cpp +++ b/src/Gui/NaviCube.cpp @@ -23,7 +23,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ # include -# include +# include # ifdef FC_OS_WIN32 # include # 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)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(); - static const float pi1_2 = boost::math::constants::half_pi(); + constexpr float pi = std::numbers::pi_v; + 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(); - static const float pi2 = boost::math::constants::two_pi(); - static const float pi1_2 = boost::math::constants::half_pi(); - static const float pi1_3 = boost::math::constants::third_pi(); - static const float pi2_3 = boost::math::constants::two_thirds_pi(); + constexpr float pi = std::numbers::pi_v; // 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 diff --git a/src/Gui/Navigation/NavigationAnimation.cpp b/src/Gui/Navigation/NavigationAnimation.cpp index 943af87706..29b0529006 100644 --- a/src/Gui/Navigation/NavigationAnimation.cpp +++ b/src/Gui/Navigation/NavigationAnimation.cpp @@ -25,6 +25,8 @@ #include "NavigationAnimation.h" #include +#include + using namespace Gui; NavigationAnimation::NavigationAnimation(NavigationStyle* navigation) @@ -69,8 +71,8 @@ void FixedTimeAnimation::initialize() SbVec3f rotationAxisPost; float angle; SbRotation(navigation->getCamera()->orientation.getValue().inverse() * targetOrientation).getValue(rotationAxisPost, angle); - if (angle > M_PI) { - angle -= float(2 * M_PI); + if (angle > std::numbers::pi) { + angle -= float(2 * std::numbers::pi); } // Convert post-multiplication axis to a pre-multiplication axis @@ -130,9 +132,9 @@ SpinningAnimation::SpinningAnimation(NavigationStyle* navigation, const SbVec3f& : NavigationAnimation(navigation) , rotationAxis(axis) { - setDuration((2 * M_PI / velocity) * 1000.0); + setDuration((2 * std::numbers::pi / velocity) * 1000.0); setStartValue(0.0); - setEndValue(2 * M_PI); + setEndValue(2 * std::numbers::pi); setLoopCount(-1); } diff --git a/src/Gui/Navigation/NavigationStyle.cpp b/src/Gui/Navigation/NavigationStyle.cpp index 3f48db267d..9a0e3fca08 100644 --- a/src/Gui/Navigation/NavigationStyle.cpp +++ b/src/Gui/Navigation/NavigationStyle.cpp @@ -39,6 +39,9 @@ # include #endif +#include +#include + #include #include @@ -719,7 +722,8 @@ void NavigationStyle::zoom(SoCamera * cam, float diffvalue) const float distorigo = newpos.length(); // sqrt(FLT_MAX) == ~ 1e+19, which should be both safe for further // calculations and ok for the end-user and app-programmer. - if (distorigo > float(sqrt(FLT_MAX))) { + float maxDistance = std::sqrt(std::numeric_limits::max()); + if (distorigo > maxDistance) { // do nothing here } else { diff --git a/src/Gui/OverlayManager.cpp b/src/Gui/OverlayManager.cpp index f7b437e54b..41cb897bc8 100644 --- a/src/Gui/OverlayManager.cpp +++ b/src/Gui/OverlayManager.cpp @@ -1819,7 +1819,7 @@ bool OverlayManager::eventFilter(QObject *o, QEvent *ev) } if (hit <= 0) { - d->_lastPos.setX(INT_MAX); + d->_lastPos.setX(std::numeric_limits::max()); if (ev->type() == QEvent::Wheel) { d->wheelDelay = QTime::currentTime().addMSecs(OverlayParams::getDockOverlayWheelDelay()); d->wheelPos = pos; diff --git a/src/Gui/PreCompiled.h b/src/Gui/PreCompiled.h index c3a5f43345..c665016cf7 100644 --- a/src/Gui/PreCompiled.h +++ b/src/Gui/PreCompiled.h @@ -50,8 +50,6 @@ #include #include #include -#include -#include #ifdef FC_OS_WIN32 #include @@ -69,6 +67,7 @@ #include #include #include +#include #include #include #include diff --git a/src/Gui/PreferencePages/DlgSettingsCacheDirectory.cpp b/src/Gui/PreferencePages/DlgSettingsCacheDirectory.cpp index 0c395195e6..9e5bd6b5ba 100644 --- a/src/Gui/PreferencePages/DlgSettingsCacheDirectory.cpp +++ b/src/Gui/PreferencePages/DlgSettingsCacheDirectory.cpp @@ -182,7 +182,7 @@ void ApplicationCache::setPeriod(ApplicationCache::Period period) numDays = 365; break; case Period::Never: - numDays = INT_MAX; + numDays = std::numeric_limits::max(); break; } } diff --git a/src/Gui/PreferencePages/DlgSettingsDocumentImp.cpp b/src/Gui/PreferencePages/DlgSettingsDocumentImp.cpp index 4297531a3f..cb352c303f 100644 --- a/src/Gui/PreferencePages/DlgSettingsDocumentImp.cpp +++ b/src/Gui/PreferencePages/DlgSettingsDocumentImp.cpp @@ -60,7 +60,7 @@ DlgSettingsDocumentImp::DlgSettingsDocumentImp(QWidget* parent) ui->prefSaveBackupDateFormat->setToolTip(tip); ui->FormatTimeDocsLabel->setText(link); - ui->prefCountBackupFiles->setMaximum(INT_MAX); + ui->prefCountBackupFiles->setMaximum(std::numeric_limits::max()); ui->prefCompression->setMinimum(Z_NO_COMPRESSION); ui->prefCompression->setMaximum(Z_BEST_COMPRESSION); connect(ui->prefLicenseType, qOverload(&QComboBox::currentIndexChanged), diff --git a/src/Gui/QuantitySpinBox.cpp b/src/Gui/QuantitySpinBox.cpp index abfbb04e34..cc18e8be11 100644 --- a/src/Gui/QuantitySpinBox.cpp +++ b/src/Gui/QuantitySpinBox.cpp @@ -66,8 +66,8 @@ public: pendingEmit(false), checkRangeInExpression(false), unitValue(0), - maximum(DOUBLE_MAX), - minimum(-DOUBLE_MAX), + maximum(std::numeric_limits::max()), + minimum(-std::numeric_limits::max()), singleStep(1.0), q_ptr(q) { diff --git a/src/Gui/Quarter/SoQTQuarterAdaptor.cpp b/src/Gui/Quarter/SoQTQuarterAdaptor.cpp index ecfbf9a142..e98bd2d77f 100644 --- a/src/Gui/Quarter/SoQTQuarterAdaptor.cpp +++ b/src/Gui/Quarter/SoQTQuarterAdaptor.cpp @@ -20,6 +20,8 @@ #include "PreCompiled.h" +#include + #include #include #include @@ -303,7 +305,7 @@ void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::convertOrtho2Perspective(const So SbRotation camrot = in->orientation.getValue(); - float focaldist = float(in->height.getValue() / (2.0*tan(M_PI / 8.0))); // NOLINT + float focaldist = float(in->height.getValue() / (2.0*tan(std::numbers::pi / 8.0))); // NOLINT SbVec3f offset(0,0,focaldist-in->focalDistance.getValue()); @@ -313,7 +315,7 @@ void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::convertOrtho2Perspective(const So out->focalDistance.setValue(focaldist); // 45° is the default value of this field in SoPerspectiveCamera. - out->heightAngle = (float)(M_PI / 4.0); // NOLINT + out->heightAngle = (float)(std::numbers::pi / 4.0); // NOLINT } void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::convertPerspective2Ortho(const SoPerspectiveCamera* in, @@ -568,7 +570,7 @@ void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::seeksensorCB(void* data, SoSensor bool end = (par == 1.0F); - par = (float)((1.0 - cos(M_PI * par)) * 0.5); // NOLINT + par = (float)((1.0 - cos(std::numbers::pi * par)) * 0.5); // NOLINT thisp->getSoRenderManager()->getCamera()->position = thisp->m_camerastartposition + (thisp->m_cameraendposition - thisp->m_camerastartposition) * par; diff --git a/src/Gui/Selection/SelectionFilter.h b/src/Gui/Selection/SelectionFilter.h index 90d3430bb7..563acd90af 100644 --- a/src/Gui/Selection/SelectionFilter.h +++ b/src/Gui/Selection/SelectionFilter.h @@ -172,8 +172,9 @@ private: struct Node_Slice { - explicit Node_Slice(int min=1,int max=INT_MAX):Min(min),Max(max){} - int Min,Max; + explicit Node_Slice(int min = 1, int max = std::numeric_limits::max()) + : Min(min), Max(max) {} + int Min, Max; }; diff --git a/src/Gui/Selection/SoFCSelectionContext.h b/src/Gui/Selection/SoFCSelectionContext.h index 3d92e00b1a..d9cb345bbf 100644 --- a/src/Gui/Selection/SoFCSelectionContext.h +++ b/src/Gui/Selection/SoFCSelectionContext.h @@ -23,7 +23,6 @@ #ifndef GUI_SOFCSELECTIONCONTEXT_H #define GUI_SOFCSELECTIONCONTEXT_H -#include #include #include #include @@ -79,11 +78,11 @@ struct GuiExport SoFCSelectionContext : SoFCSelectionContextBase } bool isHighlightAll() const{ - return highlightIndex==INT_MAX && (selectionIndex.empty() || isSelectAll()); + return highlightIndex == std::numeric_limits::max() && (selectionIndex.empty() || isSelectAll()); } void highlightAll() { - highlightIndex = INT_MAX; + highlightIndex = std::numeric_limits::max(); } void removeHighlight() { diff --git a/src/Gui/ShortcutManager.cpp b/src/Gui/ShortcutManager.cpp index c7103f7c7a..2f49e8fd7d 100644 --- a/src/Gui/ShortcutManager.cpp +++ b/src/Gui/ShortcutManager.cpp @@ -409,7 +409,7 @@ void ShortcutManager::onTimer() timer.stop(); QAction *found = nullptr; - int priority = -INT_MAX; + int priority = -std::numeric_limits::max(); int seq_length = 0; for (const auto &info : pendingActions) { if (info.action) { diff --git a/src/Gui/SoDatumLabel.cpp b/src/Gui/SoDatumLabel.cpp index fff3978b6f..978a7721a1 100644 --- a/src/Gui/SoDatumLabel.cpp +++ b/src/Gui/SoDatumLabel.cpp @@ -34,8 +34,8 @@ # endif # include -# include # include +# include # include # include @@ -78,11 +78,12 @@ void glDrawLine(const SbVec3f& p1, const SbVec3f& p2){ glEnd(); } -void glDrawArc(const SbVec3f& center, float radius, float startAngle=0., float endAngle=2.0*M_PI, int countSegments=0){ +void glDrawArc(const SbVec3f& center, float radius, float startAngle=0., + float endAngle=2.0*std::numbers::pi, int countSegments=0){ float range = endAngle - startAngle; if (countSegments == 0){ - countSegments = std::max(6, abs(int(25.0 * range / M_PI))); + countSegments = std::max(6, abs(int(25.0 * range / std::numbers::pi))); } float segment = range / (countSegments-1); @@ -238,11 +239,12 @@ public: private: void getBBox(const std::vector& corners, SbBox3f& box, SbVec3f& center) const { + constexpr float floatMax = std::numeric_limits::max(); if (corners.size() > 1) { - float minX = FLT_MAX; - float minY = FLT_MAX; - float maxX = -FLT_MAX; - float maxY = -FLT_MAX; + float minX = floatMax; + float minY = floatMax; + float maxX = -floatMax; + float maxY = -floatMax; for (SbVec3f it : corners) { minX = (it[0] < minX) ? it[0] : minX; minY = (it[1] < minY) ? it[1] : minY; @@ -288,14 +290,15 @@ private: SbVec3f dir; SbVec3f normal; + constexpr float floatEpsilon = std::numeric_limits::epsilon(); if (label->datumtype.getValue() == SoDatumLabel::DISTANCE) { dir = (p2-p1); } else if (label->datumtype.getValue() == SoDatumLabel::DISTANCEX) { - dir = SbVec3f( (p2[0] - p1[0] >= FLT_EPSILON) ? 1 : -1, 0, 0); + dir = SbVec3f( (p2[0] - p1[0] >= floatEpsilon) ? 1 : -1, 0, 0); } else if (label->datumtype.getValue() == SoDatumLabel::DISTANCEY) { - dir = SbVec3f(0, (p2[1] - p1[1] >= FLT_EPSILON) ? 1 : -1, 0); + dir = SbVec3f(0, (p2[1] - p1[1] >= floatEpsilon) ? 1 : -1, 0); } dir.normalize(); @@ -546,11 +549,11 @@ private: float startangle = atan2f(vc1[1], vc1[0]); float endangle = atan2f(vc2[1], vc2[0]); if (endangle < startangle) { - endangle += 2. * M_PI; + endangle += 2. * std::numbers::pi; } SbVec3f textCenter; - if (endangle - startangle <= M_PI) { + if (endangle - startangle <= std::numbers::pi) { textCenter = ctr + vm * (length + imgHeight); } else { textCenter = ctr - vm * (length + 2. * imgHeight); @@ -628,14 +631,16 @@ SbVec3f SoDatumLabel::getLabelTextCenterDistance(const SbVec3f& p1, const SbVec3 SbVec3f dir; SbVec3f normal; + + constexpr float floatEpsilon = std::numeric_limits::epsilon(); if (datumtype.getValue() == SoDatumLabel::DISTANCE) { dir = (p2 - p1); } else if (datumtype.getValue() == SoDatumLabel::DISTANCEX) { - dir = SbVec3f((p2[0] - p1[0] >= FLT_EPSILON) ? 1 : -1, 0, 0); + dir = SbVec3f((p2[0] - p1[0] >= floatEpsilon) ? 1 : -1, 0, 0); } else if (datumtype.getValue() == SoDatumLabel::DISTANCEY) { - dir = SbVec3f(0, (p2[1] - p1[1] >= FLT_EPSILON) ? 1 : -1, 0); + dir = SbVec3f(0, (p2[1] - p1[1] >= floatEpsilon) ? 1 : -1, 0); } dir.normalize(); @@ -689,7 +694,7 @@ SbVec3f SoDatumLabel::getLabelTextCenterArcLength(const SbVec3f& ctr, const SbVe float endangle = atan2f(vc2[1], vc2[0]); if (endangle < startangle) { - endangle += 2. * M_PI; + endangle += 2. * std::numbers::pi; } // Text location @@ -697,7 +702,7 @@ SbVec3f SoDatumLabel::getLabelTextCenterArcLength(const SbVec3f& ctr, const SbVe vm.normalize(); SbVec3f textCenter; - if (endangle - startangle <= M_PI) { + if (endangle - startangle <= std::numbers::pi) { textCenter = ctr + vm * (length + this->imgHeight); } else { textCenter = ctr - vm * (length + 2. * this->imgHeight); @@ -709,12 +714,13 @@ SbVec3f SoDatumLabel::getLabelTextCenterArcLength(const SbVec3f& ctr, const SbVe void SoDatumLabel::generateDistancePrimitives(SoAction * action, const SbVec3f& p1, const SbVec3f& p2) { SbVec3f dir; + constexpr float floatEpsilon = std::numeric_limits::epsilon(); if (this->datumtype.getValue() == DISTANCE) { dir = (p2-p1); } else if (this->datumtype.getValue() == DISTANCEX) { - dir = SbVec3f( (p2[0] - p1[0] >= FLT_EPSILON) ? 1 : -1, 0, 0); + dir = SbVec3f( (p2[0] - p1[0] >= floatEpsilon) ? 1 : -1, 0, 0); } else if (this->datumtype.getValue() == DISTANCEY) { - dir = SbVec3f(0, (p2[1] - p1[1] >= FLT_EPSILON) ? 1 : -1, 0); + dir = SbVec3f(0, (p2[1] - p1[1] >= floatEpsilon) ? 1 : -1, 0); } dir.normalize(); @@ -957,7 +963,8 @@ void SoDatumLabel::generateArcLengthPrimitives(SoAction * action, const SbVec3f& void SoDatumLabel::generatePrimitives(SoAction * action) { // Initialisation check (needs something more sensible) prevents an infinite loop bug - if (this->imgHeight <= FLT_EPSILON || this->imgWidth <= FLT_EPSILON) { + constexpr float floatEpsilon = std::numeric_limits::epsilon(); + if (this->imgHeight <= floatEpsilon | this->imgWidth <= floatEpsilon) { return; } @@ -1161,6 +1168,8 @@ void SoDatumLabel::getDimension(float scale, int& srcw, int& srch) void SoDatumLabel::drawDistance(const SbVec3f* points, float scale, int srch, float& angle, SbVec3f& textOffset) { + using std::numbers::pi; + float length = this->param1.getValue(); float length2 = this->param2.getValue(); @@ -1168,12 +1177,13 @@ void SoDatumLabel::drawDistance(const SbVec3f* points, float scale, int srch, fl SbVec3f p2 = points[1]; SbVec3f dir; + constexpr float floatEpsilon = std::numeric_limits::epsilon(); if (this->datumtype.getValue() == DISTANCE) { dir = (p2-p1); } else if (this->datumtype.getValue() == DISTANCEX) { - dir = SbVec3f( (p2[0] - p1[0] >= FLT_EPSILON) ? 1 : -1, 0, 0); + dir = SbVec3f( (p2[0] - p1[0] >= floatEpsilon) ? 1 : -1, 0, 0); } else if (this->datumtype.getValue() == DISTANCEY) { - dir = SbVec3f(0, (p2[1] - p1[1] >= FLT_EPSILON) ? 1 : -1, 0); + dir = SbVec3f(0, (p2[1] - p1[1] >= floatEpsilon) ? 1 : -1, 0); } dir.normalize(); @@ -1192,10 +1202,10 @@ void SoDatumLabel::drawDistance(const SbVec3f* points, float scale, int srch, fl // Get magnitude of angle between horizontal angle = atan2f(dir[1],dir[0]); - if (angle > M_PI_2+M_PI/12) { - angle -= (float)M_PI; - } else if (angle <= -M_PI_2+M_PI/12) { - angle += (float)M_PI; + if (angle > pi/2 + pi/12) { + angle -= (float)pi; + } else if (angle <= -pi/2 + pi/12) { + angle += (float)pi; } textOffset = midpos + normal * length + dir * length2; @@ -1291,7 +1301,7 @@ void SoDatumLabel::drawDistance(const SbVec3f* points) float startangle1 = this->param3.getValue(); float radius1 = this->param5.getValue(); SbVec3f center = points[2]; - int countSegments = std::max(6, abs(int(50.0 * range1 / (2 * M_PI)))); + int countSegments = std::max(6, abs(int(50.0 * range1 / (2 * std::numbers::pi)))); double segment = range1 / (countSegments - 1); glBegin(GL_LINE_STRIP); @@ -1307,7 +1317,7 @@ void SoDatumLabel::drawDistance(const SbVec3f* points) float startangle2 = this->param6.getValue(); float radius2 = this->param8.getValue(); SbVec3f center = points[3]; - int countSegments = std::max(6, abs(int(50.0 * range2 / (2 * M_PI)))); + int countSegments = std::max(6, abs(int(50.0 * range2 / (2 * std::numbers::pi)))); double segment = range2 / (countSegments - 1); glBegin(GL_LINE_STRIP); @@ -1342,10 +1352,10 @@ void SoDatumLabel::drawRadiusOrDiameter(const SbVec3f* points, float& angle, SbV // Get magnitude of angle between horizontal angle = atan2f(dir[1],dir[0]); - if (angle > M_PI_2+M_PI/12) { - angle -= (float)M_PI; - } else if (angle <= -M_PI_2+M_PI/12) { - angle += (float)M_PI; + if (angle > std::numbers::pi/2 + std::numbers::pi/12) { + angle -= (float)std::numbers::pi; + } else if (angle <= -std::numbers::pi/2 + std::numbers::pi/12) { + angle += (float)std::numbers::pi; } textOffset = pos; @@ -1401,7 +1411,7 @@ void SoDatumLabel::drawRadiusOrDiameter(const SbVec3f* points, float& angle, SbV float startangle = this->param3.getValue(); float range = this->param4.getValue(); if (range != 0.0) { - int countSegments = std::max(6, abs(int(50.0 * range / (2 * M_PI)))); + int countSegments = std::max(6, abs(int(50.0 * range / (2 * std::numbers::pi)))); double segment = range / (countSegments - 1); glBegin(GL_LINE_STRIP); @@ -1521,6 +1531,8 @@ void SoDatumLabel::drawSymmetric(const SbVec3f* points) void SoDatumLabel::drawArcLength(const SbVec3f* points, float& angle, SbVec3f& textOffset) { + using std::numbers::pi; + SbVec3f ctr = points[0]; SbVec3f p1 = points[1]; SbVec3f p2 = points[2]; @@ -1535,7 +1547,7 @@ void SoDatumLabel::drawArcLength(const SbVec3f* points, float& angle, SbVec3f& t float startangle = atan2f(vc1[1], vc1[0]); float endangle = atan2f(vc2[1], vc2[0]); if (endangle < startangle) { - endangle += 2.0F * (float)M_PI; + endangle += 2.0F * (float)pi; } float range = endangle - startangle; @@ -1547,10 +1559,10 @@ void SoDatumLabel::drawArcLength(const SbVec3f* points, float& angle, SbVec3f& t dir.normalize(); // Get magnitude of angle between horizontal angle = atan2f(dir[1],dir[0]); - if (angle > M_PI_2+M_PI/12) { - angle -= (float)M_PI; - } else if (angle <= -M_PI_2+M_PI/12) { - angle += (float)M_PI; + if (angle > pi/2 + pi/12) { + angle -= (float)pi; + } else if (angle <= -pi/2 + pi/12) { + angle += (float)pi; } // Text location textOffset = getLabelTextCenterArcLength(ctr, p1, p2); @@ -1566,7 +1578,7 @@ void SoDatumLabel::drawArcLength(const SbVec3f* points, float& angle, SbVec3f& t SbVec3f pnt4 = p2 + (length-radius) * vm; // Draw arc - if (range <= M_PI) { + if (range <= pi) { glDrawArc(ctr + (length-radius)*vm, radius, startangle, endangle); } else { @@ -1606,7 +1618,7 @@ void SoDatumLabel::drawText(SoState *state, int srcw, int srch, float angle, con const SbViewVolume & vv = SoViewVolumeElement::get(state); SbVec3f z = vv.zVector(); - bool flip = norm.getValue().dot(z) > FLT_EPSILON; + bool flip = norm.getValue().dot(z) > std::numeric_limits::epsilon(); static bool init = false; static bool npot = false; @@ -1678,7 +1690,7 @@ void SoDatumLabel::drawText(SoState *state, int srcw, int srch, float angle, con // Apply a rotation and translation matrix glTranslatef(textOffset[0], textOffset[1], textOffset[2]); - glRotatef((GLfloat) angle * 180 / M_PI, 0,0,1); + glRotatef((GLfloat) angle * 180 / std::numbers::pi, 0,0,1); glBegin(GL_QUADS); glColor3f(1.F, 1.F, 1.F); diff --git a/src/Gui/SoFCCSysDragger.cpp b/src/Gui/SoFCCSysDragger.cpp index 39130d3b9e..21142b5def 100644 --- a/src/Gui/SoFCCSysDragger.cpp +++ b/src/Gui/SoFCCSysDragger.cpp @@ -23,6 +23,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ #include +#include #include #include @@ -743,7 +744,7 @@ RDragger::RDragger() } SO_KIT_ADD_FIELD(rotation, (SbVec3f(0.0, 0.0, 1.0), 0.0)); - SO_KIT_ADD_FIELD(rotationIncrement, (M_PI / 8.0)); + SO_KIT_ADD_FIELD(rotationIncrement, (std::numbers::pi / 8.0)); SO_KIT_ADD_FIELD(rotationIncrementCount, (0)); SO_KIT_INIT_INSTANCE(); @@ -808,7 +809,7 @@ SoGroup* RDragger::buildGeometry() unsigned int segments = 15; - float angleIncrement = static_cast(M_PI / 2.0) / static_cast(segments); + float angleIncrement = (std::numbers::pi_v / 2.f) / static_cast(segments); SbRotation rotation(SbVec3f(0.0, 0.0, 1.0), angleIncrement); SbVec3f point(arcRadius, 0.0, 0.0); for (unsigned int index = 0; index <= segments; ++index) { @@ -965,9 +966,10 @@ void RDragger::drag() appendRotation(getStartMotionMatrix(), localRotation, SbVec3f(0.0, 0.0, 0.0))); } - Base::Quantity quantity(static_cast(rotationIncrementCount.getValue()) * (180.0 / M_PI) - * rotationIncrement.getValue(), - Base::Unit::Angle); + Base::Quantity quantity( + static_cast(rotationIncrementCount.getValue()) + * (180.0 / std::numbers::pi)* rotationIncrement.getValue(), + Base::Unit::Angle); QString message = QStringLiteral("%1 %2").arg(QObject::tr("Rotation:"), QString::fromStdString(quantity.getUserString())); @@ -1179,7 +1181,7 @@ SoFCCSysDragger::SoFCCSysDragger() SO_KIT_ADD_FIELD(translationIncrementCountZ, (0)); SO_KIT_ADD_FIELD(rotation, (SbVec3f(0.0, 0.0, 1.0), 0.0)); - SO_KIT_ADD_FIELD(rotationIncrement, (M_PI / 8.0)); + SO_KIT_ADD_FIELD(rotationIncrement, (std::numbers::pi / 8.0)); SO_KIT_ADD_FIELD(rotationIncrementCountX, (0)); SO_KIT_ADD_FIELD(rotationIncrementCountY, (0)); SO_KIT_ADD_FIELD(rotationIncrementCountZ, (0)); @@ -1272,7 +1274,7 @@ SoFCCSysDragger::SoFCCSysDragger() SoRotation* localRotation; SbRotation tempRotation; - auto angle = static_cast(M_PI / 2.0); + auto angle = static_cast(std::numbers::pi / 2.0); // Translator localRotation = SO_GET_ANY_PART(this, "xTranslatorRotation", SoRotation); localRotation->rotation.setValue(SbVec3f(0.0, 0.0, -1.0), angle); diff --git a/src/Gui/SoTextLabel.cpp b/src/Gui/SoTextLabel.cpp index 6e533bea98..07f0839d04 100644 --- a/src/Gui/SoTextLabel.cpp +++ b/src/Gui/SoTextLabel.cpp @@ -31,7 +31,6 @@ # else # include # endif -# include # include # include # include diff --git a/src/Gui/SoTouchEvents.cpp b/src/Gui/SoTouchEvents.cpp index 628fb089c3..8b99c606e8 100644 --- a/src/Gui/SoTouchEvents.cpp +++ b/src/Gui/SoTouchEvents.cpp @@ -22,6 +22,8 @@ #include "PreCompiled.h" +#include + #include #include #include @@ -86,8 +88,8 @@ SoGesturePinchEvent::SoGesturePinchEvent(QPinchGesture* qpinch, QWidget *widget) deltaZoom = qpinch->scaleFactor(); totalZoom = qpinch->totalScaleFactor(); - deltaAngle = -unbranchAngle((qpinch->rotationAngle()-qpinch->lastRotationAngle()) / 180.0 * M_PI); - totalAngle = -qpinch->totalRotationAngle() / 180 * M_PI; + deltaAngle = -unbranchAngle((qpinch->rotationAngle()-qpinch->lastRotationAngle()) / 180.0 * std::numbers::pi); + totalAngle = -qpinch->totalRotationAngle() / 180 * std::numbers::pi; state = SbGestureState(qpinch->state()); @@ -111,7 +113,9 @@ SbBool SoGesturePinchEvent::isSoGesturePinchEvent(const SoEvent *ev) const */ double SoGesturePinchEvent::unbranchAngle(double ang) { - return ang - 2.0 * M_PI * floor((ang + M_PI) / (2.0 * M_PI)); + using std::numbers::pi; + + return ang - 2.0 * pi * floor((ang + pi) / (2.0 * pi)); } diff --git a/src/Gui/SpinBox.cpp b/src/Gui/SpinBox.cpp index 207ec81335..a4fdb99add 100644 --- a/src/Gui/SpinBox.cpp +++ b/src/Gui/SpinBox.cpp @@ -238,7 +238,7 @@ UnsignedValidator::UnsignedValidator( QObject * parent ) : QValidator( parent ) { b = 0; - t = UINT_MAX; + t = std::numeric_limits::max(); } UnsignedValidator::UnsignedValidator( uint minimum, uint maximum, QObject * parent ) @@ -295,27 +295,31 @@ public: uint mapToUInt( int v ) const { uint ui; - if ( v == INT_MIN ) { + if ( v == std::numeric_limits::min() ) { ui = 0; - } else if ( v == INT_MAX ) { - ui = UINT_MAX; + } else if ( v == std::numeric_limits::max() ) { + ui = std::numeric_limits::max(); } else if ( v < 0 ) { - v -= INT_MIN; ui = (uint)v; + v -= std::numeric_limits::min(); + ui = static_cast(v); } else { - ui = (uint)v; ui -= INT_MIN; + ui = static_cast(v); + ui -= std::numeric_limits::min(); } return ui; } int mapToInt( uint v ) const { int in; - if ( v == UINT_MAX ) { - in = INT_MAX; + if ( v == std::numeric_limits::max() ) { + in = std::numeric_limits::max(); } else if ( v == 0 ) { - in = INT_MIN; - } else if ( v > INT_MAX ) { - v += INT_MIN; in = (int)v; + in = std::numeric_limits::min(); + } else if ( v > std::numeric_limits::max() ) { + v += std::numeric_limits::min(); + in = static_cast(v); } else { - in = v; in += INT_MIN; + in = v; + in += std::numeric_limits::min(); } return in; } }; diff --git a/src/Gui/Transform.cpp b/src/Gui/Transform.cpp index e1d22d1105..b6b0e68b81 100644 --- a/src/Gui/Transform.cpp +++ b/src/Gui/Transform.cpp @@ -378,6 +378,7 @@ Base::Vector3d Transform::getDirection() const Base::Placement Transform::getPlacementData() const { + using std::numbers::pi; int index = ui->rotationInput->currentIndex(); Base::Rotation rot; Base::Vector3d pos; @@ -388,7 +389,7 @@ Base::Placement Transform::getPlacementData() const if (index == 0) { Base::Vector3d dir = getDirection(); - rot.setValue(Base::Vector3d(dir.x,dir.y,dir.z),ui->angle->value().getValue()*D_PI/180.0); + rot.setValue(Base::Vector3d(dir.x,dir.y,dir.z),ui->angle->value().getValue()*pi/180.0); } else if (index == 1) { rot.setYawPitchRoll( diff --git a/src/Gui/VectorListEditor.cpp b/src/Gui/VectorListEditor.cpp index 9450145b7f..0e432920d1 100644 --- a/src/Gui/VectorListEditor.cpp +++ b/src/Gui/VectorListEditor.cpp @@ -255,8 +255,8 @@ QWidget *VectorTableDelegate::createEditor(QWidget *parent, const QStyleOptionVi { auto editor = new QDoubleSpinBox(parent); editor->setDecimals(decimals); - editor->setMinimum(INT_MIN); - editor->setMaximum(INT_MAX); + editor->setMinimum(std::numeric_limits::min()); + editor->setMaximum(std::numeric_limits::max()); editor->setSingleStep(0.1); return editor; @@ -299,11 +299,14 @@ VectorListEditor::VectorListEditor(int decimals, QWidget* parent) ui->tableWidget->setModel(model); ui->widget->hide(); - ui->coordX->setRange(INT_MIN, INT_MAX); + ui->coordX->setRange(std::numeric_limits::min(), + std::numeric_limits::max()); ui->coordX->setDecimals(decimals); - ui->coordY->setRange(INT_MIN, INT_MAX); + ui->coordY->setRange(std::numeric_limits::min(), + std::numeric_limits::max()); ui->coordY->setDecimals(decimals); - ui->coordZ->setRange(INT_MIN, INT_MAX); + ui->coordZ->setRange(std::numeric_limits::min(), + std::numeric_limits::max()); ui->coordZ->setDecimals(decimals); ui->toolButtonMouse->setDisabled(true); diff --git a/src/Gui/View3DInventorRiftViewer.cpp b/src/Gui/View3DInventorRiftViewer.cpp index 7dc8c49a62..3dd1a92647 100644 --- a/src/Gui/View3DInventorRiftViewer.cpp +++ b/src/Gui/View3DInventorRiftViewer.cpp @@ -43,7 +43,7 @@ View3DInventorRiftViewer::View3DInventorRiftViewer() : CoinRiftWidget() rotation1 = new SoRotationXYZ ; rotation1->axis.setValue(SoRotationXYZ::X); - rotation1->angle.setValue(-M_PI/2); + rotation1->angle.setValue(-std::numbers::pi/2); workplace->addChild(rotation1); rotation2 = new SoRotationXYZ ; @@ -104,7 +104,7 @@ void View3DInventorRiftViewer::setSceneGraph(SoNode *sceneGraph) void View3DInventorRiftViewer::keyPressEvent(QKeyEvent *event) { static const float increment = 0.02; // move two centimeter per key - static const float rotIncrement = M_PI/4; // move two 90° per key + static const float rotIncrement = std::numbers::pi / 4; // move two 90° per key if (event->key() == Qt::Key_Plus) { diff --git a/src/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp index 3103b1afde..819cce36ab 100644 --- a/src/Gui/View3DInventorViewer.cpp +++ b/src/Gui/View3DInventorViewer.cpp @@ -23,7 +23,6 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include # ifdef FC_OS_WIN32 # include # 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(cam)->heightAngle = (float)(M_PI / 4.0); // NOLINT + static_cast(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(cam)->heightAngle = (float)(M_PI / 4.0); // NOLINT + static_cast(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); diff --git a/src/Gui/View3DPy.cpp b/src/Gui/View3DPy.cpp index b99918ddba..dab66a874b 100644 --- a/src/Gui/View3DPy.cpp +++ b/src/Gui/View3DPy.cpp @@ -658,7 +658,7 @@ Py::Object View3DInventorPy::viewRotateLeft() SbRotation rot = cam->orientation.getValue(); SbVec3f vdir(0, 0, -1); rot.multVec(vdir, vdir); - SbRotation nrot(vdir, (float)M_PI/2); + SbRotation nrot(vdir, (float)std::numbers::pi/2); cam->orientation.setValue(rot*nrot); } catch (const Base::Exception& e) { @@ -681,7 +681,7 @@ Py::Object View3DInventorPy::viewRotateRight() SbRotation rot = cam->orientation.getValue(); SbVec3f vdir(0, 0, -1); rot.multVec(vdir, vdir); - SbRotation nrot(vdir, (float)-M_PI/2); + SbRotation nrot(vdir, (float)-std::numbers::pi/2); cam->orientation.setValue(rot*nrot); } catch (const Base::Exception& e) { diff --git a/src/Gui/ViewProviderAnnotation.cpp b/src/Gui/ViewProviderAnnotation.cpp index c1cb67e3ce..6d04cd2bfa 100644 --- a/src/Gui/ViewProviderAnnotation.cpp +++ b/src/Gui/ViewProviderAnnotation.cpp @@ -155,7 +155,7 @@ void ViewProviderAnnotation::onChanged(const App::Property* prop) } } else if (prop == &Rotation) { - pRotationXYZ->angle = (Rotation.getValue()/360)*(2*M_PI); + pRotationXYZ->angle = (Rotation.getValue()/360)*(2*std::numbers::pi); } else { ViewProviderDocumentObject::onChanged(prop); diff --git a/src/Gui/propertyeditor/PropertyItem.cpp b/src/Gui/propertyeditor/PropertyItem.cpp index e07d3fdf20..94bbd659f7 100644 --- a/src/Gui/propertyeditor/PropertyItem.cpp +++ b/src/Gui/propertyeditor/PropertyItem.cpp @@ -968,7 +968,8 @@ QWidget* PropertyIntegerItem::createEditor(QWidget* parent, void PropertyIntegerItem::setEditorData(QWidget* editor, const QVariant& data) const { auto sb = qobject_cast(editor); - sb->setRange(INT_MIN, INT_MAX); + sb->setRange(std::numeric_limits::min(), + std::numeric_limits::max()); sb->setValue(data.toInt()); } @@ -1128,7 +1129,8 @@ QWidget* PropertyFloatItem::createEditor(QWidget* parent, const std::function(editor); - sb->setRange((double)INT_MIN, (double)INT_MAX); + sb->setRange(static_cast(std::numeric_limits::min()), + static_cast(std::numeric_limits::max())); sb->setValue(data.toDouble()); } diff --git a/src/Gui/propertyeditor/PropertyItem.h b/src/Gui/propertyeditor/PropertyItem.h index c27300cadb..b8182c4fd8 100644 --- a/src/Gui/propertyeditor/PropertyItem.h +++ b/src/Gui/propertyeditor/PropertyItem.h @@ -360,8 +360,8 @@ protected: PropertyIntegerConstraintItem(); private: - int min = INT_MIN; - int max = INT_MAX; + int min = std::numeric_limits::min(); + int max = std::numeric_limits::max(); int steps = 1; }; @@ -434,8 +434,8 @@ protected: PropertyUnitConstraintItem(); private: - double min = double(INT_MIN); - double max = double(INT_MAX); + double min = static_cast(std::numeric_limits::min()); + double max = static_cast(std::numeric_limits::max()); double steps = 0.1; }; @@ -472,8 +472,8 @@ protected: PropertyFloatConstraintItem(); private: - double min = double(INT_MIN); - double max = double(INT_MAX); + double min = static_cast(std::numeric_limits::min()); + double max = static_cast(std::numeric_limits::max()); double steps = 0.1; }; diff --git a/src/Gui/propertyeditor/PropertyModel.cpp b/src/Gui/propertyeditor/PropertyModel.cpp index bb5e565f8d..aa93d2563a 100644 --- a/src/Gui/propertyeditor/PropertyModel.cpp +++ b/src/Gui/propertyeditor/PropertyModel.cpp @@ -96,7 +96,7 @@ bool PropertyModel::setData(const QModelIndex& index, const QVariant& value, int // now? double d = data.toDouble(); double v = value.toDouble(); - if (fabs(d - v) > DBL_EPSILON) { + if (fabs(d - v) > std::numeric_limits::epsilon()) { return item->setData(value); } }