geom/segment: add normalised and unnormalised direction queries

This commit is contained in:
Danny Robson 2019-03-21 17:36:05 +11:00
parent 3baf7c6e94
commit 4cf6bb292b

View File

@ -64,6 +64,25 @@ namespace cruft::geom {
}
/// Returns the un-normalised direction of the segment from its start to
/// end components. ie, `a' to `b'.
template <size_t S, typename T>
cruft::vector<S,T>
udirection (segment<S,T> const &val)
{
return val.b - val.a;
}
/// Returns the normalised direction of the segment.
template <size_t S, typename T>
cruft::vector<S,T>
ndirection (segment<S,T> const &val)
{
return normalised (udirection (val));
}
using segment2i = segment<2,int>;
using segment3i = segment<3,int>;