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
28
packages/math/rectangle.ts
Normal file
28
packages/math/rectangle.ts
Normal file
|
@ -0,0 +1,28 @@
|
|||
import { invariant } from "../excalidraw/utils";
|
||||
import type { GenericPoint, Rectangle } from "./types";
|
||||
|
||||
export function rectangle<P extends GenericPoint>(
|
||||
a: P,
|
||||
b: P,
|
||||
c: P,
|
||||
d: P,
|
||||
): Rectangle<P> {
|
||||
return [a, b, c, d] as Rectangle<P>;
|
||||
}
|
||||
|
||||
export function rectangleFromQuad<P extends GenericPoint>(
|
||||
quad: [a: P, b: P, c: P, d: P],
|
||||
): Rectangle<P> {
|
||||
return quad as Rectangle<P>;
|
||||
}
|
||||
|
||||
export function rectangleFromArray<P extends GenericPoint>(
|
||||
pointArray: P[],
|
||||
): Rectangle<P> {
|
||||
invariant(
|
||||
pointArray.length === 4,
|
||||
"Point array contains more or less points to create a rectangle from",
|
||||
);
|
||||
|
||||
return pointArray as Rectangle<P>;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue