coord: use consistent naming for point coverage tests
use inclusive for tests that include all borders, and exclusive for tests that do not accept the bottom right borders.
This commit is contained in:
parent
efb719b822
commit
6e32ad84a7
25
extent.hpp
25
extent.hpp
@ -11,7 +11,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Copyright 2010-2015 Danny Robson <danny@nerdcruft.net>
|
||||
* Copyright 2010-2017 Danny Robson <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
#ifndef __UTIL_EXTENT_HPP
|
||||
@ -41,8 +41,27 @@ namespace util {
|
||||
constexpr
|
||||
U aspect (void) const;
|
||||
|
||||
template <typename U>
|
||||
bool includes (util::point<S,U>) const;
|
||||
|
||||
/// tests whether a point would lie within:
|
||||
/// region { origin, *this }, inclusive of borders.
|
||||
///
|
||||
/// included for parity with util::region.
|
||||
constexpr bool
|
||||
inclusive (util::point<S,T> p) const
|
||||
{
|
||||
return all (p >= T{0} && p <= *this);
|
||||
}
|
||||
|
||||
|
||||
/// tests whether a point would like within:
|
||||
/// region { origin, *this }, exclusive of the bottom-right border
|
||||
/// included for parity with util::region
|
||||
constexpr bool
|
||||
exclusive (point<S,T> p) const
|
||||
{
|
||||
return all (p >= T{0} && p < *this);
|
||||
}
|
||||
|
||||
|
||||
extent expanded (vector<S,T>) const;
|
||||
extent expanded (T) const;
|
||||
|
15
extent.ipp
15
extent.ipp
@ -11,7 +11,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Copyright 2015 Danny Robson <danny@nerdcruft.net>
|
||||
* Copyright 2015-2017 Danny Robson <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
|
||||
@ -66,19 +66,6 @@ util::extent<S,T>::aspect (void) const
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <size_t S, typename T>
|
||||
template <typename U>
|
||||
bool
|
||||
util::extent<S,T>::includes (point<S,U> p) const
|
||||
{
|
||||
for (size_t i = 0; i < S; ++i)
|
||||
if (p[i] < 0 || static_cast<T> (p[i]) >= this->data[i])
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <size_t S, typename T>
|
||||
constexpr
|
||||
|
@ -206,15 +206,6 @@ util::region<S,T>::covers (region<S, T> r) const noexcept
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <size_t S, typename T>
|
||||
bool
|
||||
region<S,T>::covers (const point<S,T> q) const noexcept
|
||||
{
|
||||
return all (p <= q) && all (p + e >= q);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <size_t S, typename T>
|
||||
util::region<S,T>
|
||||
|
19
region.hpp
19
region.hpp
@ -70,13 +70,28 @@ namespace util {
|
||||
//---------------------------------------------------------------------
|
||||
// exclusive of borders
|
||||
bool intersects (region<S,T>) const;
|
||||
|
||||
// Compute binary region combinations
|
||||
region intersection (region<S,T>) const;
|
||||
|
||||
// Test if a region lies completely within our space
|
||||
bool covers (region<S,T>) const noexcept;
|
||||
// Test if a point lies within out space. Inclusive of borders
|
||||
bool covers (point<S,T>) const noexcept;
|
||||
|
||||
/// Test if a point lies within our space. Inclusive of borders
|
||||
constexpr
|
||||
bool
|
||||
inclusive (point<S,T> q) const noexcept
|
||||
{
|
||||
return all (p <= q && p + e >= q);
|
||||
}
|
||||
|
||||
/// test if a point lies within our space, exclusive of the
|
||||
/// bottom-right border
|
||||
constexpr bool
|
||||
exclusive (point<S,T> q) const noexcept
|
||||
{
|
||||
return all (p <= q && p + e > q);
|
||||
}
|
||||
|
||||
// Move a point to be within the region bounds
|
||||
point_t constrain (point_t) const noexcept;
|
||||
|
@ -51,12 +51,12 @@ main (int, char **)
|
||||
const util::extent2f e0 { 2 };
|
||||
const util::region2f r {p0, e0};
|
||||
|
||||
tap.expect (!r.covers (util::point2f {-1, 1}), "region/point covers, invalid x");
|
||||
tap.expect (!r.covers (util::point2f { 1, 3}), "region/point covers, invalid y ");
|
||||
tap.expect (!r.inclusive (util::point2f {-1, 1}), "region/point inclusive, invalid x");
|
||||
tap.expect (!r.inclusive (util::point2f { 1, 3}), "region/point inclusive, invalid y ");
|
||||
|
||||
tap.expect (r.covers (util::point2f {1, 1}), "region/point covers, centre");
|
||||
tap.expect (r.covers (util::point2f {0, 0}), "region/point covers, base");
|
||||
tap.expect (r.covers (util::point2f {2, 2}), "region/point covers, corner");
|
||||
tap.expect (r.inclusive (util::point2f {1, 1}), "region/point inclusive, centre");
|
||||
tap.expect (r.inclusive (util::point2f {0, 0}), "region/point inclusive, base");
|
||||
tap.expect (r.inclusive (util::point2f {2, 2}), "region/point inclusive, corner");
|
||||
}
|
||||
|
||||
// ensure make_union behaves as expected
|
||||
|
Loading…
Reference in New Issue
Block a user