extent: add rotate90

This commit is contained in:
Danny Robson 2020-08-21 11:34:29 +10:00
parent 8eca4175ec
commit 38e1ce63fd
2 changed files with 47 additions and 25 deletions

View File

@ -76,6 +76,25 @@ extent<S,T>::empty (void) const
}
///////////////////////////////////////////////////////////////////////////////
template <typename T>
cruft::extent2<T>
cruft::rotate90 (cruft::extent2<T> obj, int steps)
{
if (steps % 2) {
return { obj.h, obj.w };
} else {
return obj;
}
}
//-----------------------------------------------------------------------------
template cruft::extent2<i32> cruft::rotate90 (cruft::extent2<i32>, int);
template cruft::extent2<i64> cruft::rotate90 (cruft::extent2<i64>, int);
template cruft::extent2<f32> cruft::rotate90 (cruft::extent2<f32>, int);
///////////////////////////////////////////////////////////////////////////////
namespace cruft::debug {
template <size_t S, typename T>

View File

@ -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 <danny@nerdcruft.net>
* Copyright 2010-2020, Danny Robson <danny@nerdcruft.net>
*/
#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 <typename T> using extent2 = extent<2,T>;
template <typename T> using extent3 = extent<3,T>;
template <size_t S> using extentu = extent<S,unsigned>;
template <size_t S> using extenti = extent<S,int>;
template <size_t S> using extentf = extent<S,float>;
template <size_t S> using extentd = extent<S,double>;
typedef extent2<int> extent2i;
typedef extent2<unsigned> extent2u;
typedef extent2<float> extent2f;
typedef extent2<double> extent2d;
typedef extent3<unsigned> extent3u;
typedef extent3<float> extent3f;
///////////////////////////////////////////////////////////////////////////
template <size_t S, typename T>
cruft::point<S,T>
sample (cruft::extent<S,T> shape)
@ -181,26 +202,8 @@ namespace cruft {
}
///////////////////////////////////////////////////////////////////////////
// convenience typedefs
template <typename T> using extent2 = extent<2,T>;
template <typename T> using extent3 = extent<3,T>;
template <size_t S> using extentu = extent<S,unsigned>;
template <size_t S> using extenti = extent<S,int>;
template <size_t S> using extentf = extent<S,float>;
template <size_t S> using extentd = extent<S,double>;
typedef extent2<int> extent2i;
typedef extent2<unsigned> extent2u;
typedef extent2<float> extent2f;
typedef extent2<double> extent2d;
typedef extent3<unsigned> extent3u;
typedef extent3<float> extent3f;
//-------------------------------------------------------------------------
template <typename T>
extent2<T>
rotate90 (extent2<T> val, int steps);
}
#endif