Clone in a terminal:
Commit 81d86c2
Johan Mattsson - 2012-08-28T12:11:35+00:00
81d86c228290c8b7b5c4ca2c87b0b06d1e9de420johan.mattsson.m@gmail.com

convert pixel position to cartesian coordinate

Changed files (2)

Diff

diff --git a/src/Glyph.vala b/src/Glyph.valaindex a24a998..9f723d7 100644--- a/src/Glyph.vala+++ b/src/Glyph.vala@@ -710,42 +710,25 @@ class Glyph : FontDisplay {  	public static double path_coordinate_x (double x) { 		Glyph g = MainWindow.get_current_glyph ();-		double xc = Glyph.yc ();-		-		return_if_fail (xc != 0);-		-		x *= 1 / g.view_zoom;-		return (x - xc + g.view_offset_x);+		return_if_fail (g.view_zoom != 0);+		return x * g.ivz () - g.xc () + g.view_offset_x; 	}  	public static int reverse_path_coordinate_x (double x) { 		Glyph g = MainWindow.get_current_glyph ();-		double xc = Glyph.xc ();-		-		return_if_fail (xc != 0);-		-		x *= g.view_zoom;-		return (int) (x + xc + g.view_offset_x);+		return_if_fail (g.view_zoom != 0);+		return (int) ((x - g.view_offset_x + g.xc ()) * g.view_zoom + 0.5); 	}  	public static double path_coordinate_y (double y) {-		Glyph? t = MainWindow.get_current_glyph ();-		-		return_val_if_fail (t != null, 0);-		-		Glyph g = (!) t;-		double yc = (g.allocation.height / 2.0);--		y *= 1 / g.view_zoom;-		-		return (yc - y) - g.view_offset_y;+		Glyph g = MainWindow.get_current_glyph ();+		return g.yc () - y * g.ivz () - g.view_offset_y; 	}  	public static int reverse_path_coordinate_y (double y) { 		Glyph g = MainWindow.get_current_glyph ();-		double yc = (g.allocation.height / 2.0);-		y *= g.view_zoom;-		return (int) ((yc - y) + g.view_offset_y);+		y = ((y + g.view_offset_y - g.yc ()) * g.view_zoom);+		return (int) (-y + 0.5); 	}  	public static void reverse (double x, double y, out int rx, out int ry) {diff --git a/src/PenTool.vala b/src/PenTool.valaindex 0802a8e..88bc192 100644--- a/src/PenTool.vala+++ b/src/PenTool.vala@@ -626,9 +626,10 @@ class PenTool : Tool { 	/** Test path coordinates and reverse path coordinates. */ 	public void test_coordinates () { 		int x, y, xc, yc;-		double px, py;+		double px, py, mx, my; 		string n; 		+		Tool.test_open_next_glyph (); 		Glyph g = MainWindow.get_current_glyph (); 		 		xc = (int) (g.allocation.width / 2.0);@@ -642,6 +643,13 @@ class PenTool : Tool { 		px = g.path_coordinate_x (x); 		py = g.path_coordinate_y (y); +		mx = x * g.ivz () - g.xc () + g.view_offset_x;+		my = g.yc () - y * g.ivz () - g.view_offset_y;+		+		if (mx != px || my != py) {+			warning (@"bad coordinate $mx != $px || $my != $py");+		}+			 		test_reverse_coordinate (x, y, px, py, "ten fifteen"); 		test_click_action (1, x, y); 	@@ -649,11 +657,9 @@ class PenTool : Tool { 		n = "Offset no zoom"; 		g.reset_zoom (); 		-		 		px = g.path_coordinate_x (x); 		py = g.path_coordinate_y (y); 		-		test_coordinate (px, py, x, y, n); 		test_reverse_coordinate (x, y, px, py, n); 		test_click_action (1, x, y); 				@@ -693,7 +699,7 @@ class PenTool : Tool { 		bool d = ((!)MainWindow.get_current_glyph ().get_last_path ()).is_clockwise (); 		 		if (d) {-				critical (@"\nPath $name is clockwise, in test_last_is_counter_clockwise");+			critical (@"\nPath $name is clockwise, in test_last_is_counter_clockwise"); 		}		 	} 	

Contact

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