fix: rectangle select negative dragging for x and y

This commit is contained in:
trafficlunar 2025-01-18 22:50:47 +00:00
parent 5b05a8a95c
commit 89d8a93964

View file

@ -244,11 +244,15 @@ function Canvas() {
setSelectionCoords(() => { setSelectionCoords(() => {
const newSelection: CoordinateArray = []; const newSelection: CoordinateArray = [];
// todo: fix dragging from bottom to top const startX = Math.min(dragStartCoords.x, mouseCoords.x);
const isEven = radius % 2 == 0; const endX = Math.max(dragStartCoords.x, mouseCoords.x);
const startY = Math.min(dragStartCoords.y, mouseCoords.y);
const endY = Math.max(dragStartCoords.y, mouseCoords.y);
for (let x = dragStartCoords.x; x < mouseCoords.x + (isEven ? radius : radius - 1); x++) { const isRadiusEven = radius % 2 == 0;
for (let y = dragStartCoords.y; y < mouseCoords.y + (isEven ? radius : radius - 1); y++) {
for (let x = startX; x < endX + (isRadiusEven ? radius : radius - 1); x++) {
for (let y = startY; y < endY + (isRadiusEven ? radius : radius - 1); y++) {
newSelection.push([x, y]); newSelection.push([x, y]);
} }
} }