From b307246cda3ad55e4a00b596de964a492196c0fa Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Fri, 13 Apr 2012 23:42:28 +0200 Subject: small 2geom update (bzr r11239) --- src/2geom/d2-sbasis.cpp | 13 +++++++++++++ src/2geom/d2-sbasis.h | 5 +++++ src/live_effects/lpe-powerstroke.cpp | 15 --------------- 3 files changed, 18 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/2geom/d2-sbasis.cpp b/src/2geom/d2-sbasis.cpp index 7bfb7c6c5..486ada9a2 100644 --- a/src/2geom/d2-sbasis.cpp +++ b/src/2geom/d2-sbasis.cpp @@ -185,6 +185,19 @@ split_at_discontinuities (Geom::Piecewise > const & pwsbi return ret; } +Point unitTangentAt(D2 const & a, Coord t, unsigned n) +{ + std::vector derivs = a.valueAndDerivatives(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); +} + static void set_first_point(Piecewise > &f, Point a){ if ( f.empty() ){ f.concat(Piecewise >(D2(Linear(a[X]),Linear(a[Y])))); diff --git a/src/2geom/d2-sbasis.h b/src/2geom/d2-sbasis.h index e61067e1b..965ec8746 100644 --- a/src/2geom/d2-sbasis.h +++ b/src/2geom/d2-sbasis.h @@ -83,6 +83,11 @@ std::vector > > fuse_nearby_ends(std::vector > > split_at_discontinuities (Geom::Piecewise > const & pwsbin, double tol = .0001); +/** +* note that -unitTangentAt(reverse(a),0.) == unitTangentAt(a,1.) but the former is more reliable (sometimes the sign is wrong for the latter) +*/ +Point unitTangentAt(D2 const & a, Coord t, unsigned n = 3); + class CoordIterator : public std::iterator { diff --git a/src/live_effects/lpe-powerstroke.cpp b/src/live_effects/lpe-powerstroke.cpp index 79997ff94..281376cde 100644 --- a/src/live_effects/lpe-powerstroke.cpp +++ b/src/live_effects/lpe-powerstroke.cpp @@ -34,21 +34,6 @@ namespace Geom { // should all be moved to 2geom at some point -/** -* note that -unitTangentAt(reverse(a),0.) == unitTangentAt(a,1.) but the former is more reliable (sometimes the sign is wrong for the latter) -*/ -Point unitTangentAt( D2 const & a, Coord t, unsigned n = 3) { - std::vector derivs = a.valueAndDerivatives(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); -} - /** Find the point where two straight lines cross. */ boost::optional intersection_point( Point const & origin_a, Point const & vector_a, -- cgit v1.2.3