16inline constexpr T abs(
const T& rhs)
18 return rhs < 0 ? -rhs : rhs;
27 constexpr double Pi = 3.1415926535897932384626433832795;
30 constexpr double HalfPi = 1.5707963267948966192313216916398;
33 constexpr double TwoPi = 6.283185307179586476925286766559;
36 constexpr double DegToRad = 0.017453292519943295769236907684886;
39 constexpr double RadToDeg = 57.295779513082320876798154814105;
47 template <
typename A,
typename B>
49 Min(
const A& lhs,
const B& rhs) ->
decltype(lhs, rhs)
51 return lhs < rhs ? lhs : rhs;
55 template <
typename A,
typename B>
57 Max(
const A& lhs,
const B& rhs) ->
decltype(lhs, rhs)
59 return lhs > rhs ? lhs : rhs;
67 template <
typename A,
typename B,
typename C>
69 Constrain(
const A& amt,
const B& low,
const C& high)
71 return Min(
Max(amt, low), high);
78 template <
typename A,
typename B,
typename C = B>
108 template <
typename T>
112 return rhs < 0 ? -rhs : rhs;
118 template <
typename T>
129 return x - (int)x < 0 ? (
int)x - 1 : (int)x;
136 return x - (int)x >= 0.5 ? (
int)x + 1 : (int)x;
143 return x - (int)x > 0 ? (
int)x + 1 : (int)x;
147 inline constexpr double
148 Map(
const double value,
const double inputMin,
const double inputMax,
const double outputMin,
const double outputMax)
150 return (value - inputMin) * (outputMax - outputMin) / (inputMax - inputMin) + outputMin;
168 const auto cycle = max - min;
170 const auto modValue = fmod((value - min), cycle) + min;
174 return modValue + cycle;
189 return sqrt(x * x + y * y);
constexpr T Abs(const T &rhs)
絶対値を返す (std::abs)
Definition Math.hpp:110
constexpr auto Max(const A &lhs, const B &rhs) -> decltype(lhs, rhs)
2つの値のうち大きい方を返す (std::max)
Definition Math.hpp:57
constexpr T ToRadians(const T &rhs)
度数法の角度を弧度法に変換する
Definition Math.hpp:90
double Hypotenuse(double x, double y)
三平方の定理を用いて、2辺の長さから斜辺の長さを求める
Definition Math.hpp:187
constexpr double Pi
π
Definition Math.hpp:27
constexpr T Sq(const T &x)
二乗を求める (std::pow(x, 2))
Definition Math.hpp:120
constexpr int Round(double x)
四捨五入 (std::round)
Definition Math.hpp:134
constexpr double DegToRad
度数法から弧度法に変換する係数
Definition Math.hpp:36
double Normalized(double value, double min, double max)
値を正規化する
Definition Math.hpp:166
constexpr double RadToDeg
弧度法から度数法に変換する係数
Definition Math.hpp:39
constexpr T ToDegrees(const T &rhs)
弧度法の角度を度数法に変換する
Definition Math.hpp:100
constexpr A Constrain(const A &amt, const B &low, const C &high)
値を指定された範囲内に収める (std::clamp)
Definition Math.hpp:69
constexpr int Floor(double x)
小数点切り捨て (std::floor)
Definition Math.hpp:127
constexpr auto Min(const A &lhs, const B &rhs) -> decltype(lhs, rhs)
2つの値のうち小さい方を返す (std::min)
Definition Math.hpp:49
constexpr double HalfPi
π/2
Definition Math.hpp:30
constexpr double TwoPi
π*2
Definition Math.hpp:33
constexpr int Ceil(double x)
小数点切り上げ (std::ceil)
Definition Math.hpp:141
constexpr double Map(const double value, const double inputMin, const double inputMax, const double outputMin, const double outputMax)
数値をある範囲から別の範囲に再マッピングする
Definition Math.hpp:148
範囲を表す型
Definition Range.hpp:8
MinT min
最小値
Definition Range.hpp:9
MaxT max
最大値
Definition Range.hpp:10