Clone in a terminal:
Commit 6c9c4d7
Johan Mattsson - 2015-11-25T21:45:09+00:00
6c9c4d7fef3253406ca1d68b91357ea6ca279020johan.mattsson.m@gmail.com

More interpolation code

Changed files (4)

Diff

diff --git a/libbirdfont/EditPointHandle.vala b/libbirdfont/EditPointHandle.valaindex ee5feb4..6ba7c02 100644--- a/libbirdfont/EditPointHandle.vala+++ b/libbirdfont/EditPointHandle.vala@@ -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;diff --git a/libbirdfont/Glyph.vala b/libbirdfont/Glyph.valaindex 91bdfb2..4744806 100644--- a/libbirdfont/Glyph.vala+++ b/libbirdfont/Glyph.vala@@ -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 (); 			diff --git a/libbirdfont/Path.vala b/libbirdfont/Path.valaindex 4b7f5f2..70c20bb 100644--- a/libbirdfont/Path.vala+++ b/libbirdfont/Path.vala@@ -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) {diff --git a/libbirdfont/StrokeTool.vala b/libbirdfont/StrokeTool.valaindex e612157..9cde9ff 100644--- a/libbirdfont/StrokeTool.vala+++ b/libbirdfont/StrokeTool.vala@@ -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 ()) {

Contact

Email: johan.mattsson.m@gmail.com
Mastodon: typo.social/@birdfont
GitHub: johanmattssonm
LinkedIn: johan-mattsson-2ab324112