From bbb1b1e6952ac21ca78c4b89d3421769d6fe94f2 Mon Sep 17 00:00:00 2001 From: johanengelen Date: Fri, 25 Jul 2008 21:53:35 +0000 Subject: [PATCH] in node tool to select a segment of a path, use 2geom methods instead of livarot. --- src/nodepath.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/nodepath.cpp b/src/nodepath.cpp index f6b151837..f3d07a313 100644 --- a/src/nodepath.cpp +++ b/src/nodepath.cpp @@ -1901,15 +1901,23 @@ sp_nodepath_select_segment_near_point(Inkscape::NodePath::Path *nodepath, NR::Po return; } - sp_nodepath_ensure_livarot_path(nodepath); - NR::Maybe maybe_position = get_nearest_position_on_Path(nodepath->livarot_path, p); - if (!maybe_position) { - return; + SPCurve *curve = create_curve(nodepath); // perhaps we can use nodepath->curve here instead? + Geom::PathVector const &pathv = curve->get_pathvector(); + Geom::PathVectorPosition pvpos = Geom::nearestPoint(pathv, p); + + // calculate index for nodepath's representation. + unsigned int segment_index = floor(pvpos.t) + 1; + for (unsigned int i = 0; i < pvpos.path_nr; ++i) { + segment_index += pathv[i].size() + 1; + if (pathv[i].closed()) { + segment_index += 1; + } } - Path::cut_position position = *maybe_position; + + curve->unref(); //find segment to segment - Inkscape::NodePath::Node *e = sp_nodepath_get_node_by_index(position.piece); + Inkscape::NodePath::Node *e = sp_nodepath_get_node_by_index(segment_index); //fixme: this can return NULL, so check before proceeding. g_return_if_fail(e != NULL); @@ -1939,7 +1947,7 @@ sp_nodepath_add_node_near_point(Inkscape::NodePath::Path *nodepath, NR::Point p) SPCurve *curve = create_curve(nodepath); // perhaps we can use nodepath->curve here instead? Geom::PathVector const &pathv = curve->get_pathvector(); - Geom::PathVectorPosition pvpos = nearestPoint(pathv, p); + Geom::PathVectorPosition pvpos = Geom::nearestPoint(pathv, p); // calculate index for nodepath's representation. double int_part; -- 2.30.2