mirror of
https://github.com/konvajs/konva.git
synced 2025-04-29 01:55:54 +08:00
fixed slop calculation bug with dashed line logic
This commit is contained in:
parent
c6040ebf9d
commit
5045c3fbc4
16
dist/kinetic-core.js
vendored
16
dist/kinetic-core.js
vendored
@ -3795,7 +3795,7 @@ Kinetic.Line.prototype = {
|
|||||||
* of Numbers. e.g. [{x:1,y:2},{x:3,y:4}] == [1,2,3,4]
|
* of Numbers. e.g. [{x:1,y:2},{x:3,y:4}] == [1,2,3,4]
|
||||||
*/
|
*/
|
||||||
setPoints: function(points) {
|
setPoints: function(points) {
|
||||||
var c = {};
|
var c = {};
|
||||||
c.points = points;
|
c.points = points;
|
||||||
this.setAttrs(c);
|
this.setAttrs(c);
|
||||||
},
|
},
|
||||||
@ -3845,8 +3845,9 @@ Kinetic.Line.prototype = {
|
|||||||
var dashCount = dashArray.length;
|
var dashCount = dashArray.length;
|
||||||
|
|
||||||
var dx = (x2 - x), dy = (y2 - y);
|
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 slope = (xSlope) ? dy / dx : dx / dy;
|
||||||
|
|
||||||
var distRemaining = Math.sqrt(dx * dx + dy * dy);
|
var distRemaining = Math.sqrt(dx * dx + dy * dy);
|
||||||
var dashIndex = 0, draw = true;
|
var dashIndex = 0, draw = true;
|
||||||
while(distRemaining >= 0.1 && dashIndex < 10000) {
|
while(distRemaining >= 0.1 && dashIndex < 10000) {
|
||||||
@ -3858,18 +3859,21 @@ Kinetic.Line.prototype = {
|
|||||||
dashLength = distRemaining;
|
dashLength = distRemaining;
|
||||||
}
|
}
|
||||||
var step = Math.sqrt(dashLength * dashLength / (1 + slope * slope));
|
var step = Math.sqrt(dashLength * dashLength / (1 + slope * slope));
|
||||||
|
|
||||||
if(xSlope) {
|
if(xSlope) {
|
||||||
x += step;
|
x += dx < 0 && dy < 0 ? step * -1 : step;
|
||||||
y += slope * step;
|
y += dx < 0 && dy < 0 ? slope * step * -1 : slope * step;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
x += slope * step;
|
x += dx < 0 && dy < 0 ? slope * step * -1 : slope * step;
|
||||||
y += step;
|
y += dx < 0 && dy < 0 ? step * -1 : step;
|
||||||
}
|
}
|
||||||
context[draw ? 'lineTo' : 'moveTo'](x, y);
|
context[draw ? 'lineTo' : 'moveTo'](x, y);
|
||||||
distRemaining -= dashLength;
|
distRemaining -= dashLength;
|
||||||
draw = !draw;
|
draw = !draw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context.moveTo(x2, y2)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
2
dist/kinetic-core.min.js
vendored
2
dist/kinetic-core.min.js
vendored
File diff suppressed because one or more lines are too long
@ -56,7 +56,7 @@ Kinetic.Line.prototype = {
|
|||||||
* of Numbers. e.g. [{x:1,y:2},{x:3,y:4}] == [1,2,3,4]
|
* of Numbers. e.g. [{x:1,y:2},{x:3,y:4}] == [1,2,3,4]
|
||||||
*/
|
*/
|
||||||
setPoints: function(points) {
|
setPoints: function(points) {
|
||||||
var c = {};
|
var c = {};
|
||||||
c.points = points;
|
c.points = points;
|
||||||
this.setAttrs(c);
|
this.setAttrs(c);
|
||||||
},
|
},
|
||||||
@ -106,8 +106,9 @@ Kinetic.Line.prototype = {
|
|||||||
var dashCount = dashArray.length;
|
var dashCount = dashArray.length;
|
||||||
|
|
||||||
var dx = (x2 - x), dy = (y2 - y);
|
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 slope = (xSlope) ? dy / dx : dx / dy;
|
||||||
|
|
||||||
var distRemaining = Math.sqrt(dx * dx + dy * dy);
|
var distRemaining = Math.sqrt(dx * dx + dy * dy);
|
||||||
var dashIndex = 0, draw = true;
|
var dashIndex = 0, draw = true;
|
||||||
while(distRemaining >= 0.1 && dashIndex < 10000) {
|
while(distRemaining >= 0.1 && dashIndex < 10000) {
|
||||||
@ -119,18 +120,21 @@ Kinetic.Line.prototype = {
|
|||||||
dashLength = distRemaining;
|
dashLength = distRemaining;
|
||||||
}
|
}
|
||||||
var step = Math.sqrt(dashLength * dashLength / (1 + slope * slope));
|
var step = Math.sqrt(dashLength * dashLength / (1 + slope * slope));
|
||||||
|
|
||||||
if(xSlope) {
|
if(xSlope) {
|
||||||
x += step;
|
x += dx < 0 && dy < 0 ? step * -1 : step;
|
||||||
y += slope * step;
|
y += dx < 0 && dy < 0 ? slope * step * -1 : slope * step;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
x += slope * step;
|
x += dx < 0 && dy < 0 ? slope * step * -1 : slope * step;
|
||||||
y += step;
|
y += dx < 0 && dy < 0 ? step * -1 : step;
|
||||||
}
|
}
|
||||||
context[draw ? 'lineTo' : 'moveTo'](x, y);
|
context[draw ? 'lineTo' : 'moveTo'](x, y);
|
||||||
distRemaining -= dashLength;
|
distRemaining -= dashLength;
|
||||||
draw = !draw;
|
draw = !draw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context.moveTo(x2, y2)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user