From 2cdb2f9439129fba16728110ac50633065dfa9ca Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Sun, 4 Mar 2012 21:14:33 +0100 Subject: 2geom: isConstant and isZero should check a finite neighbourhood around zero. (bzr r11045) --- src/2geom/bezier.h | 8 ++++---- src/2geom/d2.h | 8 ++++---- src/2geom/linear.h | 4 ++-- src/2geom/sbasis.h | 10 +++++----- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/2geom/bezier.h b/src/2geom/bezier.h index 1e1b88587..176128328 100644 --- a/src/2geom/bezier.h +++ b/src/2geom/bezier.h @@ -193,15 +193,15 @@ public: //IMPL: FragmentConcept typedef Coord output_type; - inline bool isZero() const { + inline bool isZero(double eps=EPSILON) const { for(unsigned i = 0; i <= order(); i++) { - if(c_[i] != 0) return false; + if( ! are_near(c_[i], 0., eps) ) return false; } return true; } - inline bool isConstant() const { + inline bool isConstant(double eps=EPSILON) const { for(unsigned i = 1; i <= order(); i++) { - if(c_[i] != c_[0]) return false; + if( ! are_near(c_[i], c_[0], eps) ) return false; } return true; } diff --git a/src/2geom/d2.h b/src/2geom/d2.h index 4a4f45a63..ef88b2d68 100644 --- a/src/2geom/d2.h +++ b/src/2geom/d2.h @@ -72,13 +72,13 @@ class D2{ //IMPL: FragmentConcept typedef Point output_type; - bool isZero() const { + bool isZero(double eps=EPSILON) const { boost::function_requires >(); - return f[X].isZero() && f[Y].isZero(); + return f[X].isZero(eps) && f[Y].isZero(eps); } - bool isConstant() const { + bool isConstant(double eps=EPSILON) const { boost::function_requires >(); - return f[X].isConstant() && f[Y].isConstant(); + return f[X].isConstant(eps) && f[Y].isConstant(eps); } bool isFinite() const { boost::function_requires >(); diff --git a/src/2geom/linear.h b/src/2geom/linear.h index df6dd9904..6e5132e12 100644 --- a/src/2geom/linear.h +++ b/src/2geom/linear.h @@ -72,8 +72,8 @@ public: //IMPL: FragmentConcept typedef double output_type; - inline bool isZero() const { return a[0] == 0 && a[1] == 0; } - inline bool isConstant() const { return a[0] == a[1]; } + inline bool isZero(double eps=EPSILON) const { return are_near(a[0], 0., eps) && are_near(a[1], 0., eps); } + inline bool isConstant(double eps=EPSILON) const { return are_near(a[0], a[1], eps); } inline bool isFinite() const { return IS_FINITE(a[0]) && IS_FINITE(a[1]); } inline double at0() const { return a[0]; } diff --git a/src/2geom/sbasis.h b/src/2geom/sbasis.h index dd2df55b9..e201f16ec 100644 --- a/src/2geom/sbasis.h +++ b/src/2geom/sbasis.h @@ -122,18 +122,18 @@ public: //IMPL: FragmentConcept typedef double output_type; - inline bool isZero() const { + inline bool isZero(double eps=EPSILON) const { if(empty()) return true; for(unsigned i = 0; i < size(); i++) { - if(!(*this)[i].isZero()) return false; + if(!(*this)[i].isZero(eps)) return false; } return true; } - inline bool isConstant() const { + inline bool isConstant(double eps=EPSILON) const { if (empty()) return true; - if(!(*this)[0].isConstant()) return false; + if(!(*this)[0].isConstant(eps)) return false; for (unsigned i = 1; i < size(); i++) { - if(!(*this)[i].isZero()) return false; + if(!(*this)[i].isZero(eps)) return false; } return true; } -- cgit v1.2.3