Code

update 2geom
[inkscape.git] / src / 2geom / curve.h
1 /*
2  * Abstract Curve Type
3  *
4  * Authors:
5  *              MenTaLguY <mental@rydia.net>
6  *              Marco Cecchetti <mrcekets at gmail.com>
7  * 
8  * Copyright 2007-2008  authors
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it either under the terms of the GNU Lesser General Public
12  * License version 2.1 as published by the Free Software Foundation
13  * (the "LGPL") or, at your option, under the terms of the Mozilla
14  * Public License Version 1.1 (the "MPL"). If you do not alter this
15  * notice, a recipient may use your version of this file under either
16  * the MPL or the LGPL.
17  *
18  * You should have received a copy of the LGPL along with this library
19  * in the file COPYING-LGPL-2.1; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21  * You should have received a copy of the MPL along with this library
22  * in the file COPYING-MPL-1.1
23  *
24  * The contents of this file are subject to the Mozilla Public License
25  * Version 1.1 (the "License"); you may not use this file except in
26  * compliance with the License. You may obtain a copy of the License at
27  * http://www.mozilla.org/MPL/
28  *
29  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
30  * OF ANY KIND, either express or implied. See the LGPL or the MPL for
31  * the specific language governing rights and limitations.
32  */
37 #ifndef _2GEOM_CURVE_H_
38 #define _2GEOM_CURVE_H_
41 #include "coord.h"
42 #include "point.h"
43 #include "interval.h"
44 #include "nearest-point.h"
45 #include "sbasis.h"
46 #include "d2.h"
47 #include "matrix.h"
48 #include "exception.h"
50 #include <vector>
53 namespace Geom 
54 {
56 class Curve;
58 struct CurveHelpers {
59 protected:
60   static int root_winding(Curve const &c, Point p);
61 };
63 class Curve : private CurveHelpers {
64 public:
65   virtual ~Curve() {}
67   virtual Point initialPoint() const = 0;
68   virtual Point finalPoint() const = 0;
70   virtual bool isDegenerate() const = 0;
72   virtual Curve *duplicate() const = 0;
74   virtual Rect boundsFast() const = 0;
75   virtual Rect boundsExact() const = 0;
76   virtual Rect boundsLocal(Interval i, unsigned deg) const = 0;
77   Rect boundsLocal(Interval i) const { return boundsLocal(i, 0); }
79   virtual std::vector<double> roots(double v, Dim2 d) const = 0;
81   virtual int winding(Point p) const { return root_winding(*this, p); }
83   //mental: review these
84   virtual Curve *portion(double f, double t) const = 0;
85   virtual Curve *reverse() const { return portion(1, 0); }
86   virtual Curve *derivative() const = 0;
88   virtual void setInitial(Point v) = 0;
89   virtual void setFinal(Point v) = 0;
90   
91   virtual
92   double nearestPoint( Point const& p, double from = 0, double to = 1 ) const
93   {
94           return nearest_point(p, toSBasis(), from, to);
95   }
96   
97   virtual
98   std::vector<double> 
99   allNearestPoints( Point const& p, double from = 0, double to = 1 ) const
100   {
101           return all_nearest_points(p, toSBasis(), from, to);
102   }
104   virtual Curve *transformed(Matrix const &m) const = 0;
106   virtual Point pointAt(Coord t) const { return pointAndDerivatives(t, 0).front(); }
107   virtual Coord valueAt(Coord t, Dim2 d) const { return pointAt(t)[d]; }
108   virtual Point operator() (double t)  const { return pointAt(t); }
109   
110   /* pointAndDerivatives returns a vector that looks like the following:
111    *  [ point at t, 1st derivative at t, 2nd derivative at t, ... , n'th derivative at t] */
112   virtual std::vector<Point> pointAndDerivatives(Coord t, unsigned n) const = 0;
114   virtual D2<SBasis> toSBasis() const = 0;
115 };
117 inline
118 Coord nearest_point(Point const& p, Curve const& c)
120         return c.nearestPoint(p);
123 } // end namespace Geom
126 #endif // _2GEOM_CURVE_H_
130 /*
131   Local Variables:
132   mode:c++
133   c-file-style:"stroustrup"
134   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
135   indent-tabs-mode:nil
136   fill-column:99
137   End:
138 */
139 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :