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> dot(Piecewise<D2<SBasis> > const &a, Point const &b);
77 Piecewise<SBasis> cross(Piecewise<D2<SBasis> > const &a, Piecewise<D2<SBasis> > const &b);
79 Piecewise<D2<SBasis> > operator*(Piecewise<D2<SBasis> > const &a, Matrix const &m);
81 Piecewise<D2<SBasis> > force_continuity(Piecewise<D2<SBasis> > const &f, double tol=0, bool closed=false);
83 std::vector<Piecewise<D2<SBasis> > > fuse_nearby_ends(std::vector<Piecewise<D2<SBasis> > > const &f, double tol=0);
85 std::vector<Geom::Piecewise<Geom::D2<Geom::SBasis> > > split_at_discontinuities (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwsbin, double tol = .0001);
87 class CoordIterator
88 : public std::iterator<std::input_iterator_tag, SBasis const>
89 {
90 public:
91 CoordIterator(std::vector<D2<SBasis> >::const_iterator const &iter, unsigned d) : impl_(iter), ix_(d) {}
93 inline bool operator==(CoordIterator const &other) { return other.impl_ == impl_; }
94 inline bool operator!=(CoordIterator const &other) { return other.impl_ != impl_; }
96 inline SBasis operator*() const {
97 return (*impl_)[ix_];
98 }
100 inline CoordIterator &operator++() {
101 ++impl_;
102 return *this;
103 }
104 inline CoordIterator operator++(int) {
105 CoordIterator old=*this;
106 ++(*this);
107 return old;
108 }
110 private:
111 std::vector<D2<SBasis> >::const_iterator impl_;
112 unsigned ix_;
113 };
115 inline CoordIterator iterateCoord(Piecewise<D2<SBasis> > const &a, unsigned d) {
116 return CoordIterator(a.segs.begin(), d);
117 }
119 //bounds specializations with order
120 inline OptRect bounds_fast(D2<SBasis> const & s, unsigned order=0) {
121 OptRect retval;
122 OptInterval xint = bounds_fast(s[X], order);
123 if (xint) {
124 OptInterval yint = bounds_fast(s[Y], order);
125 if (yint) {
126 retval = Rect(*xint, *yint);
127 }
128 }
129 return retval;
130 }
131 inline OptRect bounds_local(D2<SBasis> const & s, OptInterval i, unsigned order=0) {
132 OptRect retval;
133 OptInterval xint = bounds_local(s[X], i, order);
134 OptInterval yint = bounds_local(s[Y], i, order);
135 if (xint && yint) {
136 retval = Rect(*xint, *yint);
137 }
138 return retval;
139 }
141 }
143 #endif
144 #endif
147 /*
148 Local Variables:
149 mode:c++
150 c-file-style:"stroustrup"
151 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
152 indent-tabs-mode:nil
153 fill-column:99
154 End:
155 */
156 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :