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 < template <
typename K, typename K,
typename = std::enable_if_t< typename = std::enable_if_t<
@ -1219,14 +1224,16 @@ namespace util {
constexpr auto constexpr auto
floor (const K &k) floor (const K &k)
{ {
using value_type = typename K::value_type;
value_type (*floor_func)(value_type) = std::floor;
K out {}; K out {};
std::transform (std::cbegin (k), std::transform (
std::cbegin (k),
std::cend (k), std::cend (k),
std::begin (out), std::begin (out),
floor_func); [] (auto i) {
return i >= 0 ? static_cast<intmax_t> (i) : static_cast<intmax_t> (i) - 1;
}
);
return out; return out;
} }