portability: replace M_PI / std::numbers::pi with a host+device-safe PI

M_PI is a POSIX <math.h> extension that MSVC does not define without
_USE_MATH_DEFINES. std::numbers::pi (introduced in the viewer guard commit) is
C++20, but CUDA here is compiled as C++17 (CMAKE_CUDA_STANDARD 17) and several
common/ headers are pulled into .cu device translation units, so std::numbers is
not available there.

Add common/JFJochMath.h with a dependency-free `constexpr double PI` that works
in host code (including MSVC), in CUDA device code, and under C++17/20, and use
it everywhere:
- common/ and image_analysis/ (incl. CUDA .cu): 78 M_PI occurrences, 22 files
- broker/OpenAPIConvert.cpp
- viewer/: the 5 files that used std::numbers::pi now use PI, for one consistent
  convention across the codebase

Verified to build: JFJochImageAnalysis (incl. CUDA), jfjoch_viewer, JFJochBroker.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-18 14:54:01 +02:00
co-authored by Claude Opus 4.8
parent d0a1175c65
commit 5d9e1be814
29 changed files with 120 additions and 87 deletions
+2 -2
View File
@@ -5,7 +5,7 @@
#include <QVBoxLayout>
#include "../../common/JFJochException.h"
#include <numbers>
#include "../../common/JFJochMath.h"
JFJochAzIntImage::JFJochAzIntImage(QWidget *parent)
: JFJochImage(parent) {
@@ -110,7 +110,7 @@ void JFJochAzIntImage::mouseDoubleClickEvent(QMouseEvent *event) {
float phi = image->Dataset().az_int_bin_to_phi[idx];
auto geom = image->Dataset().experiment.GetDiffractionGeometry();
auto coord = geom.ResPhiToPxl(2 * std::numbers::pi / q, phi / 180.0 * std::numbers::pi);
auto coord = geom.ResPhiToPxl(2 * PI / q, phi / 180.0 * PI);
emit zoomOnBin(QPointF(coord.first, coord.second));
}
}