summaryrefslogtreecommitdiffstats
path: root/src/2geom
diff options
context:
space:
mode:
authorKrzysztof Kosi??ski <tweenk.pl@gmail.com>2015-08-13 15:48:12 +0000
committerKrzysztof KosiƄski <tweenk.pl@gmail.com>2015-08-13 15:48:12 +0000
commit9616befcd379cc7173356998ff4c7b055b21e361 (patch)
treeec1fe99e0fc5ee450c99b08bf28c778f85fcfce1 /src/2geom
parentFix bug in Maithili .po file. (diff)
downloadinkscape-9616befcd379cc7173356998ff4c7b055b21e361.tar.gz
inkscape-9616befcd379cc7173356998ff4c7b055b21e361.zip
2Geom: update to r2422.
Fixes LP #1482806: crash on Pattern along Path with horizontal segments. This was caused by empty SBasis objects. After the changes in 2Geom, empty SBasis objects should no longer be created. Fixed bugs: - https://launchpad.net/bugs/1482806 (bzr r14299)
Diffstat (limited to 'src/2geom')
-rw-r--r--src/2geom/d2-sbasis.cpp20
-rw-r--r--src/2geom/numeric/fitting-model.h1
-rw-r--r--src/2geom/sbasis-geometric.cpp2
-rw-r--r--src/2geom/sbasis-roots.cpp6
-rw-r--r--src/2geom/sbasis-to-bezier.cpp4
-rw-r--r--src/2geom/sbasis.h73
6 files changed, 51 insertions, 55 deletions
diff --git a/src/2geom/d2-sbasis.cpp b/src/2geom/d2-sbasis.cpp
index ebec16fdd..4f00ff6a5 100644
--- a/src/2geom/d2-sbasis.cpp
+++ b/src/2geom/d2-sbasis.cpp
@@ -147,12 +147,12 @@ Piecewise<D2<SBasis> > force_continuity(Piecewise<D2<SBasis> > const &f, double
SBasis &prev_sb=result.segs[prev][dim];
SBasis &cur_sb =result.segs[cur][dim];
Coord const c=pt0[dim];
- if (prev_sb.empty()) {
+ if (prev_sb.isZero(0)) {
prev_sb = SBasis(Linear(0.0, c));
} else {
prev_sb[0][1] = c;
}
- if (cur_sb.empty()) {
+ if (cur_sb.isZero(0)) {
cur_sb = SBasis(Linear(c, 0.0));
} else {
cur_sb[0][0] = c;
@@ -198,30 +198,22 @@ Point unitTangentAt(D2<SBasis> const & a, Coord t, unsigned n)
return Point (0,0);
}
-static void set_first_point(Piecewise<D2<SBasis> > &f, Point a){
+static void set_first_point(Piecewise<D2<SBasis> > &f, Point const &a){
if ( f.empty() ){
f.concat(Piecewise<D2<SBasis> >(D2<SBasis>(SBasis(Linear(a[X])), SBasis(Linear(a[Y])))));
return;
}
for (unsigned dim=0; dim<2; dim++){
- if (f.segs.front()[dim].size() == 0){
- f.segs.front()[dim] = SBasis(Linear(a[dim],0));
- }else{
- f.segs.front()[dim][0][0] = a[dim];
- }
+ f.segs.front()[dim][0][0] = a[dim];
}
}
-static void set_last_point(Piecewise<D2<SBasis> > &f, Point a){
+static void set_last_point(Piecewise<D2<SBasis> > &f, Point const &a){
if ( f.empty() ){
f.concat(Piecewise<D2<SBasis> >(D2<SBasis>(SBasis(Linear(a[X])), SBasis(Linear(a[Y])))));
return;
}
for (unsigned dim=0; dim<2; dim++){
- if (f.segs.back()[dim].size() == 0){
- f.segs.back()[dim] = SBasis(Linear(0,a[dim]));
- }else{
- f.segs.back()[dim][0][1] = a[dim];
- }
+ f.segs.back()[dim][0][1] = a[dim];
}
}
diff --git a/src/2geom/numeric/fitting-model.h b/src/2geom/numeric/fitting-model.h
index fb96d1d2a..b2ca92ad8 100644
--- a/src/2geom/numeric/fitting-model.h
+++ b/src/2geom/numeric/fitting-model.h
@@ -372,7 +372,6 @@ class LFMSBasis
void instance(SBasis & sb, ConstVectorView const& raw_data) const
{
- sb.clear();
sb.resize(m_order+1);
for (unsigned int i = 0, k = 0; i < raw_data.size(); i+=2, ++k)
{
diff --git a/src/2geom/sbasis-geometric.cpp b/src/2geom/sbasis-geometric.cpp
index 4c474f7f0..8aaa15144 100644
--- a/src/2geom/sbasis-geometric.cpp
+++ b/src/2geom/sbasis-geometric.cpp
@@ -228,7 +228,7 @@ Geom::unitVector(D2<SBasis> const &V_in, double tol, unsigned order){
// -This done, unitVector will have jumps at zeros: fill the gaps with arcs of circles.
D2<SBasis> V = RescaleForNonVanishingEnds(V_in);
- if (V[0].empty() && V[1].empty())
+ if (V[0].isZero(0) && V[1].isZero(0))
return Piecewise<D2<SBasis> >(D2<SBasis>(Linear(1),SBasis()));
SBasis x = V[0], y = V[1];
SBasis r_eqn1, r_eqn2;
diff --git a/src/2geom/sbasis-roots.cpp b/src/2geom/sbasis-roots.cpp
index 57bef4c0f..e3e5e4441 100644
--- a/src/2geom/sbasis-roots.cpp
+++ b/src/2geom/sbasis-roots.cpp
@@ -222,7 +222,7 @@ static void multi_roots_internal(SBasis const &f,
double b,
double fb){
- if (f.size()==0){
+ if (f.isZero(0)){
int idx;
idx=upper_level(levels,0,vtol);
if (idx<(int)levels.size()&&fabs(levels.at(idx))<=vtol){
@@ -414,7 +414,7 @@ static void level_sets_internal(SBasis const &f,
double fb,
double tol=1e-5){
- if (f.size()==0){
+ if (f.isZero(0)){
unsigned idx;
idx=upper_level( levels, 0. );
if (idx<levels.size() && levels[idx].contains(0.)){
@@ -614,6 +614,7 @@ std::vector<double> roots1(SBasis const & s, Interval const ivl) {
std::vector<double> roots(SBasis const & s) {
switch(s.size()) {
case 0:
+ assert(false);
return std::vector<double>();
case 1:
return roots1(s);
@@ -628,6 +629,7 @@ std::vector<double> roots(SBasis const & s) {
std::vector<double> roots(SBasis const & s, Interval const ivl) {
switch(s.size()) {
case 0:
+ assert(false);
return std::vector<double>();
case 1:
return roots1(s, ivl);
diff --git a/src/2geom/sbasis-to-bezier.cpp b/src/2geom/sbasis-to-bezier.cpp
index 09fbb03ef..d9a90aace 100644
--- a/src/2geom/sbasis-to-bezier.cpp
+++ b/src/2geom/sbasis-to-bezier.cpp
@@ -100,9 +100,7 @@ int sgn(unsigned int j, unsigned int k)
*/
void sbasis_to_bezier (Bezier & bz, SBasis const& sb, size_t sz)
{
- if (sb.size() == 0) {
- THROW_RANGEERROR("size of sb is too small");
- }
+ assert(sb.size() > 0);
size_t q, n;
bool even;
diff --git a/src/2geom/sbasis.h b/src/2geom/sbasis.h
index 787e8b722..6923017be 100644
--- a/src/2geom/sbasis.h
+++ b/src/2geom/sbasis.h
@@ -83,49 +83,52 @@ public:
const_iterator end() const { return d.end();}
iterator begin() { return d.begin();}
iterator end() { return d.end();}
- bool empty() const {return d.empty();}
+ bool empty() const { return d.size() == 1 && d[0][0] == 0 && d[0][1] == 0; }
Linear &back() {return d.back();}
Linear const &back() const {return d.back();}
- void pop_back() { d.pop_back();}
- void resize(unsigned n) { d.resize(n);}
- void resize(unsigned n, Linear const& l) { d.resize(n, l);}
+ void pop_back() {
+ if (d.size() > 1) {
+ d.pop_back();
+ } else {
+ d[0][0] = 0;
+ d[0][1] = 0;
+ }
+ }
+ void resize(unsigned n) { d.resize(std::max<unsigned>(n, 1));}
+ void resize(unsigned n, Linear const& l) { d.resize(std::max<unsigned>(n, 1), l);}
void reserve(unsigned n) { d.reserve(n);}
- void clear() {d.clear();}
+ void clear() {
+ d.resize(1);
+ d[0][0] = 0;
+ d[0][1] = 0;
+ }
void insert(iterator before, const_iterator src_begin, const_iterator src_end) { d.insert(before, src_begin, src_end);}
Linear& at(unsigned i) { return d.at(i);}
//void insert(Linear* before, int& n, Linear const &l) { d.insert(std::vector<Linear>::iterator(before), n, l);}
bool operator==(SBasis const&B) const { return d == B.d;}
bool operator!=(SBasis const&B) const { return d != B.d;}
- operator std::vector<Linear>() { return d;}
-
- SBasis() {}
+ SBasis()
+ : d(1, Linear(0, 0))
+ {}
explicit SBasis(double a)
- : d(1)
- {
- d[0][0] = a;
- d[0][1] = a;
- }
+ : d(1, Linear(a, a))
+ {}
explicit SBasis(double a, double b)
- : d(1)
- {
- d[0][0] = a;
- d[0][1] = b;
- }
- SBasis(SBasis const & a) :
- d(a.d)
+ : d(1, Linear(a, b))
{}
- SBasis(std::vector<Linear> const & ls) :
- d(ls)
+ SBasis(SBasis const &a)
+ : d(a.d)
+ {}
+ SBasis(std::vector<Linear> const &ls)
+ : d(ls)
+ {}
+ SBasis(Linear const &bo)
+ : d(1, bo)
+ {}
+ SBasis(Linear* bo)
+ : d(1, bo ? *bo : Linear(0, 0))
{}
- SBasis(Linear const & bo) {
- push_back(bo);
- }
- SBasis(Linear* bo) {
- if (bo) {
- push_back(*bo);
- }
- }
explicit SBasis(size_t n, Linear const&l) : d(n, l) {}
SBasis(Coord c0, Coord c1, Coord c2, Coord c3)
@@ -179,6 +182,7 @@ public:
template <typename Iter>
SBasis(Iter first, Iter last) {
assert(std::distance(first, last) % 2 == 0);
+ assert(std::distance(first, last) >= 2);
for (; first != last; ++first) {
--last;
push_back(Linear(*first, *last));
@@ -188,14 +192,14 @@ public:
//IMPL: FragmentConcept
typedef double output_type;
inline bool isZero(double eps=EPSILON) const {
- if(empty()) return true;
+ assert(size() > 0);
for(unsigned i = 0; i < size(); i++) {
if(!(*this)[i].isZero(eps)) return false;
}
return true;
}
inline bool isConstant(double eps=EPSILON) const {
- if (empty()) return true;
+ assert(size() > 0);
if(!(*this)[0].isConstant(eps)) return false;
for (unsigned i = 1; i < size(); i++) {
if(!(*this)[i].isZero(eps)) return false;
@@ -212,6 +216,7 @@ public:
int degreesOfFreedom() const { return size()*2;}
double valueAt(double t) const {
+ assert(size() > 0);
double s = t*(1-t);
double p0 = 0, p1 = 0;
for(unsigned k = size(); k > 0; k--) {
@@ -239,11 +244,11 @@ public:
//MUTATOR PRISON
//remove extra zeros
void normalize() {
- while(!empty() && 0 == back()[0] && 0 == back()[1])
+ while(size() > 1 && back().isZero(0))
pop_back();
}
- void truncate(unsigned k) { if(k < size()) resize(k); }
+ void truncate(unsigned k) { if(k < size()) resize(std::max<size_t>(k, 1)); }
private:
void derive(); // in place version
};