The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Fix merging of 2x2 paths

These changes was commited to the Birdfont repository Mon, 24 Aug 2015 11:03: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
[Mon, 24 Aug 2015 11:03:16 +0000]

Updated Files

libbirdfont/StrokeTool.vala
--- a/libbirdfont/StrokeTool.vala +++ b/libbirdfont/StrokeTool.vala @@ -291,41 +291,7 @@ if (pp.points.size > 1) { pp.get_closest_point_on_path (lep, ep.x, ep.y, null, null); - // add hidden double points to make sure that path does not change - // when new points are added to a 2x2 path. - if (lep.get_right_handle ().type == PointType.DOUBLE_CURVE) { - return_val_if_fail (lep.prev != null, r); - return_val_if_fail (lep.next != null, r); - - EditPoint before = lep.get_prev (); - EditPoint after = lep.get_next (); - EditPoint hidden = new EditPoint (0, 0, PointType.QUADRATIC); - hidden.get_right_handle ().type = PointType.QUADRATIC; - hidden.get_left_handle ().type = PointType.QUADRATIC; - - before.get_right_handle ().type = PointType.QUADRATIC; - after.get_left_handle ().type = PointType.QUADRATIC; - before.type = PointType.QUADRATIC; - after.type = PointType.QUADRATIC; - - double px = before.get_right_handle ().x - + (after.get_left_handle ().x - before.get_right_handle ().x) / 2.0; - double py = before.get_right_handle ().y - + (after.get_left_handle ().y - before.get_right_handle ().y) / 2.0; - hidden.independent_x = px; - hidden.independent_y = py; - - hidden.get_right_handle ().x = after.get_left_handle ().x; - hidden.get_right_handle ().y = after.get_left_handle ().y; - hidden.get_left_handle ().x = before.get_right_handle ().x; - hidden.get_left_handle ().y = before.get_right_handle ().y; - - pp.add_point_after (hidden, before); - - pp.get_closest_point_on_path (lep, ep.x, ep.y, null, null); - } - - if (Path.distance_to_point (ep, lep) < 0.1) { + 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); @@ -364,7 +330,10 @@ if (Path.distance_to_point (lep, (!) lep.next) < 0.001) { continue; } - + + add_double_point_at_intersection (pp, lep, ep); + add_double_point_at_intersection (pp, lep2, ep); + pp.insert_new_point_on_path (lep); pp.insert_new_point_on_path (lep2); @@ -389,7 +358,8 @@ lep.get_next ().reflective_point = false; continue; } - + + add_double_point_at_intersection (pp, lep, ep); pp.insert_new_point_on_path (lep); lep.flags |= EditPoint.INTERSECTION; lep.tie_handles = false; @@ -467,6 +437,43 @@ reset_intersections (path2); return parts; + } + + /** Add hidden double points to make sure that the path does not + * change when new points are added to a 2x2 path. + */ + static void add_double_point_at_intersection (Path pp, EditPoint lep, EditPoint ep) { + if (lep.get_right_handle ().type == PointType.DOUBLE_CURVE) { + return_if_fail (lep.prev != null); + return_if_fail (lep.next != null); + + EditPoint before = lep.get_prev (); + EditPoint after = lep.get_next (); + EditPoint hidden = new EditPoint (0, 0, PointType.QUADRATIC); + hidden.get_right_handle ().type = PointType.QUADRATIC; + hidden.get_left_handle ().type = PointType.QUADRATIC; + + before.get_right_handle ().type = PointType.QUADRATIC; + after.get_left_handle ().type = PointType.QUADRATIC; + before.type = PointType.QUADRATIC; + after.type = PointType.QUADRATIC; + + double px = before.get_right_handle ().x + + (after.get_left_handle ().x - before.get_right_handle ().x) / 2.0; + double py = before.get_right_handle ().y + + (after.get_left_handle ().y - before.get_right_handle ().y) / 2.0; + hidden.independent_x = px; + hidden.independent_y = py; + + hidden.get_right_handle ().x = after.get_left_handle ().x; + hidden.get_right_handle ().y = after.get_left_handle ().y; + hidden.get_left_handle ().x = before.get_right_handle ().x; + hidden.get_left_handle ().y = before.get_right_handle ().y; + + pp.add_point_after (hidden, before); + + pp.get_closest_point_on_path (lep, ep.x, ep.y, null, null); + } } static PathList remove_self_intersections (Path original) {