mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Further math refactor and simplifications
This commit is contained in:
parent
41885b4bb3
commit
0e2f8c958e
18 changed files with 262 additions and 175 deletions
|
@ -19,7 +19,6 @@ import {
|
|||
isLinearElement,
|
||||
isTextElement,
|
||||
} from "./typeChecks";
|
||||
import { rescalePoints } from "../points";
|
||||
import { getBoundTextElement, getContainerElement } from "./textElement";
|
||||
import { LinearElementEditor } from "./linearElementEditor";
|
||||
import { ShapeCache } from "../scene/ShapeCache";
|
||||
|
@ -38,6 +37,7 @@ import {
|
|||
pointDistance,
|
||||
pointFromArray,
|
||||
pointRotateRads,
|
||||
pointRescaleFromTopLeft,
|
||||
} from "../../math";
|
||||
import type { Mutable } from "../utility-types";
|
||||
|
||||
|
@ -859,10 +859,10 @@ export const getResizedElementAbsoluteCoords = (
|
|||
];
|
||||
}
|
||||
|
||||
const points = rescalePoints(
|
||||
const points = pointRescaleFromTopLeft(
|
||||
0,
|
||||
nextWidth,
|
||||
rescalePoints(1, nextHeight, element.points, normalizePoints),
|
||||
pointRescaleFromTopLeft(1, nextHeight, element.points, normalizePoints),
|
||||
normalizePoints,
|
||||
);
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import type { ExcalidrawElement } from "./types";
|
||||
import Scene from "../scene/Scene";
|
||||
import { getSizeFromPoints } from "../points";
|
||||
import { randomInteger } from "../random";
|
||||
import { getUpdatedTimestamp } from "../utils";
|
||||
import type { Mutable } from "../utility-types";
|
||||
import { ShapeCache } from "../scene/ShapeCache";
|
||||
import { pointExtent } from "../../math";
|
||||
|
||||
export type ElementUpdate<TElement extends ExcalidrawElement> = Omit<
|
||||
Partial<TElement>,
|
||||
|
@ -27,7 +27,7 @@ export const mutateElement = <TElement extends Mutable<ExcalidrawElement>>(
|
|||
const { points, fileId } = updates as any;
|
||||
|
||||
if (typeof points !== "undefined") {
|
||||
updates = { ...getSizeFromPoints(points), ...updates };
|
||||
updates = { ...pointExtent(points), ...updates };
|
||||
}
|
||||
|
||||
for (const key in updates) {
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import { MIN_FONT_SIZE, SHIFT_LOCKING_ANGLE } from "../constants";
|
||||
import { rescalePoints } from "../points";
|
||||
import type {
|
||||
ExcalidrawLinearElement,
|
||||
ExcalidrawTextElement,
|
||||
|
@ -62,6 +61,7 @@ import {
|
|||
pointFromPair,
|
||||
pointRotateRads,
|
||||
type Radians,
|
||||
pointRescaleFromTopLeft,
|
||||
} from "../../math";
|
||||
|
||||
// Returns true when transform (resizing/rotation) happened
|
||||
|
@ -191,10 +191,10 @@ export const rescalePointsInElement = (
|
|||
) =>
|
||||
isLinearElement(element) || isFreeDrawElement(element)
|
||||
? {
|
||||
points: rescalePoints(
|
||||
points: pointRescaleFromTopLeft(
|
||||
0,
|
||||
width,
|
||||
rescalePoints(1, height, element.points, normalizePoints),
|
||||
pointRescaleFromTopLeft(1, height, element.points, normalizePoints),
|
||||
normalizePoints,
|
||||
),
|
||||
}
|
||||
|
@ -674,14 +674,14 @@ export const resizeSingleElement = (
|
|||
let rescaledElementPointsY;
|
||||
let rescaledPoints;
|
||||
if (isLinearElement(element) || isFreeDrawElement(element)) {
|
||||
rescaledElementPointsY = rescalePoints(
|
||||
rescaledElementPointsY = pointRescaleFromTopLeft(
|
||||
1,
|
||||
eleNewHeight,
|
||||
(stateAtResizeStart as ExcalidrawLinearElement).points,
|
||||
true,
|
||||
);
|
||||
|
||||
rescaledPoints = rescalePoints(
|
||||
rescaledPoints = pointRescaleFromTopLeft(
|
||||
0,
|
||||
eleNewWidth,
|
||||
rescaledElementPointsY,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import type { Radians } from "../../math";
|
||||
import {
|
||||
pointExtent,
|
||||
point,
|
||||
pointScaleFromOrigin,
|
||||
pointTranslate,
|
||||
|
@ -12,7 +13,6 @@ import {
|
|||
type Vector,
|
||||
} from "../../math";
|
||||
import BinaryHeap from "../binaryheap";
|
||||
import { getSizeFromPoints } from "../points";
|
||||
import { aabbForElement, pointInsideBounds } from "../shapes";
|
||||
import { isAnyTrue, toBrandedType } from "../utils";
|
||||
import {
|
||||
|
@ -955,7 +955,7 @@ const normalizedArrowElementUpdate = (
|
|||
points,
|
||||
x: offsetX + (externalOffsetX ?? 0),
|
||||
y: offsetY + (externalOffsetY ?? 0),
|
||||
...getSizeFromPoints(points),
|
||||
...pointExtent(points),
|
||||
};
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue