@technobuddha/library
Version: 
A large library of useful functions
43 lines (42 loc) • 1.22 kB
TypeScript
import { type Cartesian, type Polygon, type Rect } from './@types/geometry.ts';
/**
 * Converts two {@link Cartesian} points into a {@link Polygon}.
 *
 * Construct a rectangle defined by two points as opposite corners.
 * @param pointA - The first corner point of the rectangle.
 * @param pointB - The opposite corner point of the rectangle.
 * @returns A rectangle shaped {@link Polygon}.
 * @example
 * ```typescript
 * toPolygon({ x: 1, y: 2 }, { x: 4, y: 6 });
 * // [
 * //   { x: 1, y: 2 },
 * //   { x: 4, y: 2 },
 * //   { x: 4, y: 6 },
 * //   { x: 1, y: 6 }
 * // ]
 * ```
 * @group Geometry
 * @category Polygon
 */
export declare function toPolygon(pointA: Cartesian, pointB: Cartesian): Polygon;
/**
 * Convert a {@link Rect} into a {@link Polygon}.
 *
 * Construct a rectangle defined by location and dimensions.
 * @param rect - The {@link Rect} to convert.
 * @returns A rectangle shaped {@link Polygon}.
 * @example
 * ```typescript
 * toPolygon({ x: 1, y: 2, width: 3, height: 4 });
 * // [
 * //   { x: 1, y: 2 },
 * //   { x: 4, y: 2 },
 * //   { x: 4, y: 6 },
 * //   { x: 1, y: 6 }
 * // ]
 * ```
 * @group Geometry
 * @category Polygon
 */
export declare function toPolygon(rect: Rect): Polygon;