From 5b05a8a95c40a953bfd8621f9410bc9ba2de36d5 Mon Sep 17 00:00:00 2001 From: trafficlunar Date: Sat, 18 Jan 2025 22:45:34 +0000 Subject: [PATCH] feat: radius in selection tools --- src/components/canvas/Canvas.tsx | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/components/canvas/Canvas.tsx b/src/components/canvas/Canvas.tsx index 79c4c16..2f152d9 100644 --- a/src/components/canvas/Canvas.tsx +++ b/src/components/canvas/Canvas.tsx @@ -147,8 +147,20 @@ function Canvas() { } case "lasso": { setSelectionCoords((prev) => { - const exists = prev.some(([x2, y2]) => x2 === mouseCoords.x && y2 === mouseCoords.y); - return exists ? prev : [...prev, [mouseCoords.x, mouseCoords.y]]; + const radiusPosition = getRadiusPosition(); + const radiusCoords: CoordinateArray = []; + + for (let x = 0; x < radius; x++) { + for (let y = 0; y < radius; y++) { + const tileX = radiusPosition.x + x; + const tileY = radiusPosition.y + y; + + const exists = prev.some(([x2, y2]) => x2 === tileX && y2 === tileY); + if (!exists) radiusCoords.push([tileX, tileY]); + } + } + + return [...prev, ...radiusCoords]; }); break; } @@ -233,8 +245,10 @@ function Canvas() { const newSelection: CoordinateArray = []; // todo: fix dragging from bottom to top - for (let x = dragStartCoords.x; x < mouseCoords.x + 1; x++) { - for (let y = dragStartCoords.y; y < mouseCoords.y + 1; y++) { + const isEven = radius % 2 == 0; + + for (let x = dragStartCoords.x; x < mouseCoords.x + (isEven ? radius : radius - 1); x++) { + for (let y = dragStartCoords.y; y < mouseCoords.y + (isEven ? radius : radius - 1); y++) { newSelection.push([x, y]); } }