summaryrefslogtreecommitdiffstats
path: root/src/2geom
diff options
context:
space:
mode:
authorMaximilian Albert <maximilian.albert@gmail.com>2009-01-26 14:41:05 +0000
committercilix42 <cilix42@users.sourceforge.net>2009-01-26 14:41:05 +0000
commit87f6a22451870cf5993212d1e90327280b2e14ae (patch)
tree25cea0126b6df96208c4d6301f971630cd2f48a0 /src/2geom
parentremoving a g_warning (diff)
downloadinkscape-87f6a22451870cf5993212d1e90327280b2e14ae.tar.gz
inkscape-87f6a22451870cf5993212d1e90327280b2e14ae.zip
display guide anchor on canvas; anchor and angle can be edited by mouse
(bzr r7180)
Diffstat (limited to 'src/2geom')
-rw-r--r--src/2geom/point.cpp14
-rw-r--r--src/2geom/point.h3
2 files changed, 16 insertions, 1 deletions
diff --git a/src/2geom/point.cpp b/src/2geom/point.cpp
index 5dd7b52f2..b8a858f8d 100644
--- a/src/2geom/point.cpp
+++ b/src/2geom/point.cpp
@@ -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
/*
diff --git a/src/2geom/point.h b/src/2geom/point.h
index d89b53f83..39538c832 100644
--- a/src/2geom/point.h
+++ b/src/2geom/point.h
@@ -229,6 +229,9 @@ Point operator*(Point const &v, Matrix const &m);
Point operator/(Point const &p, Matrix const &m);
+/** Constrains the angle between a and b to a multiple of pi/n with respect to dir. */
+Point constrain_angle(Point const &ref, Point const &pt, unsigned int n = 4, Geom::Point const &dir = Geom::Point(1,0));
+
} /* namespace Geom */
#endif /* !SEEN_Geom_POINT_H */