1 /**
2 * \file
3 * \brief Do not include this file \todo brief description
4 *
5 * We don't actually want anyone to
6 * include this, other than D2.h. If somone else tries, D2
7 * won't be defined. If it is, this will already be included.
8 *
9 * Authors:
10 * ? <?@?.?>
11 *
12 * Copyright ?-? authors
13 *
14 * This library is free software; you can redistribute it and/or
15 * modify it either under the terms of the GNU Lesser General Public
16 * License version 2.1 as published by the Free Software Foundation
17 * (the "LGPL") or, at your option, under the terms of the Mozilla
18 * Public License Version 1.1 (the "MPL"). If you do not alter this
19 * notice, a recipient may use your version of this file under either
20 * the MPL or the LGPL.
21 *
22 * You should have received a copy of the LGPL along with this library
23 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * You should have received a copy of the MPL along with this library
26 * in the file COPYING-MPL-1.1
27 *
28 * The contents of this file are subject to the Mozilla Public License
29 * Version 1.1 (the "License"); you may not use this file except in
30 * compliance with the License. You may obtain a copy of the License at
31 * http://www.mozilla.org/MPL/
32 *
33 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
34 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
35 * the specific language governing rights and limitations.
36 *
37 */
39 #ifdef _2GEOM_D2 /*This is intentional: we don't actually want anyone to
40 include this, other than D2.h. If somone else tries, D2
41 won't be defined. If it is, this will already be included. */
42 #ifndef __2GEOM_SBASIS_CURVE_H
43 #define __2GEOM_SBASIS_CURVE_H
45 #include <2geom/sbasis.h>
46 #include <2geom/sbasis-2d.h>
47 #include <2geom/piecewise.h>
48 #include <2geom/matrix.h>
50 //TODO: implement intersect
52 namespace Geom {
54 inline D2<SBasis> compose(D2<SBasis> const & a, SBasis const & b) {
55 return D2<SBasis>(compose(a[X], b), compose(a[Y], b));
56 }
58 SBasis L2(D2<SBasis> const & a, unsigned k);
59 double L2(D2<double> const & a);
61 D2<SBasis> multiply(Linear const & a, D2<SBasis> const & b);
62 inline D2<SBasis> operator*(Linear const & a, D2<SBasis> const & b) { return multiply(a, b); }
63 D2<SBasis> multiply(SBasis const & a, D2<SBasis> const & b);
64 inline D2<SBasis> operator*(SBasis const & a, D2<SBasis> const & b) { return multiply(a, b); }
65 D2<SBasis> truncate(D2<SBasis> const & a, unsigned terms);
67 unsigned sbasis_size(D2<SBasis> const & a);
68 double tail_error(D2<SBasis> const & a, unsigned tail);
70 //Piecewise<D2<SBasis> > specific decls:
72 Piecewise<D2<SBasis> > sectionize(D2<Piecewise<SBasis> > const &a);
73 D2<Piecewise<SBasis> > make_cuts_independent(Piecewise<D2<SBasis> > const &a);
74 Piecewise<D2<SBasis> > rot90(Piecewise<D2<SBasis> > const &a);
75 Piecewise<SBasis> dot(Piecewise<D2<SBasis> > const &a, Piecewise<D2<SBasis> > const &b);
76 Piecewise<SBasis> cross(Piecewise<D2<SBasis> > const &a, Piecewise<D2<SBasis> > const &b);
78 Piecewise<D2<SBasis> > operator*(Piecewise<D2<SBasis> > const &a, Matrix const &m);
80 Piecewise<D2<SBasis> > force_continuity(Piecewise<D2<SBasis> > const &f, double tol=0, bool closed=false);
82 std::vector<Piecewise<D2<SBasis> > > fuse_nearby_ends(std::vector<Piecewise<D2<SBasis> > > const &f, double tol=0);
84 std::vector<Geom::Piecewise<Geom::D2<Geom::SBasis> > > split_at_discontinuities (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwsbin, double tol = .0001);
86 class CoordIterator
87 : public std::iterator<std::input_iterator_tag, SBasis const>
88 {
89 public:
90 CoordIterator(std::vector<D2<SBasis> >::const_iterator const &iter, unsigned d) : impl_(iter), ix_(d) {}
92 inline bool operator==(CoordIterator const &other) { return other.impl_ == impl_; }
93 inline bool operator!=(CoordIterator const &other) { return other.impl_ != impl_; }
95 inline SBasis operator*() const {
96 return (*impl_)[ix_];
97 }
99 inline CoordIterator &operator++() {
100 ++impl_;
101 return *this;
102 }
103 inline CoordIterator operator++(int) {
104 CoordIterator old=*this;
105 ++(*this);
106 return old;
107 }
109 private:
110 std::vector<D2<SBasis> >::const_iterator impl_;
111 unsigned ix_;
112 };
114 inline CoordIterator iterateCoord(Piecewise<D2<SBasis> > const &a, unsigned d) {
115 return CoordIterator(a.segs.begin(), d);
116 }
118 //bounds specializations with order
119 inline OptRect bounds_fast(D2<SBasis> const & s, unsigned order=0) {
120 OptRect retval;
121 OptInterval xint = bounds_fast(s[X], order);
122 if (xint) {
123 OptInterval yint = bounds_fast(s[Y], order);
124 if (yint) {
125 retval = Rect(*xint, *yint);
126 }
127 }
128 return retval;
129 }
130 inline OptRect bounds_local(D2<SBasis> const & s, OptInterval i, unsigned order=0) {
131 OptRect retval;
132 OptInterval xint = bounds_local(s[X], i, order);
133 OptInterval yint = bounds_local(s[Y], i, order);
134 if (xint && yint) {
135 retval = Rect(*xint, *yint);
136 }
137 return retval;
138 }
140 }
142 #endif
143 #endif
146 /*
147 Local Variables:
148 mode:c++
149 c-file-style:"stroustrup"
150 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
151 indent-tabs-mode:nil
152 fill-column:99
153 End:
154 */
155 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :