From 9d0e9a9f1d86d0bd56be13f9dcbabdd217369359 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Fri, 21 Aug 2020 11:34:52 +1000 Subject: [PATCH] region: move rotate90 out of the header --- region.cpp | 75 +++++++++++++++++++++++++++++++++++++++++-------- region.hpp | 44 ++--------------------------- test/region.cpp | 2 +- 3 files changed, 67 insertions(+), 54 deletions(-) diff --git a/region.cpp b/region.cpp index 860a36e6..d459d117 100644 --- a/region.cpp +++ b/region.cpp @@ -243,6 +243,59 @@ cruft::region::operator== (region rhs) const } +/////////////////////////////////////////////////////////////////////////////// +template +cruft::region<2,T> +cruft::rotate90 (cruft::region<2,T> obj, int steps) +{ + CHECK_LIMIT (steps, 0, 3); + + switch (steps) { + case 0: + return obj; + + case 1: + return region2 { + point2 { + T(obj.p.x - obj.e.h), + obj.p.y + }, + extent2 { + obj.e.h, + obj.e.w, + } + }; + + case 2: + return region2 { + point2 { + obj.p.x, + T(obj.p.y - obj.e.h), + }, + obj.e, + }; + + case 3: + return region2 { + obj.p, + extent2 { + obj.e.h, + obj.e.w, + }, + }; + } + + unreachable(); +} + + +//----------------------------------------------------------------------------- +template cruft::region2 cruft::rotate90 (cruft::region2, int); +template cruft::region2 cruft::rotate90 (cruft::region2, int); +template cruft::region2 cruft::rotate90 (cruft::region2, int); + + + /////////////////////////////////////////////////////////////////////////////// template std::ostream& @@ -264,22 +317,22 @@ namespace cruft::debug { /////////////////////////////////////////////////////////////////////////////// -#define INSTANTIATE_S_T(S,T) \ -template struct cruft::region; \ -template std::ostream& cruft::operator<< (std::ostream&, const region&); \ +#define INSTANTIATE_S_T(S,T) \ +template struct cruft::region; \ +template std::ostream& cruft::operator<< (std::ostream&, const region&); \ template struct cruft::debug::validator>; #define INSTANTIATE(T) \ INSTANTIATE_S_T(2,T) \ INSTANTIATE_S_T(3,T) -INSTANTIATE(int16_t); -INSTANTIATE(int32_t); -INSTANTIATE(int64_t); +INSTANTIATE(i16); +INSTANTIATE(i32); +INSTANTIATE(i64); -INSTANTIATE(uint16_t) -INSTANTIATE(uint32_t) -INSTANTIATE(uint64_t) +INSTANTIATE(u16) +INSTANTIATE(u32) +INSTANTIATE(u64) -INSTANTIATE(float) -INSTANTIATE(double) +INSTANTIATE(f32) +INSTANTIATE(f64) diff --git a/region.hpp b/region.hpp index 6379f873..eec878de 100644 --- a/region.hpp +++ b/region.hpp @@ -349,48 +349,8 @@ namespace cruft { /// `steps` must lie in the range [0, 4) so we can avoid an expensive /// modulus in the typical case. template - cruft::region<2,T> - rotate (cruft::region<2,T> obj, int steps) - { - CHECK_LIMIT (steps, 0, 3); - - switch (steps) { - case 0: - return obj; - - case 1: - return region2 { - point2 { - obj.p.x - obj.e.h, - obj.p.y - }, - extent2 { - obj.e.h, - obj.e.w, - } - }; - - case 2: - return region2 { - point2 { - obj.p.x, - obj.p.y - obj.e.h, - }, - obj.e, - }; - - case 3: - return region2 { - obj.p, - extent2 { - obj.e.h, - obj.e.w, - }, - }; - } - - unreachable(); - } + cruft::region2 + rotate90 (cruft::region2 obj, int steps); /////////////////////////////////////////////////////////////////////////// diff --git a/test/region.cpp b/test/region.cpp index 9a8786ae..6a56498a 100644 --- a/test/region.cpp +++ b/test/region.cpp @@ -228,7 +228,7 @@ main (int, char **) }; for (auto const &obj: TESTS) { - auto const computed = rotate (orig, obj.rotation); + auto const computed = rotate90 (orig, obj.rotation); tap.expect_eq (computed, obj.res, "%! rotation", obj.rotation); } }