The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Set a new start points before spitting paths in stroke.

These changes was commited to the Birdfont repository Wed, 15 Apr 2015 15:25:56 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
[Wed, 15 Apr 2015 15:25:56 +0000]

Updated Files

libbirdfont/Path.vala
libbirdfont/StrokeTool.vala
--- a/libbirdfont/Path.vala +++ b/libbirdfont/Path.vala @@ -1837,7 +1837,6 @@ ep.type = PenTool.to_curve (ep.type); set_new_start (current_path.points.get (0)); path_list.add (current_path); - ep = current_path.points.get (current_path.points.size - 1); ep.get_right_handle ().type = PenTool.to_line (ep.type); ep.type = PenTool.to_curve (ep.get_right_handle ().type); @@ -1865,48 +1864,26 @@ return path_list; } - public void set_new_start (EditPoint ep) { + public void set_new_start (EditPoint ep) + requires (points.size > 0) { Gee.ArrayList<EditPoint> list = new Gee.ArrayList<EditPoint> (); - uint len = points.size; - EditPoint iter = points.get (0); - EditPoint? ni = null; - bool found = false; - - foreach (EditPoint it in points) { - if (it == ep) { - found = true; - break; + int start = 0; + + for (int i = 0; i < points.size; i++) { + if (ep == points.get (i)) { + start = i; } - - iter = iter.get_next (); - ni = (!) iter; } - if (unlikely (!found)) { - warning ("Could not find edit point."); + for (int i = start; i < points.size; i++) { + list.add (points.get (i)); } - - if (ni == null) { - return; - } - - iter = (!) ni; - - for (uint i = 0; i < len; i++) { - list.add (iter); - - if (iter == points.get (points.size - 1)) { - iter = points.get (0).get_link_item (); - } else { - iter = iter.get_next (); - } - } - - points.clear (); - - foreach (EditPoint p in list) { - points.add (p); + + for (int i = 0; i < start; i++) { + list.add (points.get (i)); } + + control_points = list; } public void append_path (Path path) {
--- a/libbirdfont/StrokeTool.vala +++ b/libbirdfont/StrokeTool.vala @@ -820,7 +820,16 @@ } else { warning ("points already created."); } - + + foreach (EditPoint p in path.points) { + if (insides (p, path) == 1) { + path.set_new_start (p); + p.color = Color.green (); + path.close (); + break; + } + } + i = mark_intersection_as_deleted (path); if (!(i == 0 || i == 2)) { @@ -1390,6 +1399,30 @@ foreach (Path mm in r.paths) ((!) BirdFont.get_current_font ().get_glyph ("j")).add_path (mm); } + } + + public static int insides (EditPoint point, Path path) { + EditPoint prev; + int inside = 0; + + if (path.points.size <= 1) { + return 0; + } + + prev = path.get_last_point (); + + foreach (EditPoint start in path.points) { + if (start.x == point.x && point.y == start.y) { + inside++; + } else if ((start.y > point.y) != (prev.y > point.y) + && point.x < (prev.x - start.x) * (point.y - start.y) / (prev.y - start.y) + start.x) { + inside++; + } + + prev = start; + } + + return inside; } static bool merge_path (Path path1, Path path2, out PathList merged_paths, out bool error) { @@ -1431,7 +1464,9 @@ s = 0; foreach (EditPoint e in original_path1.points) { - if (!SvgParser.is_inside (e, original_path2)) { + print (@"insides: (e, original_path1): $(insides (e, original_path1)) $(e.x),$(e.y)\n"); + if (!SvgParser.is_inside (e, original_path2) + && insides (e, original_path1) == 1) { // FIXME: later as well break; } s++; @@ -1444,6 +1479,7 @@ original_path2 = t; s = 0; foreach (EditPoint e in original_path1.points) { + print (@"insides2: (e, original_path1): $(insides (e, original_path1))\n"); if (!SvgParser.is_inside (e, original_path2)) { break; } @@ -1776,7 +1812,6 @@ int i = 0; foreach (EditPoint p in path.points) { - if ((p.flags & EditPoint.INTERSECTION) > 0) { p.deleted = true; i++;