From c68bdfafb56886a3f33d8c05efff042a0d66b9b6 Mon Sep 17 00:00:00 2001 From: johanengelen Date: Fri, 4 Jul 2008 23:36:25 +0000 Subject: [PATCH] create pathvector_for_curve method. --- src/object-snapper.cpp | 2 +- src/splivarot.cpp | 23 ++++++++++++++++++++++- src/splivarot.h | 2 ++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index 88e709b7f..ef6c5fce2 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -320,7 +320,7 @@ void Inkscape::ObjectSnapper::_collectPaths(Inkscape::Snapper::PointType const & if (!very_lenghty_prose && !very_complex_path) { SPCurve *curve = curve_for_item(root_item); if (curve) { - NArtBpath *bpath = bpath_for_curve(root_item, curve, true, true); + NArtBpath *bpath = bpath_for_curve(root_item, curve, true, true); // perhaps for speed, get a reference to the Geom::pathvector, and store the transformation besides it. apply transformation on the snap points, instead of generating whole new path _bpaths_to_snap_to->push_back(bpath); // we will get a dupe of the path, which must be freed at some point curve->unref(); } diff --git a/src/splivarot.cpp b/src/splivarot.cpp index 944c15f84..88daaa666 100644 --- a/src/splivarot.cpp +++ b/src/splivarot.cpp @@ -48,7 +48,7 @@ #include "libnr/nr-path.h" #include "xml/repr.h" #include "xml/repr-sorting.h" - +#include <2geom/pathvector.h> #include #include #include @@ -1764,6 +1764,27 @@ bpath_for_curve(SPItem *item, SPCurve *curve, bool doTransformation, bool transf return new_bpath; } +/* + * NOTE: Returns empty pathvector if curve == NULL + * TODO: see if calling this method can be optimized. All the pathvector copying might be slow. + */ +Geom::PathVector +pathvector_for_curve(SPItem *item, SPCurve *curve, bool doTransformation, bool transformFull) +{ + if (curve == NULL) + return Geom::PathVector(); + + if (doTransformation) { + if (transformFull) { + return (curve->get_pathvector()) * sp_item_i2doc_affine(item); + } else { + return (curve->get_pathvector()) * to_2geom(item->transform); + } + } else { + return curve->get_pathvector(); + } +} + SPCurve* curve_for_item(SPItem *item) { if (!item) diff --git a/src/splivarot.h b/src/splivarot.h index 2ac47135a..6e59d2cc5 100644 --- a/src/splivarot.h +++ b/src/splivarot.h @@ -8,6 +8,7 @@ */ #include "livarot/Path.h" +#include <2geom/forward.h> // boolean operations // work on the current selection @@ -45,6 +46,7 @@ void sp_selected_path_simplify (); Path *Path_for_item(SPItem *item, bool doTransformation, bool transformFull = true); NArtBpath *bpath_for_curve(SPItem *item, SPCurve *curve, bool doTransformation, bool transformFull); +Geom::PathVector pathvector_for_curve(SPItem *item, SPCurve *curve, bool doTransformation, bool transformFull); SPCurve *curve_for_item(SPItem *item); NR::Maybe get_nearest_position_on_Path(Path *path, NR::Point p, unsigned seg = 0); NR::Point get_point_on_Path(Path *path, int piece, double t); -- 2.30.2