From dc249e33217a0cf547f743fbc08fbce188911972 Mon Sep 17 00:00:00 2001 From: johanengelen Date: Wed, 7 Jan 2009 22:00:50 +0000 Subject: [PATCH] update to 2geom rev.1773 mostly bugfixes --- src/2geom/bezier-utils.cpp | 3 +- src/2geom/piecewise.h | 57 +++++++++++++++++++++----------------- src/2geom/poly.cpp | 1 - src/2geom/rect.h | 2 +- src/2geom/sbasis.cpp | 2 +- src/2geom/sbasis.h | 4 ++- src/2geom/transforms.h | 2 +- 7 files changed, 40 insertions(+), 31 deletions(-) diff --git a/src/2geom/bezier-utils.cpp b/src/2geom/bezier-utils.cpp index 83767af98..4aa720127 100644 --- a/src/2geom/bezier-utils.cpp +++ b/src/2geom/bezier-utils.cpp @@ -48,7 +48,7 @@ #define noBEZIER_DEBUG #ifdef HAVE_IEEEFP_H -# include +# include #endif #include <2geom/bezier-utils.h> @@ -171,6 +171,7 @@ copy_without_nans_or_adjacent_duplicates(Point const src[], unsigned src_len, Po ++si; break; } + si++; } unsigned di = 0; for (; si < src_len; ++si) { diff --git a/src/2geom/piecewise.h b/src/2geom/piecewise.h index 31bf6872a..144d7a9b2 100644 --- a/src/2geom/piecewise.h +++ b/src/2geom/piecewise.h @@ -90,6 +90,8 @@ class Piecewise { push_cut(1.); } + inline void reserve(unsigned i) { segs.reserve(i); cuts.reserve(i + 1); } + inline T operator[](unsigned i) const { return segs[i]; } inline T &operator[](unsigned i) { return segs[i]; } inline output_type operator()(double t) const { return valueAt(t); } @@ -225,6 +227,7 @@ class Piecewise { segs.insert(segs.end(), other.segs.begin(), other.segs.end()); double t = cuts.back() - other.cuts.front(); + cuts.reserve(cuts.size() + other.size()); for(unsigned i = 0; i < other.size(); i++) push_cut(other.cuts[i + 1] + t); } @@ -234,15 +237,11 @@ class Piecewise { boost::function_requires >(); if(other.empty()) return; - if(empty()) { - for(unsigned i = 0; i < other.size(); i++) - push_seg(other[i]); - cuts = other.cuts; - return; - } + if(empty()) { segs = other.segs; cuts = other.cuts; return; } typename T::output_type y = segs.back().at1() - other.segs.front().at0(); double t = cuts.back() - other.cuts.front(); + reserve(size() + other.size()); for(unsigned i = 0; i < other.size(); i++) push(other[i] + y, other.cuts[i + 1] + t); } @@ -327,8 +326,7 @@ Piecewise partition(const Piecewise &pw, std::vector const &c) { if(c.empty()) return Piecewise(pw); Piecewise ret = Piecewise(); - ret.cuts.reserve(c.size() + pw.cuts.size()); - ret.segs.reserve(c.size() + pw.cuts.size() - 1); + ret.reserve(c.size() + pw.cuts.size() - 1); if(pw.empty()) { ret.cuts = c; @@ -408,6 +406,7 @@ Piecewise portion(const Piecewise &pw, double from, double to) { ret.push_seg(portion( pw[i], pw.segT(from, i), 1.0 )); i++; unsigned fi = pw.segN(to, i); + ret.reserve(fi - i + 1); if (to == pw.cuts[fi]) fi-=1; ret.segs.insert(ret.segs.end(), pw.segs.begin() + i, pw.segs.begin() + fi); //copy segs @@ -419,10 +418,12 @@ Piecewise portion(const Piecewise &pw, double from, double to) { return ret; } +//TODO: seems like these should be mutating template Piecewise remove_short_cuts(Piecewise const &f, double tol) { if(f.empty()) return f; Piecewise ret; + ret.reserve(f.size()); ret.push_cut(f.cuts[0]); for(unsigned i=0; i= tol || i==f.size()-1) { @@ -432,10 +433,12 @@ Piecewise remove_short_cuts(Piecewise const &f, double tol) { return ret; } +//TODO: seems like these should be mutating template Piecewise remove_short_cuts_extending(Piecewise const &f, double tol) { if(f.empty()) return f; Piecewise ret; + ret.reserve(f.size()); ret.push_cut(f.cuts[0]); double last = f.cuts[0]; // last cut included for(unsigned i=0; i Piecewise operator+(Piecewise const &a, typename T::output_type b) { boost::function_requires >(); //TODO:empty - Piecewise ret = Piecewise(); + Piecewise ret; + ret.segs.reserve(a.size()); ret.cuts = a.cuts; for(unsigned i = 0; i < a.size();i++) ret.push_seg(a[i] + b); @@ -473,14 +477,15 @@ template Piecewise operator-(Piecewise const &a, typename T::output_type b) { boost::function_requires >(); //TODO: empty - Piecewise ret = Piecewise(); + Piecewise ret; + ret.segs.reserve(a.size()); ret.cuts = a.cuts; for(unsigned i = 0; i < a.size();i++) ret.push_seg(a[i] - b); return ret; } template -Piecewise operator+=(Piecewise& a, typename T::output_type b) { +Piecewise& operator+=(Piecewise& a, typename T::output_type b) { boost::function_requires >(); if(a.empty()) { a.push_cut(0.); a.push(T(b), 1.); return a; } @@ -490,10 +495,10 @@ Piecewise operator+=(Piecewise& a, typename T::output_type b) { return a; } template -Piecewise operator-=(Piecewise& a, typename T::output_type b) { +Piecewise& operator-=(Piecewise& a, typename T::output_type b) { boost::function_requires >(); - if(a.empty()) { a.push_cut(0.); a.push(T(b), 1.); return a; } + if(a.empty()) { a.push_cut(0.); a.push(T(-b), 1.); return a; } for(unsigned i = 0;i < a.size();i++) a[i] -= b; @@ -506,6 +511,7 @@ Piecewise operator-(Piecewise const &a) { boost::function_requires >(); Piecewise ret; + ret.segs.reserve(a.size()); ret.cuts = a.cuts; for(unsigned i = 0; i < a.size();i++) ret.push_seg(- a[i]); @@ -518,6 +524,7 @@ Piecewise operator*(Piecewise const &a, double b) { if(a.empty()) return Piecewise(); Piecewise ret; + ret.segs.reserve(a.size()); ret.cuts = a.cuts; for(unsigned i = 0; i < a.size();i++) ret.push_seg(a[i] * b); @@ -531,27 +538,25 @@ Piecewise operator/(Piecewise const &a, double b) { if(a.empty()) return Piecewise(); Piecewise ret; + ret.segs.reserve(a.size()); ret.cuts = a.cuts; for(unsigned i = 0; i < a.size();i++) ret.push_seg(a[i] / b); return ret; } template -Piecewise operator*=(Piecewise& a, double b) { +Piecewise& operator*=(Piecewise& a, double b) { boost::function_requires >(); - if(a.empty()) return Piecewise(); - for(unsigned i = 0; i < a.size();i++) a[i] *= b; return a; } template -Piecewise operator/=(Piecewise& a, double b) { +Piecewise& operator/=(Piecewise& a, double b) { boost::function_requires >(); //FIXME: b == 0? - if(a.empty()) return Piecewise(); for(unsigned i = 0; i < a.size();i++) a[i] /= b; @@ -564,8 +569,9 @@ Piecewise operator+(Piecewise const &a, Piecewise const &b) { boost::function_requires >(); Piecewise pa = partition(a, b.cuts), pb = partition(b, a.cuts); - Piecewise ret = Piecewise(); + Piecewise ret; assert(pa.size() == pb.size()); + ret.segs.reserve(pa.size()); ret.cuts = pa.cuts; for (unsigned i = 0; i < pa.size(); i++) ret.push_seg(pa[i] + pb[i]); @@ -578,18 +584,19 @@ Piecewise operator-(Piecewise const &a, Piecewise const &b) { Piecewise pa = partition(a, b.cuts), pb = partition(b, a.cuts); Piecewise ret = Piecewise(); assert(pa.size() == pb.size()); + ret.segs.reserve(pa.size()); ret.cuts = pa.cuts; for (unsigned i = 0; i < pa.size(); i++) ret.push_seg(pa[i] - pb[i]); return ret; } template -inline Piecewise operator+=(Piecewise &a, Piecewise const &b) { +inline Piecewise& operator+=(Piecewise &a, Piecewise const &b) { a = a+b; return a; } template -inline Piecewise operator-=(Piecewise &a, Piecewise const &b) { +inline Piecewise& operator-=(Piecewise &a, Piecewise const &b) { a = a-b; return a; } @@ -603,6 +610,7 @@ Piecewise operator*(Piecewise const &a, Piecewise const &b) { Piecewise pb = partition(b, a.cuts); Piecewise ret = Piecewise(); assert(pa.size() == pb.size()); + ret.segs.reserve(pa.size()); ret.cuts = pa.cuts; for (unsigned i = 0; i < pa.size(); i++) ret.push_seg(pa[i] * pb[i]); @@ -610,7 +618,7 @@ Piecewise operator*(Piecewise const &a, Piecewise const &b) { } template -inline Piecewise operator*=(Piecewise &a, Piecewise const &b) { +inline Piecewise& operator*=(Piecewise &a, Piecewise const &b) { a = a * b; return a; } @@ -740,8 +748,7 @@ std::vector >multi_roots(Piecewise const &f, std::ve template Piecewise reverse(Piecewise const &f) { Piecewise ret = Piecewise(); - ret.cuts.resize(f.cuts.size()); - ret.segs.resize(f.segs.size()); + ret.reserve(f.size()); double start = f.cuts[0]; double end = f.cuts.back(); for (unsigned i = 0; i < f.cuts.size(); i++) { @@ -759,7 +766,7 @@ Piecewise reverse(Piecewise const &f) { * \return a if t = 0, b if t = 1, or an interpolation between a and b for t in [0,1] */ template -Piecewise lerp(Piecewise const &a, Piecewise b, double t) { +Piecewise lerp(double t, Piecewise const &a, Piecewise b) { // Make sure both paths have the same number of segments and cuts at the same locations b.setDomain(a.domain()); Piecewise pA = partition(a, b.cuts); diff --git a/src/2geom/poly.cpp b/src/2geom/poly.cpp index d8b379557..9dbfc0967 100644 --- a/src/2geom/poly.cpp +++ b/src/2geom/poly.cpp @@ -1,6 +1,5 @@ #include <2geom/poly.h> -#define HAVE_GSL #ifdef HAVE_GSL #include #endif diff --git a/src/2geom/rect.h b/src/2geom/rect.h index fb42ff92d..fe2cc297b 100644 --- a/src/2geom/rect.h +++ b/src/2geom/rect.h @@ -215,7 +215,7 @@ public: /** * Check whether this OptRect is empty or not. */ - inline bool isEmpty() { return (*this == false); }; + inline bool isEmpty() const { return (*this == false); }; /** * If \c this is empty, copy argument \c b. Otherwise, union with it (and do nothing when \c b is empty) diff --git a/src/2geom/sbasis.cpp b/src/2geom/sbasis.cpp index bdc40c936..b5c1a05a7 100644 --- a/src/2geom/sbasis.cpp +++ b/src/2geom/sbasis.cpp @@ -70,7 +70,7 @@ std::vector SBasis::valueAndDerivatives(double t, unsigned n) const { SBasis tmp = *this; for(unsigned i = 1; i < n+1; i++) { tmp.derive(); - ret[i+1] = tmp.valueAt(t); + ret[i] = tmp.valueAt(t); } return ret; } diff --git a/src/2geom/sbasis.h b/src/2geom/sbasis.h index 3038c1776..ae045b222 100644 --- a/src/2geom/sbasis.h +++ b/src/2geom/sbasis.h @@ -69,9 +69,9 @@ class SBasis{ void push_back(Linear const&l) { d.push_back(l); } public: + // As part of our migration away from SBasis isa vector we provide this minimal set of vector interface methods. size_t size() const {return d.size();} Linear operator[](unsigned i) const { - assert(i < size()); return d[i]; } Linear& operator[](unsigned i) { return d.at(i); } @@ -91,6 +91,8 @@ public: //void insert(Linear* aa, Linear* bb, Linear* cc} { d.insert(aa, bb, cc);} Linear& at(unsigned i) { return d.at(i);} //void insert(Linear* before, int& n, Linear const &l) { d.insert(std::vector::iterator(before), n, l);} + bool operator==(SBasis const&B) { return d == B.d;} + operator std::vector() { return d;} SBasis() {} diff --git a/src/2geom/transforms.h b/src/2geom/transforms.h index ac5a775c4..29aab11aa 100644 --- a/src/2geom/transforms.h +++ b/src/2geom/transforms.h @@ -1,6 +1,6 @@ /** * \file - * \brief \todo brief description + * \brief Transforms should be applied left to right. scale * translate means: first scale, then translate. * * Authors: * ? -- 2.30.2