3#include <janus/math/Arithmetic.hpp>
4#include <janus/math/Logic.hpp>
19template <
typename Scalar>
bool is_finite(
const Scalar &x) {
20 if constexpr (std::is_same_v<Scalar, SymbolicScalar>) {
30template <
typename Scalar>
31auto is_in_range(
const Scalar &x,
const Scalar &min,
const Scalar &max) {
32 return x >= min && x <= max;
40template <
typename Scalar>
41Scalar
clamp(
const Scalar &x,
const Scalar &min,
const Scalar &max) {
43 return janus::min(janus::max(x, min), max);
51template <
typename Scalar>
53 if constexpr (!std::is_same_v<Scalar, SymbolicScalar>) {
55 std::ostringstream ss;
56 ss << name <<
" must be finite (got " << x <<
").";
63template <
typename Scalar>
65 if constexpr (!std::is_same_v<Scalar, SymbolicScalar>) {
67 std::ostringstream ss;
68 ss << name <<
" must be positive (got " << x <<
").";
75template <
typename Scalar>
77 if constexpr (!std::is_same_v<Scalar, SymbolicScalar>) {
79 std::ostringstream ss;
80 ss << name <<
" must be non-negative (got " << x <<
").";
87template <
typename Scalar>
89 const Scalar &min_val,
const Scalar &max_val) {
90 if constexpr (!std::is_same_v<Scalar, SymbolicScalar>) {
91 if (x < min_val || x > max_val) {
92 std::ostringstream ss;
93 ss << name <<
" must be in range [" << min_val <<
", " << max_val
94 <<
"] (got " << x <<
").";
101template <
typename Scalar>
103 const Scalar &max_val) {
104 if constexpr (!std::is_same_v<Scalar, SymbolicScalar>) {
106 std::ostringstream ss;
107 ss << name <<
" must be at most " << max_val <<
" (got " << x
115template <
typename Scalar>
117 const Scalar &min_val) {
118 if constexpr (!std::is_same_v<Scalar, SymbolicScalar>) {
120 std::ostringstream ss;
121 ss << name <<
" must be at least " << min_val <<
" (got " << x
131template <
typename VectorType>
133 using Scalar =
typename VectorType::Scalar;
135 if constexpr (!std::is_same_v<Scalar, SymbolicScalar>) {
136 Scalar norm_sq = q.squaredNorm();
139 if (abs(norm_sq - Scalar(1.0)) > Scalar(tolerance)) {
140 std::ostringstream ss;
141 ss <<
"Quaternion must be unit magnitude (squared norm = "
142 << norm_sq <<
", expected 1.0 ± " << tolerance <<
").";
Exception hierarchy for Vulcan aerospace library.
Validation errors (invalid input ranges, non-finite values).
Definition VulcanError.hpp:107
Definition Validation.hpp:12
Scalar clamp(const Scalar &x, const Scalar &min, const Scalar &max)
Clamp value to [min, max].
Definition Validation.hpp:41
void assert_in_range(const Scalar &x, const std::string &name, const Scalar &min_val, const Scalar &max_val)
Assert value is in range [min, max].
Definition Validation.hpp:88
void assert_unit_quaternion(const VectorType &q, double tolerance=1e-6)
Definition Validation.hpp:132
void assert_finite(const Scalar &x, const std::string &name)
Assert value is finite.
Definition Validation.hpp:52
void assert_at_least(const Scalar &x, const std::string &name, const Scalar &min_val)
Assert value is greater than or equal to min.
Definition Validation.hpp:116
bool is_finite(const Scalar &x)
Check if value is finite (not NaN or Inf).
Definition Validation.hpp:19
void assert_at_most(const Scalar &x, const std::string &name, const Scalar &max_val)
Assert value is less than or equal to max.
Definition Validation.hpp:102
auto is_in_range(const Scalar &x, const Scalar &min, const Scalar &max)
Definition Validation.hpp:31
void assert_positive(const Scalar &x, const std::string &name)
Assert value is positive (> 0).
Definition Validation.hpp:64
void assert_non_negative(const Scalar &x, const std::string &name)
Assert value is non-negative (>= 0).
Definition Validation.hpp:76