updated distanceLine and fix drag bug

This commit is contained in:
Nalvazhuthi
2025-03-31 18:22:40 +05:30
parent 7c85d2041e
commit 9611ad69cf
7 changed files with 535 additions and 151 deletions

View File

@@ -8,11 +8,9 @@ export function determinePosition(
right: number | "auto";
bottom: number | "auto";
} {
// Calculate the midpoints of the canvas
const centerX = canvasRect.width / 2;
const centerY = canvasRect.height / 2;
// Initialize position with default values
let position: {
top: number | "auto";
left: number | "auto";
@@ -21,9 +19,8 @@ export function determinePosition(
};
if (relativeY < centerY) {
// Top half
if (relativeX < centerX) {
// Left side
console.log("Top-left");
position = {
top: relativeY,
left: relativeX,
@@ -31,7 +28,7 @@ export function determinePosition(
bottom: "auto",
};
} else {
// Right side
console.log("Top-right");
position = {
top: relativeY,
right: canvasRect.width - relativeX,
@@ -40,9 +37,8 @@ export function determinePosition(
};
}
} else {
// Bottom half
if (relativeX < centerX) {
// Left side
console.log("Bottom-left");
position = {
bottom: canvasRect.height - relativeY,
left: relativeX,
@@ -50,7 +46,7 @@ export function determinePosition(
top: "auto",
};
} else {
// Right side
console.log("Bottom-right");
position = {
bottom: canvasRect.height - relativeY,
right: canvasRect.width - relativeX,
@@ -61,4 +57,4 @@ export function determinePosition(
}
return position;
}
}