|
@@ -49,7 +49,7 @@ import type Scene from "../scene/Scene";
|
|
import type { Radians } from "../../math";
|
|
import type { Radians } from "../../math";
|
|
import {
|
|
import {
|
|
pointCenter,
|
|
pointCenter,
|
|
- point,
|
|
|
|
|
|
+ pointFrom,
|
|
pointRotateRads,
|
|
pointRotateRads,
|
|
pointsEqual,
|
|
pointsEqual,
|
|
vector,
|
|
vector,
|
|
@@ -108,7 +108,7 @@ export class LinearElementEditor {
|
|
this.elementId = element.id as string & {
|
|
this.elementId = element.id as string & {
|
|
_brand: "excalidrawLinearElementId";
|
|
_brand: "excalidrawLinearElementId";
|
|
};
|
|
};
|
|
- if (!pointsEqual(element.points[0], point(0, 0))) {
|
|
|
|
|
|
+ if (!pointsEqual(element.points[0], pointFrom(0, 0))) {
|
|
console.error("Linear element is not normalized", Error().stack);
|
|
console.error("Linear element is not normalized", Error().stack);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -287,7 +287,7 @@ export class LinearElementEditor {
|
|
element,
|
|
element,
|
|
elementsMap,
|
|
elementsMap,
|
|
referencePoint,
|
|
referencePoint,
|
|
- point(scenePointerX, scenePointerY),
|
|
|
|
|
|
+ pointFrom(scenePointerX, scenePointerY),
|
|
event[KEYS.CTRL_OR_CMD] ? null : app.getEffectiveGridSize(),
|
|
event[KEYS.CTRL_OR_CMD] ? null : app.getEffectiveGridSize(),
|
|
);
|
|
);
|
|
|
|
|
|
@@ -296,7 +296,7 @@ export class LinearElementEditor {
|
|
[
|
|
[
|
|
{
|
|
{
|
|
index: selectedIndex,
|
|
index: selectedIndex,
|
|
- point: point(
|
|
|
|
|
|
+ point: pointFrom(
|
|
width + referencePoint[0],
|
|
width + referencePoint[0],
|
|
height + referencePoint[1],
|
|
height + referencePoint[1],
|
|
),
|
|
),
|
|
@@ -329,7 +329,7 @@ export class LinearElementEditor {
|
|
scenePointerY - linearElementEditor.pointerOffset.y,
|
|
scenePointerY - linearElementEditor.pointerOffset.y,
|
|
event[KEYS.CTRL_OR_CMD] ? null : app.getEffectiveGridSize(),
|
|
event[KEYS.CTRL_OR_CMD] ? null : app.getEffectiveGridSize(),
|
|
)
|
|
)
|
|
- : point(
|
|
|
|
|
|
+ : pointFrom(
|
|
element.points[pointIndex][0] + deltaX,
|
|
element.points[pointIndex][0] + deltaX,
|
|
element.points[pointIndex][1] + deltaY,
|
|
element.points[pointIndex][1] + deltaY,
|
|
);
|
|
);
|
|
@@ -590,11 +590,11 @@ export class LinearElementEditor {
|
|
linearElementEditor.segmentMidPointHoveredCoords;
|
|
linearElementEditor.segmentMidPointHoveredCoords;
|
|
if (existingSegmentMidpointHitCoords) {
|
|
if (existingSegmentMidpointHitCoords) {
|
|
const distance = pointDistance(
|
|
const distance = pointDistance(
|
|
- point(
|
|
|
|
|
|
+ pointFrom(
|
|
existingSegmentMidpointHitCoords[0],
|
|
existingSegmentMidpointHitCoords[0],
|
|
existingSegmentMidpointHitCoords[1],
|
|
existingSegmentMidpointHitCoords[1],
|
|
),
|
|
),
|
|
- point(scenePointer.x, scenePointer.y),
|
|
|
|
|
|
+ pointFrom(scenePointer.x, scenePointer.y),
|
|
);
|
|
);
|
|
if (distance <= threshold) {
|
|
if (distance <= threshold) {
|
|
return existingSegmentMidpointHitCoords;
|
|
return existingSegmentMidpointHitCoords;
|
|
@@ -606,8 +606,8 @@ export class LinearElementEditor {
|
|
while (index < midPoints.length) {
|
|
while (index < midPoints.length) {
|
|
if (midPoints[index] !== null) {
|
|
if (midPoints[index] !== null) {
|
|
const distance = pointDistance(
|
|
const distance = pointDistance(
|
|
- point(midPoints[index]![0], midPoints[index]![1]),
|
|
|
|
- point(scenePointer.x, scenePointer.y),
|
|
|
|
|
|
+ pointFrom(midPoints[index]![0], midPoints[index]![1]),
|
|
|
|
+ pointFrom(scenePointer.x, scenePointer.y),
|
|
);
|
|
);
|
|
if (distance <= threshold) {
|
|
if (distance <= threshold) {
|
|
return midPoints[index];
|
|
return midPoints[index];
|
|
@@ -626,8 +626,8 @@ export class LinearElementEditor {
|
|
zoom: AppState["zoom"],
|
|
zoom: AppState["zoom"],
|
|
) {
|
|
) {
|
|
let distance = pointDistance(
|
|
let distance = pointDistance(
|
|
- point(startPoint[0], startPoint[1]),
|
|
|
|
- point(endPoint[0], endPoint[1]),
|
|
|
|
|
|
+ pointFrom(startPoint[0], startPoint[1]),
|
|
|
|
+ pointFrom(endPoint[0], endPoint[1]),
|
|
);
|
|
);
|
|
if (element.points.length > 2 && element.roundness) {
|
|
if (element.points.length > 2 && element.roundness) {
|
|
distance = getBezierCurveLength(element, endPoint);
|
|
distance = getBezierCurveLength(element, endPoint);
|
|
@@ -829,11 +829,11 @@ export class LinearElementEditor {
|
|
const targetPoint =
|
|
const targetPoint =
|
|
clickedPointIndex > -1 &&
|
|
clickedPointIndex > -1 &&
|
|
pointRotateRads(
|
|
pointRotateRads(
|
|
- point(
|
|
|
|
|
|
+ pointFrom(
|
|
element.x + element.points[clickedPointIndex][0],
|
|
element.x + element.points[clickedPointIndex][0],
|
|
element.y + element.points[clickedPointIndex][1],
|
|
element.y + element.points[clickedPointIndex][1],
|
|
),
|
|
),
|
|
- point(cx, cy),
|
|
|
|
|
|
+ pointFrom(cx, cy),
|
|
element.angle,
|
|
element.angle,
|
|
);
|
|
);
|
|
|
|
|
|
@@ -928,11 +928,11 @@ export class LinearElementEditor {
|
|
element,
|
|
element,
|
|
elementsMap,
|
|
elementsMap,
|
|
lastCommittedPoint,
|
|
lastCommittedPoint,
|
|
- point(scenePointerX, scenePointerY),
|
|
|
|
|
|
+ pointFrom(scenePointerX, scenePointerY),
|
|
event[KEYS.CTRL_OR_CMD] ? null : app.getEffectiveGridSize(),
|
|
event[KEYS.CTRL_OR_CMD] ? null : app.getEffectiveGridSize(),
|
|
);
|
|
);
|
|
|
|
|
|
- newPoint = point(
|
|
|
|
|
|
+ newPoint = pointFrom(
|
|
width + lastCommittedPoint[0],
|
|
width + lastCommittedPoint[0],
|
|
height + lastCommittedPoint[1],
|
|
height + lastCommittedPoint[1],
|
|
);
|
|
);
|
|
@@ -984,8 +984,8 @@ export class LinearElementEditor {
|
|
|
|
|
|
const { x, y } = element;
|
|
const { x, y } = element;
|
|
return pointRotateRads(
|
|
return pointRotateRads(
|
|
- point(x + p[0], y + p[1]),
|
|
|
|
- point(cx, cy),
|
|
|
|
|
|
+ pointFrom(x + p[0], y + p[1]),
|
|
|
|
+ pointFrom(cx, cy),
|
|
element.angle,
|
|
element.angle,
|
|
);
|
|
);
|
|
}
|
|
}
|
|
@@ -1001,8 +1001,8 @@ export class LinearElementEditor {
|
|
return element.points.map((p) => {
|
|
return element.points.map((p) => {
|
|
const { x, y } = element;
|
|
const { x, y } = element;
|
|
return pointRotateRads(
|
|
return pointRotateRads(
|
|
- point(x + p[0], y + p[1]),
|
|
|
|
- point(cx, cy),
|
|
|
|
|
|
+ pointFrom(x + p[0], y + p[1]),
|
|
|
|
+ pointFrom(cx, cy),
|
|
element.angle,
|
|
element.angle,
|
|
);
|
|
);
|
|
});
|
|
});
|
|
@@ -1025,8 +1025,12 @@ export class LinearElementEditor {
|
|
const { x, y } = element;
|
|
const { x, y } = element;
|
|
|
|
|
|
return p
|
|
return p
|
|
- ? pointRotateRads(point(x + p[0], y + p[1]), point(cx, cy), element.angle)
|
|
|
|
- : pointRotateRads(point(x, y), point(cx, cy), element.angle);
|
|
|
|
|
|
+ ? pointRotateRads(
|
|
|
|
+ pointFrom(x + p[0], y + p[1]),
|
|
|
|
+ pointFrom(cx, cy),
|
|
|
|
+ element.angle,
|
|
|
|
+ )
|
|
|
|
+ : pointRotateRads(pointFrom(x, y), pointFrom(cx, cy), element.angle);
|
|
}
|
|
}
|
|
|
|
|
|
static pointFromAbsoluteCoords(
|
|
static pointFromAbsoluteCoords(
|
|
@@ -1036,7 +1040,7 @@ export class LinearElementEditor {
|
|
): LocalPoint {
|
|
): LocalPoint {
|
|
if (isElbowArrow(element)) {
|
|
if (isElbowArrow(element)) {
|
|
// No rotation for elbow arrows
|
|
// No rotation for elbow arrows
|
|
- return point(
|
|
|
|
|
|
+ return pointFrom(
|
|
absoluteCoords[0] - element.x,
|
|
absoluteCoords[0] - element.x,
|
|
absoluteCoords[1] - element.y,
|
|
absoluteCoords[1] - element.y,
|
|
);
|
|
);
|
|
@@ -1046,11 +1050,11 @@ export class LinearElementEditor {
|
|
const cx = (x1 + x2) / 2;
|
|
const cx = (x1 + x2) / 2;
|
|
const cy = (y1 + y2) / 2;
|
|
const cy = (y1 + y2) / 2;
|
|
const [x, y] = pointRotateRads(
|
|
const [x, y] = pointRotateRads(
|
|
- point(absoluteCoords[0], absoluteCoords[1]),
|
|
|
|
- point(cx, cy),
|
|
|
|
|
|
+ pointFrom(absoluteCoords[0], absoluteCoords[1]),
|
|
|
|
+ pointFrom(cx, cy),
|
|
-element.angle as Radians,
|
|
-element.angle as Radians,
|
|
);
|
|
);
|
|
- return point(x - element.x, y - element.y);
|
|
|
|
|
|
+ return pointFrom(x - element.x, y - element.y);
|
|
}
|
|
}
|
|
|
|
|
|
static getPointIndexUnderCursor(
|
|
static getPointIndexUnderCursor(
|
|
@@ -1071,7 +1075,7 @@ export class LinearElementEditor {
|
|
while (--idx > -1) {
|
|
while (--idx > -1) {
|
|
const p = pointHandles[idx];
|
|
const p = pointHandles[idx];
|
|
if (
|
|
if (
|
|
- pointDistance(point(x, y), point(p[0], p[1])) * zoom.value <
|
|
|
|
|
|
+ pointDistance(pointFrom(x, y), pointFrom(p[0], p[1])) * zoom.value <
|
|
// +1px to account for outline stroke
|
|
// +1px to account for outline stroke
|
|
LinearElementEditor.POINT_HANDLE_SIZE + 1
|
|
LinearElementEditor.POINT_HANDLE_SIZE + 1
|
|
) {
|
|
) {
|
|
@@ -1093,12 +1097,12 @@ export class LinearElementEditor {
|
|
const cx = (x1 + x2) / 2;
|
|
const cx = (x1 + x2) / 2;
|
|
const cy = (y1 + y2) / 2;
|
|
const cy = (y1 + y2) / 2;
|
|
const [rotatedX, rotatedY] = pointRotateRads(
|
|
const [rotatedX, rotatedY] = pointRotateRads(
|
|
- point(pointerOnGrid[0], pointerOnGrid[1]),
|
|
|
|
- point(cx, cy),
|
|
|
|
|
|
+ pointFrom(pointerOnGrid[0], pointerOnGrid[1]),
|
|
|
|
+ pointFrom(cx, cy),
|
|
-element.angle as Radians,
|
|
-element.angle as Radians,
|
|
);
|
|
);
|
|
|
|
|
|
- return point(rotatedX - element.x, rotatedY - element.y);
|
|
|
|
|
|
+ return pointFrom(rotatedX - element.x, rotatedY - element.y);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -1118,7 +1122,7 @@ export class LinearElementEditor {
|
|
|
|
|
|
return {
|
|
return {
|
|
points: points.map((p) => {
|
|
points: points.map((p) => {
|
|
- return point(p[0] - offsetX, p[1] - offsetY);
|
|
|
|
|
|
+ return pointFrom(p[0] - offsetX, p[1] - offsetY);
|
|
}),
|
|
}),
|
|
x: element.x + offsetX,
|
|
x: element.x + offsetX,
|
|
y: element.y + offsetY,
|
|
y: element.y + offsetY,
|
|
@@ -1172,8 +1176,8 @@ export class LinearElementEditor {
|
|
}
|
|
}
|
|
acc.push(
|
|
acc.push(
|
|
nextPoint
|
|
nextPoint
|
|
- ? point((p[0] + nextPoint[0]) / 2, (p[1] + nextPoint[1]) / 2)
|
|
|
|
- : point(p[0], p[1]),
|
|
|
|
|
|
+ ? pointFrom((p[0] + nextPoint[0]) / 2, (p[1] + nextPoint[1]) / 2)
|
|
|
|
+ : pointFrom(p[0], p[1]),
|
|
);
|
|
);
|
|
|
|
|
|
nextSelectedIndices.push(indexCursor + 1);
|
|
nextSelectedIndices.push(indexCursor + 1);
|
|
@@ -1194,7 +1198,7 @@ export class LinearElementEditor {
|
|
[
|
|
[
|
|
{
|
|
{
|
|
index: element.points.length - 1,
|
|
index: element.points.length - 1,
|
|
- point: point(lastPoint[0] + 30, lastPoint[1] + 30),
|
|
|
|
|
|
+ point: pointFrom(lastPoint[0] + 30, lastPoint[1] + 30),
|
|
},
|
|
},
|
|
],
|
|
],
|
|
elementsMap,
|
|
elementsMap,
|
|
@@ -1235,7 +1239,9 @@ export class LinearElementEditor {
|
|
const nextPoints = element.points.reduce((acc: LocalPoint[], p, idx) => {
|
|
const nextPoints = element.points.reduce((acc: LocalPoint[], p, idx) => {
|
|
if (!pointIndices.includes(idx)) {
|
|
if (!pointIndices.includes(idx)) {
|
|
acc.push(
|
|
acc.push(
|
|
- !acc.length ? point(0, 0) : point(p[0] - offsetX, p[1] - offsetY),
|
|
|
|
|
|
+ !acc.length
|
|
|
|
+ ? pointFrom(0, 0)
|
|
|
|
+ : pointFrom(p[0] - offsetX, p[1] - offsetY),
|
|
);
|
|
);
|
|
}
|
|
}
|
|
return acc;
|
|
return acc;
|
|
@@ -1312,9 +1318,9 @@ export class LinearElementEditor {
|
|
const deltaY =
|
|
const deltaY =
|
|
selectedPointData.point[1] - points[selectedPointData.index][1];
|
|
selectedPointData.point[1] - points[selectedPointData.index][1];
|
|
|
|
|
|
- return point(p[0] + deltaX - offsetX, p[1] + deltaY - offsetY);
|
|
|
|
|
|
+ return pointFrom(p[0] + deltaX - offsetX, p[1] + deltaY - offsetY);
|
|
}
|
|
}
|
|
- return offsetX || offsetY ? point(p[0] - offsetX, p[1] - offsetY) : p;
|
|
|
|
|
|
+ return offsetX || offsetY ? pointFrom(p[0] - offsetX, p[1] - offsetY) : p;
|
|
});
|
|
});
|
|
|
|
|
|
LinearElementEditor._updatePoints(
|
|
LinearElementEditor._updatePoints(
|
|
@@ -1368,8 +1374,8 @@ export class LinearElementEditor {
|
|
|
|
|
|
const origin = linearElementEditor.pointerDownState.origin!;
|
|
const origin = linearElementEditor.pointerDownState.origin!;
|
|
const dist = pointDistance(
|
|
const dist = pointDistance(
|
|
- point(origin.x, origin.y),
|
|
|
|
- point(pointerCoords.x, pointerCoords.y),
|
|
|
|
|
|
+ pointFrom(origin.x, origin.y),
|
|
|
|
+ pointFrom(pointerCoords.x, pointerCoords.y),
|
|
);
|
|
);
|
|
if (
|
|
if (
|
|
!appState.editingLinearElement &&
|
|
!appState.editingLinearElement &&
|
|
@@ -1493,8 +1499,8 @@ export class LinearElementEditor {
|
|
const dX = prevCenterX - nextCenterX;
|
|
const dX = prevCenterX - nextCenterX;
|
|
const dY = prevCenterY - nextCenterY;
|
|
const dY = prevCenterY - nextCenterY;
|
|
const rotated = pointRotateRads(
|
|
const rotated = pointRotateRads(
|
|
- point(offsetX, offsetY),
|
|
|
|
- point(dX, dY),
|
|
|
|
|
|
+ pointFrom(offsetX, offsetY),
|
|
|
|
+ pointFrom(dX, dY),
|
|
element.angle,
|
|
element.angle,
|
|
);
|
|
);
|
|
mutateElement(element, {
|
|
mutateElement(element, {
|
|
@@ -1540,8 +1546,8 @@ export class LinearElementEditor {
|
|
);
|
|
);
|
|
|
|
|
|
return pointRotateRads(
|
|
return pointRotateRads(
|
|
- point(width, height),
|
|
|
|
- point(0, 0),
|
|
|
|
|
|
+ pointFrom(width, height),
|
|
|
|
+ pointFrom(0, 0),
|
|
-element.angle as Radians,
|
|
-element.angle as Radians,
|
|
);
|
|
);
|
|
}
|
|
}
|
|
@@ -1611,36 +1617,36 @@ export class LinearElementEditor {
|
|
);
|
|
);
|
|
const boundTextX2 = boundTextX1 + boundTextElement.width;
|
|
const boundTextX2 = boundTextX1 + boundTextElement.width;
|
|
const boundTextY2 = boundTextY1 + boundTextElement.height;
|
|
const boundTextY2 = boundTextY1 + boundTextElement.height;
|
|
- const centerPoint = point(cx, cy);
|
|
|
|
|
|
+ const centerPoint = pointFrom(cx, cy);
|
|
|
|
|
|
const topLeftRotatedPoint = pointRotateRads(
|
|
const topLeftRotatedPoint = pointRotateRads(
|
|
- point(x1, y1),
|
|
|
|
|
|
+ pointFrom(x1, y1),
|
|
centerPoint,
|
|
centerPoint,
|
|
element.angle,
|
|
element.angle,
|
|
);
|
|
);
|
|
const topRightRotatedPoint = pointRotateRads(
|
|
const topRightRotatedPoint = pointRotateRads(
|
|
- point(x2, y1),
|
|
|
|
|
|
+ pointFrom(x2, y1),
|
|
centerPoint,
|
|
centerPoint,
|
|
element.angle,
|
|
element.angle,
|
|
);
|
|
);
|
|
|
|
|
|
const counterRotateBoundTextTopLeft = pointRotateRads(
|
|
const counterRotateBoundTextTopLeft = pointRotateRads(
|
|
- point(boundTextX1, boundTextY1),
|
|
|
|
|
|
+ pointFrom(boundTextX1, boundTextY1),
|
|
centerPoint,
|
|
centerPoint,
|
|
-element.angle as Radians,
|
|
-element.angle as Radians,
|
|
);
|
|
);
|
|
const counterRotateBoundTextTopRight = pointRotateRads(
|
|
const counterRotateBoundTextTopRight = pointRotateRads(
|
|
- point(boundTextX2, boundTextY1),
|
|
|
|
|
|
+ pointFrom(boundTextX2, boundTextY1),
|
|
centerPoint,
|
|
centerPoint,
|
|
-element.angle as Radians,
|
|
-element.angle as Radians,
|
|
);
|
|
);
|
|
const counterRotateBoundTextBottomLeft = pointRotateRads(
|
|
const counterRotateBoundTextBottomLeft = pointRotateRads(
|
|
- point(boundTextX1, boundTextY2),
|
|
|
|
|
|
+ pointFrom(boundTextX1, boundTextY2),
|
|
centerPoint,
|
|
centerPoint,
|
|
-element.angle as Radians,
|
|
-element.angle as Radians,
|
|
);
|
|
);
|
|
const counterRotateBoundTextBottomRight = pointRotateRads(
|
|
const counterRotateBoundTextBottomRight = pointRotateRads(
|
|
- point(boundTextX2, boundTextY2),
|
|
|
|
|
|
+ pointFrom(boundTextX2, boundTextY2),
|
|
centerPoint,
|
|
centerPoint,
|
|
-element.angle as Radians,
|
|
-element.angle as Radians,
|
|
);
|
|
);
|