The Birdfont Source Code
Fix stroke code and remove points on points
These changes was commited to the Birdfont repository Fri, 09 Oct 2015 06:10:23 +0000.
Contributing
Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
Fix stroke code and remove points on points
--- a/libbirdfont/Path.vala
+++ b/libbirdfont/Path.vala
@@ -2294,28 +2294,45 @@
Gee.ArrayList<EditPoint> remove = new Gee.ArrayList<EditPoint> ();
EditPoint n;
EditPointHandle hr, h;
+ double t3 = t / 3;
if (points.size == 0) {
return;
+ }
+
+ for (int i = 0; i < points.size + 1; i++) {
+ EditPoint ep = points.get (i % points.size);
+ if (ep.get_right_handle ().length < t3
+ && ep.get_left_handle ().length < t3
+ && !is_endpoint (ep)) {
+ ep.deleted = true;
+ }
}
- create_list ();
+ remove_deleted_points ();
- foreach (EditPoint ep in points) {
- if (ep.next != null) {
- n = ep.get_next ();
- } else {
- n = points.get (0);
- }
-
- if (fabs (n.x - ep.x) < t && fabs (n.y - ep.y) < t) {
- if ((ep.flags & EditPoint.NEW_CORNER) == 0) {
+ for (int i = 0; i < points.size + 1; i++) {
+ EditPoint ep = points.get (i % points.size);
+ n = points.get ((i + 1) % points.size);
+
+ if ((ep.flags & EditPoint.NEW_CORNER) == 0) {
+ if (ep.get_right_handle ().length < t
+ && ep.get_left_handle ().length < t
+ && !is_endpoint (ep)) {
+ ep.deleted = true;
+ } else if (Path.distance_to_point (n, ep) < t) {
remove.add (ep);
}
}
}
+
+ create_list ();
foreach (EditPoint r in remove) {
+ if (points.size == 0) {
+ return;
+ }
+
if (r.next != null) {
n = r.get_next ();
} else {
@@ -2338,6 +2355,14 @@
}
recalculate_linear_handles ();
+ }
+
+ public bool is_endpoint (EditPoint ep) {
+ if (points.size == 0) {
+ return false;
+ }
+
+ return ep == points.get (0) || ep == points.get (points.size - 1);
}
public void remove_deleted_points () {
--- a/libbirdfont/StrokeTool.vala
+++ b/libbirdfont/StrokeTool.vala
@@ -84,7 +84,7 @@
StrokeTool s = new StrokeTool ();
stroke = path.copy ();
- stroke.remove_points_on_points (0.3);
+ stroke.remove_points_on_points (0.1);
o = s.create_stroke (stroke, thickness, false); // set to true for faster stroke
return o;
@@ -95,7 +95,7 @@
Path stroke;
stroke = path.copy ();
- stroke.remove_points_on_points (0.3);
+ stroke.remove_points_on_points (0.1);
o = create_stroke (stroke, thickness, false);
o = get_all_parts (o);
o = remove_intersection_paths (o);
@@ -957,11 +957,19 @@
PenTool.convert_point_type (e, PointType.CUBIC);
}
+ bool has_curve_start = true;
foreach (EditPoint e in p.points) {
+ e.flags &= uint.MAX ^ EditPoint.NEW_CORNER;
+
if ((e.flags & EditPoint.CURVE) == 0) {
p.set_new_start (e);
+ has_curve_start = false;
break;
}
+ }
+
+ if (has_curve_start) {
+ warning ("Curve start");
}
for (int i = 0; i < p.points.size; i++) {
@@ -1054,8 +1062,6 @@
simplified.recalculate_linear_handles ();
simplified.close ();
remove_single_point_intersections (simplified);
-
- simplified.remove_points_on_points ();
return simplified;
}