The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Revert "Error handeling in merge code"

These changes was commited to the Birdfont repository Sat, 03 Oct 2015 13:47:45 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
[Sat, 03 Oct 2015 13:47:45 +0000]

Updated Files

libbirdfont/OtfTags.vala
libbirdfont/StrokeTool.vala
--- a/libbirdfont/OtfTags.vala +++ b/libbirdfont/OtfTags.vala @@ -35,8 +35,16 @@ } return tags; + } + + public string to_string () { + StringBuilder sb = new StringBuilder (); + foreach (string s in elements) { + sb.append (s); + } + return sb.str; } } }
--- a/libbirdfont/StrokeTool.vala +++ b/libbirdfont/StrokeTool.vala @@ -119,29 +119,16 @@ PathList o = new PathList (); PathList r; PathList new_paths = new PathList (); - bool error = false; g.store_undo_state (); foreach (Path p in g.active_paths) { - if (p.stroke > 0) { - o.append (p.get_stroke ()); - } else { - o.add (p); - } - } - - foreach (Path p in o.paths) { p.close (); p.remove_points_on_points (); + o.add (p); } - o = remove_overlap (o, out error); - - if (error) { - warning ("remove_overlap failed"); - return; - } + o = remove_overlap (o); reset_flags (o); new_paths.append (o); @@ -170,12 +157,7 @@ continue; } - r = merge_selected (p1, p2, false, out error); - - if (error) { - warning ("Paths can not be merged."); - return; - } + r = merge_selected (p1, p2, false); remove_merged_curve_parts (r); @@ -215,17 +197,11 @@ GlyphCanvas.redraw (); } - static PathList remove_overlap (PathList pl, out bool error) { + static PathList remove_overlap (PathList pl) { PathList r = new PathList (); - error = false; - + foreach (Path p in pl.paths) { - PathList m = merge_selected (p, new Path (), true, out error); - - if (error) { - warning ("Can not merge selected paths."); - return pl; - } + PathList m = merge_selected (p, new Path (), true); if (m.paths.size > 0) { r.append (m); @@ -281,14 +257,12 @@ } public static PathList merge_selected (Path path1, Path path2, - bool self_intersection, out bool error) { + bool self_intersection) { PathList flat = new PathList (); PathList o = new PathList (); PathList pl = new PathList (); PathList r = new PathList (); - - error = false; pl.add (path1); pl.add (path2); @@ -442,23 +416,12 @@ // remove overlap PathList self_parts; - self_parts = remove_self_intersections (p1, out error); - - if (error) { - warning ("Can't remove self intersections."); - return parts; - } - + self_parts = remove_self_intersections (p1); parts.append (self_parts); } else { // merge two path - PathList merged_paths = merge_paths_with_curves (p1, p2, out error); + PathList merged_paths = merge_paths_with_curves (p1, p2); - if (error) { - warning ("Can't merge paths."); - return parts; - } - if (merged_paths.paths.size > 0) { parts.append (merged_paths); } else { @@ -522,7 +485,7 @@ } } - static PathList remove_self_intersections (Path original, out bool error) { + static PathList remove_self_intersections (Path original) { Path merged = new Path (); IntersectionList intersections = new IntersectionList (); EditPoint ep1, ep2, found; @@ -534,7 +497,6 @@ int i = 0; Path path = original.copy (); - error = false; parts = new PathList (); if (path.points.size <= 1) { @@ -594,7 +556,6 @@ } if (intersections.points.size == 0) { - error = true; warning ("No intersection points."); return parts; } @@ -637,7 +598,6 @@ i = index_of (current, other ? new_start.point : new_start.other_point); if (!(0 <= i < current.points.size)) { - error = true; warning (@"Index out of bounds. ($i)"); return parts; } @@ -689,7 +649,7 @@ return parts; } - static PathList merge_paths_with_curves (Path path1, Path path2, out bool error) { + static PathList merge_paths_with_curves (Path path1, Path path2) { PathList r = new PathList (); IntersectionList intersections = new IntersectionList (); EditPoint ep1, ep2, found; @@ -698,8 +658,6 @@ Path current; bool found_intersection; Path flat1, flat2; - - error = false; if (path1.points.size <= 1 || path2.points.size <= 1) { return r; @@ -760,7 +718,6 @@ } if (intersections.points.size == 0) { - error = true; warning ("No intersection points."); return r; } @@ -920,6 +877,13 @@ foreach (EditPoint e in p.points) { PenTool.convert_point_type (e, PointType.CUBIC); + } + + foreach (EditPoint e in p.points) { + if ((e.flags & EditPoint.CURVE) == 0) { + p.set_new_start (e); + break; + } } for (int i = 0; i < p.points.size; i++) { @@ -927,7 +891,6 @@ if ((ep.flags & EditPoint.CURVE) > 0) { start = i; - for (j = start + 1; j < p.points.size; j++) { ep = p.points.get (j); if ((ep.flags & EditPoint.CURVE) == 0) { @@ -942,11 +905,7 @@ warning ("start < 0"); start = 0; } - - if (start + 1 == stop) { - warning ("length of segment is one"); - } - + if (stop >= p.points.size) { warning ("stop >= p.points.size"); stop = p.points.size - 1; @@ -2102,24 +2061,6 @@ } return r; - } - - static void remove_single_points (PathList pl) { - PathList r = new PathList (); - - foreach (Path p in pl.paths) { - p.update_region_boundaries (); - if (p.points.size < 10 - || p.xmax - p.xmin < 0.01 - || p.ymax - p.ymin < 0.01) { - - r.add (p); - } - } - - foreach (Path p in r.paths) { - pl.remove (p); - } } public static PathList merge (PathList pl) { @@ -2129,9 +2070,8 @@ Path p1, p2; r = get_all_parts (r); - remove_single_points (r); - while (paths_has_intersection (r, out p1, out p2)) { + while (paths_has_intersection (r, out p1, out p2)) { if (merge_path (p1, p2, out m, out error)) { r.paths.remove (p1); r.paths.remove (p2); @@ -2142,7 +2082,6 @@ } r = get_all_parts (r); - remove_single_points (r); } else { warning ("Not merged."); error = true; @@ -2155,7 +2094,6 @@ } if (!error) { - remove_single_points (r); remove_merged_parts (r); } @@ -2311,6 +2249,14 @@ error = false; merged_paths = new PathList (); intersections = new IntersectionList (); + + if (path1.points.size == 0) { + return false; + } + + if (path2.points.size == 0) { + return false; + } reset_intersections (path1); reset_intersections (path2); @@ -2322,6 +2268,7 @@ if (path1.points.size == 0 || path2.points.size == 0) { warning ("No points in path."); + error = true; return false; } @@ -2380,13 +2327,7 @@ merged = new Path (); path1_direction = is_clockwise (original_path1); - path2_direction = is_clockwise (original_path1); // 2? - - if (path1 == path2) { - warning ("Same path."); - error = true; - return false; - } + path2_direction = is_clockwise (original_path1); while (true) { ep1 = path.points.get (i % path.points.size); @@ -2409,13 +2350,7 @@ break; } } - - if (intersections.points.size == 1) { - warning ("Only one intersection.\n"); - error = true; - return false; - } - + if (!find_parts) { break; // done, no more parts to merge } else { @@ -2429,7 +2364,7 @@ } i = index_of (path, new_start.get_point (path)); - + if (i < 0) { warning ("Start point not found."); error = true;