summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKrzysztof Kosi??ski <tweenk.pl@gmail.com>2011-02-03 23:13:20 +0000
committerKrzysztof Kosiński <tweenk.pl@gmail.com>2011-02-03 23:13:20 +0000
commit7c620545cbc054aaf59605e37b50bdd3c1cb1133 (patch)
tree622fc936eacd8bb0e85f7106d5020e175da88be4 /src
parentTranslations. Context removed in filter-enums (context support too complex to... (diff)
downloadinkscape-7c620545cbc054aaf59605e37b50bdd3c1cb1133.tar.gz
inkscape-7c620545cbc054aaf59605e37b50bdd3c1cb1133.zip
Fix Linux build after 2Geom update
(bzr r10031)
Diffstat (limited to 'src')
-rw-r--r--src/2geom/Makefile_insert109
-rw-r--r--src/2geom/bezier-curve.cpp358
-rw-r--r--src/2geom/chebyshev.cpp126
-rw-r--r--src/2geom/chebyshev.h30
-rw-r--r--src/2geom/curve.cpp (renamed from src/2geom/curve-helpers.cpp)47
-rw-r--r--src/extension/dbus/dbus-init.cpp2
-rw-r--r--src/extension/dbus/document-interface.cpp45
-rw-r--r--src/extension/dbus/document-interface.h8
8 files changed, 477 insertions, 248 deletions
diff --git a/src/2geom/Makefile_insert b/src/2geom/Makefile_insert
index ead0e3517..174f56433 100644
--- a/src/2geom/Makefile_insert
+++ b/src/2geom/Makefile_insert
@@ -6,109 +6,110 @@
rm -f 2geom/lib2geom.a $(2geom_lib2geom_a_OBJECTS)
2geom_lib2geom_a_SOURCES = \
- 2geom/basic-intersection.cpp \
- 2geom/bezier-clipping.cpp \
- 2geom/utils.cpp \
- 2geom/bezier-utils.cpp \
- 2geom/circle-circle.cpp \
- 2geom/circle.cpp \
- 2geom/circle.h \
- 2geom/conjugate_gradient.cpp \
- 2geom/convex-cover.cpp \
- 2geom/crossing.cpp \
- 2geom/curve-helpers.cpp \
- 2geom/d2-sbasis.cpp \
- 2geom/ellipse.cpp \
- 2geom/elliptical-arc.cpp \
- 2geom/geom.cpp \
- 2geom/line.cpp \
2geom/affine.cpp \
- 2geom/nearest-point.cpp \
- 2geom/path-intersection.cpp \
- 2geom/path.cpp \
- 2geom/pathvector.cpp \
- 2geom/piecewise.cpp \
- 2geom/point.cpp \
- 2geom/poly.cpp \
- 2geom/quadtree.cpp \
- 2geom/region.cpp \
- 2geom/sbasis-2d.cpp \
- 2geom/sbasis-geometric.cpp \
- 2geom/sbasis-math.cpp \
- 2geom/sbasis-poly.cpp \
- 2geom/sbasis-roots.cpp \
- 2geom/sbasis-to-bezier.cpp \
- 2geom/sbasis.cpp \
- 2geom/shape.cpp \
- 2geom/solve-bezier-one-d.cpp \
- 2geom/solve-bezier-parametric.cpp \
- 2geom/svg-elliptical-arc.cpp \
- 2geom/svg-path-parser.cpp \
- 2geom/svg-path.cpp \
- 2geom/sweep.cpp \
- 2geom/transforms.cpp \
2geom/angle.h \
+ 2geom/basic-intersection.cpp \
2geom/basic-intersection.h \
+ 2geom/bezier-clipping.cpp \
+ 2geom/bezier-curve.cpp \
2geom/bezier-curve.h \
+ 2geom/bezier.h \
2geom/bezier-to-sbasis.h \
+ 2geom/bezier-utils.cpp \
2geom/bezier-utils.h \
- 2geom/bezier.h \
2geom/choose.h \
+ 2geom/circle-circle.cpp \
+ 2geom/circle.cpp \
+ 2geom/circle.h \
2geom/circulator.h \
2geom/concepts.h \
+ 2geom/conjugate_gradient.cpp \
2geom/conjugate_gradient.h \
+ 2geom/convex-cover.cpp \
2geom/convex-cover.h \
2geom/coord.h \
+ 2geom/crossing.cpp \
2geom/crossing.h \
+ 2geom/curve.cpp \
2geom/curve.h \
2geom/curves.h \
- 2geom/d2-sbasis.h \
2geom/d2.h \
+ 2geom/d2-sbasis.cpp \
+ 2geom/d2-sbasis.h \
+ 2geom/ellipse.cpp \
2geom/ellipse.h \
+ 2geom/elliptical-arc.cpp \
2geom/elliptical-arc.h \
2geom/exception.h \
2geom/forward.h \
+ 2geom/geom.cpp \
2geom/geom.h \
2geom/hvlinesegment.h \
2geom/interval.h \
2geom/isnan.h \
- 2geom/line.h \
2geom/linear.h \
+ 2geom/line.cpp \
+ 2geom/line.h \
2geom/matrix.h \
+ 2geom/nearest-point.cpp \
2geom/nearest-point.h \
+ 2geom/numeric/fitting-model.h \
+ 2geom/numeric/fitting-tool.h \
+ 2geom/numeric/linear_system.h \
+ 2geom/numeric/matrix.cpp \
+ 2geom/numeric/matrix.h \
+ 2geom/numeric/vector.h \
2geom/ord.h \
- 2geom/path-intersection.h \
+ 2geom/path.cpp \
2geom/path.h \
+ 2geom/path-intersection.cpp \
+ 2geom/path-intersection.h \
+ 2geom/pathvector.cpp \
2geom/pathvector.h \
+ 2geom/piecewise.cpp \
2geom/piecewise.h \
+ 2geom/point.cpp \
+ 2geom/point.h \
2geom/point-l.h \
2geom/point-ops.h \
- 2geom/point.h \
+ 2geom/poly.cpp \
2geom/poly.h \
+ 2geom/quadtree.cpp \
2geom/quadtree.h \
2geom/ray.h \
2geom/rect.h \
+ 2geom/region.cpp \
2geom/region.h \
+ 2geom/sbasis-2d.cpp \
2geom/sbasis-2d.h \
+ 2geom/sbasis.cpp \
2geom/sbasis-curve.h \
+ 2geom/sbasis-geometric.cpp \
2geom/sbasis-geometric.h \
+ 2geom/sbasis.h \
+ 2geom/sbasis-math.cpp \
2geom/sbasis-math.h \
+ 2geom/sbasis-poly.cpp \
2geom/sbasis-poly.h \
+ 2geom/sbasis-roots.cpp \
+ 2geom/sbasis-to-bezier.cpp \
2geom/sbasis-to-bezier.h \
- 2geom/sbasis.h \
+ 2geom/shape.cpp \
2geom/shape.h \
+ 2geom/solve-bezier-one-d.cpp \
+ 2geom/solve-bezier-parametric.cpp \
2geom/solver.h \
2geom/sturm.h \
+ 2geom/svg-elliptical-arc.cpp \
2geom/svg-elliptical-arc.h \
- 2geom/svg-path-parser.h \
+ 2geom/svg-path.cpp \
2geom/svg-path.h \
+ 2geom/svg-path-parser.cpp \
+ 2geom/svg-path-parser.h \
+ 2geom/sweep.cpp \
2geom/sweep.h \
+ 2geom/transforms.cpp \
2geom/transforms.h \
- 2geom/utils.h \
- 2geom/numeric/matrix.cpp \
- 2geom/numeric/fitting-model.h \
- 2geom/numeric/fitting-tool.h \
- 2geom/numeric/linear_system.h \
- 2geom/numeric/matrix.h \
- 2geom/numeric/vector.h
+ 2geom/utils.cpp \
+ 2geom/utils.h
diff --git a/src/2geom/bezier-curve.cpp b/src/2geom/bezier-curve.cpp
new file mode 100644
index 000000000..1a2e079bf
--- /dev/null
+++ b/src/2geom/bezier-curve.cpp
@@ -0,0 +1,358 @@
+/**
+ * \file
+ * \brief Bezier curve
+ *
+ *//*
+ * Authors:
+ * MenTaLguY <mental@rydia.net>
+ * Marco Cecchetti <mrcekets at gmail.com>
+ * Krzysztof Kosiński <tweenk.pl@gmail.com>
+ *
+ * Copyright 2007-2009 Authors
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it either under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation
+ * (the "LGPL") or, at your option, under the terms of the Mozilla
+ * Public License Version 1.1 (the "MPL"). If you do not alter this
+ * notice, a recipient may use your version of this file under either
+ * the MPL or the LGPL.
+ *
+ * You should have received a copy of the LGPL along with this library
+ * in the file COPYING-LGPL-2.1; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * You should have received a copy of the MPL along with this library
+ * in the file COPYING-MPL-1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
+ * OF ANY KIND, either express or implied. See the LGPL or the MPL for
+ * the specific language governing rights and limitations.
+ */
+
+#include <2geom/bezier-curve.h>
+
+namespace Geom
+{
+
+/**
+ * @class BezierCurve
+ * @brief Two-dimensional Bezier curve of arbitrary order.
+ *
+ * Bezier curves are an expansion of the concept of linear interpolation to n points.
+ * Linear segments in 2Geom are in fact Bezier curves of order 1.
+ *
+ * Let \f$\mathbf{B}_{\mathbf{p}_0\mathbf{p}_1\ldots\mathbf{p}_n}\f$ denote a Bezier curve
+ * of order \f$n\f$ defined by the points \f$\mathbf{p}_0, \mathbf{p}_1, \ldots, \mathbf{p}_n\f$.
+ * Bezier curve of order 1 is a linear interpolation curve between two points, defined as
+ * \f[ \mathbf{B}_{\mathbf{p}_0\mathbf{p}_1}(t) = (1-t)\mathbf{p}_0 + t\mathbf{p}_1 \f]
+ * If we now substitute points \f$\mathbf{p_0}\f$ and \f$\mathbf{p_1}\f$ in this definition
+ * by linear interpolations, we get the definition of a Bezier curve of order 2, also called
+ * a quadratic Bezier curve.
+ * \f{align*}{ \mathbf{B}_{\mathbf{p}_0\mathbf{p}_1\mathbf{p}_2}(t)
+ &= (1-t) \mathbf{B}_{\mathbf{p}_0\mathbf{p}_1}(t) + t \mathbf{B}_{\mathbf{p}_1\mathbf{p}_2}(t) \\
+ \mathbf{B}_{\mathbf{p}_0\mathbf{p}_1\mathbf{p}_2}(t)
+ &= (1-t)^2\mathbf{p}_0 + 2(1-t)t\mathbf{p}_1 + t^2\mathbf{p}_2 \f}
+ * By substituting points for quadratic Bezier curves in the original definition,
+ * we get a Bezier curve of order 3, called a cubic Bezier curve.
+ * \f{align*}{ \mathbf{B}_{\mathbf{p}_0\mathbf{p}_1\mathbf{p}_2\mathbf{p}_3}(t)
+ &= (1-t) \mathbf{B}_{\mathbf{p}_0\mathbf{p}_1\mathbf{p}_2}(t)
+ + t \mathbf{B}_{\mathbf{p}_1\mathbf{p}_2\mathbf{p}_3}(t) \\
+ \mathbf{B}_{\mathbf{p}_0\mathbf{p}_1\mathbf{p}_2\mathbf{p}_3}(t)
+ &= (1-t)^3\mathbf{p}_0+3(1-t)^2t\mathbf{p}_1+3(1-t)t^2\mathbf{p}_2+t^3\mathbf{p}_3 \f}
+ * In general, a Bezier curve or order \f$n\f$ can be recursively defined as
+ * \f[ \mathbf{B}_{\mathbf{p}_0\mathbf{p}_1\ldots\mathbf{p}_n}(t)
+ = (1-t) \mathbf{B}_{\mathbf{p}_0\mathbf{p}_1\ldots\mathbf{p}_{n-1}}(t)
+ + t \mathbf{B}_{\mathbf{p}_1\mathbf{p}_2\ldots\mathbf{p}_n}(t) \f]
+ *
+ * This substitution can be repeated an arbitrary number of times. To picture this, imagine
+ * the evaluation of a point on the curve as follows: first, all control points are joined with
+ * straight lines, and a point corresponding to the selected time value is marked on them.
+ * Then, the marked points are joined with straight lines and the point corresponding to
+ * the time value is marked. This is repeated until only one marked point remains, which is the
+ * point at the selected time value.
+ *
+ * @image html bezier-curve-evaluation.png "Evaluation of the Bezier curve"
+ *
+ * An important property of the Bezier curves is that their parameters (control points)
+ * have an intutive geometric interpretation. Because of this, they are frequently used
+ * in vector graphics editors.
+ *
+ * Every bezier curve is contained in its control polygon (the convex polygon composed
+ * of its control points). This fact is useful for sweepline algorithms and intersection.
+ *
+ * Bezier curves of order 1, 2 and 3 are common enough to have their own more specific subclasses.
+ * Note that if you create a generic BezierCurve, you cannot use a dynamic cast to those more
+ * specific types, and you might face a slight preformance penalty relative to the more specific
+ * classes. To obtain an instance of the correct optimized type, use the optimize()
+ * or duplicate() methods. The difference is that optimize() will not create a new object
+ * if it can't be optimized or is already an instance of one of the specific types, while
+ * duplicate() will always create a new object.
+ *
+ * @ingroup Curves
+ */
+
+/** @brief Create an optimized instance of the curve.
+ * If the curve was created as a generic Bezier curve but has an order between 1 and 3,
+ * this method will create a newly allocated curve that is a LineSegment, a QuadraticBezier,
+ * or a CubicBezier. For other cases it returns the pointer to the current curve, to avoid
+ * allocating extra memory. Be careful when you use this method, because whether you have
+ * to delete the returned object or not depends on its return value! If easier deletion
+ * semantics are required, you can use the duplicate() method instead, which returns
+ * optimized objects by default.
+ * @return Pointer to a curve that is an instance of LineSegment, QuadraticBezier
+ * or CubicBezier based on the order. If the object is already an instance
+ * of te more specific types or the order is above 3, a pointer to the original
+ * object is returned instead, and no memory is allocated. */
+BezierCurve *BezierCurve::optimize() const
+{
+ switch(order()) {
+ case 1:
+ if (!dynamic_cast<LineSegment const *>(this))
+ return new LineSegment((*this)[0], (*this)[1]);
+ break;
+ case 2:
+ if (!dynamic_cast<QuadraticBezier const *>(this))
+ return new QuadraticBezier((*this)[0], (*this)[1], (*this)[2]);
+ break;
+ case 3:
+ if (!dynamic_cast<CubicBezier const *>(this))
+ return new CubicBezier((*this)[0], (*this)[1], (*this)[2], (*this)[3]);
+ break;
+ }
+ return const_cast<BezierCurve*>(this);
+}
+Curve *BezierCurve::duplicate() const
+{
+ switch(order()) {
+ case 1:
+ return new LineSegment((*this)[0], (*this)[1]);
+ case 2:
+ return new QuadraticBezier((*this)[0], (*this)[1], (*this)[2]);
+ case 3:
+ return new CubicBezier((*this)[0], (*this)[1], (*this)[2], (*this)[3]);
+ }
+ return new BezierCurve(*this);
+}
+
+Curve *BezierCurve::derivative() const
+{
+ if (order() == 1) {
+ double dx = inner[X][1] - inner[X][0], dy = inner[Y][1] - inner[Y][0];
+ return new LineSegment(Point(dx,dy),Point(dx,dy));
+ }
+ return new BezierCurve(Geom::derivative(inner[X]), Geom::derivative(inner[Y]));
+}
+
+Coord BezierCurve::length(Coord tolerance) const
+{
+ switch (order())
+ {
+ case 0:
+ return 0.0;
+ case 1:
+ return distance(initialPoint(), finalPoint());
+ case 2:
+ {
+ std::vector<Point> pts = points();
+ return bezier_length(pts[0], pts[1], pts[2], tolerance);
+ }
+ case 3:
+ {
+ std::vector<Point> pts = points();
+ return bezier_length(pts[0], pts[1], pts[2], pts[3], tolerance);
+ }
+ default:
+ return bezier_length(points(), tolerance);
+ }
+}
+
+/**
+ * @class LineSegment
+ * @brief Linear segment, a special case of a Bezier curve.
+ *
+ * This class uses some optimizations for a linear segment (a Bezier curve of order 1).
+ * Note that if you created a BezierCurve, you will not be able to cast it to a LineSegment
+ * using a dynamic cast regardless of its order - use the optimize() method.
+ *
+ * @ingroup Curves */
+Coord LineSegment::nearestPoint(Point const& p, Coord from, Coord to) const {
+ if ( from > to ) std::swap(from, to);
+ Point ip = pointAt(from);
+ Point fp = pointAt(to);
+ Point v = fp - ip;
+ Coord l2v = L2sq(v);
+ if (l2v == 0) return 0;
+ Coord t = dot( p - ip, v ) / l2v;
+ if ( t <= 0 ) return from;
+ else if ( t >= 1 ) return to;
+ else return from + t*(to-from);
+}
+
+
+/**
+ * @class QuadraticBezier
+ * @brief Quadratic Bezier curve.
+ * Note that if you created a BezierCurve, you will not be able to cast it to a QuadraticBezier
+ * using a dynamic cast regardless of its order - use the optimize() method.
+ * @ingroup Curves */
+
+Coord QuadraticBezier::length(Coord tolerance) const
+{
+ std::vector<Point> pts = points();
+ return bezier_length(pts[0], pts[1], pts[2], tolerance);
+}
+
+/**
+ * @class CubicBezier
+ * @brief Cubic Bezier curve.
+ * Note that if you created a BezierCurve, you will not be able to cast it to a CubicBezier
+ * using a dynamic cast regardless of its order - use the optimize() method.
+ * @ingroup Curves */
+
+Coord CubicBezier::length(Coord tolerance) const
+{
+ std::vector<Point> pts = points();
+ return bezier_length(pts[0], pts[1], pts[2], pts[3], tolerance);
+}
+
+static Coord bezier_length_internal(std::vector<Point> &v1, Coord tolerance)
+{
+ /* The Bezier length algorithm used in 2Geom utilizes a simple fact:
+ * the Bezier curve is longer than the distance between its endpoints
+ * but shorter than the length of the polyline formed by its control
+ * points. When the difference between the two values is smaller than the
+ * error tolerance, we can be sure that the true value is no further than
+ * 2*tolerance from their arithmetic mean. When it's larger, we recursively
+ * subdivide the Bezier curve into two parts and add their lengths.
+ */
+ Coord lower = distance(v1.front(), v1.back());
+ Coord upper = 0.0;
+ for (size_t i = 0; i < v1.size() - 1; ++i) {
+ upper += distance(v1[i], v1[i+1]);
+ }
+ if (upper - lower < 2*tolerance) {
+ return (lower + upper) / 2;
+ }
+
+
+ std::vector<Point> v2 = v1;
+
+ /* Compute the right subdivision directly in v1 and the left one in v2.
+ * Explanation of the algorithm used:
+ * We have to compute the left and right edges of this triangle in which
+ * the top row are the control points of the Bezier curve, and each cell
+ * is equal to the arithmetic mean of the cells directly above it
+ * to the right and left. This corresponds to subdividing the Bezier curve
+ * at time value 0.5: the left edge has the control points of the first
+ * portion of the Bezier curve and the right edge - the second one.
+ * In the example we subdivide a curve with 5 control points (order 4).
+ *
+ * Start:
+ * 0 1 2 3 4
+ * ? ? ? ?
+ * ? ? ?
+ * ? ?
+ * ?
+ * # means we have overwritten the value, ? means we don't know
+ * the value yet. Numbers mean the value is at i-th position in the vector.
+ *
+ * After loop with i==1
+ * # 1 2 3 4
+ * 0 ? ? ? -> write 0 to v2[1]
+ * ? ? ?
+ * ? ?
+ * ?
+ *
+ * After loop with i==2
+ * # # 2 3 4
+ * # 1 ? ?
+ * 0 ? ? -> wirte 0 to v2[2]
+ * ? ?
+ * ?
+ *
+ * After loop with i==3
+ * # # # 3 4
+ * # # 2 ?
+ * # 1 ?
+ * 0 ? -> write 0 to v2[3]
+ * ?
+ *
+ * After loop with i==4, we have the right edge of the triangle in v1,
+ * and we write the last value needed for the left edge in v2[4].
+ */
+
+ for (size_t i = 1; i < v1.size(); ++i) {
+ for (size_t j = i; j > 0; --j) {
+ v1[j-1] = 0.5 * (v1[j-1] + v1[j]);
+ }
+ v2[i] = v1[0];
+ }
+
+ return bezier_length_internal(v1, 0.5*tolerance) + bezier_length_internal(v2, 0.5*tolerance);
+}
+
+/** @brief Compute the length of a bezier curve given by a vector of its control points
+ * @relates BezierCurve */
+Coord bezier_length(std::vector<Point> const &points, Coord tolerance)
+{
+ if (points.size() < 2) return 0.0;
+ std::vector<Point> v1 = points;
+ return bezier_length_internal(v1, tolerance);
+}
+
+/** @brief Compute the length of a quadratic bezier curve given by its control points
+ * @relates QuadraticBezier */
+Coord bezier_length(Point a0, Point a1, Point a2, Coord tolerance)
+{
+ Coord lower = distance(a0, a2);
+ Coord upper = distance(a0, a1) + distance(a1, a2);
+
+ if (upper - lower < 2*tolerance) return (lower + upper)/2;
+
+ Point // Casteljau subdivision
+ // b0 = a0,
+ // c0 = a2,
+ b1 = 0.5*(a0 + a1),
+ c1 = 0.5*(a1 + a2),
+ b2 = 0.5*(b1 + c1); // == c2
+ return bezier_length(a0, b1, b2, 0.5*tolerance) + bezier_length(b2, c1, a2, 0.5*tolerance);
+}
+
+/** @brief Compute the length of a cubic bezier curve given by its control points
+ * @relates CubicBezier */
+Coord bezier_length(Point a0, Point a1, Point a2, Point a3, Coord tolerance)
+{
+ Coord lower = distance(a0, a3);
+ Coord upper = distance(a0, a1) + distance(a1, a2) + distance(a2, a3);
+
+ if (upper - lower < 2*tolerance) return (lower + upper)/2;
+
+ Point // Casteljau subdivision
+ // b0 = a0,
+ // c0 = a3,
+ b1 = 0.5*(a0 + a1),
+ t0 = 0.5*(a1 + a2),
+ c1 = 0.5*(a2 + a3),
+ b2 = 0.5*(b1 + t0),
+ c2 = 0.5*(t0 + c1),
+ b3 = 0.5*(b2 + c2); // == c3
+ return bezier_length(a0, b1, b2, b3, 0.5*tolerance) + bezier_length(b3, c2, c1, a3, 0.5*tolerance);
+}
+
+} // end namespace Geom
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
diff --git a/src/2geom/chebyshev.cpp b/src/2geom/chebyshev.cpp
deleted file mode 100644
index c886daf88..000000000
--- a/src/2geom/chebyshev.cpp
+++ /dev/null
@@ -1,126 +0,0 @@
-#include <2geom/chebyshev.h>
-
-#include <2geom/sbasis.h>
-#include <2geom/sbasis-poly.h>
-
-#include <vector>
-using std::vector;
-
-#include <gsl/gsl_math.h>
-#include <gsl/gsl_chebyshev.h>
-
-namespace Geom{
-
-SBasis cheb(unsigned n) {
- static std::vector<SBasis> basis;
- if(basis.empty()) {
- basis.push_back(Linear(1,1));
- basis.push_back(Linear(0,1));
- }
- for(unsigned i = basis.size(); i <= n; i++) {
- basis.push_back(Linear(0,2)*basis[i-1] - basis[i-2]);
- }
-
- return basis[n];
-}
-
-SBasis cheb_series(unsigned n, double* cheb_coeff) {
- SBasis r;
- for(unsigned i = 0; i < n; i++) {
- double cof = cheb_coeff[i];
- //if(i == 0)
- //cof /= 2;
- r += cheb(i)*cof;
- }
-
- return r;
-}
-
-SBasis clenshaw_series(unsigned m, double* cheb_coeff) {
- /** b_n = a_n
- b_n-1 = 2*x*b_n + a_n-1
- b_n-k = 2*x*b_{n-k+1} + a_{n-k} - b_{n - k + 2}
- b_0 = x*b_1 + a_0 - b_2
- */
-
- double a = -1, b = 1;
- SBasis d, dd;
- SBasis y = (Linear(0, 2) - (a+b)) / (b-a);
- SBasis y2 = 2*y;
- for(int j = m - 1; j >= 1; j--) {
- SBasis sv = d;
- d = y2*d - dd + cheb_coeff[j];
- dd = sv;
- }
-
- return y*d - dd + 0.5*cheb_coeff[0];
-}
-
-SBasis chebyshev_approximant (double (*f)(double,void*), int order, Interval in, void* p) {
- gsl_cheb_series *cs = gsl_cheb_alloc (order+2);
-
- gsl_function F;
-
- F.function = f;
- F.params = p;
-
- gsl_cheb_init (cs, &F, in[0], in[1]);
-
- SBasis r = compose(clenshaw_series(order, cs->c), Linear(-1,1));
-
- gsl_cheb_free (cs);
- return r;
-}
-
-struct wrap {
- double (*f)(double,void*);
- void* pp;
- double fa, fb;
- Interval in;
-};
-
-double f_interp(double x, void* p) {
- struct wrap *wr = (struct wrap *)p;
- double z = (x - wr->in[0]) / (wr->in[1] - wr->in[0]);
- return (wr->f)(x, wr->pp) - ((1 - z)*wr->fa + z*wr->fb);
-}
-
-SBasis chebyshev_approximant_interpolating (double (*f)(double,void*),
- int order, Interval in, void* p) {
- double fa = f(in[0], p);
- double fb = f(in[1], p);
- struct wrap wr;
- wr.fa = fa;
- wr.fb = fb;
- wr.in = in;
- printf("%f %f\n", fa, fb);
- wr.f = f;
- wr.pp = p;
- return compose(Linear(in[0], in[1]), Linear(fa, fb)) + chebyshev_approximant(f_interp, order, in, &wr) + Linear(fa, fb);
-}
-
-SBasis chebyshev(unsigned n) {
- static std::vector<SBasis> basis;
- if(basis.empty()) {
- basis.push_back(Linear(1,1));
- basis.push_back(Linear(0,1));
- }
- for(unsigned i = basis.size(); i <= n; i++) {
- basis.push_back(Linear(0,2)*basis[i-1] - basis[i-2]);
- }
-
- return basis[n];
-}
-
-};
-
-/*
- Local Variables:
- mode:c++
- c-file-style:"stroustrup"
- c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
- indent-tabs-mode:nil
- fill-column:99
- End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
diff --git a/src/2geom/chebyshev.h b/src/2geom/chebyshev.h
deleted file mode 100644
index f729e1f07..000000000
--- a/src/2geom/chebyshev.h
+++ /dev/null
@@ -1,30 +0,0 @@
-#ifndef _CHEBYSHEV
-#define _CHEBYSHEV
-
-#include <2geom/sbasis.h>
-#include <2geom/interval.h>
-
-/*** Conversion between Chebyshev approximation and SBasis.
- *
- */
-
-namespace Geom{
-
-SBasis chebyshev_approximant (double (*f)(double,void*), int order, Interval in, void* p=0);
-SBasis chebyshev_approximant_interpolating (double (*f)(double,void*), int order, Interval in, void* p=0);
-SBasis chebyshev(unsigned n);
-
-};
-
-/*
- Local Variables:
- mode:c++
- c-file-style:"stroustrup"
- c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
- indent-tabs-mode:nil
- fill-column:99
- End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
-
-#endif
diff --git a/src/2geom/curve-helpers.cpp b/src/2geom/curve.cpp
index 0ecd7d425..49e011a8b 100644
--- a/src/2geom/curve-helpers.cpp
+++ b/src/2geom/curve.cpp
@@ -1,10 +1,14 @@
-/*
- *
+/**
+ * \file
+ * \brief Abstract curve type - implementation of default methods
+ *
+ *//*
* Authors:
- * MenTaLguY <mental@rydia.net>
- * Marco Cecchetti <mrcekets at gmail.com>
+ * MenTaLguY <mental@rydia.net>
+ * Marco Cecchetti <mrcekets at gmail.com>
+ * Krzysztof Kosiński <tweenk.pl@gmail.com>
*
- * Copyright 2007-2008 authors
+ * Copyright 2007-2009 Authors
*
* This library is free software; you can redistribute it and/or
* modify it either under the terms of the GNU Lesser General Public
@@ -30,11 +34,11 @@
* the specific language governing rights and limitations.
*/
-
#include <2geom/curve.h>
+#include <2geom/nearest-point.h>
+#include <2geom/sbasis-geometric.h>
#include <2geom/ord.h>
-
namespace Geom
{
@@ -79,8 +83,35 @@ int CurveHelpers::root_winding(Curve const &c, Point p) {
return wind;
}
+Coord Curve::nearestPoint(Point const& p, Coord a, Coord b) const
+{
+ return nearest_point(p, toSBasis(), a, b);
+}
+
+std::vector<Coord> Curve::allNearestPoints(Point const& p, Coord from, Coord to) const
+{
+ return all_nearest_points(p, toSBasis(), from, to);
+}
+
+Coord Curve::length(Coord tolerance) const
+{
+ return ::Geom::length(toSBasis(), tolerance);
+}
+
+Point Curve::unitTangentAt(Coord t, unsigned n) const
+{
+ std::vector<Point> derivs = pointAndDerivatives(t, n);
+ for (unsigned deriv_n = 1; deriv_n < derivs.size(); deriv_n++) {
+ Coord length = derivs[deriv_n].length();
+ if ( ! are_near(length, 0) ) {
+ // length of derivative is non-zero, so return unit vector
+ return derivs[deriv_n] / length;
+ }
+ }
+ return Point (0,0);
+};
-} // end namespace Geom
+} // namespace Geom
/*
Local Variables:
diff --git a/src/extension/dbus/dbus-init.cpp b/src/extension/dbus/dbus-init.cpp
index 2ae606940..9c562d169 100644
--- a/src/extension/dbus/dbus-init.cpp
+++ b/src/extension/dbus/dbus-init.cpp
@@ -14,6 +14,8 @@
*/
#include <dbus/dbus-glib.h>
+// this is reguired so that giomm headers won't barf
+#undef DBUS_MESSAGE_TYPE_INVALID
#include "dbus-init.h"
#include "application-interface.h"
diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp
index 485e92aa6..0e5d8de50 100644
--- a/src/extension/dbus/document-interface.cpp
+++ b/src/extension/dbus/document-interface.cpp
@@ -18,41 +18,26 @@
#include "document-interface.h"
#include <string.h>
-#include "verbs.h"
-#include "helper/action.h" //sp_action_perform
-
-#include "inkscape.h" //inkscape_find_desktop_by_dkey, activate desktops
-
#include "desktop-handles.h" //sp_desktop_document()
-#include "xml/repr.h" //sp_repr_document_new
-
-#include "sp-object.h"
-
-#include "document.h" // getReprDoc()
-
#include "desktop-style.h" //sp_desktop_get_style
-
-#include "selection.h" //selection struct
+#include "display/canvas-text.h" //text
+#include "display/sp-canvas.h" //text
+#include "document.h" // getReprDoc()
+#include "extension/output.h" //IO
+#include "extension/system.h" //IO
+#include "file.h" //IO
+#include "helper/action.h" //sp_action_perform
+#include "inkscape.h" //inkscape_find_desktop_by_dkey, activate desktops
+#include "layer-fns.h" //LPOS_BELOW
+#include "live_effects/parameter/text.h" //text
+#include "print.h" //IO
#include "selection-chemistry.h"// lots of selection functions
-
+#include "selection.h" //selection struct
#include "sp-ellipse.h"
-
-#include "layer-fns.h" //LPOS_BELOW
-
+#include "sp-object.h"
#include "style.h" //style_write
-
-#include "file.h" //IO
-
-#include "extension/system.h" //IO
-
-#include "extension/output.h" //IO
-
-#include "print.h" //IO
-
-#include "live_effects/parameter/text.h" //text
-#include "display/canvas-text.h" //text
-
-#include "display/sp-canvas.h" //text
+#include "verbs.h"
+#include "xml/repr.h" //sp_repr_document_new
//#include "2geom/svg-path-parser.h" //get_node_coordinates
diff --git a/src/extension/dbus/document-interface.h b/src/extension/dbus/document-interface.h
index ac9fd11c1..12e033918 100644
--- a/src/extension/dbus/document-interface.h
+++ b/src/extension/dbus/document-interface.h
@@ -22,6 +22,14 @@
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-bindings.h>
#include <dbus/dbus-glib-lowlevel.h>
+
+// this is reguired so that giomm headers won't barf
+#undef DBUS_MESSAGE_TYPE_INVALID
+#undef DBUS_MESSAGE_TYPE_METHOD_CALL
+#undef DBUS_MESSAGE_TYPE_METHOD_RETURN
+#undef DBUS_MESSAGE_TYPE_ERROR
+#undef DBUS_MESSAGE_TYPE_SIGNAL
+
#include "desktop.h"
#define DBUS_DOCUMENT_INTERFACE_PATH "/org/inkscape/document"