Code

in node tool to select a segment of a path, use 2geom methods instead of livarot.
authorjohanengelen <johanengelen@users.sourceforge.net>
Fri, 25 Jul 2008 21:53:35 +0000 (21:53 +0000)
committerjohanengelen <johanengelen@users.sourceforge.net>
Fri, 25 Jul 2008 21:53:35 +0000 (21:53 +0000)
src/nodepath.cpp

index f6b151837a65b7c92f8c39180673312b7fc9f9f3..f3d07a313b0ef918af69c844c70157fb2f887ef2 100644 (file)
@@ -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<Path::cut_position> 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;