The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Merge ../birdfont-2.x

These changes was commited to the Birdfont repository Sun, 15 May 2016 13:02:10 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
[Sun, 15 May 2016 13:02:10 +0000]

Updated Files

libbirdfont/BezierTool.vala
libbirdfont/PenTool.vala
libbirdfont/PointTool.vala
--- a/libbirdfont/BezierTool.vala +++ b/libbirdfont/BezierTool.vala @@ -366,21 +366,21 @@ GlyphCanvas.redraw (); } else if (state == MOVE_HANDLE_ON_AXIS) { EditPointHandle h = current_point.get_right_handle (); - double horizontal, vertical; - - vertical = Path.distance (px, h.parent.x, py, py); - horizontal = Path.distance (h.parent.y, py, py, py); current_path.hide_end_handle = false; current_point.set_reflective_handles (true); current_point.convert_to_curve (); - - if (horizontal < vertical) { - h.move_to_coordinate (px, current_point.y); - } else { - h.move_to_coordinate (current_point.x, py); - } - + + double tied_x = 0; + double tied_y = 0; + + PointTool.tie_angle (h.parent.x, h.parent.y, + px, py, out tied_x, out tied_y); + + h.x = tied_x; + h.y = tied_y; + + current_path.reset_stroke (); GlyphCanvas.redraw (); }
--- a/libbirdfont/PenTool.vala +++ b/libbirdfont/PenTool.vala @@ -833,27 +833,14 @@ selected_handle.y = coordinate_y; if (on_axis) { - double length = fabs (Path.distance (selected_handle.parent.x, coordinate_x, - selected_handle.parent.y, coordinate_y)); - - double min = double.MAX; - double circle_edge; - double circle_x; - double circle_y; - - for (double circle_angle = 0; circle_angle < 2 * PI; circle_angle += PI / 4) { - circle_x = selected_handle.parent.x + cos (circle_angle) * length; - circle_y = selected_handle.parent.y + sin (circle_angle) * length; - - circle_edge = fabs (Path.distance (coordinate_x, circle_x, - coordinate_y, circle_y)); - - if (circle_edge < min) { - selected_handle.x = circle_x; - selected_handle.y = circle_y; - min = circle_edge; - } - } + double tied_x = 0; + double tied_y = 0; + + PointTool.tie_angle (selected_handle.parent.x, selected_handle.parent.y, + coordinate_x, coordinate_y, out tied_x, out tied_y); + + selected_handle.x = tied_x; + selected_handle.y = tied_y; } }
--- a/libbirdfont/PointTool.vala +++ b/libbirdfont/PointTool.vala @@ -92,8 +92,38 @@ public static Tool pen () { return MainWindow.get_toolbox ().get_tool ("pen_tool"); + } + + public static void tie_angle (double center_x, double center_y, + double coordinate_x, double coordinate_y, + out double tied_x, out double tied_y) { + + double length = fabs (Path.distance (center_x, coordinate_x, + center_y, coordinate_y)); + + tied_x = 0; + tied_y = 0; + + double min = double.MAX; + double circle_edge; + double circle_x; + double circle_y; + + for (double circle_angle = 0; circle_angle < 2 * PI; circle_angle += PI / 4) { + circle_x = center_x + cos (circle_angle) * length; + circle_y = center_y + sin (circle_angle) * length; + + circle_edge = fabs (Path.distance (coordinate_x, circle_x, + coordinate_y, circle_y)); + + if (circle_edge < min) { + tied_x = circle_x; + tied_y = circle_y; + min = circle_edge; + } + } } } }