Revert "refactor(linear): split point snapping helpers"
This reverts commit 702e029755.
This commit is contained in:
@@ -1884,150 +1884,6 @@ export class LinearElementEditor {
|
|||||||
: app.getEffectiveGridSize();
|
: app.getEffectiveGridSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static _getSnappedScenePointForLinearElement({
|
|
||||||
app,
|
|
||||||
event,
|
|
||||||
elementsMap,
|
|
||||||
element,
|
|
||||||
pointIndex,
|
|
||||||
scenePoint,
|
|
||||||
selectedPointsIndices,
|
|
||||||
}: {
|
|
||||||
app: AppClassProperties;
|
|
||||||
event: PointerEvent | React.PointerEvent<HTMLCanvasElement>;
|
|
||||||
elementsMap: ElementsMap;
|
|
||||||
element: NonDeleted<ExcalidrawLinearElement>;
|
|
||||||
pointIndex: number;
|
|
||||||
scenePoint: GlobalPoint;
|
|
||||||
selectedPointsIndices?: readonly number[];
|
|
||||||
}): {
|
|
||||||
point: GlobalPoint;
|
|
||||||
snapLines: SnapLine[];
|
|
||||||
} {
|
|
||||||
const { snapOffset, snapLines } = snapLinearElementPoint(
|
|
||||||
app.scene.getNonDeletedElements(),
|
|
||||||
element,
|
|
||||||
pointIndex,
|
|
||||||
scenePoint,
|
|
||||||
app,
|
|
||||||
event,
|
|
||||||
elementsMap,
|
|
||||||
{
|
|
||||||
includeSelfPoints: true,
|
|
||||||
selectedPointsIndices,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
|
||||||
point: pointFrom<GlobalPoint>(
|
|
||||||
scenePoint[0] + snapOffset.x,
|
|
||||||
scenePoint[1] + snapOffset.y,
|
|
||||||
),
|
|
||||||
snapLines,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private static _getShiftLockedPointForLinearElement({
|
|
||||||
app,
|
|
||||||
event,
|
|
||||||
elementsMap,
|
|
||||||
element,
|
|
||||||
pointIndex,
|
|
||||||
scenePointerX,
|
|
||||||
scenePointerY,
|
|
||||||
gridSize,
|
|
||||||
referencePoint,
|
|
||||||
selectedPointsIndices,
|
|
||||||
customLineAngle,
|
|
||||||
}: {
|
|
||||||
app: AppClassProperties;
|
|
||||||
event: PointerEvent | React.PointerEvent<HTMLCanvasElement>;
|
|
||||||
elementsMap: ElementsMap;
|
|
||||||
element: NonDeleted<ExcalidrawLinearElement>;
|
|
||||||
pointIndex: number;
|
|
||||||
scenePointerX: number;
|
|
||||||
scenePointerY: number;
|
|
||||||
gridSize: NullableGridSize;
|
|
||||||
referencePoint: LocalPoint;
|
|
||||||
selectedPointsIndices?: readonly number[];
|
|
||||||
customLineAngle?: number | null;
|
|
||||||
}): {
|
|
||||||
point: LocalPoint;
|
|
||||||
snapLines: SnapLine[];
|
|
||||||
} {
|
|
||||||
const referencePointCoords = LinearElementEditor.getPointGlobalCoordinates(
|
|
||||||
element,
|
|
||||||
referencePoint,
|
|
||||||
elementsMap,
|
|
||||||
);
|
|
||||||
const [gridX, gridY] = getGridPoint(scenePointerX, scenePointerY, gridSize);
|
|
||||||
|
|
||||||
let { width: dxFromReference, height: dyFromReference } =
|
|
||||||
getLockedLinearCursorAlignSize(
|
|
||||||
referencePointCoords[0],
|
|
||||||
referencePointCoords[1],
|
|
||||||
gridX,
|
|
||||||
gridY,
|
|
||||||
customLineAngle ?? undefined,
|
|
||||||
);
|
|
||||||
|
|
||||||
const lockedScenePoint = pointFrom<GlobalPoint>(
|
|
||||||
referencePointCoords[0] + dxFromReference,
|
|
||||||
referencePointCoords[1] + dyFromReference,
|
|
||||||
);
|
|
||||||
let snapLines: SnapLine[] = [];
|
|
||||||
|
|
||||||
if (!isElbowArrow(element)) {
|
|
||||||
const snappedScenePoint =
|
|
||||||
LinearElementEditor._getSnappedScenePointForLinearElement({
|
|
||||||
app,
|
|
||||||
event,
|
|
||||||
elementsMap,
|
|
||||||
element,
|
|
||||||
pointIndex,
|
|
||||||
scenePoint: lockedScenePoint,
|
|
||||||
selectedPointsIndices,
|
|
||||||
});
|
|
||||||
|
|
||||||
snapLines = snappedScenePoint.snapLines;
|
|
||||||
|
|
||||||
if (snapLines.length > 0) {
|
|
||||||
const result = snapToDiscreteAngle(
|
|
||||||
snapLines,
|
|
||||||
line(
|
|
||||||
lockedScenePoint,
|
|
||||||
pointFrom(referencePointCoords[0], referencePointCoords[1]),
|
|
||||||
),
|
|
||||||
pointFrom(gridX, gridY),
|
|
||||||
referencePointCoords,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (result.snapLines.length > 0) {
|
|
||||||
dxFromReference = result.dxFromReference;
|
|
||||||
dyFromReference = result.dyFromReference;
|
|
||||||
snapLines = result.snapLines;
|
|
||||||
} else {
|
|
||||||
dxFromReference = snappedScenePoint.point[0] - referencePointCoords[0];
|
|
||||||
dyFromReference = snappedScenePoint.point[1] - referencePointCoords[1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const [rotatedX, rotatedY] = pointRotateRads(
|
|
||||||
pointFrom(dxFromReference, dyFromReference),
|
|
||||||
pointFrom(0, 0),
|
|
||||||
-element.angle as Radians,
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
|
||||||
point: pointFrom(
|
|
||||||
referencePoint[0] + rotatedX,
|
|
||||||
referencePoint[1] + rotatedY,
|
|
||||||
),
|
|
||||||
snapLines,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private static _getSnappedPointForLinearElement({
|
private static _getSnappedPointForLinearElement({
|
||||||
app,
|
app,
|
||||||
event,
|
event,
|
||||||
@@ -2063,42 +1919,101 @@ export class LinearElementEditor {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (referencePoint) {
|
if (referencePoint) {
|
||||||
return LinearElementEditor._getShiftLockedPointForLinearElement({
|
const referencePointCoords = LinearElementEditor.getPointGlobalCoordinates(
|
||||||
app,
|
|
||||||
event,
|
|
||||||
elementsMap,
|
|
||||||
element,
|
element,
|
||||||
pointIndex,
|
|
||||||
scenePointerX,
|
|
||||||
scenePointerY,
|
|
||||||
gridSize,
|
|
||||||
referencePoint,
|
referencePoint,
|
||||||
selectedPointsIndices,
|
elementsMap,
|
||||||
customLineAngle,
|
);
|
||||||
});
|
const [gridX, gridY] = getGridPoint(scenePointerX, scenePointerY, gridSize);
|
||||||
|
|
||||||
|
let { width: dxFromReference, height: dyFromReference } =
|
||||||
|
getLockedLinearCursorAlignSize(
|
||||||
|
referencePointCoords[0],
|
||||||
|
referencePointCoords[1],
|
||||||
|
gridX,
|
||||||
|
gridY,
|
||||||
|
customLineAngle ?? undefined,
|
||||||
|
);
|
||||||
|
|
||||||
|
const effectiveGridX = referencePointCoords[0] + dxFromReference;
|
||||||
|
const effectiveGridY = referencePointCoords[1] + dyFromReference;
|
||||||
|
|
||||||
|
let snapLines: SnapLine[] = [];
|
||||||
|
|
||||||
|
if (!isElbowArrow(element)) {
|
||||||
|
const { snapOffset, snapLines: nextSnapLines } = snapLinearElementPoint(
|
||||||
|
app.scene.getNonDeletedElements(),
|
||||||
|
element,
|
||||||
|
pointIndex,
|
||||||
|
pointFrom<GlobalPoint>(effectiveGridX, effectiveGridY),
|
||||||
|
app,
|
||||||
|
event,
|
||||||
|
elementsMap,
|
||||||
|
{
|
||||||
|
includeSelfPoints: true,
|
||||||
|
selectedPointsIndices,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
snapLines = nextSnapLines;
|
||||||
|
|
||||||
|
if (nextSnapLines.length > 0) {
|
||||||
|
const result = snapToDiscreteAngle(
|
||||||
|
nextSnapLines,
|
||||||
|
line(
|
||||||
|
pointFrom(effectiveGridX, effectiveGridY),
|
||||||
|
pointFrom(referencePointCoords[0], referencePointCoords[1]),
|
||||||
|
),
|
||||||
|
pointFrom(gridX, gridY),
|
||||||
|
referencePointCoords,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result.snapLines.length > 0) {
|
||||||
|
dxFromReference = result.dxFromReference;
|
||||||
|
dyFromReference = result.dyFromReference;
|
||||||
|
snapLines = result.snapLines;
|
||||||
|
} else {
|
||||||
|
dxFromReference = effectiveGridX + snapOffset.x - referencePointCoords[0];
|
||||||
|
dyFromReference = effectiveGridY + snapOffset.y - referencePointCoords[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const [rotatedX, rotatedY] = pointRotateRads(
|
||||||
|
pointFrom(dxFromReference, dyFromReference),
|
||||||
|
pointFrom(0, 0),
|
||||||
|
-element.angle as Radians,
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
point: pointFrom(referencePoint[0] + rotatedX, referencePoint[1] + rotatedY),
|
||||||
|
snapLines,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const originalPointerPoint = pointFrom<GlobalPoint>(
|
const originalPointerX = scenePointerX - pointerOffset.x;
|
||||||
scenePointerX - pointerOffset.x,
|
const originalPointerY = scenePointerY - pointerOffset.y;
|
||||||
scenePointerY - pointerOffset.y,
|
|
||||||
);
|
const { snapOffset, snapLines } = snapLinearElementPoint(
|
||||||
const { point: scenePoint, snapLines } =
|
app.scene.getNonDeletedElements(),
|
||||||
LinearElementEditor._getSnappedScenePointForLinearElement({
|
element,
|
||||||
app,
|
pointIndex,
|
||||||
event,
|
pointFrom(originalPointerX, originalPointerY),
|
||||||
elementsMap,
|
app,
|
||||||
element,
|
event,
|
||||||
pointIndex,
|
elementsMap,
|
||||||
scenePoint: originalPointerPoint,
|
{
|
||||||
|
includeSelfPoints: true,
|
||||||
selectedPointsIndices,
|
selectedPointsIndices,
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
point: LinearElementEditor.createPointAt(
|
point: LinearElementEditor.createPointAt(
|
||||||
element,
|
element,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
scenePoint[0],
|
originalPointerX + snapOffset.x,
|
||||||
scenePoint[1],
|
originalPointerY + snapOffset.y,
|
||||||
gridSize,
|
gridSize,
|
||||||
),
|
),
|
||||||
snapLines,
|
snapLines,
|
||||||
|
|||||||
Reference in New Issue
Block a user