You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
success/packages/math/rectangle.ts

29 lines
653 B
TypeScript

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