The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Run split before merge

These changes was commited to the Birdfont repository Mon, 17 Aug 2015 13:01:16 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
author Johan Mattsson <johan.mattsson.m@gmail.com>
Mon, 17 Aug 2015 13:01:16 +0000 (15:01 +0200)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Mon, 17 Aug 2015 13:01:16 +0000 (15:01 +0200)
commit 6fd04cc00b187264f7233afaf4289b7e70c1b57a
tree c94f94045d7775ba960e69ad029b855d9c7bce31
parent f1196f0efe1400c59cb72ff26acf5fb329a72c46
Run split before merge

libbirdfont/Path.vala
libbirdfont/StrokeTool.vala
--- a/libbirdfont/Path.vala +++ b/libbirdfont/Path.vala @@ -1398,8 +1398,8 @@ double ox = 0; double oy = 0; - EditPoint prev = points.get (points.size - 1).get_link_item (); - EditPoint i = points.get (0).get_link_item (); + EditPoint prev = points.get (points.size - 1); + EditPoint i = points.get (0); bool done = false; bool exit = false; @@ -1440,17 +1440,29 @@ i = i.get_next (); prev = i.get_prev (); } else if (done && !is_open ()) { - i = points.get (0).get_link_item (); - prev = points.get (points.size - 1).get_link_item (); + i = points.get (0); + prev = points.get (points.size - 1); exit = true; } else { break; } - if (skip_previous == prev && skip_next == i) { + if (skip_previous == prev) { continue; } + if (prev.prev != null && skip_previous == prev.get_prev ()) { + continue; + } + + if (skip_next == i) { + continue; + } + + if (prev.next != null && skip_next == prev.get_next ()) { + continue; + } + all_of (prev, i, (cx, cy, t) => { n = pow (x - cx, 2) + pow (y - cy, 2);
--- a/libbirdfont/StrokeTool.vala +++ b/libbirdfont/StrokeTool.vala @@ -130,37 +130,51 @@ o = remove_overlap (o); reset_flags (o); - new_paths.append (o); - for (int i = 0; i < o.paths.size; i++) { - for (int j = 0; j < o.paths.size; j++) { - Path p1, p2; - - p1 = o.paths.get (i); - p2 = o.paths.get (j); - - if (i == j) { - continue; - } + + for (int merge = 0; merge < 2; merge++) { + for (int i = 0; i < o.paths.size; i++) { + for (int j = 0; j < o.paths.size; j++) { + Path p1, p2; + + p1 = o.paths.get (i); + p2 = o.paths.get (j); + + if (merge == 0) { + if (p1.is_clockwise () == p2.is_clockwise ()) { + continue; + } + } - r = merge_selected (p1, p2, false); + if (merge == 1) { + if (p1.is_clockwise () != p2.is_clockwise ()) { + continue; + } + } + + if (i == j) { + continue; + } - remove_merged_curve_parts (r); - - if (r.paths.size > 0) { - reset_flags (r); - new_paths.append (r); + r = merge_selected (p1, p2, false); - new_paths.remove (p1); - new_paths.remove (p2); + remove_merged_curve_parts (r); + + if (r.paths.size > 0) { + reset_flags (r); + new_paths.append (r); - o.remove (p1); - o.remove (p2); - - o.append (r); - - i = 0; - j = 0; + new_paths.remove (p1); + new_paths.remove (p2); + + o.remove (p1); + o.remove (p2); + + o.append (r); + + i = 0; + j = 0; + } } } } @@ -274,15 +288,9 @@ foreach (Path pp in o.paths) { EditPoint lep = new EditPoint (); - if (pp.points.size > 1) { + if (pp.points.size > 1) { pp.get_closest_point_on_path (lep, ep.x, ep.y, null, null); - - if (Path.distance_to_point (lep, (!) lep.prev) < 0.1 - || Path.distance_to_point (lep, (!) lep.next) < 0.1) { - // FIXME: find a better solution - continue; - } - + if (Path.distance_to_point (ep, lep) < 0.1) { EditPoint lep2 = new EditPoint (); pp.get_closest_point_on_path (lep2, ep.x, ep.y, lep.prev, lep.next); @@ -309,14 +317,23 @@ lep2.get_right_handle ().type = lep2.get_next ().get_left_handle ().type; } else { lep2.get_left_handle ().type = pp.get_last_point ().get_right_handle ().type; - } - + } + // self intersection if (Path.distance_to_point (ep, lep2) < 0.1 && Path.distance_to_point (ep, lep) < 0.1) { + + if (Path.distance_to_point (lep, (!) lep.prev) < 0.001) { + continue; + } + + if (Path.distance_to_point (lep, (!) lep.next) < 0.001) { + continue; + } + pp.insert_new_point_on_path (lep); pp.insert_new_point_on_path (lep2); - + lep.flags |= EditPoint.SELF_INTERSECTION; lep2.flags |= EditPoint.SELF_INTERSECTION; @@ -324,11 +341,26 @@ lep.reflective_point = false; lep2.tie_handles = false; lep2.reflective_point = false; + + // FIXME: DELETE + lep.color = Color.magenta (); + lep2.color = Color.magenta (); } else { + if (Path.distance_to_point (lep, (!) lep.prev) < 0.001) { + continue; + } + + if (Path.distance_to_point (lep, (!) lep.next) < 0.001) { + continue; + } + pp.insert_new_point_on_path (lep); lep.flags |= EditPoint.INTERSECTION; lep.tie_handles = false; lep.reflective_point = false; + + // FIXME: DELETE + lep.color = Color.pink (); } has_split_point = true; @@ -341,6 +373,11 @@ if (!has_split_point) { return r; + } + + // FIXME: DELETE + foreach (Path p in o.paths) { + ((!) BirdFont.get_current_font ().get_glyph_by_name ("a")).add_path (p.copy ()); } // remove double intersection points @@ -361,7 +398,12 @@ foreach (Path pp in o.paths) { pp.remove_deleted_points (); } - + + // FIXME: DELETE + foreach (Path p in o.paths) { + ((!) BirdFont.get_current_font ().get_glyph_by_name ("b")).add_path (p.copy ()); + } + foreach (Path p in o.paths) { foreach (EditPoint ep in p.points) { ep.flags &= uint.MAX ^ EditPoint.COPIED;