Commit 6c9c4d7
More interpolation code
Changed files (4)
modifiedlibbirdfont/EditPointHandle.valamodifiedlibbirdfont/Glyph.valamodifiedlibbirdfont/Path.valamodifiedlibbirdfont/StrokeTool.vala
Diff
@@ -310,13 +310,13 @@ public class EditPointHandle : GLib.Object { } public static double average_angle (double angle1, double angle2) {- EditPointHandle handle = new EditPointHandle (new EditPoint (0, 0), 0, 1);+ EditPointHandle handle = new EditPointHandle (new EditPoint (0, 0, PointType.CUBIC), 0, 1); double x = (cos (angle1) + cos (angle2)) / 2; double y = (sin (angle1) + sin (angle2)) / 2; handle.move_to_coordinate (x, y); if (fabs (x) < 0.001 && fabs (y) < 0.001) {- return (angle1 + PI / 2) % 2 * PI;+ return (angle1 + PI / 2) % (2 * PI); } return handle.angle;@@ -2456,12 +2456,11 @@ public class Glyph : FontDisplay { foreach (Path p in g1.get_visible_paths ()) { bool counter = !p.is_clockwise ();- //g2.add_path (p.self_interpolate (weight, counter)); g2.add_path (p.copy ()); p.remove_points_on_points ();- Path master = p.get_self_interpolated_master (counter);+ Path master = p.get_self_interpolated_master (counter, weight); p = p.interpolate_estimated_path (master, weight); p.recalculate_linear_handles (); @@ -2647,7 +2647,7 @@ public class Path : GLib.Object { } } else { remove_points_on_points ();- master = get_self_interpolated_master (counter);+ master = get_self_interpolated_master (counter, weight); p = interpolate_estimated_path (master, weight); recalculate_linear_handles (); }@@ -2659,7 +2659,10 @@ public class Path : GLib.Object { Path p = copy (); EditPoint ep, master_point; double x, y;-+ double direction = weight;+ + weight = fabs(weight);+ if (p.points.size <= 1 || master.points.size <= 1) { return p; }@@ -2669,12 +2672,15 @@ public class Path : GLib.Object { for (int i = 0; i < p.points.size; i++) { ep = p.points.get (i); - bool debug = (-19 < ep.x < -21) && (39 < ep.y < 41);- double right_angle = ep.get_right_handle ().angle; double left_angle = ep.get_left_handle ().angle; double angle = EditPointHandle.average_angle (right_angle, left_angle);- angle += PI;+ angle += direction > 0 ? -PI : PI;+ + if (angle < 0) {+ angle += 2 * PI;+ }+ angle %= 2 * PI; double close_x, close_y;@@ -2685,19 +2691,17 @@ public class Path : GLib.Object { close_x = Glyph.CANVAS_MAX; close_y = Glyph.CANVAS_MAX; + master_point = new EditPoint (); while (Path.distance (close_x, master_point.x, close_y, master_point.y) > 0.1) { x = ep.x + distance_to_edge * cos (angle); y = ep.y + distance_to_edge * sin (angle); - if (debug) {- print(@"Search $x $y\n");- }- master_point = new EditPoint (); master.get_closest_point_on_path (master_point, x, y); master_point.color = Color.red ();- master.insert_new_point_on_path (master_point);- master_point.get_right_handle ().angle = angle;+ //master.insert_new_point_on_path (master_point);+ master_point.convert_to_curve ();+ master_point.get_right_handle().angle = angle; distance_to_edge += 0.1; @@ -2711,13 +2715,15 @@ public class Path : GLib.Object { if (distance_to_edge > 5) { break; }+ }+ master_point.color = Color.blue (); x = close_x; y = close_x; - ep.x += (master_point.x - ep.x) * weight;- ep.y += (master_point.y - ep.y) * weight;+ ep.x += (close_x - ep.x) * direction;+ ep.y += (close_y - ep.y) * direction; } p.adjust_interpolated_handles (master, fabs ((5 / 2.0) * weight));@@ -2725,8 +2731,8 @@ public class Path : GLib.Object { return p; } - public Path get_self_interpolated_master (bool counter) {- return StrokeTool.change_weight (this, counter); + public Path get_self_interpolated_master (bool counter, double weight) {+ return StrokeTool.change_weight (this, counter, weight); } void adjust_interpolated_handles (Path master, double edge) {@@ -3130,19 +3130,24 @@ public class StrokeTool : GLib.Object { return pl.paths.get (1); } - public static Path change_weight (Path path, bool counter) {+ public static Path change_weight (Path path, bool counter, double weight) { StrokeTool tool = new StrokeTool (); Path o = path.copy (); Path interpolated = new Path(); o.force_direction (Direction.CLOCKWISE);+ double default_weight = 5; - PathList pl = tool.get_stroke (o, 5);+ PathList pl = tool.get_stroke (o, default_weight); Gee.ArrayList<PointSelection> deleted; deleted = new Gee.ArrayList<PointSelection> (); return_val_if_fail (pl.paths.size > 0, new Path ()); + if (weight < 0) {+ counter = !counter;+ }+ foreach (Path sp in pl.paths) { if (sp.points.size > interpolated.points.size && counter == !sp.is_clockwise ()) {