geom/segment: add more documentation

This commit is contained in:
Danny Robson 2019-03-21 17:29:26 +11:00
parent 39bbaa5a80
commit 3baf7c6e94

View File

@ -12,13 +12,17 @@
namespace cruft::geom {
/// Represents a line that has a start and an end.
///
/// It is not valid to create an unbounded segment by fixing one of the
/// points at infinity.
template <size_t S, typename T>
struct segment {
cruft::point<S,T> a;
cruft::point<S,T> b;
cruft::point<S,T> a; /// The start of the segment.
cruft::point<S,T> b; /// The end of the segment.
// Return a copy of this object with the underlying type casted to
// the specified type.
/// Return a copy of this object with the underlying type casted to
/// the specified type.
template <typename CastT>
segment<S,CastT>
cast (void) const {
@ -30,13 +34,8 @@ namespace cruft::geom {
};
using segment2i = segment<2,int>;
using segment3i = segment<3,int>;
using segment2f = segment<2,float>;
using segment3f = segment<3,float>;
/// Return the squared distance from the closest point of the segment `s`
/// to the point `p`.
template <size_t S, typename T>
T
distance2 (segment<S,T> s, point<S,T> p)
@ -55,10 +54,19 @@ namespace cruft::geom {
}
/// Return the distance from a the closest point of the segment `s` to
/// the point `p`.
template <size_t S, typename T>
T
distance (segment<S,T> s, point<S,T> p)
{
return std::sqrt (distance2 (s, p));
}
using segment2i = segment<2,int>;
using segment3i = segment<3,int>;
using segment2f = segment<2,float>;
using segment3f = segment<3,float>;
}