region: move rotate90 out of the header

This commit is contained in:
Danny Robson 2020-08-21 11:34:52 +10:00
parent 38e1ce63fd
commit 9d0e9a9f1d
3 changed files with 67 additions and 54 deletions

View File

@ -243,6 +243,59 @@ cruft::region<S,T>::operator== (region rhs) const
}
///////////////////////////////////////////////////////////////////////////////
template <typename T>
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<T> {
point2<T> {
T(obj.p.x - obj.e.h),
obj.p.y
},
extent2<T> {
obj.e.h,
obj.e.w,
}
};
case 2:
return region2<T> {
point2<T> {
obj.p.x,
T(obj.p.y - obj.e.h),
},
obj.e,
};
case 3:
return region2<T> {
obj.p,
extent2<T> {
obj.e.h,
obj.e.w,
},
};
}
unreachable();
}
//-----------------------------------------------------------------------------
template cruft::region2<i32> cruft::rotate90 (cruft::region2<i32>, int);
template cruft::region2<i64> cruft::rotate90 (cruft::region2<i64>, int);
template cruft::region2<f32> cruft::rotate90 (cruft::region2<f32>, int);
///////////////////////////////////////////////////////////////////////////////
template <size_t S, typename T>
std::ostream&
@ -273,13 +326,13 @@ template struct cruft::debug::validator<cruft::region<S,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)

View File

@ -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 <typename T>
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<T> {
point2<T> {
obj.p.x - obj.e.h,
obj.p.y
},
extent2<T> {
obj.e.h,
obj.e.w,
}
};
case 2:
return region2<T> {
point2<T> {
obj.p.x,
obj.p.y - obj.e.h,
},
obj.e,
};
case 3:
return region2<T> {
obj.p,
extent2<T> {
obj.e.h,
obj.e.w,
},
};
}
unreachable();
}
cruft::region2<T>
rotate90 (cruft::region2<T> obj, int steps);
///////////////////////////////////////////////////////////////////////////

View File

@ -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);
}
}