diff options
| author | Johan B. C. Engelen <jbc.engelen@swissonline.ch> | 2008-06-18 23:31:50 +0000 |
|---|---|---|
| committer | johanengelen <johanengelen@users.sourceforge.net> | 2008-06-18 23:31:50 +0000 |
| commit | 20458ea11cceeb57adbfbc8a20667c0ce0d79e74 (patch) | |
| tree | 47c7441fa2494766a323ac212f332178b010d728 /src | |
| parent | update 2geom (diff) | |
| download | inkscape-20458ea11cceeb57adbfbc8a20667c0ce0d79e74.tar.gz inkscape-20458ea11cceeb57adbfbc8a20667c0ce0d79e74.zip | |
update 2geom (r1350)
(bzr r5999)
Diffstat (limited to 'src')
| -rw-r--r-- | src/2geom/curve.h | 17 | ||||
| -rw-r--r-- | src/2geom/transforms.cpp | 1 | ||||
| -rw-r--r-- | src/2geom/transforms.h | 2 |
3 files changed, 19 insertions, 1 deletions
diff --git a/src/2geom/curve.h b/src/2geom/curve.h index 7f138dabf..22d2ec556 100644 --- a/src/2geom/curve.h +++ b/src/2geom/curve.h @@ -111,6 +111,23 @@ public: * [ point at t, 1st derivative at t, 2nd derivative at t, ... , n'th derivative at t] */ virtual std::vector<Point> pointAndDerivatives(Coord t, unsigned n) const = 0; + /* unitTangentAt returns the unit vector tangent to the curve at position t + * (in the direction of increasing t). The method uses l'Hopital's rule when the derivative + * is (0,0), parameter n determines the maximum nr of iterations (for when higher derivatives are also (0,0) ). + * Point(0,0) is returned if no non-zero derivative could be found. */ + virtual Point unitTangentAt(Coord t, unsigned n = 3) const + { + for (unsigned deriv_n = 1; deriv_n <= n; deriv_n++) { + Point deriv = pointAndDerivatives(t, deriv_n)[deriv_n]; + Coord length = deriv.length(); + if ( ! are_near(length, 0) ) { + // length of derivative is non-zero, so return unit vector + return deriv / length; + } + } + return Point (0,0); + }; + virtual D2<SBasis> toSBasis() const = 0; }; diff --git a/src/2geom/transforms.cpp b/src/2geom/transforms.cpp index b2f305d18..62b340221 100644 --- a/src/2geom/transforms.cpp +++ b/src/2geom/transforms.cpp @@ -46,6 +46,7 @@ Matrix operator*(Matrix const &m, Scale const &s) { } Matrix operator*(Matrix const &m, Rotate const &r) { + // TODO: we just convert the Rotate to a matrix and use the existing operator*(); is there a better way? Matrix ret(m); ret *= (Matrix) r; return ret; diff --git a/src/2geom/transforms.h b/src/2geom/transforms.h index 0e276bfc2..fb077a910 100644 --- a/src/2geom/transforms.h +++ b/src/2geom/transforms.h @@ -82,7 +82,7 @@ class Rotate { explicit Rotate(Coord theta) : vec(std::cos(theta), std::sin(theta)) {} Rotate(Point const &p) {Point v = p; v.normalize(); vec = v;} //TODO: UGLY! explicit Rotate(Coord x, Coord y) { Rotate(Point(x, y)); } - inline operator Matrix() const { return Matrix(vec[X], -vec[Y], vec[Y], vec[X], 0, 0); } + inline operator Matrix() const { return Matrix(vec[X], vec[Y], -vec[Y], vec[X], 0, 0); } inline Coord operator[](Dim2 const dim) const { return vec[dim]; } inline Coord operator[](unsigned const dim) const { return vec[dim]; } |
