coord/ops: use manual integer casting for floor
This commit is contained in:
parent
d0f075108e
commit
92de21982a
@ -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::cend (k),
|
std::cbegin (k),
|
||||||
std::begin (out),
|
std::cend (k),
|
||||||
floor_func);
|
std::begin (out),
|
||||||
|
[] (auto i) {
|
||||||
|
return i >= 0 ? static_cast<intmax_t> (i) : static_cast<intmax_t> (i) - 1;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user