fixed slop calculation bug with dashed line logic

This commit is contained in:
Eric Rowell 2012-05-13 16:00:18 -07:00
parent c6040ebf9d
commit 5045c3fbc4
3 changed files with 21 additions and 13 deletions

16
dist/kinetic-core.js vendored
View File

@ -3795,7 +3795,7 @@ Kinetic.Line.prototype = {
* of Numbers. e.g. [{x:1,y:2},{x:3,y:4}] == [1,2,3,4]
*/
setPoints: function(points) {
var c = {};
var c = {};
c.points = points;
this.setAttrs(c);
},
@ -3845,8 +3845,9 @@ Kinetic.Line.prototype = {
var dashCount = dashArray.length;
var dx = (x2 - x), dy = (y2 - y);
var xSlope = (Math.abs(dx) > Math.abs(dy));
var xSlope = dx > dy;
var slope = (xSlope) ? dy / dx : dx / dy;
var distRemaining = Math.sqrt(dx * dx + dy * dy);
var dashIndex = 0, draw = true;
while(distRemaining >= 0.1 && dashIndex < 10000) {
@ -3858,18 +3859,21 @@ Kinetic.Line.prototype = {
dashLength = distRemaining;
}
var step = Math.sqrt(dashLength * dashLength / (1 + slope * slope));
if(xSlope) {
x += step;
y += slope * step;
x += dx < 0 && dy < 0 ? step * -1 : step;
y += dx < 0 && dy < 0 ? slope * step * -1 : slope * step;
}
else {
x += slope * step;
y += step;
x += dx < 0 && dy < 0 ? slope * step * -1 : slope * step;
y += dx < 0 && dy < 0 ? step * -1 : step;
}
context[draw ? 'lineTo' : 'moveTo'](x, y);
distRemaining -= dashLength;
draw = !draw;
}
context.moveTo(x2, y2)
}
};

File diff suppressed because one or more lines are too long

View File

@ -56,7 +56,7 @@ Kinetic.Line.prototype = {
* of Numbers. e.g. [{x:1,y:2},{x:3,y:4}] == [1,2,3,4]
*/
setPoints: function(points) {
var c = {};
var c = {};
c.points = points;
this.setAttrs(c);
},
@ -106,8 +106,9 @@ Kinetic.Line.prototype = {
var dashCount = dashArray.length;
var dx = (x2 - x), dy = (y2 - y);
var xSlope = (Math.abs(dx) > Math.abs(dy));
var xSlope = dx > dy;
var slope = (xSlope) ? dy / dx : dx / dy;
var distRemaining = Math.sqrt(dx * dx + dy * dy);
var dashIndex = 0, draw = true;
while(distRemaining >= 0.1 && dashIndex < 10000) {
@ -119,18 +120,21 @@ Kinetic.Line.prototype = {
dashLength = distRemaining;
}
var step = Math.sqrt(dashLength * dashLength / (1 + slope * slope));
if(xSlope) {
x += step;
y += slope * step;
x += dx < 0 && dy < 0 ? step * -1 : step;
y += dx < 0 && dy < 0 ? slope * step * -1 : slope * step;
}
else {
x += slope * step;
y += step;
x += dx < 0 && dy < 0 ? slope * step * -1 : slope * step;
y += dx < 0 && dy < 0 ? step * -1 : step;
}
context[draw ? 'lineTo' : 'moveTo'](x, y);
distRemaining -= dashLength;
draw = !draw;
}
context.moveTo(x2, y2)
}
};