From 6e32ad84a7ce7ada36f8f72a02060daf17817ab3 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Thu, 24 Aug 2017 15:54:51 +1000 Subject: [PATCH] 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. --- extent.hpp | 25 ++++++++++++++++++++++--- extent.ipp | 15 +-------------- region.cpp | 9 --------- region.hpp | 19 +++++++++++++++++-- test/region.cpp | 10 +++++----- 5 files changed, 45 insertions(+), 33 deletions(-) diff --git a/extent.hpp b/extent.hpp index cde8c587..5c456803 100644 --- a/extent.hpp +++ b/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 + * Copyright 2010-2017 Danny Robson */ #ifndef __UTIL_EXTENT_HPP @@ -41,8 +41,27 @@ namespace util { constexpr U aspect (void) const; - template - bool includes (util::point) 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 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 p) const + { + return all (p >= T{0} && p < *this); + } + extent expanded (vector) const; extent expanded (T) const; diff --git a/extent.ipp b/extent.ipp index 2f732d56..8c725523 100644 --- a/extent.ipp +++ b/extent.ipp @@ -11,7 +11,7 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * Copyright 2015 Danny Robson + * Copyright 2015-2017 Danny Robson */ @@ -66,19 +66,6 @@ util::extent::aspect (void) const } -/////////////////////////////////////////////////////////////////////////////// -template -template -bool -util::extent::includes (point p) const -{ - for (size_t i = 0; i < S; ++i) - if (p[i] < 0 || static_cast (p[i]) >= this->data[i]) - return false; - return true; -} - - /////////////////////////////////////////////////////////////////////////////// template constexpr diff --git a/region.cpp b/region.cpp index b25079d5..65f62462 100644 --- a/region.cpp +++ b/region.cpp @@ -206,15 +206,6 @@ util::region::covers (region r) const noexcept } -//----------------------------------------------------------------------------- -template -bool -region::covers (const point q) const noexcept -{ - return all (p <= q) && all (p + e >= q); -} - - /////////////////////////////////////////////////////////////////////////////// template util::region diff --git a/region.hpp b/region.hpp index a22ffd3c..7299b726 100644 --- a/region.hpp +++ b/region.hpp @@ -70,13 +70,28 @@ namespace util { //--------------------------------------------------------------------- // exclusive of borders bool intersects (region) const; + // Compute binary region combinations region intersection (region) const; // Test if a region lies completely within our space bool covers (region) const noexcept; - // Test if a point lies within out space. Inclusive of borders - bool covers (point) const noexcept; + + /// Test if a point lies within our space. Inclusive of borders + constexpr + bool + inclusive (point 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 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; diff --git a/test/region.cpp b/test/region.cpp index 4d41729f..dceb0ceb 100644 --- a/test/region.cpp +++ b/test/region.cpp @@ -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