[英]How to compare QVector3D or Eigen::Vector3d for equality with tolerance?
I would like to use the BOOST_TEST
machinery to compare mathematical vector types using plain (in)equality operators.我想使用
BOOST_TEST
机器来比较使用普通(不)等式运算符的数学向量类型。
I can only find how to tell Boost.Test that it should do that for a type (by specializing boost::math::fpc::tolerance_based
for that type), given the presence of the usual arithmetic and comparison operators, but I can't tell it to do the comparison in a specific way (I'd like the element-wise comparison here, and only really need (in)equality, no less/greater etc.).考虑到通常的算术和比较运算符的存在,我只能找到如何告诉 Boost.Test 它应该对一个类型执行此操作(通过专门针对该类型的
boost::math::fpc::tolerance_based
),但我可以'不要告诉它以特定的方式进行比较(我想要这里的元素比较,并且只需要(不)平等,而不是更少/更大等)。
Is there any customization point for this functionality?此功能是否有任何自定义点? If not, how can I easily enable such behaviour only in my tests?
如果没有,我怎样才能轻松地仅在我的测试中启用这种行为?
You can always write a custom operator that will do the comparison.您始终可以编写一个自定义运算符来进行比较。 For example:
例如:
bool operator == (const Vector3d &lhs, const double &rhs){
return (lhs.array() == rhs).all();
}
My guess would be the authors of Eigen didn't include these because they provided the array
class to give you access for element-wise operations.我的猜测是 Eigen 的作者没有包括这些,因为他们提供了
array
类来让您访问元素操作。 Also there are many ways to define inequalities like this and everyone will have a different set of requirements.还有很多方法可以定义这样的不平等,每个人都会有不同的要求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.