From fe0f7ac550d0d5bde816a0f6a6dd346d17dbc84c Mon Sep 17 00:00:00 2001 From: johanengelen Date: Thu, 30 Aug 2007 19:47:20 +0000 Subject: [PATCH] update 2geom to rev 1114 and fix error. --- src/2geom/Makefile_insert | 1 - src/2geom/d2-sbasis.cpp | 288 ++++++++++++++++++++------------------ src/2geom/d2-sbasis.h | 145 +++++++++---------- src/2geom/d2.cpp | 177 ----------------------- 4 files changed, 223 insertions(+), 388 deletions(-) delete mode 100644 src/2geom/d2.cpp diff --git a/src/2geom/Makefile_insert b/src/2geom/Makefile_insert index 4a87c1a93..4e8fb13d8 100644 --- a/src/2geom/Makefile_insert +++ b/src/2geom/Makefile_insert @@ -24,7 +24,6 @@ 2geom/crossing.cpp \ 2geom/d2-sbasis.cpp \ 2geom/d2-sbasis.h \ - 2geom/d2.cpp \ 2geom/d2.h \ 2geom/geom.cpp \ 2geom/geom.h \ diff --git a/src/2geom/d2-sbasis.cpp b/src/2geom/d2-sbasis.cpp index b68e3e6c5..c5c005c24 100644 --- a/src/2geom/d2-sbasis.cpp +++ b/src/2geom/d2-sbasis.cpp @@ -4,145 +4,155 @@ * 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 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 > operator*(Piecewise > const &a, Matrix const &m) { + Piecewise > result; + if(a.empty()) return result; + result.push_cut(a.cuts[0]); + for (unsigned i = 0; i < a.size(); i++) { + result.push(a[i] * m, a.cuts[i+1]); + } + return result; +} + /* Replaced by remove_short_cuts in piecewise.h -//this recursively removes the shortest cut interval until none is shorter than tol. -//TODO: code this in a more efficient way! -Piecewise > 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 (idx > 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(cur0, 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 compose(D2 const & a, SBasis const & b) { - return D2(compose(a[X], b), compose(a[Y], b)); -} - -SBasis L2(D2 const & a, unsigned k); -double L2(D2 const & a); - -D2 multiply(Linear const & a, D2 const & b); -inline D2 operator*(Linear const & a, D2 const & b) { return multiply(a, b); } -D2 multiply(SBasis const & a, D2 const & b); -inline D2 operator*(SBasis const & a, D2 const & b) { return multiply(a, b); } -D2 truncate(D2 const & a, unsigned terms); - -unsigned sbasis_size(D2 const & a); -double tail_error(D2 const & a, unsigned tail); - -//Piecewise > specific decls: - -Piecewise > sectionize(D2 > const &a); -D2 > make_cuts_independant(Piecewise > const &a); -Piecewise > rot90(Piecewise > const &a); -Piecewise dot(Piecewise > const &a, Piecewise > const &b); -Piecewise cross(Piecewise > const &a, Piecewise > const &b); - -Piecewise > force_continuity(Piecewise > const &f, - double tol=0, - bool closed=false); - -class CoordIterator -: public std::iterator -{ -public: - CoordIterator(std::vector >::const_iterator const &iter, unsigned d) : impl_(iter), ix_(d) {} - - inline bool operator==(CoordIterator const &other) { return other.impl_ == impl_; } - inline bool operator!=(CoordIterator const &other) { return other.impl_ != impl_; } - - inline SBasis operator*() const { - return (*impl_)[ix_]; - } - - inline CoordIterator &operator++() { - ++impl_; - return *this; - } - inline CoordIterator operator++(int) { - CoordIterator old=*this; - ++(*this); - return old; - } - -private: - std::vector >::const_iterator impl_; - unsigned ix_; -}; - -inline CoordIterator iterateCoord(Piecewise > const &a, unsigned d) { - return CoordIterator(a.segs.begin(), d); -} - -//bounds specializations with order -inline Rect bounds_fast(D2 const & s, unsigned order=0) { - return Rect(bounds_fast(s[X], order), - bounds_fast(s[Y], order)); -} -inline Rect bounds_local(D2 const & s, Interval i, unsigned order=0) { - return Rect(bounds_local(s[X], i, order), - bounds_local(s[Y], i, order)); + +inline D2 compose(D2 const & a, SBasis const & b) { + return D2(compose(a[X], b), compose(a[Y], b)); +} + +SBasis L2(D2 const & a, unsigned k); +double L2(D2 const & a); + +D2 multiply(Linear const & a, D2 const & b); +inline D2 operator*(Linear const & a, D2 const & b) { return multiply(a, b); } +D2 multiply(SBasis const & a, D2 const & b); +inline D2 operator*(SBasis const & a, D2 const & b) { return multiply(a, b); } +D2 truncate(D2 const & a, unsigned terms); + +unsigned sbasis_size(D2 const & a); +double tail_error(D2 const & a, unsigned tail); + +//Piecewise > specific decls: + +Piecewise > sectionize(D2 > const &a); +D2 > make_cuts_independant(Piecewise > const &a); +Piecewise > rot90(Piecewise > const &a); +Piecewise dot(Piecewise > const &a, Piecewise > const &b); +Piecewise cross(Piecewise > const &a, Piecewise > const &b); + +Piecewise > operator*(Piecewise > const &a, Matrix const &m); + +Piecewise > force_continuity(Piecewise > const &f, + double tol=0, + bool closed=false); + +class CoordIterator +: public std::iterator +{ +public: + CoordIterator(std::vector >::const_iterator const &iter, unsigned d) : impl_(iter), ix_(d) {} + + inline bool operator==(CoordIterator const &other) { return other.impl_ == impl_; } + inline bool operator!=(CoordIterator const &other) { return other.impl_ != impl_; } + + inline SBasis operator*() const { + return (*impl_)[ix_]; + } + + inline CoordIterator &operator++() { + ++impl_; + return *this; + } + inline CoordIterator operator++(int) { + CoordIterator old=*this; + ++(*this); + return old; + } + +private: + std::vector >::const_iterator impl_; + unsigned ix_; +}; + +inline CoordIterator iterateCoord(Piecewise > const &a, unsigned d) { + return CoordIterator(a.segs.begin(), d); +} + +//bounds specializations with order +inline Rect bounds_fast(D2 const & s, unsigned order=0) { + return Rect(bounds_fast(s[X], order), + bounds_fast(s[Y], order)); +} +inline Rect bounds_local(D2 const & s, Interval i, unsigned order=0) { + return Rect(bounds_local(s[X], i, order), + bounds_local(s[Y], i, order)); } } diff --git a/src/2geom/d2.cpp b/src/2geom/d2.cpp deleted file mode 100644 index 86538062b..000000000 --- a/src/2geom/d2.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/* - * d2.cpp - Lifts one dimensional objects into 2d - * - * Copyright 2007 Michael Sloan - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, output to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - */ - -#include "d2.h" - -namespace Geom { - -SBasis L2(D2 const & a, unsigned k) { return sqrt(dot(a, a), k); } -double L2(D2 const & a) { return hypot(a[0], a[1]); } - -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