Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
curve.h
Go to the documentation of this file.
1/*
6 * Authors:
7 * MenTaLguY <mental@rydia.net>
8 * Marco Cecchetti <mrcekets at gmail.com>
9 * Krzysztof KosiƄski <tweenk.pl@gmail.com>
10 *
11 * Copyright 2007-2009 Authors
12 *
13 * This library is free software; you can redistribute it and/or
14 * modify it either under the terms of the GNU Lesser General Public
15 * License version 2.1 as published by the Free Software Foundation
16 * (the "LGPL") or, at your option, under the terms of the Mozilla
17 * Public License Version 1.1 (the "MPL"). If you do not alter this
18 * notice, a recipient may use your version of this file under either
19 * the MPL or the LGPL.
20 *
21 * You should have received a copy of the LGPL along with this library
22 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * You should have received a copy of the MPL along with this library
25 * in the file COPYING-MPL-1.1
26 *
27 * The contents of this file are subject to the Mozilla Public License
28 * Version 1.1 (the "License"); you may not use this file except in
29 * compliance with the License. You may obtain a copy of the License at
30 * http://www.mozilla.org/MPL/
31 *
32 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
33 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
34 * the specific language governing rights and limitations.
35 */
36
37
38#ifndef LIB2GEOM_SEEN_CURVE_H
39#define LIB2GEOM_SEEN_CURVE_H
40
41#include <vector>
42#include <boost/operators.hpp>
43#include <2geom/coord.h>
44#include <2geom/point.h>
45#include <2geom/interval.h>
46#include <2geom/sbasis.h>
47#include <2geom/d2.h>
48#include <2geom/affine.h>
49#include <2geom/intersection.h>
50
51namespace Geom {
52
53class PathSink;
55
76class Curve
77 : boost::equality_comparable<Curve>
78{
79public:
80 virtual ~Curve() {}
81
84
86 virtual Point initialPoint() const = 0;
87
90 virtual Point finalPoint() const = 0;
91
95 virtual bool isDegenerate() const = 0;
96
98 virtual bool isLineSegment() const { return false; }
99
102 virtual Interval timeRange() const {
103 Interval tr(0, 1);
104 return tr;
105 }
106
110 virtual Point pointAt(Coord t) const { return pointAndDerivatives(t, 0).front(); }
111
116 virtual Coord valueAt(Coord t, Dim2 d) const { return pointAt(t)[d]; }
117
120 virtual Point operator() (Coord t) const { return pointAt(t); }
121
130 virtual std::vector<Point> pointAndDerivatives(Coord t, unsigned n) const = 0;
132
135
140 virtual void setInitial(Point const &v) = 0;
141
147 virtual void setFinal(Point const &v) = 0;
149
152
156 virtual Rect boundsFast() const = 0;
157
161 virtual Rect boundsExact() const = 0;
162
167 virtual void expandToTransformed(Rect &bbox, Affine const &transform) const = 0;
168
169 // I have no idea what the 'deg' parameter is for, so this is undocumented for now.
170 virtual OptRect boundsLocal(OptInterval const &i, unsigned deg) const = 0;
171
180 OptRect boundsLocal(OptInterval const &a) const { return boundsLocal(a, 0); }
182
185
187 virtual Curve *duplicate() const = 0;
188
193 void transform(Affine const &m) {
194 *this *= m;
195 }
196
197 virtual void operator*=(Translate const &tr) { *this *= Affine(tr); }
198 virtual void operator*=(Scale const &s) { *this *= Affine(s); }
199 virtual void operator*=(Rotate const &r) { *this *= Affine(r); }
200 virtual void operator*=(HShear const &hs) { *this *= Affine(hs); }
201 virtual void operator*=(VShear const &vs) { *this *= Affine(vs); }
202 virtual void operator*=(Zoom const &z) { *this *= Affine(z); }
203 virtual void operator*=(Affine const &m) = 0;
204
209 virtual Curve *transformed(Affine const &m) const {
210 Curve *ret = duplicate();
211 ret->transform(m);
212 return ret;
213 }
214
225 virtual Curve *portion(Coord a, Coord b) const = 0;
226
228 Curve *portion(Interval const &i) const { return portion(i.min(), i.max()); }
229
234 virtual Curve *reverse() const { return portion(1, 0); }
235
242 virtual Curve *derivative() const = 0;
244
247
254 virtual Coord nearestTime( Point const& p, Coord a = 0, Coord b = 1 ) const;
255
257 Coord nearestTime(Point const &p, Interval const &i) const {
258 return nearestTime(p, i.min(), i.max());
259 }
260
266 virtual std::vector<Coord> allNearestTimes( Point const& p, Coord from = 0,
267 Coord to = 1 ) const;
268
270 std::vector<Coord> allNearestTimes(Point const &p, Interval const &i) {
271 return allNearestTimes(p, i.min(), i.max());
272 }
273
284 virtual Coord length(Coord tolerance=0.01) const;
285
289 virtual std::vector<Coord> roots(Coord v, Dim2 d) const = 0;
290
299 virtual int winding(Point const &p) const;
300
302 virtual std::vector<CurveIntersection> intersect(Curve const &other, Coord eps = EPSILON) const;
303
305 virtual std::vector<CurveIntersection> intersectSelf(Coord eps = EPSILON) const;
306
317 virtual Point unitTangentAt(Coord t, unsigned n = 3) const;
318
325 virtual D2<SBasis> toSBasis() const = 0;
327
330
333 virtual int degreesOfFreedom() const { return 0;}
334
340 bool operator==(Curve const &c) const { return _equalTo(c); }
341
343 virtual bool isNear(Curve const &c, Coord precision) const = 0;
344
346 virtual void feed(PathSink &sink, bool moveto_initial) const;
348
349protected:
350 virtual bool _equalTo(Curve const &c) const = 0;
351};
352
353inline
354Coord nearest_time(Point const& p, Curve const& c) {
355 return c.nearestTime(p);
356}
357
358// for make benefit glorious library of Boost Pointer Container
359inline
361 return c.duplicate();
362}
363
364} // end namespace Geom
365
366
367#endif // _2GEOM_CURVE_H_
368
369/*
370 Local Variables:
371 mode:c++
372 c-file-style:"stroustrup"
373 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
374 indent-tabs-mode:nil
375 fill-column:99
376 End:
377*/
378// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
Cartesian point / 2D vector and related operations.
3x3 affine transformation matrix.
3x3 matrix representing an affine transformation.
Definition affine.h:70
Abstract continuous curve on a plane defined on [0,1].
Definition curve.h:78
virtual D2< SBasis > toSBasis() const =0
Convert the curve to a symmetric power basis polynomial.
virtual Point operator()(Coord t) const
Evaluate the function at the specified time value.
Definition curve.h:120
Curve * portion(Interval const &i) const
A version of that accepts an Interval.
Definition curve.h:228
virtual Point initialPoint() const =0
Retrieve the start of the curve.
virtual Point finalPoint() const =0
Retrieve the end of the curve.
virtual Rect boundsFast() const =0
Quickly compute the curve's approximate bounding box.
virtual Curve * reverse() const
Create a reversed version of this curve.
Definition curve.h:234
virtual ~Curve()
Definition curve.h:80
virtual Curve * transformed(Affine const &m) const
Create a curve transformed by an affine transformation.
Definition curve.h:209
virtual Point unitTangentAt(Coord t, unsigned n=3) const
Compute a vector tangent to the curve.
Definition curve.cpp:201
virtual void operator*=(Scale const &s)
Definition curve.h:198
virtual Interval timeRange() const
Get the interval of allowed time values.
Definition curve.h:102
virtual std::vector< Coord > roots(Coord v, Dim2 d) const =0
Computes time values at which the curve intersects an axis-aligned line.
virtual void feed(PathSink &sink, bool moveto_initial) const
Feed the curve to a PathSink.
Definition curve.cpp:214
virtual void operator*=(VShear const &vs)
Definition curve.h:201
virtual std::vector< CurveIntersection > intersect(Curve const &other, Coord eps=EPSILON) const
Compute intersections with another curve.
Definition curve.cpp:97
virtual bool isDegenerate() const =0
Check whether the curve has exactly zero length.
virtual int winding(Point const &p) const
Compute the partial winding number of this curve.
Definition curve.cpp:61
virtual void operator*=(Affine const &m)=0
virtual Rect boundsExact() const =0
Compute the curve's exact bounding box.
virtual int degreesOfFreedom() const
Return the number of independent parameters required to represent all variations of this curve.
Definition curve.h:333
virtual Coord valueAt(Coord t, Dim2 d) const
Evaluate one of the coordinates at the specified time value.
Definition curve.h:116
virtual std::vector< Coord > allNearestTimes(Point const &p, Coord from=0, Coord to=1) const
Compute time values at which the curve comes closest to a specified point.
Definition curve.cpp:51
bool operator==(Curve const &c) const
Test equality of two curves.
Definition curve.h:340
virtual Coord nearestTime(Point const &p, Coord a=0, Coord b=1) const
Compute a time value at which the curve comes closest to a specified point.
Definition curve.cpp:46
virtual void operator*=(Translate const &tr)
Definition curve.h:197
virtual void expandToTransformed(Rect &bbox, Affine const &transform) const =0
Expand the given rectangle to include the transformed curve, assuming it already contains its initial...
virtual std::vector< CurveIntersection > intersectSelf(Coord eps=EPSILON) const
Compute intersections of this curve with itself.
Definition curve.cpp:103
virtual void operator*=(Zoom const &z)
Definition curve.h:202
virtual Coord length(Coord tolerance=0.01) const
Compute the arc length of this curve.
Definition curve.cpp:56
std::vector< Coord > allNearestTimes(Point const &p, Interval const &i)
A version that takes an Interval.
Definition curve.h:270
virtual Curve * derivative() const =0
Create a derivative of this curve.
OptRect boundsLocal(OptInterval const &a) const
Compute the bounding box of a part of the curve.
Definition curve.h:180
virtual void setInitial(Point const &v)=0
Change the starting point of the curve.
virtual bool _equalTo(Curve const &c) const =0
virtual bool isNear(Curve const &c, Coord precision) const =0
Test whether two curves are approximately the same.
virtual Curve * duplicate() const =0
Create an exact copy of this curve.
virtual void operator*=(Rotate const &r)
Definition curve.h:199
virtual void operator*=(HShear const &hs)
Definition curve.h:200
virtual Curve * portion(Coord a, Coord b) const =0
Create a curve that corresponds to a part of this curve.
virtual std::vector< Point > pointAndDerivatives(Coord t, unsigned n) const =0
Evaluate the curve and its derivatives.
virtual OptRect boundsLocal(OptInterval const &i, unsigned deg) const =0
virtual bool isLineSegment() const
Check whether the curve is a line segment.
Definition curve.h:98
virtual void setFinal(Point const &v)=0
Change the ending point of the curve.
virtual Point pointAt(Coord t) const
Evaluate the curve at a specified time value.
Definition curve.h:110
Coord nearestTime(Point const &p, Interval const &i) const
A version that takes an Interval.
Definition curve.h:257
void transform(Affine const &m)
Transform this curve by an affine transformation.
Definition curve.h:193
Adaptor that creates 2D functions from 1D ones.
Definition d2.h:55
constexpr C min() const
constexpr C max() const
Horizontal shearing.
Definition transforms.h:257
Intersection between two shapes.
Range of real numbers that is never empty.
Definition interval.h:59
Range of real numbers that can be empty.
Definition interval.h:199
Axis-aligned rectangle that can be empty.
Definition rect.h:203
Callback interface for processing path data.
Definition path-sink.h:56
Two-dimensional point that doubles as a vector.
Definition point.h:66
Axis aligned, non-empty rectangle.
Definition rect.h:92
Rotation around the origin.
Definition transforms.h:187
Scaling from the origin.
Definition transforms.h:150
Translation by a vector.
Definition transforms.h:115
Vertical shearing.
Definition transforms.h:274
Combination of a translation and uniform scale.
Definition transforms.h:292
Integral and real coordinate types and some basic utilities.
double c[8][4]
Lifts one dimensional objects into 2D.
Dim2
2D axis enumeration (X or Y).
Definition coord.h:48
double Coord
Floating point type used to store coordinates.
Definition coord.h:76
constexpr Coord EPSILON
Default "acceptably small" value.
Definition coord.h:84
Intersection utilities.
Simple closed interval class.
Various utility functions.
Definition affine.h:22
Intersection CurveIntersection
Definition curve.h:54
Coord nearest_time(Point const &p, Curve const &c)
Definition curve.h:354
Curve * new_clone(Curve const &c)
Definition curve.h:360
Polynomial in symmetric power basis (S-basis)