summaryrefslogtreecommitdiffstats
path: root/src/2geom
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2008-10-11 15:16:23 +0000
committerTed Gould <ted@canonical.com>2008-10-11 15:16:23 +0000
commit2f5eb047d9e05be5e68549ef6b75070d2faa7d2f (patch)
treeca2e94164b6d7aaebfc17196ca46bfc825a7665a /src/2geom
parentMerge from trunk. (diff)
downloadinkscape-2f5eb047d9e05be5e68549ef6b75070d2faa7d2f.tar.gz
inkscape-2f5eb047d9e05be5e68549ef6b75070d2faa7d2f.zip
Merging from trunk
(bzr r6884)
Diffstat (limited to 'src/2geom')
-rw-r--r--src/2geom/piecewise.cpp13
-rw-r--r--src/2geom/piecewise.h2
-rw-r--r--src/2geom/rect.h12
-rw-r--r--src/2geom/sbasis.cpp4
-rw-r--r--src/2geom/transforms.h1
5 files changed, 29 insertions, 3 deletions
diff --git a/src/2geom/piecewise.cpp b/src/2geom/piecewise.cpp
index 2d8638818..4c63b20df 100644
--- a/src/2geom/piecewise.cpp
+++ b/src/2geom/piecewise.cpp
@@ -158,7 +158,6 @@ std::vector<double> roots(Piecewise<SBasis> const &f){
std::vector<double> result;
for (unsigned i=0; i<f.size(); i++){
std::vector<double> rts=roots(f.segs[i]);
- rts=roots(f.segs[i]);
for (unsigned r=0; r<rts.size(); r++){
result.push_back(f.mapToDomain(rts[r], i));
@@ -167,6 +166,18 @@ std::vector<double> roots(Piecewise<SBasis> const &f){
return result;
}
+std::vector<std::vector<double> > multi_roots(Piecewise<SBasis> const &f, std::vector<double> const &values) {
+ std::vector<std::vector<double> > result(values.size());
+ for (unsigned i=0; i<f.size(); i++) {
+ std::vector<std::vector<double> > rts = multi_roots(f.segs[i], values);
+ for(unsigned j=0; j<rts.size(); j++) {
+ for(unsigned r=0; r<rts[j].size(); r++){
+ result[j].push_back(f.mapToDomain(rts[j][r], i));
+ }
+ }
+ }
+ return result;
+}
}
/*
diff --git a/src/2geom/piecewise.h b/src/2geom/piecewise.h
index 3979643b2..d25c04bc4 100644
--- a/src/2geom/piecewise.h
+++ b/src/2geom/piecewise.h
@@ -706,6 +706,8 @@ Piecewise<T> derivative(Piecewise<T> const &a) {
std::vector<double> roots(Piecewise<SBasis> const &f);
+std::vector<std::vector<double> >multi_roots(Piecewise<SBasis> const &f, std::vector<double> const &values);
+
template<typename T>
Piecewise<T> reverse(Piecewise<T> const &f) {
Piecewise<T> ret = Piecewise<T>();
diff --git a/src/2geom/rect.h b/src/2geom/rect.h
index f8ac7a2f7..ee1b0d764 100644
--- a/src/2geom/rect.h
+++ b/src/2geom/rect.h
@@ -140,6 +140,18 @@ inline Rect unify(Rect const & a, Rect const & b) {
return Rect(unify(a[X], b[X]), unify(a[Y], b[Y]));
}
+/** Returns the smallest rectangle that encloses both rectangles.
+ * An empty argument is assumed to be an empty rectangle */
+inline boost::optional<Rect> unify(boost::optional<Rect> const & a, boost::optional<Rect> const & b) {
+ if (!a) {
+ return b;
+ } else if (!b) {
+ return a;
+ } else {
+ return unify(*a, *b);
+ }
+}
+
inline Rect union_list(std::vector<Rect> const &r) {
if(r.empty()) return Rect(Interval(0,0), Interval(0,0));
Rect ret = r[0];
diff --git a/src/2geom/sbasis.cpp b/src/2geom/sbasis.cpp
index 377238d92..a7e049def 100644
--- a/src/2geom/sbasis.cpp
+++ b/src/2geom/sbasis.cpp
@@ -70,9 +70,9 @@ bool SBasis::isFinite() const {
std::vector<double> SBasis::valueAndDerivatives(double t, unsigned n) const {
std::vector<double> ret(n+1);
- ret.push_back(valueAt(t));
+ ret[0]=valueAt(t);
SBasis tmp = *this;
- for(unsigned i = 0; i < n; i++) {
+ for(unsigned i = 1; i < n+1; i++) {
tmp.derive();
ret[i] = tmp.valueAt(t);
}
diff --git a/src/2geom/transforms.h b/src/2geom/transforms.h
index 898b095b5..d21c5c617 100644
--- a/src/2geom/transforms.h
+++ b/src/2geom/transforms.h
@@ -84,6 +84,7 @@ class Rotate {
explicit Rotate(Coord x, Coord y) { Rotate(Point(x, y)); }
inline operator Matrix() const { return Matrix(vec[X], vec[Y], -vec[Y], vec[X], 0, 0); }
+ inline Point vector() const { return vec; }
inline Coord operator[](Dim2 const dim) const { return vec[dim]; }
inline Coord operator[](unsigned const dim) const { return vec[dim]; }
inline bool operator==(Rotate const &o) const { return vec == o.vec; }