mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
refactor: point()
-> pointFrom()
to fix compiler issue (#8578)
This commit is contained in:
parent
a977dd1bf5
commit
47ee8a0094
51 changed files with 845 additions and 703 deletions
|
@ -445,7 +445,7 @@ import {
|
|||
} from "../element/flowchart";
|
||||
import { searchItemInFocusAtom } from "./SearchMenu";
|
||||
import type { LocalPoint, Radians } from "../../math";
|
||||
import { point, pointDistance, vector } from "../../math";
|
||||
import { pointFrom, pointDistance, vector } from "../../math";
|
||||
|
||||
const AppContext = React.createContext<AppClassProperties>(null!);
|
||||
const AppPropsContext = React.createContext<AppProps>(null!);
|
||||
|
@ -4910,7 +4910,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||
this.getElementHitThreshold(),
|
||||
);
|
||||
|
||||
return isPointInShape(point(x, y), selectionShape);
|
||||
return isPointInShape(pointFrom(x, y), selectionShape);
|
||||
}
|
||||
|
||||
// take bound text element into consideration for hit collision as well
|
||||
|
@ -5269,7 +5269,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||
element,
|
||||
this.scene.getNonDeletedElementsMap(),
|
||||
this.state,
|
||||
point(scenePointer.x, scenePointer.y),
|
||||
pointFrom(scenePointer.x, scenePointer.y),
|
||||
this.device.editor.isMobile,
|
||||
)
|
||||
);
|
||||
|
@ -5281,11 +5281,14 @@ class App extends React.Component<AppProps, AppState> {
|
|||
isTouchScreen: boolean,
|
||||
) => {
|
||||
const draggedDistance = pointDistance(
|
||||
point(
|
||||
pointFrom(
|
||||
this.lastPointerDownEvent!.clientX,
|
||||
this.lastPointerDownEvent!.clientY,
|
||||
),
|
||||
point(this.lastPointerUpEvent!.clientX, this.lastPointerUpEvent!.clientY),
|
||||
pointFrom(
|
||||
this.lastPointerUpEvent!.clientX,
|
||||
this.lastPointerUpEvent!.clientY,
|
||||
),
|
||||
);
|
||||
if (
|
||||
!this.hitLinkElement ||
|
||||
|
@ -5304,7 +5307,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||
this.hitLinkElement,
|
||||
elementsMap,
|
||||
this.state,
|
||||
point(lastPointerDownCoords.x, lastPointerDownCoords.y),
|
||||
pointFrom(lastPointerDownCoords.x, lastPointerDownCoords.y),
|
||||
this.device.editor.isMobile,
|
||||
);
|
||||
const lastPointerUpCoords = viewportCoordsToSceneCoords(
|
||||
|
@ -5315,7 +5318,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||
this.hitLinkElement,
|
||||
elementsMap,
|
||||
this.state,
|
||||
point(lastPointerUpCoords.x, lastPointerUpCoords.y),
|
||||
pointFrom(lastPointerUpCoords.x, lastPointerUpCoords.y),
|
||||
this.device.editor.isMobile,
|
||||
);
|
||||
if (lastPointerDownHittingLinkIcon && lastPointerUpHittingLinkIcon) {
|
||||
|
@ -5565,7 +5568,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||
// threshold, add a point
|
||||
if (
|
||||
pointDistance(
|
||||
point(scenePointerX - rx, scenePointerY - ry),
|
||||
pointFrom(scenePointerX - rx, scenePointerY - ry),
|
||||
lastPoint,
|
||||
) >= LINE_CONFIRM_THRESHOLD
|
||||
) {
|
||||
|
@ -5574,7 +5577,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||
{
|
||||
points: [
|
||||
...points,
|
||||
point<LocalPoint>(scenePointerX - rx, scenePointerY - ry),
|
||||
pointFrom<LocalPoint>(scenePointerX - rx, scenePointerY - ry),
|
||||
],
|
||||
},
|
||||
false,
|
||||
|
@ -5588,7 +5591,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||
points.length > 2 &&
|
||||
lastCommittedPoint &&
|
||||
pointDistance(
|
||||
point(scenePointerX - rx, scenePointerY - ry),
|
||||
pointFrom(scenePointerX - rx, scenePointerY - ry),
|
||||
lastCommittedPoint,
|
||||
) < LINE_CONFIRM_THRESHOLD
|
||||
) {
|
||||
|
@ -5636,7 +5639,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||
this.scene.getNonDeletedElementsMap(),
|
||||
[
|
||||
...points.slice(0, -1),
|
||||
point<LocalPoint>(
|
||||
pointFrom<LocalPoint>(
|
||||
lastCommittedX + dxFromLastCommitted,
|
||||
lastCommittedY + dyFromLastCommitted,
|
||||
),
|
||||
|
@ -5655,7 +5658,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||
{
|
||||
points: [
|
||||
...points.slice(0, -1),
|
||||
point<LocalPoint>(
|
||||
pointFrom<LocalPoint>(
|
||||
lastCommittedX + dxFromLastCommitted,
|
||||
lastCommittedY + dyFromLastCommitted,
|
||||
),
|
||||
|
@ -5884,8 +5887,8 @@ class App extends React.Component<AppProps, AppState> {
|
|||
};
|
||||
|
||||
const distance = pointDistance(
|
||||
point(pointerDownState.lastCoords.x, pointerDownState.lastCoords.y),
|
||||
point(scenePointer.x, scenePointer.y),
|
||||
pointFrom(pointerDownState.lastCoords.x, pointerDownState.lastCoords.y),
|
||||
pointFrom(scenePointer.x, scenePointer.y),
|
||||
);
|
||||
const threshold = this.getElementHitThreshold();
|
||||
const p = { ...pointerDownState.lastCoords };
|
||||
|
@ -6397,7 +6400,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||
this.hitLinkElement,
|
||||
this.scene.getNonDeletedElementsMap(),
|
||||
this.state,
|
||||
point(scenePointer.x, scenePointer.y),
|
||||
pointFrom(scenePointer.x, scenePointer.y),
|
||||
)
|
||||
) {
|
||||
this.handleEmbeddableCenterClick(this.hitLinkElement);
|
||||
|
@ -7088,7 +7091,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||
simulatePressure,
|
||||
locked: false,
|
||||
frameId: topLayerFrame ? topLayerFrame.id : null,
|
||||
points: [point<LocalPoint>(0, 0)],
|
||||
points: [pointFrom<LocalPoint>(0, 0)],
|
||||
pressures: simulatePressure ? [] : [event.pressure],
|
||||
});
|
||||
|
||||
|
@ -7297,7 +7300,10 @@ class App extends React.Component<AppProps, AppState> {
|
|||
multiElement.points.length > 1 &&
|
||||
lastCommittedPoint &&
|
||||
pointDistance(
|
||||
point(pointerDownState.origin.x - rx, pointerDownState.origin.y - ry),
|
||||
pointFrom(
|
||||
pointerDownState.origin.x - rx,
|
||||
pointerDownState.origin.y - ry,
|
||||
),
|
||||
lastCommittedPoint,
|
||||
) < LINE_CONFIRM_THRESHOLD
|
||||
) {
|
||||
|
@ -7399,7 +7405,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||
};
|
||||
});
|
||||
mutateElement(element, {
|
||||
points: [...element.points, point<LocalPoint>(0, 0)],
|
||||
points: [...element.points, pointFrom<LocalPoint>(0, 0)],
|
||||
});
|
||||
const boundElement = getHoveredElementForBinding(
|
||||
pointerDownState.origin,
|
||||
|
@ -7652,8 +7658,8 @@ class App extends React.Component<AppProps, AppState> {
|
|||
) {
|
||||
if (
|
||||
pointDistance(
|
||||
point(pointerCoords.x, pointerCoords.y),
|
||||
point(pointerDownState.origin.x, pointerDownState.origin.y),
|
||||
pointFrom(pointerCoords.x, pointerCoords.y),
|
||||
pointFrom(pointerDownState.origin.x, pointerDownState.origin.y),
|
||||
) < DRAGGING_THRESHOLD
|
||||
) {
|
||||
return;
|
||||
|
@ -8002,7 +8008,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||
mutateElement(
|
||||
newElement,
|
||||
{
|
||||
points: [...points, point<LocalPoint>(dx, dy)],
|
||||
points: [...points, pointFrom<LocalPoint>(dx, dy)],
|
||||
pressures,
|
||||
},
|
||||
false,
|
||||
|
@ -8031,7 +8037,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||
mutateElement(
|
||||
newElement,
|
||||
{
|
||||
points: [...points, point<LocalPoint>(dx, dy)],
|
||||
points: [...points, pointFrom<LocalPoint>(dx, dy)],
|
||||
},
|
||||
false,
|
||||
);
|
||||
|
@ -8039,7 +8045,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||
mutateElbowArrow(
|
||||
newElement,
|
||||
elementsMap,
|
||||
[...points.slice(0, -1), point<LocalPoint>(dx, dy)],
|
||||
[...points.slice(0, -1), pointFrom<LocalPoint>(dx, dy)],
|
||||
vector(0, 0),
|
||||
undefined,
|
||||
{
|
||||
|
@ -8051,7 +8057,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||
mutateElement(
|
||||
newElement,
|
||||
{
|
||||
points: [...points.slice(0, -1), point<LocalPoint>(dx, dy)],
|
||||
points: [...points.slice(0, -1), pointFrom<LocalPoint>(dx, dy)],
|
||||
},
|
||||
false,
|
||||
);
|
||||
|
@ -8360,9 +8366,9 @@ class App extends React.Component<AppProps, AppState> {
|
|||
: [...newElement.pressures, childEvent.pressure];
|
||||
|
||||
mutateElement(newElement, {
|
||||
points: [...points, point<LocalPoint>(dx, dy)],
|
||||
points: [...points, pointFrom<LocalPoint>(dx, dy)],
|
||||
pressures,
|
||||
lastCommittedPoint: point<LocalPoint>(dx, dy),
|
||||
lastCommittedPoint: pointFrom<LocalPoint>(dx, dy),
|
||||
});
|
||||
|
||||
this.actionManager.executeAction(actionFinalize);
|
||||
|
@ -8409,7 +8415,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||
mutateElement(newElement, {
|
||||
points: [
|
||||
...newElement.points,
|
||||
point<LocalPoint>(
|
||||
pointFrom<LocalPoint>(
|
||||
pointerCoords.x - newElement.x,
|
||||
pointerCoords.y - newElement.y,
|
||||
),
|
||||
|
@ -8723,8 +8729,8 @@ class App extends React.Component<AppProps, AppState> {
|
|||
this.eraserTrail.endPath();
|
||||
|
||||
const draggedDistance = pointDistance(
|
||||
point(pointerStart.clientX, pointerStart.clientY),
|
||||
point(pointerEnd.clientX, pointerEnd.clientY),
|
||||
pointFrom(pointerStart.clientX, pointerStart.clientY),
|
||||
pointFrom(pointerEnd.clientX, pointerEnd.clientY),
|
||||
);
|
||||
|
||||
if (draggedDistance === 0) {
|
||||
|
|
|
@ -20,7 +20,7 @@ import { getAtomicUnits, getStepSizedValue, isPropertyEditable } from "./utils";
|
|||
import { getElementsInAtomicUnit, resizeElement } from "./utils";
|
||||
import type { AtomicUnit } from "./utils";
|
||||
import { MIN_WIDTH_OR_HEIGHT } from "../../constants";
|
||||
import { point, type GlobalPoint } from "../../../math";
|
||||
import { pointFrom, type GlobalPoint } from "../../../math";
|
||||
|
||||
interface MultiDimensionProps {
|
||||
property: "width" | "height";
|
||||
|
@ -182,7 +182,7 @@ const handleDimensionChange: DragInputCallbackType<
|
|||
nextHeight,
|
||||
initialHeight,
|
||||
aspectRatio,
|
||||
point(x1, y1),
|
||||
pointFrom(x1, y1),
|
||||
property,
|
||||
latestElements,
|
||||
originalElements,
|
||||
|
@ -287,7 +287,7 @@ const handleDimensionChange: DragInputCallbackType<
|
|||
nextHeight,
|
||||
initialHeight,
|
||||
aspectRatio,
|
||||
point(x1, y1),
|
||||
pointFrom(x1, y1),
|
||||
property,
|
||||
latestElements,
|
||||
originalElements,
|
||||
|
|
|
@ -13,7 +13,7 @@ import { useMemo } from "react";
|
|||
import { getElementsInAtomicUnit, moveElement } from "./utils";
|
||||
import type { AtomicUnit } from "./utils";
|
||||
import type { AppState } from "../../types";
|
||||
import { point, pointRotateRads } from "../../../math";
|
||||
import { pointFrom, pointRotateRads } from "../../../math";
|
||||
|
||||
interface MultiPositionProps {
|
||||
property: "x" | "y";
|
||||
|
@ -44,8 +44,8 @@ const moveElements = (
|
|||
origElement.y + origElement.height / 2,
|
||||
];
|
||||
const [topLeftX, topLeftY] = pointRotateRads(
|
||||
point(origElement.x, origElement.y),
|
||||
point(cx, cy),
|
||||
pointFrom(origElement.x, origElement.y),
|
||||
pointFrom(cx, cy),
|
||||
origElement.angle,
|
||||
);
|
||||
|
||||
|
@ -97,8 +97,8 @@ const moveGroupTo = (
|
|||
];
|
||||
|
||||
const [topLeftX, topLeftY] = pointRotateRads(
|
||||
point(latestElement.x, latestElement.y),
|
||||
point(cx, cy),
|
||||
pointFrom(latestElement.x, latestElement.y),
|
||||
pointFrom(cx, cy),
|
||||
latestElement.angle,
|
||||
);
|
||||
|
||||
|
@ -171,8 +171,8 @@ const handlePositionChange: DragInputCallbackType<
|
|||
origElement.y + origElement.height / 2,
|
||||
];
|
||||
const [topLeftX, topLeftY] = pointRotateRads(
|
||||
point(origElement.x, origElement.y),
|
||||
point(cx, cy),
|
||||
pointFrom(origElement.x, origElement.y),
|
||||
pointFrom(cx, cy),
|
||||
origElement.angle,
|
||||
);
|
||||
|
||||
|
@ -241,8 +241,8 @@ const MultiPosition = ({
|
|||
const [cx, cy] = [el.x + el.width / 2, el.y + el.height / 2];
|
||||
|
||||
const [topLeftX, topLeftY] = pointRotateRads(
|
||||
point(el.x, el.y),
|
||||
point(cx, cy),
|
||||
pointFrom(el.x, el.y),
|
||||
pointFrom(cx, cy),
|
||||
el.angle,
|
||||
);
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import type { DragInputCallbackType } from "./DragInput";
|
|||
import { getStepSizedValue, moveElement } from "./utils";
|
||||
import type Scene from "../../scene/Scene";
|
||||
import type { AppState } from "../../types";
|
||||
import { point, pointRotateRads } from "../../../math";
|
||||
import { pointFrom, pointRotateRads } from "../../../math";
|
||||
|
||||
interface PositionProps {
|
||||
property: "x" | "y";
|
||||
|
@ -33,8 +33,8 @@ const handlePositionChange: DragInputCallbackType<"x" | "y"> = ({
|
|||
origElement.y + origElement.height / 2,
|
||||
];
|
||||
const [topLeftX, topLeftY] = pointRotateRads(
|
||||
point(origElement.x, origElement.y),
|
||||
point(cx, cy),
|
||||
pointFrom(origElement.x, origElement.y),
|
||||
pointFrom(cx, cy),
|
||||
origElement.angle,
|
||||
);
|
||||
|
||||
|
@ -93,8 +93,8 @@ const Position = ({
|
|||
appState,
|
||||
}: PositionProps) => {
|
||||
const [topLeftX, topLeftY] = pointRotateRads(
|
||||
point(element.x, element.y),
|
||||
point(element.x + element.width / 2, element.y + element.height / 2),
|
||||
pointFrom(element.x, element.y),
|
||||
pointFrom(element.x + element.width / 2, element.y + element.height / 2),
|
||||
element.angle,
|
||||
);
|
||||
const value =
|
||||
|
|
|
@ -25,7 +25,7 @@ import { API } from "../../tests/helpers/api";
|
|||
import { actionGroup } from "../../actions";
|
||||
import { isInGroup } from "../../groups";
|
||||
import type { Degrees } from "../../../math";
|
||||
import { degreesToRadians, point, pointRotateRads } from "../../../math";
|
||||
import { degreesToRadians, pointFrom, pointRotateRads } from "../../../math";
|
||||
|
||||
const { h } = window;
|
||||
const mouse = new Pointer("mouse");
|
||||
|
@ -264,8 +264,8 @@ describe("stats for a generic element", () => {
|
|||
rectangle.y + rectangle.height / 2,
|
||||
];
|
||||
const [topLeftX, topLeftY] = pointRotateRads(
|
||||
point(rectangle.x, rectangle.y),
|
||||
point(cx, cy),
|
||||
pointFrom(rectangle.x, rectangle.y),
|
||||
pointFrom(cx, cy),
|
||||
rectangle.angle,
|
||||
);
|
||||
|
||||
|
@ -283,8 +283,8 @@ describe("stats for a generic element", () => {
|
|||
testInputProperty(rectangle, "angle", "A", 0, 45);
|
||||
|
||||
let [newTopLeftX, newTopLeftY] = pointRotateRads(
|
||||
point(rectangle.x, rectangle.y),
|
||||
point(cx, cy),
|
||||
pointFrom(rectangle.x, rectangle.y),
|
||||
pointFrom(cx, cy),
|
||||
rectangle.angle,
|
||||
);
|
||||
|
||||
|
@ -294,8 +294,8 @@ describe("stats for a generic element", () => {
|
|||
testInputProperty(rectangle, "angle", "A", 45, 66);
|
||||
|
||||
[newTopLeftX, newTopLeftY] = pointRotateRads(
|
||||
point(rectangle.x, rectangle.y),
|
||||
point(cx, cy),
|
||||
pointFrom(rectangle.x, rectangle.y),
|
||||
pointFrom(cx, cy),
|
||||
rectangle.angle,
|
||||
);
|
||||
expect(newTopLeftX.toString()).not.toEqual(xInput.value);
|
||||
|
@ -311,8 +311,8 @@ describe("stats for a generic element", () => {
|
|||
rectangle.y + rectangle.height / 2,
|
||||
];
|
||||
const [topLeftX, topLeftY] = pointRotateRads(
|
||||
point(rectangle.x, rectangle.y),
|
||||
point(cx, cy),
|
||||
pointFrom(rectangle.x, rectangle.y),
|
||||
pointFrom(cx, cy),
|
||||
rectangle.angle,
|
||||
);
|
||||
testInputProperty(rectangle, "width", "W", rectangle.width, 400);
|
||||
|
@ -321,8 +321,8 @@ describe("stats for a generic element", () => {
|
|||
rectangle.y + rectangle.height / 2,
|
||||
];
|
||||
let [currentTopLeftX, currentTopLeftY] = pointRotateRads(
|
||||
point(rectangle.x, rectangle.y),
|
||||
point(cx, cy),
|
||||
pointFrom(rectangle.x, rectangle.y),
|
||||
pointFrom(cx, cy),
|
||||
rectangle.angle,
|
||||
);
|
||||
expect(currentTopLeftX).toBeCloseTo(topLeftX, 4);
|
||||
|
@ -334,8 +334,8 @@ describe("stats for a generic element", () => {
|
|||
rectangle.y + rectangle.height / 2,
|
||||
];
|
||||
[currentTopLeftX, currentTopLeftY] = pointRotateRads(
|
||||
point(rectangle.x, rectangle.y),
|
||||
point(cx, cy),
|
||||
pointFrom(rectangle.x, rectangle.y),
|
||||
pointFrom(cx, cy),
|
||||
rectangle.angle,
|
||||
);
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import type { Radians } from "../../../math";
|
||||
import { point, pointRotateRads } from "../../../math";
|
||||
import { pointFrom, pointRotateRads } from "../../../math";
|
||||
import {
|
||||
bindOrUnbindLinearElements,
|
||||
updateBoundElements,
|
||||
|
@ -231,8 +231,8 @@ export const moveElement = (
|
|||
originalElement.y + originalElement.height / 2,
|
||||
];
|
||||
const [topLeftX, topLeftY] = pointRotateRads(
|
||||
point(originalElement.x, originalElement.y),
|
||||
point(cx, cy),
|
||||
pointFrom(originalElement.x, originalElement.y),
|
||||
pointFrom(cx, cy),
|
||||
originalElement.angle,
|
||||
);
|
||||
|
||||
|
@ -240,8 +240,8 @@ export const moveElement = (
|
|||
const changeInY = newTopLeftY - topLeftY;
|
||||
|
||||
const [x, y] = pointRotateRads(
|
||||
point(newTopLeftX, newTopLeftY),
|
||||
point(cx + changeInX, cy + changeInY),
|
||||
pointFrom(newTopLeftX, newTopLeftY),
|
||||
pointFrom(cx + changeInX, cy + changeInY),
|
||||
-originalElement.angle as Radians,
|
||||
);
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ import { trackEvent } from "../../analytics";
|
|||
import { useAppProps, useExcalidrawAppState } from "../App";
|
||||
import { isEmbeddableElement } from "../../element/typeChecks";
|
||||
import { getLinkHandleFromCoords } from "./helpers";
|
||||
import { point, type GlobalPoint } from "../../../math";
|
||||
import { pointFrom, type GlobalPoint } from "../../../math";
|
||||
|
||||
const CONTAINER_WIDTH = 320;
|
||||
const SPACE_BOTTOM = 85;
|
||||
|
@ -181,7 +181,7 @@ export const Hyperlink = ({
|
|||
element,
|
||||
elementsMap,
|
||||
appState,
|
||||
point(event.clientX, event.clientY),
|
||||
pointFrom(event.clientX, event.clientY),
|
||||
) as boolean;
|
||||
if (shouldHide) {
|
||||
timeoutId = window.setTimeout(() => {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import type { GlobalPoint, Radians } from "../../../math";
|
||||
import { point, pointRotateRads } from "../../../math";
|
||||
import { pointFrom, pointRotateRads } from "../../../math";
|
||||
import { MIME_TYPES } from "../../constants";
|
||||
import type { Bounds } from "../../element/bounds";
|
||||
import { getElementAbsoluteCoords } from "../../element/bounds";
|
||||
|
@ -35,8 +35,8 @@ export const getLinkHandleFromCoords = (
|
|||
const y = y1 - dashedLineMargin - linkMarginY + centeringOffset;
|
||||
|
||||
const [rotatedX, rotatedY] = pointRotateRads(
|
||||
point(x + linkWidth / 2, y + linkHeight / 2),
|
||||
point(centerX, centerY),
|
||||
pointFrom(x + linkWidth / 2, y + linkHeight / 2),
|
||||
pointFrom(centerX, centerY),
|
||||
angle,
|
||||
);
|
||||
return [
|
||||
|
@ -85,5 +85,10 @@ export const isPointHittingLink = (
|
|||
) {
|
||||
return true;
|
||||
}
|
||||
return isPointHittingLinkIcon(element, elementsMap, appState, point(x, y));
|
||||
return isPointHittingLinkIcon(
|
||||
element,
|
||||
elementsMap,
|
||||
appState,
|
||||
pointFrom(x, y),
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue