From 38e1ce63fd7e18943174b8f3d4604637b9866458 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Fri, 21 Aug 2020 11:34:29 +1000 Subject: [PATCH] extent: add rotate90 --- extent.cpp | 19 +++++++++++++++++++ extent.hpp | 53 ++++++++++++++++++++++++++++------------------------- 2 files changed, 47 insertions(+), 25 deletions(-) diff --git a/extent.cpp b/extent.cpp index 8196ab8c..1945d354 100644 --- a/extent.cpp +++ b/extent.cpp @@ -76,6 +76,25 @@ extent::empty (void) const } +/////////////////////////////////////////////////////////////////////////////// +template +cruft::extent2 +cruft::rotate90 (cruft::extent2 obj, int steps) +{ + if (steps % 2) { + return { obj.h, obj.w }; + } else { + return obj; + } +} + + +//----------------------------------------------------------------------------- +template cruft::extent2 cruft::rotate90 (cruft::extent2, int); +template cruft::extent2 cruft::rotate90 (cruft::extent2, int); +template cruft::extent2 cruft::rotate90 (cruft::extent2, int); + + /////////////////////////////////////////////////////////////////////////////// namespace cruft::debug { template diff --git a/extent.hpp b/extent.hpp index d3587b03..707f1a2c 100644 --- a/extent.hpp +++ b/extent.hpp @@ -3,11 +3,10 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * - * Copyright 2010-2017 Danny Robson + * Copyright 2010-2020, Danny Robson */ -#ifndef CRUFT_UTIL_EXTENT_HPP -#define CRUFT_UTIL_EXTENT_HPP +#pragma once #include "coord/fwd.hpp" #include "coord/base.hpp" @@ -158,6 +157,28 @@ namespace cruft { }; + /////////////////////////////////////////////////////////////////////////// + // convenience typedefs + template using extent2 = extent<2,T>; + template using extent3 = extent<3,T>; + + template using extentu = extent; + template using extenti = extent; + template using extentf = extent; + template using extentd = extent; + + + typedef extent2 extent2i; + typedef extent2 extent2u; + typedef extent2 extent2f; + typedef extent2 extent2d; + + + typedef extent3 extent3u; + typedef extent3 extent3f; + + + /////////////////////////////////////////////////////////////////////////// template cruft::point sample (cruft::extent shape) @@ -181,26 +202,8 @@ namespace cruft { } - /////////////////////////////////////////////////////////////////////////// - // convenience typedefs - template using extent2 = extent<2,T>; - template using extent3 = extent<3,T>; - - template using extentu = extent; - template using extenti = extent; - template using extentf = extent; - template using extentd = extent; - - - typedef extent2 extent2i; - typedef extent2 extent2u; - typedef extent2 extent2f; - typedef extent2 extent2d; - - - typedef extent3 extent3u; - typedef extent3 extent3f; + //------------------------------------------------------------------------- + template + extent2 + rotate90 (extent2 val, int steps); } - - -#endif