eos 1.4.0
Loading...
Searching...
No Matches
math.hpp
1/*
2 * eos - A 3D Morphable Model fitting library written in modern C++11/14.
3 *
4 * File: include/eos/core/math.hpp
5 *
6 * Copyright 2023 Patrik Huber
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20#pragma once
21
22#ifndef EOS_MATH_HPP
23#define EOS_MATH_HPP
24
25#include <limits>
26#include <type_traits>
27
28namespace eos {
29namespace core {
30
34template <class T>
35constexpr T pi = T(3.1415926535897932385L);
36
40template <typename T>
42{
43 // Note: We may want to remove this assert, to allow ceres::Jet as type.
44 static_assert(std::numeric_limits<T>::is_iec559, "radians() only accepts floating-point inputs.");
45 return degrees * static_cast<T>(0.01745329251994329576923690768489);
46};
47
51template <typename T>
53{
54 // Note: We may want to remove this assert, to allow ceres::Jet as type.
55 static_assert(std::numeric_limits<T>::is_iec559, "radians() only accepts floating-point inputs.");
56 return radians * static_cast<T>(57.295779513082320876798154814105);
57};
58
65template <typename T>
66typename std::enable_if<std::is_unsigned<T>::value, int>::type inline constexpr sign(T const x)
67{
68 return T(0) < x;
69};
70
77template <typename T>
78typename std::enable_if<std::is_signed<T>::value, int>::type inline constexpr sign(T const x)
79{
80 return (T(0) < x) - (x < T(0));
81};
82
83} /* namespace core */
84} /* namespace eos */
85
86#endif /* EOS_MATH_HPP */
constexpr T pi
Compile-time constant for pi (19 digits).
Definition: math.hpp:35
std::enable_if< std::is_unsigned< T >::value, int >::type constexpr sign(T const x)
Returns the sign of the given number (-1, 0 or +1).
Definition: math.hpp:66
T radians(T degrees)
Convert given degrees to radians.
Definition: math.hpp:41
T degrees(T radians)
Convert given radians to degree.
Definition: math.hpp:52
Namespace containing all of eos's 3D model fitting functionality.