Commit 118c54d
delete edit points
Changed files (5)
modifiedsrc/EditPoint.valamodifiedsrc/Glyph.valamodifiedsrc/Path.valamodifiedsrc/PenTool.valamodifiedsrc/TestSupplement.vala
Diff
@@ -98,13 +98,13 @@ class EditPoint { left_handle = t; } }- + /** Set bezier points for linear paths. */ public void recalculate_linear_handles () {- EditPointHandle h;- EditPoint n;+ unowned EditPointHandle h;+ unowned EditPoint n; double nx, ny;- + // left handle if (prev != null) { n = get_prev ().data;@@ -116,7 +116,7 @@ class EditPoint { h.move_to_coordinate (nx, ny); }- + h = n.get_right_handle (); if (h.type == PointType.LINE) { @@ -126,7 +126,7 @@ class EditPoint { h.move_to_coordinate (nx, ny); } }- + // right handle if (next != null) { n = get_next ().data;@@ -444,25 +444,8 @@ class Glyph : FontDisplay { /** Delete edit point from path. */ public void delete_edit_point (EditPoint ep) {- foreach (Path p in path_list) {- foreach (EditPoint e in p.points) {- if (likely (e == ep)) {- - p.set_new_start (e);-- if (p.is_open ()) {- p.close ();- p.points.remove (e);- p.reopen ();- } else {- p.reopen ();- }- - redraw_area (0, 0, allocation.width, allocation.height);- return;- }- }+ p.delete_edit_point (ep); } warning ("This point does not exist.");@@ -509,16 +509,6 @@ class Path { return false; } - public void delete_edit_point (EditPoint e) {- foreach (var p in points) {- if (likely (p == e)) {- points.remove (p);- }- }- - warning ("Edit point does not exist.");- }- /** Switch direction from clockwise path to counter clockwise path or vise versa. */ public void reverse () { bool direction = is_clockwise ();@@ -1032,8 +1022,15 @@ class Path { }); } - return_if_fail (previous_point != null);- return_if_fail (next_point != null);+ if (previous_point == null) {+ warning ("previous_point == null");+ return;+ }+ + if (next_point == null) {+ warning ("next_point != null");+ return;+ } previous = ((!) previous_point).data; next = ((!) next_point).data;@@ -1186,7 +1183,31 @@ class Path { ep.data.next = ep.first (); ep.data.prev = ep.prev; }- ++ public void delete_edit_point (EditPoint ep) + requires (points.length () > 0)+ {+ unowned List<EditPoint>? pl = null;+ EditPoint p = points.first ().data;+ + for (uint i = 0; i < points.length (); i++) {+ p = points.nth (i).data;+ + if (p == ep) {+ p.prev = null;+ p.next = null;+ + pl = points.nth (i);+ }+ }+ + return_if_fail (pl != null);+ + points.delete_link ((!) pl);+ + create_list ();+ }+ public void set_new_start (EditPoint ep) { List<EditPoint> list = new List<EditPoint> (); uint len = points.length ();@@ -103,14 +103,11 @@ class PenTool : Tool { GridTool.tie (ref x, ref y); } - selected_handle.parent.set_point_type (PointType.CURVE); // FIXA: find a way to remove selected_handle.set_point_type (PointType.CURVE); selected_handle.move_to (x, y); selected_handle.parent.recalculate_linear_handles (); - selected_handle.parent.get_prev ().data.set_point_type (PointType.CURVE); // FIXA: find a way to remove- // Fixa: redraw line only glyph.redraw_area (0, 0, glyph.allocation.width, glyph.allocation.height); @@ -782,6 +779,30 @@ class PenTool : Tool { return pen_tool; } + public bool test_delete_points () {+ PenTool pen;+ Tool delete_tool = MainWindow.get_toolbox ().get_tool ("erase_tool");+ + test_open_next_glyph ();+ + // draw a line with ten points+ pen = (PenTool) select_pen ();+ for (int i = 1; i <= 10; i++) {+ pen.test_click_action (1, 20*i, 20);+ } + + // TODO: it would be nice to test if points were created here+ + // delete points+ delete_tool.test_select_action ();+ for (int i = 1; i <= 10; i++) {+ pen.move (20*i, 20);+ pen.test_click_action (1, 20*i, 20);+ }+ + return true;+ }+ public bool test_reverse_random_triangles () { Tool pen; @@ -39,10 +39,16 @@ class TestCases { add (test_reverse_random_paths, "Reverse random paths"); add (test_coordinates, "Coordinates"); add (test_drawing, "Pen tool"); + add (test_delete_points, "Delete edit points"); add (test_view_result, "View result in web browser"); add (test_save_backup, "Save backup"); } + public static void test_delete_points () { + PenTool tool = (PenTool) MainWindow.get_toolbox ().get_tool ("pen_tool"); + tool.test_delete_points (); + } + public static void test_active_edit_point () { PenTool tool = (PenTool) MainWindow.get_toolbox ().get_tool ("pen_tool"); tool.test_active_edit_point ();