From 13e73fa386cd7843d7079ec7c162ef43d15097c4 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Thu, 30 Aug 2007 18:32:36 +0000 Subject: Update to 2Geom rev. 1113 (bzr r3622) --- src/2geom/d2-sbasis.cpp | 148 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 src/2geom/d2-sbasis.cpp (limited to 'src/2geom/d2-sbasis.cpp') diff --git a/src/2geom/d2-sbasis.cpp b/src/2geom/d2-sbasis.cpp new file mode 100644 index 000000000..b68e3e6c5 --- /dev/null +++ b/src/2geom/d2-sbasis.cpp @@ -0,0 +1,148 @@ +#include "d2.h" +/* One would think that we would include d2-sbasis.h, however, + * you cannot actually include it in anything - only d2 may import it. + * This is due to the trickinesses of template submatching. */ + +namespace Geom { + +SBasis L2(D2 const & a, unsigned k) { return sqrt(dot(a, a), k); } + +D2 multiply(Linear const & a, D2 const & b) { + return D2(multiply(a, b[X]), multiply(a, b[Y])); +} + +D2 multiply(SBasis const & a, D2 const & b) { + return D2(multiply(a, b[X]), multiply(a, b[Y])); +} + +D2 truncate(D2 const & a, unsigned terms) { + return D2(truncate(a[X], terms), truncate(a[Y], terms)); +} + +unsigned sbasis_size(D2 const & a) { + return std::max((unsigned) a[0].size(), (unsigned) a[1].size()); +} + +//TODO: Is this sensical? shouldn't it be like pythagorean or something? +double tail_error(D2 const & a, unsigned tail) { + return std::max(a[0].tailError(tail), a[1].tailError(tail)); +} + +Piecewise > sectionize(D2 > const &a) { + Piecewise x = partition(a[0], a[1].cuts), y = partition(a[1], a[0].cuts); + assert(x.size() == y.size()); + Piecewise > ret; + for(unsigned i = 0; i < x.size(); i++) + ret.push_seg(D2(x[i], y[i])); + ret.cuts.insert(ret.cuts.end(), x.cuts.begin(), x.cuts.end()); + return ret; +} + +D2 > make_cuts_independant(Piecewise > const &a) { + D2 > ret; + for(unsigned d = 0; d < 2; d++) { + for(unsigned i = 0; i < a.size(); i++) + ret[d].push_seg(a[i][d]); + ret[d].cuts.insert(ret[d].cuts.end(), a.cuts.begin(), a.cuts.end()); + } + return ret; +} + +Piecewise > rot90(Piecewise > const &M){ + Piecewise > result; + if (M.empty()) return M; + result.push_cut(M.cuts[0]); + for (unsigned i=0; i dot(Piecewise > const &a, + Piecewise > const &b){ + Piecewise result; + if (a.empty() || b.empty()) return result; + Piecewise > aa = partition(a,b.cuts); + Piecewise > bb = partition(b,a.cuts); + + result.push_cut(aa.cuts.front()); + for (unsigned i=0; i cross(Piecewise > const &a, + Piecewise > const &b){ + Piecewise result; + if (a.empty() || b.empty()) return result; + Piecewise > aa = partition(a,b.cuts); + Piecewise > bb = partition(b,a.cuts); + + result.push_cut(aa.cuts.front()); + for (unsigned i=0; i > remove_short_cuts(Piecewise > const &f, double tol){ + double min = tol; + unsigned idx = f.size(); + for(unsigned i=0; i f.cuts[i+1]-f.cuts[i]){ + min = f.cuts[i+1]-f.cuts[i]; + idx = int(i); + } + } + if (idx==f.size()){ + return f; + } + if (f.size()==1) { + //removing this seg would result in an empty pw>... + return f; + } + Piecewise > new_f=f; + for (int dim=0; dim<2; dim++){ + double v = Hat(f.segs.at(idx)[dim][0]); + //TODO: what about closed curves? + if (idx>0 && f.segs.at(idx-1).at1()==f.segs.at(idx).at0()) + new_f.segs.at(idx-1)[dim][0][1] = v; + if (idx0, only force continuity where the jump is smaller than tol. +Piecewise > force_continuity(Piecewise > const &f, + double tol, + bool closed){ + if (f.size()==0) return f; + Piecewise > result=f; + unsigned cur = (closed)? 0:1; + unsigned prev = (closed)? f.size()-1:0; + while(cur