region: remove duplicate point/region coverage tests
This commit is contained in:
parent
f36a14973a
commit
31d2e6bfd8
52
region.cpp
52
region.cpp
@ -11,7 +11,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Copyright 2010-2016 Danny Robson <danny@nerdcruft.net>
|
||||
* Copyright 2010-2017 Danny Robson <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
|
||||
@ -23,6 +23,8 @@
|
||||
|
||||
#include <array>
|
||||
|
||||
using util::region;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <size_t S, typename T>
|
||||
@ -159,41 +161,6 @@ util::region<S,T>::closest (point_t q) const
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <size_t S, typename T>
|
||||
bool
|
||||
util::region<S,T>::includes (point_t q) const
|
||||
{
|
||||
for (size_t i = 0; i < S; ++i)
|
||||
if (q[i] < p[i] || q[i] > p[i] + e[i])
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <size_t S, typename T>
|
||||
bool
|
||||
util::region<S,T>::contains (point_t q) const
|
||||
{
|
||||
for (size_t i = 0; i < S; ++i)
|
||||
if (q[i] <= p[i] || q[i] >= p[i] + e[i])
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <size_t S, typename T>
|
||||
bool
|
||||
util::region<S,T>::has (const point_t q) const noexcept
|
||||
{
|
||||
return all (q >= p) && all (q < p + e);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// FIXME: This will fail with an actual infinite range (NaNs will be generated
|
||||
// in the conditionals).
|
||||
@ -202,7 +169,7 @@ bool
|
||||
util::region<S,T>::intersects (region<S,T> rhs) const
|
||||
{
|
||||
for (size_t i = 0; i < S; ++i)
|
||||
if (p[i] >= rhs.p[i] + rhs.e[i] ||
|
||||
if ( p[i] >= rhs.p[i] + rhs.e[i] ||
|
||||
rhs.p[i] >= p[i] + e[i])
|
||||
{ return false; }
|
||||
|
||||
@ -253,12 +220,21 @@ util::region<S,T>::intersection (region<S,T> rhs) const
|
||||
//-----------------------------------------------------------------------------
|
||||
template <size_t S, typename T>
|
||||
bool
|
||||
util::region<S,T>::encloses (const region<S,T> r) const noexcept
|
||||
util::region<S,T>::covers (region<S, T> r) const noexcept
|
||||
{
|
||||
return all (p <= r.p) && all (p + e >= r.p + r.e);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
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>
|
||||
|
20
region.hpp
20
region.hpp
@ -70,21 +70,19 @@ namespace util {
|
||||
point_t closest (point_t) const;
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Point and region relation queries
|
||||
bool includes (point_t) const; // inclusive of borders
|
||||
bool contains (point_t) const; // exclusive of borders
|
||||
bool intersects (region<S,T>) const; // exclusive of borders
|
||||
bool has (point_t) const noexcept; // inclusive of top and left borders
|
||||
|
||||
// Move a point to be within the region bounds
|
||||
void constrain (point_t&) const;
|
||||
point_t constrained (point_t) const;
|
||||
|
||||
// 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 encloses (region<S,T>) const noexcept;
|
||||
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;
|
||||
|
||||
// Move a point to be within the region bounds
|
||||
void constrain (point_t&) const;
|
||||
point_t constrained (point_t) const;
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Compute a region `mag` units into the region
|
||||
|
@ -46,21 +46,16 @@ main (int, char **)
|
||||
|
||||
// test boundary cases of includes and contains
|
||||
{
|
||||
const util::point2u p0 { 0 };
|
||||
const util::extent2u e0 { 2 };
|
||||
const util::region2u r {p0, e0};
|
||||
const util::point2f p0 { 0 };
|
||||
const util::extent2f e0 { 2 };
|
||||
const util::region2f r {p0, e0};
|
||||
|
||||
tap.expect (r.includes (util::point2u {1, 1}), "unsigned region centre inclusion");
|
||||
tap.expect (r.includes (util::point2u {0, 0}), "unsigned region base inclusion");
|
||||
tap.expect (r.includes (util::point2u {2, 2}), "unsigned region corner inclusion");
|
||||
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.contains (util::point2u {1, 1}), "unsigned region center contains");
|
||||
tap.expect (!r.contains (util::point2u {0, 0}), "unsigned region base contains");
|
||||
tap.expect (!r.contains (util::point2u {2, 2}), "unsigned region corner contains");
|
||||
|
||||
tap.expect ( r.has (util::point2u {1, 1}), "unsigned region centre has");
|
||||
tap.expect ( r.has (util::point2u {1, 1}), "unsigned region base has");
|
||||
tap.expect (!r.has (util::point2u {2, 2}), "unsigned region corner has");
|
||||
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");
|
||||
}
|
||||
|
||||
// ensure make_union behaves as expected
|
||||
|
Loading…
Reference in New Issue
Block a user