Playing with precision in path intersection.

master
Dmitry Baranovskiy 2014-05-23 21:36:04 +10:00
parent fb9c60849c
commit ddcb2a3430
3 changed files with 33 additions and 34 deletions

File diff suppressed because one or more lines are too long

53
dist/snap.svg.js vendored
View File

@ -5233,8 +5233,8 @@ Snap.plugin(function (Snap, Element, Paper, glob) {
} }
var l1 = bezlen.apply(0, bez1), var l1 = bezlen.apply(0, bez1),
l2 = bezlen.apply(0, bez2), l2 = bezlen.apply(0, bez2),
n1 = ~~(l1 / 15), n1 = ~~(l1 / 8),
n2 = ~~(l2 / 15), n2 = ~~(l2 / 8),
dots1 = [], dots1 = [],
dots2 = [], dots2 = [],
xy = {}, xy = {},
@ -5253,8 +5253,8 @@ Snap.plugin(function (Snap, Element, Paper, glob) {
di1 = dots1[i + 1], di1 = dots1[i + 1],
dj = dots2[j], dj = dots2[j],
dj1 = dots2[j + 1], dj1 = dots2[j + 1],
ci = abs(di1.x - di.x) < .0001 ? "y" : "x", ci = abs(di1.x - di.x) < .001 ? "y" : "x",
cj = abs(dj1.x - dj.x) < .0001 ? "y" : "x", cj = abs(dj1.x - dj.x) < .001 ? "y" : "x",
is = intersect(di.x, di.y, di1.x, di1.y, dj.x, dj.y, dj1.x, dj1.y); is = intersect(di.x, di.y, di1.x, di1.y, dj.x, dj.y, dj1.x, dj1.y);
if (is) { if (is) {
if (xy[is.x.toFixed(4)] == is.y.toFixed(4)) { if (xy[is.x.toFixed(4)] == is.y.toFixed(4)) {
@ -6340,7 +6340,6 @@ Snap.plugin(function (Snap, Element, Paper, glob) {
Snap.path.toString = toString; Snap.path.toString = toString;
Snap.path.clone = pathClone; Snap.path.clone = pathClone;
}); });
// Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved. // Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
@ -6854,9 +6853,10 @@ Snap.plugin(function (Snap, Element, Paper, glob) {
mousemove: "touchmove", mousemove: "touchmove",
mouseup: "touchend" mouseup: "touchend"
}, },
getScroll = function (xy) { getScroll = function (xy, el) {
var name = xy == "y" ? "scrollTop" : "scrollLeft"; var name = xy == "y" ? "scrollTop" : "scrollLeft",
return glob.doc.documentElement[name] || glob.doc.body[name]; doc = el.node.ownerDocument;
return doc[name in doc.documentElement ? "documentElement" : "body"][name];
}, },
preventDefault = function () { preventDefault = function () {
this.returnValue = false; this.returnValue = false;
@ -6874,35 +6874,35 @@ Snap.plugin(function (Snap, Element, Paper, glob) {
if (glob.doc.addEventListener) { if (glob.doc.addEventListener) {
return function (obj, type, fn, element) { return function (obj, type, fn, element) {
var realName = supportsTouch && touchMap[type] ? touchMap[type] : type, var realName = supportsTouch && touchMap[type] ? touchMap[type] : type,
f = function (e) { f = function (e) {
var scrollY = getScroll("y"), var scrollY = getScroll("y", element),
scrollX = getScroll("x"); scrollX = getScroll("x", element);
if (supportsTouch && touchMap[has](type)) { if (supportsTouch && touchMap[has](type)) {
for (var i = 0, ii = e.targetTouches && e.targetTouches.length; i < ii; i++) { for (var i = 0, ii = e.targetTouches && e.targetTouches.length; i < ii; i++) {
if (e.targetTouches[i].target == obj || obj.contains(e.targetTouches[i].target)) { if (e.targetTouches[i].target == obj || obj.contains(e.targetTouches[i].target)) {
var olde = e; var olde = e;
e = e.targetTouches[i]; e = e.targetTouches[i];
e.originalEvent = olde; e.originalEvent = olde;
e.preventDefault = preventTouch; e.preventDefault = preventTouch;
e.stopPropagation = stopTouch; e.stopPropagation = stopTouch;
break; break;
} }
} }
} }
var x = e.clientX + scrollX, var x = e.clientX + scrollX,
y = e.clientY + scrollY; y = e.clientY + scrollY;
return fn.call(element, e, x, y); return fn.call(element, e, x, y);
}; };
if (type !== realName) { if (type !== realName) {
obj.addEventListener(type, f, false); obj.addEventListener(type, f, false);
} }
obj.addEventListener(realName, f, false); obj.addEventListener(realName, f, false);
return function () { return function () {
if (type !== realName) { if (type !== realName) {
obj.removeEventListener(type, f, false); obj.removeEventListener(type, f, false);
} }
obj.removeEventListener(realName, f, false); obj.removeEventListener(realName, f, false);
@ -6912,9 +6912,9 @@ Snap.plugin(function (Snap, Element, Paper, glob) {
} else if (glob.doc.attachEvent) { } else if (glob.doc.attachEvent) {
return function (obj, type, fn, element) { return function (obj, type, fn, element) {
var f = function (e) { var f = function (e) {
e = e || glob.win.event; e = e || element.node.ownerDocument.window.event;
var scrollY = getScroll("y"), var scrollY = getScroll("y", element),
scrollX = getScroll("x"), scrollX = getScroll("x", element),
x = e.clientX + scrollX, x = e.clientX + scrollX,
y = e.clientY + scrollY; y = e.clientY + scrollY;
e.preventDefault = e.preventDefault || preventDefault; e.preventDefault = e.preventDefault || preventDefault;
@ -6957,7 +6957,6 @@ Snap.plugin(function (Snap, Element, Paper, glob) {
} }
var node = dragi.el.node, var node = dragi.el.node,
o, o,
glob = Snap._.glob,
next = node.nextSibling, next = node.nextSibling,
parent = node.parentNode, parent = node.parentNode,
display = node.style.display; display = node.style.display;
@ -7177,7 +7176,7 @@ Snap.plugin(function (Snap, Element, Paper, glob) {
this.events.push({ this.events.push({
name: eventName, name: eventName,
f: fn, f: fn,
unbind: addEvent(this.shape || this.node || glob.doc, eventName, fn, scope || this) unbind: addEvent(this.shape || this.node || this.node.ownerDocument, eventName, fn, scope || this)
}); });
} }
return this; return this;

View File

@ -300,8 +300,8 @@ Snap.plugin(function (Snap, Element, Paper, glob) {
} }
var l1 = bezlen.apply(0, bez1), var l1 = bezlen.apply(0, bez1),
l2 = bezlen.apply(0, bez2), l2 = bezlen.apply(0, bez2),
n1 = ~~(l1 / 15), n1 = ~~(l1 / 8),
n2 = ~~(l2 / 15), n2 = ~~(l2 / 8),
dots1 = [], dots1 = [],
dots2 = [], dots2 = [],
xy = {}, xy = {},
@ -320,8 +320,8 @@ Snap.plugin(function (Snap, Element, Paper, glob) {
di1 = dots1[i + 1], di1 = dots1[i + 1],
dj = dots2[j], dj = dots2[j],
dj1 = dots2[j + 1], dj1 = dots2[j + 1],
ci = abs(di1.x - di.x) < .0001 ? "y" : "x", ci = abs(di1.x - di.x) < .001 ? "y" : "x",
cj = abs(dj1.x - dj.x) < .0001 ? "y" : "x", cj = abs(dj1.x - dj.x) < .001 ? "y" : "x",
is = intersect(di.x, di.y, di1.x, di1.y, dj.x, dj.y, dj1.x, dj1.y); is = intersect(di.x, di.y, di1.x, di1.y, dj.x, dj.y, dj1.x, dj1.y);
if (is) { if (is) {
if (xy[is.x.toFixed(4)] == is.y.toFixed(4)) { if (xy[is.x.toFixed(4)] == is.y.toFixed(4)) {
@ -1406,4 +1406,4 @@ Snap.plugin(function (Snap, Element, Paper, glob) {
Snap.path.map = mapPath; Snap.path.map = mapPath;
Snap.path.toString = toString; Snap.path.toString = toString;
Snap.path.clone = pathClone; Snap.path.clone = pathClone;
}); });