Reuse constants
Change-Id: I306da23d26667e801cfa4fb12306cdd92af09a65
diff --git a/examples/nist.cc b/examples/nist.cc
index 48d5697..aa7a95b 100644
--- a/examples/nist.cc
+++ b/examples/nist.cc
@@ -1,5 +1,5 @@
// Ceres Solver - A fast non-linear least squares minimizer
-// Copyright 2023 Google Inc. All rights reserved.
+// Copyright 2025 Google Inc. All rights reserved.
// http://ceres-solver.org/
//
// Redistribution and use in source and binary forms, with or without
@@ -85,6 +85,7 @@
#include "absl/log/initialize.h"
#include "absl/log/log.h"
#include "ceres/ceres.h"
+#include "ceres/constants.h"
#include "ceres/tiny_solver.h"
#include "ceres/tiny_solver_cost_function_adapter.h"
@@ -423,8 +424,7 @@
b[0] * b[1] * x / (1.0 + b[1] * x)
NIST_END
-const double kPi = 3.141592653589793238462643383279;
-// pi = 3.141592653589793238462643383279E0
+constexpr double kPi = ceres::constants::pi;
// y = b1 - b2*x - arctan[b3/(x-b4)]/pi + e
NIST_BEGIN(Roszman1)
b[0] - b[1] * x - atan2(b[2], (x - b[3])) / kPi
diff --git a/include/ceres/rotation.h b/include/ceres/rotation.h
index 7c95172..ba7f66e 100644
--- a/include/ceres/rotation.h
+++ b/include/ceres/rotation.h
@@ -702,7 +702,7 @@
template <typename T, int row_stride, int col_stride>
void EulerAnglesToRotationMatrix(
const T* euler, const MatrixAdapter<T, row_stride, col_stride>& R) {
- const double kPi = 3.14159265358979323846;
+ const double kPi = constants::pi;
const T degrees_to_radians(kPi / 180.0);
const T pitch(euler[0] * degrees_to_radians);
diff --git a/internal/ceres/trust_region_minimizer_test.cc b/internal/ceres/trust_region_minimizer_test.cc
index ca28675..33a8f42 100644
--- a/internal/ceres/trust_region_minimizer_test.cc
+++ b/internal/ceres/trust_region_minimizer_test.cc
@@ -1,5 +1,5 @@
// Ceres Solver - A fast non-linear least squares minimizer
-// Copyright 2023 Google Inc. All rights reserved.
+// Copyright 2025 Google Inc. All rights reserved.
// http://ceres-solver.org/
//
// Redistribution and use in source and binary forms, with or without
@@ -41,6 +41,7 @@
#include "absl/log/check.h"
#include "absl/log/log.h"
#include "ceres/autodiff_cost_function.h"
+#include "ceres/constants.h"
#include "ceres/cost_function.h"
#include "ceres/dense_qr_solver.h"
#include "ceres/dense_sparse_matrix.h"
@@ -388,9 +389,8 @@
TEST(TrustRegionMinimizer, JacobiScalingTest) {
int N = 6;
std::vector<double*> y(N);
- const double pi = 3.1415926535897932384626433;
for (int i = 0; i < N; i++) {
- double theta = i * 2. * pi / static_cast<double>(N);
+ double theta = i * 2. * constants::pi / static_cast<double>(N);
y[i] = new double[2];
y[i][0] = cos(theta);
y[i][1] = sin(theta);