Temporary repository used to save branch code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

41 lines
1.9 KiB

#pragma once
#include "hash_ext.hpp"
struct eq_funcs_fn {
template <typename T, int M, int N>
bool operator()(const Eigen::Matrix<T, M, N> &lhs,
const Eigen::Matrix<T, M, N> &rhs,
double epsilon = detail::float_hash_epsilon) const
{
static_assert(M != Eigen::Dynamic && N != Eigen::Dynamic, "only fixed size matrix is supported");
if constexpr (std::is_integral_v<T>)
return lhs == rhs;
else if constexpr (std::is_floating_point_v<T>) {
using integral_type = typename detail::float_to_int_type<T>::type;
auto casted_lhs = (lhs.array() / static_cast<T>(epsilon)).template cast<integral_type>();
auto casted_rhs = (rhs.array() / static_cast<T>(epsilon)).template cast<integral_type>();
return casted_lhs.cwiseEqual(casted_rhs).all();
} else
static_assert(false, "unsupported type in hash<Eigen::Matrix>");
}
template <typename T, int N>
bool operator()(const Eigen::Transform<T, N, Eigen::AffineCompact> &lhs,
const Eigen::Transform<T, N, Eigen::AffineCompact> &rhs,
double epsilon = detail::float_hash_epsilon) const
{
if constexpr (std::is_integral_v<T>)
return lhs == rhs;
else if constexpr (std::is_floating_point_v<T>) {
using integral_type = typename detail::float_to_int_type<T>::type;
auto casted_lhs = (lhs.affine().array() / static_cast<T>(epsilon)).template cast<integral_type>();
auto casted_rhs = (rhs.affine().array() / static_cast<T>(epsilon)).template cast<integral_type>();
return casted_lhs.cwiseEqual(casted_rhs).all();
} else
static_assert(false, "unsupported type in hash<Eigen::Matrix>");
}
};
static constexpr eq_funcs_fn eq_funcs{};