geom/aabb: change contract/expand semantics to mirror region

This commit is contained in:
Danny Robson 2017-08-24 16:54:48 +10:00
parent f77cdabaee
commit 1cea1600d3
2 changed files with 11 additions and 25 deletions

View File

@ -89,27 +89,19 @@ aabb<S,T>
aabb<S,T>::expand (vector<S,T> mag) const noexcept
{
CHECK (all (mag >= T{0}));
CHECK (all (mag < p1 - p0));
return {
p0 - mag / T{2},
p1 + mag / T{2}
};
return { p0 - mag, p1 + mag };
}
//-----------------------------------------------------------------------------
template <size_t S, typename T>
aabb<S,T>
aabb<S,T>::expand (T t) const noexcept
aabb<S,T>::expand (T mag) const noexcept
{
CHECK_GE (t, T{0});
CHECK (all (t < p1 - p0));
CHECK_GE (mag, T{0});
return {
p0 - t / T{2},
p1 + t / T{2}
};
return { p0 - mag, p1 + mag };
}
@ -118,13 +110,10 @@ template <size_t S, typename T>
aabb<S,T>
aabb<S,T>::contract (util::vector<S,T> mag) const noexcept
{
CHECK (all (mag > T{0}));
CHECK (all (mag <= p1 - p0));
CHECK (all (mag >= T{0}));
CHECK (all (2 * mag <= p1 - p0));
return {
p0 + mag / T{2},
p1 - mag / T{2}
};
return { p0 + mag, p1 - mag };
}
@ -134,12 +123,9 @@ aabb<S,T>
aabb<S,T>::contract (T mag) const noexcept
{
CHECK_GE (mag, T{0});
CHECK (all (mag <= p1 - p0));
CHECK (all (2 * mag <= p1 - p0));
return {
p0 + mag / T{2},
p1 - mag / T{2}
};
return { p0 + mag, p1 - mag };
}

View File

@ -17,7 +17,7 @@ main (int, char**)
const aabb2f val { { 2, 2 }, { 8, 8 } };
const aabb2f res { { 3, 3 }, { 7, 7 } };
tap.expect_eq (val.contract (2.f), res, "over contraction");
tap.expect_eq (val.contract (1.f), res, "over contraction");
}
{
@ -25,7 +25,7 @@ main (int, char**)
const aabb2f val { { 2, 2 }, { 8, 8 } };
const aabb2f res { { 1, 1 }, { 9, 9 } };
tap.expect_eq (val.expand (2.f), res, "expansion");
tap.expect_eq (val.expand (1.f), res, "expansion");
}
return tap.status ();