Code

Super duper mega (fun!) commit: replaced encoding=utf-8 with fileencoding=utf-8 in...
[inkscape.git] / src / 2geom / sbasis-curve.h
1 /**
2  * \file
3  * \brief Symmetric Power Basis Curve
4  *
5  * Authors:
6  *              MenTaLguY <mental@rydia.net>
7  *              Marco Cecchetti <mrcekets at gmail.com>
8  * 
9  * Copyright 2007-2008  authors
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it either under the terms of the GNU Lesser General Public
13  * License version 2.1 as published by the Free Software Foundation
14  * (the "LGPL") or, at your option, under the terms of the Mozilla
15  * Public License Version 1.1 (the "MPL"). If you do not alter this
16  * notice, a recipient may use your version of this file under either
17  * the MPL or the LGPL.
18  *
19  * You should have received a copy of the LGPL along with this library
20  * in the file COPYING-LGPL-2.1; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  * You should have received a copy of the MPL along with this library
23  * in the file COPYING-MPL-1.1
24  *
25  * The contents of this file are subject to the Mozilla Public License
26  * Version 1.1 (the "License"); you may not use this file except in
27  * compliance with the License. You may obtain a copy of the License at
28  * http://www.mozilla.org/MPL/
29  *
30  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
31  * OF ANY KIND, either express or implied. See the LGPL or the MPL for
32  * the specific language governing rights and limitations.
33  */
38 #ifndef _2GEOM_SBASIS_CURVE_H_
39 #define _2GEOM_SBASIS_CURVE_H_
42 #include <2geom/curve.h>
45 namespace Geom 
46 {
48 class SBasisCurve : public Curve {
49         
50 private:
51   SBasisCurve();
52   D2<SBasis> inner;
53   
54 public:
55   explicit SBasisCurve(D2<SBasis> const &sb) : inner(sb) {}
56   explicit SBasisCurve(Curve const &other) : inner(other.toSBasis()) {}
57   Curve *duplicate() const { return new SBasisCurve(*this); }
59   Point initialPoint() const    { return inner.at0(); }
60   Point finalPoint() const      { return inner.at1(); }
61   bool isDegenerate() const     { return inner.isConstant(); }
62   Point pointAt(Coord t) const  { return inner.valueAt(t); }
63   std::vector<Point> pointAndDerivatives(Coord t, unsigned n) const {
64       return inner.valueAndDerivatives(t, n);
65   }
66   double valueAt(Coord t, Dim2 d) const { return inner[d].valueAt(t); }
68   void setInitial(Point v) { for(unsigned d = 0; d < 2; d++) { inner[d][0][0] = v[d]; } }
69   void setFinal(Point v)   { for(unsigned d = 0; d < 2; d++) { inner[d][0][1] = v[d]; } }
71   virtual OptRect boundsFast() const  { return bounds_fast(inner); }
72   virtual OptRect boundsExact() const { return bounds_exact(inner); }
73   virtual OptRect boundsLocal(OptInterval i, unsigned deg) const { return bounds_local(inner, i, deg); }
75   std::vector<double> roots(double v, Dim2 d) const { return Geom::roots(inner[d] - v); }
76   
77   double nearestPoint( Point const& p, double from = 0, double to = 1 ) const
78   {
79           return nearest_point(p, inner, from, to);
80   }
81   
82   std::vector<double> 
83   allNearestPoints( Point const& p, double from = 0, double to = 1 ) const
84   {
85           return all_nearest_points(p, inner, from, to);
86   }
88   Curve *portion(double f, double t) const {
89     return new SBasisCurve(Geom::portion(inner, f, t));
90   }
92   Curve *transformed(Matrix const &m) const {
93     return new SBasisCurve(inner * m);
94   }
96   Curve *derivative() const {
97     return new SBasisCurve(Geom::derivative(inner));
98   }
100   D2<SBasis> toSBasis() const { return inner; }
102   virtual int degreesOfFreedom() const { return inner[0].degreesOfFreedom() + inner[1].degreesOfFreedom();
103   }
104 };
107 } // end namespace Geom
110 #endif // _2GEOM_SBASIS_CURVE_H_
115 /*
116   Local Variables:
117   mode:c++
118   c-file-style:"stroustrup"
119   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
120   indent-tabs-mode:nil
121   fill-column:99
122   End:
123 */
124 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :