Merge pull request from yueyuzhao/issue/504-dots-to-sharp-corner

add precise guess first when adding points to paths
This commit is contained in:
Deep Malhan 2022-04-08 08:50:11 -04:00 committed by GitHub
commit ff15b0f5f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -851,20 +851,30 @@ export default class Path {
}
static getHitIndex (ctx, commands, pt) {
ctx.save();
ctx.beginPath();
for (var i = 0; i < commands.length; i++) {
SVG2Canvas.drawCommand(ctx, commands[i]);
ctx.stroke();
pt = Vector.floor(pt);
var pixel = ctx.getImageData(pt.x, pt.y, 1, 1).data;
if (pixel[3] != 0) {
return i;
var drawWithLineMask = function (lineWidth) {
ctx.save();
ctx.lineWidth = lineWidth;
ctx.beginPath();
for (var i = 0; i < commands.length; i++) {
SVG2Canvas.drawCommand(ctx, commands[i]);
ctx.stroke();
pt = Vector.floor(pt);
var pixel = ctx.getImageData(pt.x, pt.y, 1, 1).data;
if (pixel[3] != 0) {
return i;
}
}
ctx.stroke();
ctx.restore();
};
// When using a mouse to add dragging points to paths,
// we need to try a precise guess first.
// For more detail see #504
var index = drawWithLineMask(2);
if (index > -1) {
return index;
}
ctx.stroke();
ctx.restore();
return -1;
return drawWithLineMask(Ghost.linemask);
}
static getHitPointIndex (list, pt) {