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) { static getHitIndex (ctx, commands, pt) {
ctx.save(); var drawWithLineMask = function (lineWidth) {
ctx.beginPath(); ctx.save();
for (var i = 0; i < commands.length; i++) { ctx.lineWidth = lineWidth;
SVG2Canvas.drawCommand(ctx, commands[i]); ctx.beginPath();
ctx.stroke(); for (var i = 0; i < commands.length; i++) {
pt = Vector.floor(pt); SVG2Canvas.drawCommand(ctx, commands[i]);
var pixel = ctx.getImageData(pt.x, pt.y, 1, 1).data; ctx.stroke();
if (pixel[3] != 0) { pt = Vector.floor(pt);
return i; 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(); return drawWithLineMask(Ghost.linemask);
ctx.restore();
return -1;
} }
static getHitPointIndex (list, pt) { static getHitPointIndex (list, pt) {