Skip to content

Commit

Permalink
refactor: point() -> pointFrom() to fix compiler issue (excalidra…
Browse files Browse the repository at this point in the history
  • Loading branch information
dwelle authored Oct 1, 2024
1 parent a977dd1 commit 47ee8a0
Show file tree
Hide file tree
Showing 51 changed files with 845 additions and 703 deletions.
4 changes: 2 additions & 2 deletions packages/excalidraw/actions/actionFinalize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { isBindingElement, isLinearElement } from "../element/typeChecks";
import type { AppState } from "../types";
import { resetCursor } from "../cursor";
import { StoreAction } from "../store";
import { point } from "../../math";
import { pointFrom } from "../../math";
import { isPathALoop } from "../shapes";

export const actionFinalize = register({
Expand Down Expand Up @@ -115,7 +115,7 @@ export const actionFinalize = register({
mutateElement(multiPointElement, {
points: linePoints.map((p, index) =>
index === linePoints.length - 1
? point(firstPoint[0], firstPoint[1])
? pointFrom(firstPoint[0], firstPoint[1])
: p,
),
});
Expand Down
12 changes: 6 additions & 6 deletions packages/excalidraw/actions/actionFlip.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import { Excalidraw } from "../index";
import { render } from "../tests/test-utils";
import { API } from "../tests/helpers/api";
import { point } from "../../math";
import { pointFrom } from "../../math";
import { actionFlipHorizontal, actionFlipVertical } from "./actionFlip";

const { h } = window;
Expand Down Expand Up @@ -50,11 +50,11 @@ describe("flipping re-centers selection", () => {
startArrowhead: null,
endArrowhead: "arrow",
points: [
point(0, 0),
point(0, -35),
point(-90.9, -35),
point(-90.9, 204.9),
point(65.1, 204.9),
pointFrom(0, 0),
pointFrom(0, -35),
pointFrom(-90.9, -35),
pointFrom(-90.9, 204.9),
pointFrom(65.1, 204.9),
],
elbowed: true,
}),
Expand Down
4 changes: 2 additions & 2 deletions packages/excalidraw/actions/actionProperties.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ import {
import { mutateElbowArrow } from "../element/routing";
import { LinearElementEditor } from "../element/linearElementEditor";
import type { LocalPoint } from "../../math";
import { point, vector } from "../../math";
import { pointFrom, vector } from "../../math";

const FONT_SIZE_RELATIVE_INCREASE_STEP = 0.1;

Expand Down Expand Up @@ -1651,7 +1651,7 @@ export const actionChangeArrowType = register({
elementsMap,
[finalStartPoint, finalEndPoint].map(
(p): LocalPoint =>
point(p[0] - newElement.x, p[1] - newElement.y),
pointFrom(p[0] - newElement.x, p[1] - newElement.y),
),
vector(0, 0),
{
Expand Down
10 changes: 5 additions & 5 deletions packages/excalidraw/charts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Radians } from "../math";
import { point } from "../math";
import { pointFrom } from "../math";
import {
COLOR_PALETTE,
DEFAULT_CHART_COLOR_INDEX,
Expand Down Expand Up @@ -260,7 +260,7 @@ const chartLines = (
x,
y,
width: chartWidth,
points: [point(0, 0), point(chartWidth, 0)],
points: [pointFrom(0, 0), pointFrom(chartWidth, 0)],
});

const yLine = newLinearElement({
Expand All @@ -271,7 +271,7 @@ const chartLines = (
x,
y,
height: chartHeight,
points: [point(0, 0), point(0, -chartHeight)],
points: [pointFrom(0, 0), pointFrom(0, -chartHeight)],
});

const maxLine = newLinearElement({
Expand All @@ -284,7 +284,7 @@ const chartLines = (
strokeStyle: "dotted",
width: chartWidth,
opacity: GRID_OPACITY,
points: [point(0, 0), point(chartWidth, 0)],
points: [pointFrom(0, 0), pointFrom(chartWidth, 0)],
});

return [xLine, yLine, maxLine];
Expand Down Expand Up @@ -441,7 +441,7 @@ const chartTypeLine = (
height: cy,
strokeStyle: "dotted",
opacity: GRID_OPACITY,
points: [point(0, 0), point(0, cy)],
points: [pointFrom(0, 0), pointFrom(0, cy)],
});
});

Expand Down
64 changes: 35 additions & 29 deletions packages/excalidraw/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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!);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
)
);
Expand All @@ -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 ||
Expand All @@ -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(
Expand All @@ -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) {
Expand Down Expand Up @@ -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
) {
Expand All @@ -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,
Expand All @@ -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
) {
Expand Down Expand Up @@ -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,
),
Expand All @@ -5655,7 +5658,7 @@ class App extends React.Component<AppProps, AppState> {
{
points: [
...points.slice(0, -1),
point<LocalPoint>(
pointFrom<LocalPoint>(
lastCommittedX + dxFromLastCommitted,
lastCommittedY + dyFromLastCommitted,
),
Expand Down Expand Up @@ -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 };
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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],
});

Expand Down Expand Up @@ -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
) {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -8031,15 +8037,15 @@ class App extends React.Component<AppProps, AppState> {
mutateElement(
newElement,
{
points: [...points, point<LocalPoint>(dx, dy)],
points: [...points, pointFrom<LocalPoint>(dx, dy)],
},
false,
);
} else if (points.length > 1 && isElbowArrow(newElement)) {
mutateElbowArrow(
newElement,
elementsMap,
[...points.slice(0, -1), point<LocalPoint>(dx, dy)],
[...points.slice(0, -1), pointFrom<LocalPoint>(dx, dy)],
vector(0, 0),
undefined,
{
Expand All @@ -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,
);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
),
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions packages/excalidraw/components/Stats/MultiDimension.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -182,7 +182,7 @@ const handleDimensionChange: DragInputCallbackType<
nextHeight,
initialHeight,
aspectRatio,
point(x1, y1),
pointFrom(x1, y1),
property,
latestElements,
originalElements,
Expand Down Expand Up @@ -287,7 +287,7 @@ const handleDimensionChange: DragInputCallbackType<
nextHeight,
initialHeight,
aspectRatio,
point(x1, y1),
pointFrom(x1, y1),
property,
latestElements,
originalElements,
Expand Down
Loading

0 comments on commit 47ee8a0

Please sign in to comment.