|
|
@ -939,42 +939,22 @@ Edge.prototype._getDistanceToEdge = function (x1,y1, x2,y2, x3,y3) { // x3,y3 is |
|
|
|
yVia = via.y; |
|
|
|
} |
|
|
|
var minDistance = 1e9; |
|
|
|
var i,t,x,y,dx,dy; |
|
|
|
var distance; |
|
|
|
var i,t,x,y, lastX, lastY; |
|
|
|
for (i = 0; i < 10; i++) { |
|
|
|
t = 0.1*i; |
|
|
|
x = Math.pow(1-t,2)*x1 + (2*t*(1 - t))*xVia + Math.pow(t,2)*x2; |
|
|
|
y = Math.pow(1-t,2)*y1 + (2*t*(1 - t))*yVia + Math.pow(t,2)*y2; |
|
|
|
dx = Math.abs(x3-x); |
|
|
|
dy = Math.abs(y3-y); |
|
|
|
minDistance = Math.min(minDistance,Math.sqrt(dx*dx + dy*dy)); |
|
|
|
if (i > 0) { |
|
|
|
distance = this._getDistanceToLine(lastX,lastY,x,y, x3,y3); |
|
|
|
minDistance = distance < minDistance ? distance : minDistance; |
|
|
|
} |
|
|
|
lastX = x; lastY = y; |
|
|
|
} |
|
|
|
return minDistance |
|
|
|
} |
|
|
|
else { |
|
|
|
var px = x2-x1, |
|
|
|
py = y2-y1, |
|
|
|
something = px*px + py*py, |
|
|
|
u = ((x3 - x1) * px + (y3 - y1) * py) / something; |
|
|
|
|
|
|
|
if (u > 1) { |
|
|
|
u = 1; |
|
|
|
} |
|
|
|
else if (u < 0) { |
|
|
|
u = 0; |
|
|
|
} |
|
|
|
|
|
|
|
var x = x1 + u * px, |
|
|
|
y = y1 + u * py, |
|
|
|
dx = x - x3, |
|
|
|
dy = y - y3; |
|
|
|
|
|
|
|
//# Note: If the actual distance does not matter,
|
|
|
|
//# if you only want to compare what this function
|
|
|
|
//# returns to other results of this function, you
|
|
|
|
//# can just return the squared distance instead
|
|
|
|
//# (i.e. remove the sqrt) to gain a little performance
|
|
|
|
|
|
|
|
return Math.sqrt(dx*dx + dy*dy); |
|
|
|
return this._getDistanceToLine(x1,y1,x2,y2,x3,y3); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
@ -998,7 +978,32 @@ Edge.prototype._getDistanceToEdge = function (x1,y1, x2,y2, x3,y3) { // x3,y3 is |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
Edge.prototype._getDistanceToLine = function(x1,y1,x2,y2,x3,y3) { |
|
|
|
var px = x2-x1, |
|
|
|
py = y2-y1, |
|
|
|
something = px*px + py*py, |
|
|
|
u = ((x3 - x1) * px + (y3 - y1) * py) / something; |
|
|
|
|
|
|
|
if (u > 1) { |
|
|
|
u = 1; |
|
|
|
} |
|
|
|
else if (u < 0) { |
|
|
|
u = 0; |
|
|
|
} |
|
|
|
|
|
|
|
var x = x1 + u * px, |
|
|
|
y = y1 + u * py, |
|
|
|
dx = x - x3, |
|
|
|
dy = y - y3; |
|
|
|
|
|
|
|
//# Note: If the actual distance does not matter,
|
|
|
|
//# if you only want to compare what this function
|
|
|
|
//# returns to other results of this function, you
|
|
|
|
//# can just return the squared distance instead
|
|
|
|
//# (i.e. remove the sqrt) to gain a little performance
|
|
|
|
|
|
|
|
return Math.sqrt(dx*dx + dy*dy); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* This allows the zoom level of the network to influence the rendering |
|
|
|