Skip to content

Commit

Permalink
perf: 优化辅助线绘制 (ikuaitu#386)
Browse files Browse the repository at this point in the history
  • Loading branch information
wuchenguang1998 authored May 16, 2024
1 parent a07eceb commit 95129be
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/core/plugin/AlignGuidLinePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,8 @@ class AlignGuidLinePlugin {
function drawLine(x1: number, y1: number, x2: number, y2: number) {
if (viewportTransform == null) return;

ctx.save();
ctx.lineWidth = This.defautOption.width;
ctx.strokeStyle = This.defautOption.color;
ctx.beginPath();
ctx.moveTo(x1 * zoom + viewportTransform[4], y1 * zoom + viewportTransform[5]);
ctx.lineTo(x2 * zoom + viewportTransform[4], y2 * zoom + viewportTransform[5]);
ctx.stroke();
ctx.restore();
}

function isInRange(value1: number, value2: number) {
Expand Down Expand Up @@ -294,12 +288,18 @@ class AlignGuidLinePlugin {
});

canvas.on('after:render', () => {
ctx.save();
ctx.beginPath();
ctx.lineWidth = This.defautOption.width;
ctx.strokeStyle = This.defautOption.color;
for (let i = verticalLines.length; i--; ) {
drawVerticalLine(verticalLines[i]);
}
for (let j = horizontalLines.length; j--; ) {
drawHorizontalLine(horizontalLines[j]);
}
ctx.stroke();
ctx.restore();

// noinspection NestedAssignmentJS
verticalLines.length = 0;
Expand Down

0 comments on commit 95129be

Please sign in to comment.