From bacf092e612ad1911c5a4db58261865e54953b34 Mon Sep 17 00:00:00 2001 From: johanengelen Date: Sun, 23 Dec 2007 21:17:42 +0000 Subject: [PATCH] update to latest 2geom, bugs be gone! --- src/2geom/bezier.h | 6 ++++++ src/2geom/concepts.h | 1 + src/2geom/d2.h | 4 ++++ src/2geom/linear.h | 1 + src/2geom/path.h | 12 ++++++++++-- src/2geom/sbasis.h | 8 ++++++++ 6 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/2geom/bezier.h b/src/2geom/bezier.h index 16b4d7446..bdc672a57 100644 --- a/src/2geom/bezier.h +++ b/src/2geom/bezier.h @@ -136,6 +136,12 @@ public: } return true; } + inline bool isConstant() const { + for(unsigned i = 1; i <= order(); i++) { + if(c_[i] != c_[0]) return false; + } + return true; + } inline bool isFinite() const { for(unsigned i = 0; i <= order(); i++) { if(!is_finite(c_[i])) return false; diff --git a/src/2geom/concepts.h b/src/2geom/concepts.h index 92ec66c7f..50cef4e4b 100644 --- a/src/2geom/concepts.h +++ b/src/2geom/concepts.h @@ -72,6 +72,7 @@ struct FragmentConcept { void constraints() { t = T(o); b = t.isZero(); + b = t.isConstant(); b = t.isFinite(); o = t.at0(); o = t.at1(); diff --git a/src/2geom/d2.h b/src/2geom/d2.h index 47355eb60..3becc813d 100644 --- a/src/2geom/d2.h +++ b/src/2geom/d2.h @@ -68,6 +68,10 @@ class D2{ boost::function_requires >(); return f[X].isZero() && f[Y].isZero(); } + bool isConstant() const { + boost::function_requires >(); + return f[X].isConstant() && f[Y].isConstant(); + } bool isFinite() const { boost::function_requires >(); return f[X].isFinite() && f[Y].isFinite(); diff --git a/src/2geom/linear.h b/src/2geom/linear.h index 2b346468c..32716b9d1 100644 --- a/src/2geom/linear.h +++ b/src/2geom/linear.h @@ -87,6 +87,7 @@ 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 isFinite() const { return is_finite(a[0]) && is_finite(a[1]); } inline double at0() const { return a[0]; } diff --git a/src/2geom/path.h b/src/2geom/path.h index 3c536c1d8..72c5d50fa 100644 --- a/src/2geom/path.h +++ b/src/2geom/path.h @@ -56,6 +56,8 @@ public: virtual Point initialPoint() const = 0; virtual Point finalPoint() const = 0; + virtual bool isDegenerate() const = 0; + virtual Curve *duplicate() const = 0; virtual Rect boundsFast() const = 0; @@ -94,6 +96,7 @@ public: Point initialPoint() const { return inner.at0(); } Point finalPoint() const { return inner.at1(); } + bool isDegenerate() const { return inner.isConstant(); } Point pointAt(Coord t) const { return inner.valueAt(t); } std::vector pointAndDerivatives(Coord t, unsigned n) const { return inner.valueAndDerivatives(t, n); @@ -168,6 +171,8 @@ public: Point initialPoint() const { return inner.at0(); } Point finalPoint() const { return inner.at1(); } + bool isDegenerate() const { return inner.isConstant(); } + void setInitial(Point v) { setPoint(0, v); } void setFinal(Point v) { setPoint(1, v); } @@ -284,6 +289,7 @@ public: //TODO: implement funcs + bool isDegenerate() const { return toSBasis().isConstant(); } Rect boundsFast() const; Rect boundsExact() const; Rect boundsLocal(Interval i, unsigned deg) const; @@ -493,8 +499,10 @@ public: ret.push_cut(0); unsigned i = 1; // ignore that path is closed or open. pw> is always open. - for(const_iterator it = begin(); it != end(); ++it, i++) { - ret.push(it->toSBasis(), i); + for(const_iterator it = begin(); it != end(); ++it) { + if (!it->isDegenerate()) { + ret.push(it->toSBasis(), i++); + } } return ret; } diff --git a/src/2geom/sbasis.h b/src/2geom/sbasis.h index acaa190a6..c7489e27d 100644 --- a/src/2geom/sbasis.h +++ b/src/2geom/sbasis.h @@ -67,6 +67,14 @@ public: } return true; } + inline bool isConstant() const { + if (empty()) return true; + for (unsigned i = 0; i < size(); i++) { + if(!(*this)[i].isConstant()) return false; + } + return true; + } + bool isFinite() const; inline double at0() const { if(empty()) return 0; else return (*this)[0][0]; -- 2.30.2