mirror of
https://github.com/ceres-solver/ceres-solver.git
synced 2026-08-29 08:34:37 +08:00
Drop use of POSIX M_PI
Change-Id: I37342a366161bb13d6456ecc67569fe12705e05c
This commit is contained in:
@@ -516,12 +516,6 @@ endif (MINGW)
|
||||
|
||||
# After the tweaks for the compile settings, disable some warnings on MSVC.
|
||||
if (MSVC)
|
||||
# On MSVC, math constants are not included in <cmath> or <math.h> unless
|
||||
# _USE_MATH_DEFINES is defined [1]. As we use M_PI in the examples, ensure
|
||||
# that _USE_MATH_DEFINES is defined before the first inclusion of <cmath>.
|
||||
#
|
||||
# [1] https://msdn.microsoft.com/en-us/library/4hwaceh6.aspx
|
||||
add_compile_definitions(_USE_MATH_DEFINES)
|
||||
# Insecure standard library functions
|
||||
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
|
||||
# std::numeric_limits<T>::has_denorm is deprecated in C++23
|
||||
|
||||
@@ -396,7 +396,7 @@ int main(int argc, char** argv) {
|
||||
//
|
||||
// Initialize `X` to points on the unit circle.
|
||||
VectorXd w(num_segments + 1);
|
||||
w.setLinSpaced(num_segments + 1, 0.0, 2.0 * M_PI);
|
||||
w.setLinSpaced(num_segments + 1, 0.0, 2.0 * ceres::constants::pi);
|
||||
w.conservativeResize(num_segments);
|
||||
MatrixXd X(num_segments, 2);
|
||||
X.col(0) = w.array().cos();
|
||||
|
||||
@@ -223,7 +223,7 @@ BEGIN_MGH_PROBLEM(TestProblem7, 3, 3)
|
||||
const T x1 = x[0];
|
||||
const T x2 = x[1];
|
||||
const T x3 = x[2];
|
||||
const T theta = (0.5 / M_PI) * atan(x2 / x1) + (x1 > 0.0 ? 0.0 : 0.5);
|
||||
const T theta = (0.5 / constants::pi) * atan(x2 / x1) + (x1 > 0.0 ? 0.0 : 0.5);
|
||||
residual[0] = 10.0 * (x3 - 10.0 * theta);
|
||||
residual[1] = 10.0 * (sqrt(x1 * x1 + x2 * x2) - 1.0);
|
||||
residual[2] = x3;
|
||||
|
||||
@@ -41,9 +41,9 @@ namespace ceres::examples {
|
||||
template <typename T>
|
||||
inline T NormalizeAngle(const T& angle_radians) {
|
||||
// Use ceres::floor because it is specialized for double and Jet types.
|
||||
T two_pi(2.0 * M_PI);
|
||||
T two_pi(2.0 * constants::pi);
|
||||
return angle_radians -
|
||||
two_pi * ceres::floor((angle_radians + T(M_PI)) / two_pi);
|
||||
two_pi * ceres::floor((angle_radians + T(constants::pi)) / two_pi);
|
||||
}
|
||||
|
||||
} // namespace ceres::examples
|
||||
|
||||
@@ -39,8 +39,8 @@
|
||||
#include "ceres/autodiff_first_order_function.h"
|
||||
#include "ceres/autodiff_manifold.h"
|
||||
#include "ceres/conditioned_cost_function.h"
|
||||
#include "ceres/context.h"
|
||||
#include "ceres/constants.h"
|
||||
#include "ceres/context.h"
|
||||
#include "ceres/cost_function.h"
|
||||
#include "ceres/cost_function_to_functor.h"
|
||||
#include "ceres/covariance.h"
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
namespace ceres::constants {
|
||||
template <typename T>
|
||||
inline constexpr T pi_v(3.141592653589793238462643383279502884);
|
||||
inline constexpr double pi = pi_v<double>;
|
||||
} // namespace ceres::constants
|
||||
|
||||
#endif // CERES_PUBLIC_CONSTANTS_H_
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#ifndef CERES_PUBLIC_INTERNAL_SPHERE_MANIFOLD_HELPERS_H_
|
||||
#define CERES_PUBLIC_INTERNAL_SPHERE_MANIFOLD_HELPERS_H_
|
||||
|
||||
#include "ceres/constants.h"
|
||||
#include "ceres/internal/householder_vector.h"
|
||||
|
||||
// This module contains functions to compute the SphereManifold plus and minus
|
||||
@@ -122,7 +123,7 @@ inline void ComputeSphereManifoldMinus(
|
||||
const double hy_norm = hy.template head<TangentSpaceDim>(tangent_size).norm();
|
||||
if (hy_norm == 0.0) {
|
||||
y_minus_x->setZero();
|
||||
y_minus_x->data()[tangent_size - 1] = y_last >= 0 ? 0.0 : M_PI;
|
||||
y_minus_x->data()[tangent_size - 1] = y_last >= 0 ? 0.0 : constants::pi;
|
||||
} else {
|
||||
*y_minus_x = std::atan2(hy_norm, y_last) / hy_norm *
|
||||
hy.template head<TangentSpaceDim>(tangent_size);
|
||||
|
||||
@@ -610,7 +610,7 @@ void RotationMatrixToEulerAngles(
|
||||
// [-pi, pi) x [0, pi / 2) x [-pi, pi)
|
||||
// which is enforced here
|
||||
if constexpr (EulerSystem::kIsProperEuler) {
|
||||
const T kPi(constants::pi_v<double>);
|
||||
const T kPi(constants::pi);
|
||||
const T kTwoPi(2.0 * kPi);
|
||||
if (euler[1] < T(0.0) || ea[1] > kPi) {
|
||||
euler[0] += kPi;
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
#include <Eigen/Core>
|
||||
#include <cmath>
|
||||
|
||||
#include "ceres/constants.h"
|
||||
|
||||
namespace ceres {
|
||||
|
||||
// The brdf is based on:
|
||||
@@ -139,7 +141,7 @@ struct Brdf {
|
||||
const T gr = cggxn_dot_l * cggxn_dot_v;
|
||||
|
||||
const Vec3 result_no_cosine =
|
||||
(T(1.0 / M_PI) * Lerp(fd, ss, subsurface) * c + f_sheen) *
|
||||
(T(1.0 / constants::pi) * Lerp(fd, ss, subsurface) * c + f_sheen) *
|
||||
(T(1) - metallic) +
|
||||
gs * fs * ds +
|
||||
Vec3(T(0.25), T(0.25), T(0.25)) * clearcoat * gr * fr * dr;
|
||||
@@ -177,11 +179,11 @@ struct Brdf {
|
||||
T result = T(0);
|
||||
|
||||
if (a >= T(1)) {
|
||||
result = T(1 / M_PI);
|
||||
result = T(1 / constants::pi);
|
||||
} else {
|
||||
const T a2 = a * a;
|
||||
const T t = T(1) + (a2 - T(1)) * n_dot_h * n_dot_h;
|
||||
result = (a2 - T(1)) / (T(M_PI) * T(log(a2) * t));
|
||||
result = (a2 - T(1)) / (T(constants::pi) * T(log(a2) * t));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -192,7 +194,7 @@ struct Brdf {
|
||||
const T& h_dot_y,
|
||||
const T& ax,
|
||||
const T& ay) const {
|
||||
return T(1) / (T(M_PI) * ax * ay *
|
||||
return T(1) / (T(constants::pi) * ax * ay *
|
||||
Square(Square(h_dot_x / ax) + Square(h_dot_y / ay) +
|
||||
n_dot_h * n_dot_h));
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "ceres/constants.h"
|
||||
#include "ceres/manifold.h"
|
||||
#include "ceres/manifold_test_utils.h"
|
||||
#include "ceres/rotation.h"
|
||||
@@ -197,7 +198,7 @@ TEST(AutoDiffManifoldTest, QuaternionPlusPiBy2) {
|
||||
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
Vector delta = Vector::Zero(3);
|
||||
delta[i] = M_PI / 2;
|
||||
delta[i] = constants::pi / 2;
|
||||
Vector x_plus_delta = Vector::Zero(4);
|
||||
EXPECT_TRUE(manifold.Plus(x.data(), delta.data(), x_plus_delta.data()));
|
||||
|
||||
@@ -285,7 +286,7 @@ TEST(AutoDiffManifold, QuaternionDeltaJustBelowPi) {
|
||||
const Vector y = RandomQuaternion();
|
||||
Vector delta = Vector::Random(3);
|
||||
delta.normalize();
|
||||
delta *= (M_PI - 1e-6);
|
||||
delta *= (constants::pi - 1e-6);
|
||||
EXPECT_THAT(manifold, QuaternionPlusIsCorrectAt(x, delta));
|
||||
EXPECT_THAT_MANIFOLD_INVARIANTS_HOLD(manifold, x, delta, y, kTolerance);
|
||||
}
|
||||
|
||||
@@ -383,7 +383,7 @@ TEST(DynamicSparsity, StaticAndDynamicSparsityProduceSameSolution) {
|
||||
//
|
||||
// Initialize `X` to points on the unit circle.
|
||||
Vector w(num_segments + 1);
|
||||
w.setLinSpaced(num_segments + 1, 0.0, 2.0 * M_PI);
|
||||
w.setLinSpaced(num_segments + 1, 0.0, 2.0 * constants::pi);
|
||||
w.conservativeResize(num_segments);
|
||||
Matrix X(num_segments, 2);
|
||||
X.col(0) = w.array().cos();
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include <utility>
|
||||
|
||||
#include "Eigen/Geometry"
|
||||
#include "ceres/constants.h"
|
||||
#include "ceres/dynamic_numeric_diff_cost_function.h"
|
||||
#include "ceres/internal/eigen.h"
|
||||
#include "ceres/internal/port.h"
|
||||
@@ -504,7 +505,7 @@ TEST(QuaternionManifold, PlusPiBy2) {
|
||||
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
Vector delta = Vector::Zero(3);
|
||||
delta[i] = M_PI / 2;
|
||||
delta[i] = constants::pi / 2;
|
||||
Vector x_plus_delta = Vector::Zero(4);
|
||||
EXPECT_TRUE(manifold.Plus(x.data(), delta.data(), x_plus_delta.data()));
|
||||
|
||||
@@ -598,7 +599,7 @@ TEST(QuaternionManifold, DeltaJustBelowPi) {
|
||||
const Vector y = RandomQuaternion();
|
||||
Vector delta = Vector::Random(3);
|
||||
delta.normalize();
|
||||
delta *= (M_PI - 1e-6);
|
||||
delta *= (constants::pi - 1e-6);
|
||||
EXPECT_THAT(manifold, QuaternionManifoldPlusIsCorrectAt(x, delta));
|
||||
EXPECT_THAT_MANIFOLD_INVARIANTS_HOLD(manifold, x, delta, y, kTolerance);
|
||||
}
|
||||
@@ -669,7 +670,7 @@ TEST(EigenQuaternionManifold, DeltaJustBelowPi) {
|
||||
const Vector y = RandomQuaternion();
|
||||
Vector delta = Vector::Random(3);
|
||||
delta.normalize();
|
||||
delta *= (M_PI - 1e-6);
|
||||
delta *= (constants::pi - 1e-6);
|
||||
EXPECT_THAT(manifold, EigenQuaternionManifoldPlusIsCorrectAt(x, delta));
|
||||
EXPECT_THAT_MANIFOLD_INVARIANTS_HOLD(manifold, x, delta, y, kTolerance);
|
||||
}
|
||||
@@ -732,7 +733,7 @@ TEST(SphereManifold, Plus2DTest) {
|
||||
}
|
||||
|
||||
{
|
||||
double delta[1]{M_PI};
|
||||
double delta[1]{constants::pi};
|
||||
Eigen::Vector2d y = Eigen::Vector2d::Zero();
|
||||
EXPECT_TRUE(manifold.Plus(x.data(), delta, y.data()));
|
||||
const Eigen::Vector2d gtY = -Eigen::Vector2d::UnitY();
|
||||
@@ -740,7 +741,7 @@ TEST(SphereManifold, Plus2DTest) {
|
||||
}
|
||||
|
||||
{
|
||||
double delta[1]{2.0 * M_PI};
|
||||
double delta[1]{2.0 * constants::pi};
|
||||
Eigen::Vector2d y = Eigen::Vector2d::Zero();
|
||||
EXPECT_TRUE(manifold.Plus(x.data(), delta, y.data()));
|
||||
const Eigen::Vector2d gtY = Eigen::Vector2d::UnitY();
|
||||
@@ -761,7 +762,7 @@ TEST(SphereManifold, Plus3DTest) {
|
||||
}
|
||||
|
||||
{
|
||||
Eigen::Vector2d delta{M_PI, 0.0};
|
||||
Eigen::Vector2d delta{constants::pi, 0.0};
|
||||
Eigen::Vector3d y = Eigen::Vector3d::Zero();
|
||||
EXPECT_TRUE(manifold.Plus(x.data(), delta.data(), y.data()));
|
||||
const Eigen::Vector3d gtY = -Eigen::Vector3d::UnitZ();
|
||||
@@ -769,7 +770,7 @@ TEST(SphereManifold, Plus3DTest) {
|
||||
}
|
||||
|
||||
{
|
||||
Eigen::Vector2d delta{2.0 * M_PI, 0.0};
|
||||
Eigen::Vector2d delta{2.0 * constants::pi, 0.0};
|
||||
Eigen::Vector3d y = Eigen::Vector3d::Zero();
|
||||
EXPECT_TRUE(manifold.Plus(x.data(), delta.data(), y.data()));
|
||||
const Eigen::Vector3d gtY = Eigen::Vector3d::UnitZ();
|
||||
@@ -785,7 +786,7 @@ TEST(SphereManifold, Plus3DTest) {
|
||||
}
|
||||
|
||||
{
|
||||
Eigen::Vector2d delta{0.0, M_PI};
|
||||
Eigen::Vector2d delta{0.0, constants::pi};
|
||||
Eigen::Vector3d y = Eigen::Vector3d::Zero();
|
||||
EXPECT_TRUE(manifold.Plus(x.data(), delta.data(), y.data()));
|
||||
const Eigen::Vector3d gtY = -Eigen::Vector3d::UnitZ();
|
||||
@@ -793,7 +794,7 @@ TEST(SphereManifold, Plus3DTest) {
|
||||
}
|
||||
|
||||
{
|
||||
Eigen::Vector2d delta{0.0, 2.0 * M_PI};
|
||||
Eigen::Vector2d delta{0.0, 2.0 * constants::pi};
|
||||
Eigen::Vector3d y = Eigen::Vector3d::Zero();
|
||||
EXPECT_TRUE(manifold.Plus(x.data(), delta.data(), y.data()));
|
||||
const Eigen::Vector3d gtY = Eigen::Vector3d::UnitZ();
|
||||
@@ -809,7 +810,7 @@ TEST(SphereManifold, Plus3DTest) {
|
||||
}
|
||||
|
||||
{
|
||||
Eigen::Vector2d delta = Eigen::Vector2d(1, 1).normalized() * M_PI;
|
||||
Eigen::Vector2d delta = Eigen::Vector2d(1, 1).normalized() * constants::pi;
|
||||
Eigen::Vector3d y = Eigen::Vector3d::Zero();
|
||||
EXPECT_TRUE(manifold.Plus(x.data(), delta.data(), y.data()));
|
||||
const Eigen::Vector3d gtY = -Eigen::Vector3d::UnitZ();
|
||||
@@ -832,7 +833,7 @@ TEST(SphereManifold, Minus2DTest) {
|
||||
{
|
||||
double delta[1];
|
||||
const Eigen::Vector2d y(-1, 0);
|
||||
const double gtDelta{M_PI};
|
||||
const double gtDelta{constants::pi};
|
||||
EXPECT_TRUE(manifold.Minus(y.data(), x.data(), delta));
|
||||
EXPECT_LT(std::abs(delta[0] - gtDelta), kTolerance);
|
||||
}
|
||||
@@ -853,7 +854,7 @@ TEST(SphereManifold, Minus3DTest) {
|
||||
{
|
||||
Eigen::Vector2d delta;
|
||||
const Eigen::Vector3d y(-1, 0, 0);
|
||||
const Eigen::Vector2d gtDelta(0.0, M_PI);
|
||||
const Eigen::Vector2d gtDelta(0.0, constants::pi);
|
||||
EXPECT_TRUE(manifold.Minus(y.data(), x.data(), delta.data()));
|
||||
EXPECT_LT((delta - gtDelta).norm(), kTolerance);
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
namespace ceres {
|
||||
namespace internal {
|
||||
|
||||
inline constexpr double kPi = constants::pi_v<double>;
|
||||
inline constexpr double kPi = constants::pi;
|
||||
const double kHalfSqrt2 = 0.707106781186547524401;
|
||||
|
||||
// A tolerance value for floating-point comparisons.
|
||||
|
||||
Reference in New Issue
Block a user