From ac19e165ba3d2cb94a8c839e7a35ec9b4c9b48c4 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Thu, 24 Aug 2017 12:49:59 +1000 Subject: [PATCH] coord/ops: add comment for util::limit --- coord/ops.hpp | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/coord/ops.hpp b/coord/ops.hpp index ba70e257..c02a8700 100644 --- a/coord/ops.hpp +++ b/coord/ops.hpp @@ -704,7 +704,12 @@ namespace util { //------------------------------------------------------------------------- - + /// returns a coordinate type where each element has been clamped to the + /// range [lo,hi]. + /// + /// we specifically do not allow different coordinate types for val, lo, + /// and hi because the min and max calls are ill definied for varying + /// types (not because varying types would not be useful). template < size_t S, typename T, @@ -722,6 +727,56 @@ namespace util { } + //------------------------------------------------------------------------- + template < + size_t S, + typename T, + template class K, + typename = std::enable_if_t< + is_coord_v>, void + > + > + constexpr + K + limit (K k, T lo, K hi) + { + return limit (k, K {lo}, hi); + } + + + //------------------------------------------------------------------------- + template < + size_t S, + typename T, + template class K, + typename = std::enable_if_t< + is_coord_v>, void + > + > + constexpr + K + limit (K k, K lo, T hi) + { + return limit (k, lo, K {hi}); + } + + + //------------------------------------------------------------------------- + template < + size_t S, + typename T, + template class K, + typename = std::enable_if_t< + is_coord_v>, void + > + > + constexpr K + limit (K k, T lo, T hi) + { + return limit (k, K {lo}, K {hi}); + } + + ///------------------------------------------------------------------------ template < size_t S,