coord/ops: use manual integer casting for floor

This commit is contained in:
Danny Robson 2018-03-12 23:01:12 +11:00
parent d0f075108e
commit 92de21982a

View File

@ -1210,6 +1210,11 @@ namespace util {
///////////////////////////////////////////////////////////////////////////
// return the componentwise floor of the coordinate type
//
// don't use std::floor, it's _really_ slow in comparison.
//
// ideally we'd use SIMD or other more useful instructions here.
template <
typename K,
typename = std::enable_if_t<
@ -1219,14 +1224,16 @@ namespace util {
constexpr auto
floor (const K &k)
{
using value_type = typename K::value_type;
value_type (*floor_func)(value_type) = std::floor;
K out {};
std::transform (std::cbegin (k),
std::cend (k),
std::begin (out),
floor_func);
std::transform (
std::cbegin (k),
std::cend (k),
std::begin (out),
[] (auto i) {
return i >= 0 ? static_cast<intmax_t> (i) : static_cast<intmax_t> (i) - 1;
}
);
return out;
}