Start grid point arrow align

This commit is contained in:
Mark Tolmacs 2025-03-07 13:03:19 +01:00
parent 40f25180ea
commit 5947af5b50
2 changed files with 148 additions and 117 deletions

View file

@ -238,14 +238,15 @@ export class LinearElementEditor {
});
}
static getOutlineAvoidingPointOrNull(
static getOutlineAvoidingPoint(
element: NonDeleted<ExcalidrawLinearElement>,
coords: { x: number; y: number },
coords: GlobalPoint,
pointIndex: number,
app: AppClassProperties,
) {
fallback?: GlobalPoint,
): GlobalPoint {
const hoveredElement = getHoveredElementForBinding(
coords,
{ x: coords[0], y: coords[1] },
app.scene.getNonDeletedElements(),
app.scene.getNonDeletedElementsMap(),
app.state.zoom,
@ -254,11 +255,10 @@ export class LinearElementEditor {
);
if (hoveredElement) {
const p = pointFrom<GlobalPoint>(coords.x, coords.y);
const newPoints = Array.from(element.points);
newPoints[pointIndex] = pointFrom<LocalPoint>(
p[0] - element.x,
p[1] - element.y,
coords[0] - element.x,
coords[1] - element.y,
);
return bindPointToSnapToElementOutline(
@ -272,27 +272,7 @@ export class LinearElementEditor {
);
}
return null;
}
static getOutlineAvoidingPoint(
element: NonDeleted<ExcalidrawLinearElement>,
coords: { x: number; y: number },
pointIndex: number,
app: AppClassProperties,
): GlobalPoint {
const p = LinearElementEditor.getOutlineAvoidingPointOrNull(
element,
coords,
pointIndex,
app,
);
if (p) {
return p;
}
return pointFrom<GlobalPoint>(coords.x, coords.y);
return fallback ?? coords;
}
/**
@ -411,10 +391,10 @@ export class LinearElementEditor {
globalNewPointPosition =
LinearElementEditor.getOutlineAvoidingPoint(
element,
{
x: element.x + element.points[pointIndex][0] + deltaX,
y: element.y + element.points[pointIndex][1] + deltaY,
},
pointFrom<GlobalPoint>(
element.x + element.points[pointIndex][0] + deltaX,
element.y + element.points[pointIndex][1] + deltaY,
),
pointIndex,
app,
);