aabb: add contract and closest methods

This commit is contained in:
Danny Robson 2015-04-08 19:00:17 +10:00
parent a4c22059ed
commit 5b878983a6
2 changed files with 64 additions and 0 deletions

View File

@ -58,6 +58,63 @@ AABB<S,T>::overlaps (point<S,T> p) const
}
//-----------------------------------------------------------------------------
template <size_t S, typename T>
util::point<S,T>
AABB<S,T>::closest (point<S,T> q) const
{
point<S,T> res;
for (size_t i = 0; i < S; ++i)
res[i] = q[i] < p0[i] ? p0[i] :
q[i] > p1[i] ? p1[i] :
q[i];
return res;
}
//-----------------------------------------------------------------------------
template <size_t S, typename T>
AABB<S,T>&
AABB<S,T>::contract (util::vector<S,T> mag)
{
p0 -= mag / T{2};
p1 += mag / T{2};
return *this;
}
//-----------------------------------------------------------------------------
template <size_t S, typename T>
AABB<S,T>&
AABB<S,T>::contract (T mag)
{
return contract (util::vector<S,T> {mag});
}
//-----------------------------------------------------------------------------
template <size_t S, typename T>
AABB<S,T>
AABB<S,T>::contracted (util::vector<S,T> mag) const
{
AABB<S,T> res = *this;
res.contract (mag);
return res;
}
//-----------------------------------------------------------------------------
template <size_t S, typename T>
AABB<S,T>
AABB<S,T>::contracted (T mag) const
{
return contracted (vector<S,T> {mag});
}
//-----------------------------------------------------------------------------
template <size_t S, typename T>
void

View File

@ -37,6 +37,13 @@ namespace util {
bool overlaps (point<S,T>) const;
point<S,T> closest (point<S,T>) const;
AABB<S,T>& contract (util::vector<S,T>);
AABB<S,T>& contract (T);
AABB<S,T> contracted (util::vector<S,T>) const;
AABB<S,T> contracted (T) const;
void cover (point<S,T>);
AABB<S,T> operator+ (vector<S,T>) const;