Skip to content

Commit

Permalink
Fix minor defect in kiwi Constraint::violated
Browse files Browse the repository at this point in the history
If epsilon is used for ==, it should be used for <= and >=.
  • Loading branch information
jkl1337 committed Mar 8, 2024
1 parent 717a0b1 commit cd549e0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions kiwi/kiwi/constraint.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ class ConstraintData : public SharedData
switch (m_op)
{
case OP_EQ: return !impl::nearZero(m_expression.value());
case OP_GE: return m_expression.value() < 0.0;
case OP_LE: return m_expression.value() > 0.0;
case OP_GE: return m_expression.value() < impl::EPSILON;
case OP_LE: return m_expression.value() > impl::EPSILON;
}
std::abort();
}
Expand Down
5 changes: 3 additions & 2 deletions kiwi/kiwi/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ namespace kiwi
namespace impl
{

constexpr const double EPSILON = 1.0e-8;

inline bool nearZero(double value)
{
const double eps = 1.0e-8;
return value < 0.0 ? -value < eps : value < eps;
return value < 0.0 ? -value < EPSILON : value < EPSILON;
}

} // namespace impl
Expand Down

0 comments on commit cd549e0

Please sign in to comment.