Code

display guide anchor on canvas; anchor and angle can be edited by mouse
[inkscape.git] / src / 2geom / point.cpp
index 5dd7b52f295126b468f76d49e239202d561566cb..b8a858f8d48d6f9910441a93100cef69a9a8a743 100644 (file)
@@ -2,7 +2,7 @@
 #include <assert.h>
 #include <2geom/coord.h>
 #include <2geom/isnan.h> //temporary fix for isnan()
-#include <2geom/matrix.h>
+#include <2geom/transforms.h>
 
 namespace Geom {
 
@@ -150,6 +150,18 @@ Point &Point::operator*=(Matrix const &m)
     return *this;
 }
 
+Point constrain_angle(Point const &ref, Point const &pt, unsigned int n, Point const &dir)
+{
+    // for special cases we could perhaps use faster routines
+    if (n == 0.0) {
+        return pt;
+    }
+    Point diff(pt - ref);
+    double angle = -angle_between(diff, dir);
+    double k = round(angle * (double)n / (2.0*M_PI));
+    return ref + dir * Rotate(k * 2.0 * M_PI / (double)n) * L2(diff);
+}
+
 }  //Namespace Geom
 
 /*