Skip to content
Snippets Groups Projects
Commit bbab49b5 authored by Philip Trettner's avatar Philip Trettner
Browse files

Merge branch 'kschuster' into 'develop'

angle_between fix.

See merge request !36
parents da1698af 9c2e24d4
No related branches found
No related tags found
1 merge request!36angle_between fix.
......@@ -15,9 +15,11 @@ namespace tg
template <int D, class ScalarT>
TG_NODISCARD constexpr angle_t<fractional_result<ScalarT>> angle_between(vec<D, ScalarT> const& a, vec<D, ScalarT> const& b)
{
constexpr auto lower = decltype(dot(normalize_safe(a), normalize_safe(b)))(-1);
constexpr auto upper = decltype(dot(normalize_safe(a), normalize_safe(b)))(1);
auto a_unit = normalize_safe(a);
auto b_unit = normalize_safe(b);
return acos(saturate(dot(a_unit, b_unit)));
return acos(clamp(dot(a_unit, b_unit), lower, upper));
}
// returns the (smaller) angle between two directions, i.e. the result is in 0..pi (0°..180°)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment