diff options
| author | Johan B. C. Engelen <jbc.engelen@swissonline.ch> | 2008-07-25 21:49:23 +0000 |
|---|---|---|
| committer | johanengelen <johanengelen@users.sourceforge.net> | 2008-07-25 21:49:23 +0000 |
| commit | d88389779494d4aefcd813008b6464c75597749e (patch) | |
| tree | c6c9baf58799b7a1b10868692801ae89fd156161 /src/nodepath.cpp | |
| parent | update to 2geom rev. 1507 (diff) | |
| download | inkscape-d88389779494d4aefcd813008b6464c75597749e.tar.gz inkscape-d88389779494d4aefcd813008b6464c75597749e.zip | |
when doubleclicking a nodepath to create new knot, use 2geom methods instead of livarot.
(bzr r6417)
Diffstat (limited to 'src/nodepath.cpp')
| -rw-r--r-- | src/nodepath.cpp | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/src/nodepath.cpp b/src/nodepath.cpp index c62fb2c0f..f6b151837 100644 --- a/src/nodepath.cpp +++ b/src/nodepath.cpp @@ -51,6 +51,7 @@ #include <vector> #include <algorithm> #include <cstring> +#include <cmath> #include <string> #include "live_effects/lpeobject.h" #include "live_effects/effect.h" @@ -1936,21 +1937,32 @@ sp_nodepath_add_node_near_point(Inkscape::NodePath::Path *nodepath, NR::Point p) 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 = nearestPoint(pathv, p); + + // calculate index for nodepath's representation. + double int_part; + double t = std::modf(pvpos.t, &int_part); + unsigned int segment_index = (unsigned int)int_part + 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 split - Inkscape::NodePath::Node *e = sp_nodepath_get_node_by_index(position.piece); + Inkscape::NodePath::Node *e = sp_nodepath_get_node_by_index(segment_index); //don't know why but t seems to flip for lines if (sp_node_path_code_from_side(e, sp_node_get_side(e, -1)) == NR_LINETO) { - position.t = 1.0 - position.t; + t = 1.0 - t; } - Inkscape::NodePath::Node *n = sp_nodepath_line_add_node(e, position.t); + + Inkscape::NodePath::Node *n = sp_nodepath_line_add_node(e, t); sp_nodepath_node_select(n, FALSE, TRUE); /* fixme: adjust ? */ |
