From afbf49950fe93b8fea8a4f71d47c13b530b0c7d9 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Wed, 16 Mar 2022 16:23:57 +0300 Subject: [PATCH] Add geom::make_min & make_max --- libs/geom/include/psemek/geom/math.hpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/libs/geom/include/psemek/geom/math.hpp b/libs/geom/include/psemek/geom/math.hpp index 56aab707..89855458 100644 --- a/libs/geom/include/psemek/geom/math.hpp +++ b/libs/geom/include/psemek/geom/math.hpp @@ -171,4 +171,26 @@ namespace psemek::geom return (x / y) + ((x % y) == 0 ? 0 : 1); } + template + bool make_min(T & target, T const & source) + { + if (target > source) + { + target = source; + return true; + } + return false; + } + + template + bool make_max(T & target, T const & source) + { + if (target < source) + { + target = source; + return true; + } + return false; + } + }