diff --git a/region.cpp b/region.cpp index 3c6c9e6f..1919db23 100644 --- a/region.cpp +++ b/region.cpp @@ -180,6 +180,15 @@ util::region::contains (point_t q) const } +//----------------------------------------------------------------------------- +template +bool +util::region::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). diff --git a/region.hpp b/region.hpp index 46c6580d..906a0db5 100644 --- a/region.hpp +++ b/region.hpp @@ -74,6 +74,7 @@ namespace util { bool includes (point_t) const; // inclusive of borders bool contains (point_t) const; // exclusive of borders bool intersects (region) 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; diff --git a/test/region.cpp b/test/region.cpp index eb24e262..3c54a408 100644 --- a/test/region.cpp +++ b/test/region.cpp @@ -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 {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"); } //CHECK (region<2,intmax_t> (0, 0, 10, 10).includes (point2d (0.4, 0.01)));