Clone in a terminal:
Commit 44838bf
Johan Mattsson - 2016-07-15T18:43:27+00:00
44838bf4f3adf73d83f1335012a63f78fc5ac93djohan.mattsson.m@gmail.com

Click to object matrix transformation

Changed files (9)

Diff

diff --git a/Makefile b/Makefiledeleted file mode 100644index c121761..0000000--- a/Makefile+++ /dev/null@@ -1,6 +0,0 @@-all:-	./configure-	./build.py--install:-	./install.py -d $(DESTDIR)diff --git a/libsvgbird/Circle.vala b/libsvgbird/Circle.valaindex aacacf3..c5b1395 100644--- a/libsvgbird/Circle.vala+++ b/libsvgbird/Circle.vala@@ -26,6 +26,7 @@ public class Circle : Object { 	} 	 	public override bool is_over (double x, double y) {+		to_object_view (ref x, ref y); 		double dx = x - cx; 		double dy = y - cy; 		return Math.sqrt (dx * dx + dy * dy) <= r;diff --git a/libsvgbird/Ellipse.vala b/libsvgbird/Ellipse.valaindex df30840..f91886b 100644--- a/libsvgbird/Ellipse.vala+++ b/libsvgbird/Ellipse.vala@@ -28,6 +28,7 @@ public class Ellipse : Object { 	} 	 	public override bool is_over (double x, double y) {+		to_object_view (ref x, ref y); 		double point_x = x - cx; 		double point_y = y - cy; 		return (point_x * point_x) / (rx * rx) + (point_y * point_y) / (ry * ry) <= 1;diff --git a/libsvgbird/Layer.vala b/libsvgbird/Layer.valaindex da525b0..bcaa0f6 100644--- a/libsvgbird/Layer.vala+++ b/libsvgbird/Layer.vala@@ -32,7 +32,6 @@ public class Layer : Object { 		transforms = new SvgTransforms (); 	} - 	public override bool update_boundaries (Context cr) { 		if (objects.size == 0) { 			return false;diff --git a/libsvgbird/Object.vala b/libsvgbird/Object.valaindex bc8a6ca..febe536 100644--- a/libsvgbird/Object.vala+++ b/libsvgbird/Object.vala@@ -97,6 +97,12 @@ public abstract class Object : GLib.Object { 		return left <= x <= right && top <= y <= bottom;  	} 	+	public void to_object_view (ref double x, ref double y) {+		Matrix m = view_matrix;+		m.invert ();+		m.transform_point (ref x, ref y);+	}+	 	public abstract void draw_outline (Context cr);  	public abstract Object copy ();diff --git a/libsvgbird/Polygon.vala b/libsvgbird/Polygon.valaindex 244f001..ca46042 100644--- a/libsvgbird/Polygon.vala+++ b/libsvgbird/Polygon.vala@@ -41,7 +41,21 @@ public class Polygon : Object { 			cr.close_path (); 		}		 	}-	++	public override bool is_over (double x, double y) {+		bool inside = false;+		+		to_object_view (ref x, ref y);+		+		foreach (Points p in points) {+			if (SvgPath.is_over_points (p, point_x, point_y)) {+				inside = !inside;+			}+		}+		+		return inside;+	}+		 	public override void move (double dx, double dy) { 	} 	diff --git a/libsvgbird/Polyline.vala b/libsvgbird/Polyline.valaindex c52c54a..402a42a 100644--- a/libsvgbird/Polyline.vala+++ b/libsvgbird/Polyline.vala@@ -27,7 +27,7 @@ public class Polyline : Object { 	public override bool is_over (double x, double y) { 		return false; 	}-			+ 	public override void draw_outline (Context cr) { 		return_if_fail (points.size % 2 == 0); 		diff --git a/libsvgbird/Rectangle.vala b/libsvgbird/Rectangle.valaindex b669024..6ba2f54 100644--- a/libsvgbird/Rectangle.vala+++ b/libsvgbird/Rectangle.vala@@ -32,6 +32,7 @@ public class Rectangle : Object { 	} 	 	public override bool is_over (double x, double y) {+		to_object_view (ref x, ref y); 		return this.x <= x <= this.x + width && this.y <= y <= this.y + height;  	} 			diff --git a/libsvgbird/SvgPath.vala b/libsvgbird/SvgPath.valaindex 0b28730..ac64e5e 100644--- a/libsvgbird/SvgPath.vala+++ b/libsvgbird/SvgPath.vala@@ -39,14 +39,9 @@ public class SvgPath : Object { 	public override bool is_over (double point_x, double point_y) { 		bool inside = false; 		-		double x = point_x;-		double y = point_y;-		-		Matrix matrix = view_matrix;-		matrix.invert ();-		matrix.transform_point (ref x, ref y);-		 		if (is_over_boundaries (point_x, point_y)) {+			to_object_view (ref point_x, ref point_y);+			 			foreach (Points p in points) { 				if (is_over_points (p, point_x, point_y)) { 					inside = !inside;@@ -57,7 +52,7 @@ public class SvgPath : Object { 		return inside; 	} 	-	public bool is_over_points (Points p, double point_x, double point_y) {+	public static bool is_over_points (Points p, double point_x, double point_y) { 		double previous_x; 		double previous_y; 		bool inside = false;@@ -136,7 +131,6 @@ public class SvgPath : Object { 		if  ((next_y > point_y) != (prev_y > point_y)  			&& point_x < (prev_x - next_x) * (point_y - next_y) / (prev_y - next_y) + next_x) { 			inside = !inside;-			print (@"flip\n"); 		} 	} 			

Contact

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