region: add distance2

This commit is contained in:
Danny Robson 2018-05-30 14:35:11 +10:00
parent 16fc2effb2
commit 11a077f63d

View File

@ -209,6 +209,27 @@ namespace util {
} }
template <size_t S, typename T>
T
distance2 (region<S,T> r, point<S,T> p)
{
auto const clamped = util::max (
util::min (p, r.p + r.e),
r.p
);
return distance2 (r.p, clamped);
}
template <size_t S, typename T>
T
distance2 (point<S,T> p, region<S,T> r)
{
return distance2 (r, p);
}
template <size_t S, typename T, typename GeneratorT> template <size_t S, typename T, typename GeneratorT>
util::point<S,T> util::point<S,T>
sample (region<S,T> shape, GeneratorT &&gen) sample (region<S,T> shape, GeneratorT &&gen)