summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 44207fb)
raw | patch | inline | side by side (parent: 44207fb)
author | buliabyak <buliabyak@users.sourceforge.net> | |
Tue, 16 Oct 2007 05:09:08 +0000 (05:09 +0000) | ||
committer | buliabyak <buliabyak@users.sourceforge.net> | |
Tue, 16 Oct 2007 05:09:08 +0000 (05:09 +0000) |
src/libnr/nr-point-fns.cpp | patch | blob | history | |
src/libnr/nr-point-fns.h | patch | blob | history |
index a92c2b00bc3187d82decc90f3d918596cacf0549..a18e878b40e24edd27f2bb5bd9e8e88beaedd248 100644 (file)
return ret;
}
+NR::Point *
+get_snap_vector (NR::Point p, NR::Point o, double snap, double initial)
+{
+ double r = NR::L2 (p - o);
+ if (r < 1e-3)
+ return NULL;
+ double angle = NR::atan2 (p - o);
+ // snap angle to snaps increments, starting from initial:
+ double a_snapped = initial + floor((angle - initial)/snap + 0.5) * snap;
+ // calculate the new position and subtract p to get the vector:
+ return new NR::Point (o + r * NR::Point(cos(a_snapped), sin(a_snapped)) - p);
+}
+
+NR::Point
+snap_vector_midpoint (NR::Point p, NR::Point begin, NR::Point end, double snap)
+{
+ double length = NR::L2(end - begin);
+ NR::Point be = (end - begin) / length;
+ double r = NR::dot(p - begin, be);
+
+ if (r < 0.0) return begin;
+ if (r > length) return end;
+
+ double snapdist = length * snap;
+ double r_snapped = (snap==0) ? r : floor(r/(snapdist + 0.5)) * snapdist;
+
+ return (begin + r_snapped * be);
+}
+
+double
+get_offset_between_points (NR::Point p, NR::Point begin, NR::Point end)
+{
+ double length = NR::L2(end - begin);
+ NR::Point be = (end - begin) / length;
+ double r = NR::dot(p - begin, be);
+
+ if (r < 0.0) return 0.0;
+ if (r > length) return 1.0;
+
+ return (r / length);
+}
+
/*
Local Variables:
index 9f9a8f9e2eb98bc54b5f443a9c0803f827c3019f..a8c38466fb2bf3779f40a697e18081150a5f7292 100644 (file)
--- a/src/libnr/nr-point-fns.h
+++ b/src/libnr/nr-point-fns.h
} /* namespace NR */
+NR::Point *get_snap_vector (NR::Point p, NR::Point o, double snap, double initial);
+
+NR::Point snap_vector_midpoint (NR::Point p, NR::Point begin, NR::Point end, double snap);
+
+double get_offset_between_points (NR::Point p, NR::Point begin, NR::Point end);
+
#endif /* !__NR_POINT_OPS_H__ */
/*