Add geom::rotate_towards
This commit is contained in:
parent
a95182dc60
commit
a944f8c4f4
1 changed files with 12 additions and 0 deletions
|
|
@ -110,6 +110,7 @@ namespace psemek::geom
|
||||||
return std::pair{x1, x2};
|
return std::pair{x1, x2};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// returns (a1 - a0)
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T angle_difference(T a0, T a1)
|
T angle_difference(T a0, T a1)
|
||||||
{
|
{
|
||||||
|
|
@ -124,6 +125,17 @@ namespace psemek::geom
|
||||||
return std::atan2(y, x);
|
return std::atan2(y, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
T rotate_towards(T value, T target, T max_difference)
|
||||||
|
{
|
||||||
|
auto d = angle_difference(value, target);
|
||||||
|
if (d > max_difference)
|
||||||
|
d = max_difference;
|
||||||
|
if (d < -max_difference)
|
||||||
|
d = -max_difference;
|
||||||
|
return value + d;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T idiv(T x, T m)
|
T idiv(T x, T m)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue