region: add "has" point query
This commit is contained in:
parent
b18feb8bc4
commit
d29276a427
@ -180,6 +180,15 @@ util::region<S,T>::contains (point_t q) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
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
|
// FIXME: This will fail with an actual infinite range (NaNs will be generated
|
||||||
// in the conditionals).
|
// in the conditionals).
|
||||||
|
@ -74,6 +74,7 @@ namespace util {
|
|||||||
bool includes (point_t) const; // inclusive of borders
|
bool includes (point_t) const; // inclusive of borders
|
||||||
bool contains (point_t) const; // exclusive of borders
|
bool contains (point_t) const; // exclusive of borders
|
||||||
bool intersects (region<S,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
|
// Move a point to be within the region bounds
|
||||||
void constrain (point_t&) const;
|
void constrain (point_t&) const;
|
||||||
|
@ -57,6 +57,10 @@ main (int, char **)
|
|||||||
tap.expect ( r.contains (util::point2u {1, 1}), "unsigned region center contains");
|
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 {0, 0}), "unsigned region base contains");
|
||||||
tap.expect (!r.contains (util::point2u {2, 2}), "unsigned region corner 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");
|
||||||
}
|
}
|
||||||
|
|
||||||
//CHECK (region<2,intmax_t> (0, 0, 10, 10).includes (point2d (0.4, 0.01)));
|
//CHECK (region<2,intmax_t> (0, 0, 10, 10).includes (point2d (0.4, 0.01)));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user