Further math refactor and simplifications

This commit is contained in:
Mark Tolmacs 2024-09-23 17:13:40 +02:00
parent 41885b4bb3
commit 0e2f8c958e
No known key found for this signature in database
18 changed files with 262 additions and 175 deletions

View 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>;
}