fix(ui): brush spacing handling

This commit is contained in:
psychedelicious 2024-06-06 17:01:41 +10:00
parent c171fe2b96
commit bee3fa339d

View File

@ -1,9 +1,5 @@
import { calculateNewBrushSize } from 'features/canvas/hooks/useCanvasZoom'; import { calculateNewBrushSize } from 'features/canvas/hooks/useCanvasZoom';
import { import { getIsMouseDown, getScaledFlooredCursorPosition, snapPosToStage } from 'features/controlLayers/konva/util';
getIsMouseDown,
getScaledFlooredCursorPosition,
snapPosToStage,
} from 'features/controlLayers/konva/util';
import { import {
type AddBrushLineArg, type AddBrushLineArg,
type AddEraserLineArg, type AddEraserLineArg,
@ -74,9 +70,10 @@ const maybeAddNextPoint = (
if (lastAddedPoint) { if (lastAddedPoint) {
// Dispatching redux events impacts perf substantially - using brush spacing keeps dispatches to a reasonable number // Dispatching redux events impacts perf substantially - using brush spacing keeps dispatches to a reasonable number
if (Math.hypot(lastAddedPoint.x - currentPos.x, lastAddedPoint.y - currentPos.y) < $brushSpacingPx.get()) { if (Math.hypot(lastAddedPoint.x - currentPos.x, lastAddedPoint.y - currentPos.y) < $brushSpacingPx.get()) {
return null; return;
} }
} }
$lastAddedPoint.set(currentPos);
onPointAddedToLine({ layerId, point: [currentPos.x, currentPos.y] }); onPointAddedToLine({ layerId, point: [currentPos.x, currentPos.y] });
}; };