From: johanengelen Date: Wed, 18 Jun 2008 23:31:50 +0000 (+0000) Subject: update 2geom (r1350) X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=e28dbe59a15ff67759295fa8076354baf8b2a52c;p=inkscape.git update 2geom (r1350) --- 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 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 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]; }