summaryrefslogtreecommitdiff
path: root/test/when/raphael-utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/when/raphael-utils.js')
-rw-r--r--test/when/raphael-utils.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/when/raphael-utils.js b/test/when/raphael-utils.js
new file mode 100644
index 0000000..626713e
--- /dev/null
+++ b/test/when/raphael-utils.js
@@ -0,0 +1,33 @@
+Raphael.fn.drawGrid = function (x, y, w, h, wv, hv, color) {
+ color = color || "#000";
+ var path = ["M", Math.round(x) + .5, Math.round(y) + .5, "L", Math.round(x + w) + .5, Math.round(y) + .5, Math.round(x + w) + .5, Math.round(y + h) + .5, Math.round(x) + .5, Math.round(y + h) + .5, Math.round(x) + .5, Math.round(y) + .5],
+ rowHeight = h / hv,
+ columnWidth = w / wv;
+ for (var i = 1; i < hv; i++) {
+ path = path.concat(["M", Math.round(x) + .5, Math.round(y + i * rowHeight) + .5, "H", Math.round(x + w) + .5]);
+ }
+ for (i = 1; i < wv; i++) {
+ path = path.concat(["M", Math.round(x + i * columnWidth) + .5, Math.round(y) + .5, "V", Math.round(y + h) + .5]);
+ }
+ return this.path(path.join(",")).attr({stroke: color});
+};
+
+function getAnchors(p1x, p1y, p2x, p2y, p3x, p3y) {
+ var l1 = (p2x - p1x) / 2,
+ l2 = (p3x - p2x) / 2,
+ a = Math.atan((p2x - p1x) / Math.abs(p2y - p1y)),
+ b = Math.atan((p3x - p2x) / Math.abs(p2y - p3y));
+ a = p1y < p2y ? Math.PI - a : a;
+ b = p3y < p2y ? Math.PI - b : b;
+ var alpha = Math.PI / 2 - ((a + b) % (Math.PI * 2)) / 2,
+ dx1 = l1 * Math.sin(alpha + a),
+ dy1 = l1 * Math.cos(alpha + a),
+ dx2 = l2 * Math.sin(alpha + b),
+ dy2 = l2 * Math.cos(alpha + b);
+ return {
+ x1: p2x - dx1,
+ y1: p2y + dy1,
+ x2: p2x + dx2,
+ y2: p2y + dy2
+ };
+} \ No newline at end of file