@core-graphics/rect
Version:
JS utilities for managing rects
115 lines (114 loc) • 3.55 kB
TypeScript
import { Point, PointValue } from "@core-graphics/point";
import { Size, SizeValue } from "@core-graphics/size";
/**
* A structure that contains the location and dimensions of a rectangle.
*/
export declare class Rect {
/**
* A point that specifies the coordinates of the rectangle’s origin.
*/
origin: Point;
/**
* A size that specifies the height and width of the rectangle.
*/
size: Size;
/**
* Creates a rectangle with the specified origin and size.
*/
constructor(value: RectValue);
/**
* Creates a Rect from specified point and size as arguments
*/
static create: (rect: RectValue) => Rect;
/**
* Returns a new rect with updated origin
*/
withOrigin: (origin: Partial<PointValue>) => Rect;
/**
* Returns a new rect with updated size
*/
withSize(size: Partial<SizeValue>): Rect;
/**
* Create a copy of the current rectangle
*/
clone: () => Rect;
/**
* The rectangle whose origin and size are both zero.
*/
static get zero(): Rect;
/**
* Creates a rectangle with origin (0,0) and size (0,0).
*/
static init: () => Rect;
/**
* Returns a string representation of the rect
*/
toString: () => string;
/**
* Returns the JSON representation of the rect
*/
toJSON: () => {
height: number;
width: number;
x: number;
y: number;
};
get value(): {
height: number;
width: number;
x: number;
y: number;
};
get area(): number;
get x(): number;
get y(): number;
get width(): number;
get height(): number;
get minX(): number;
get midX(): number;
get maxX(): number;
get minY(): number;
get midY(): number;
get maxY(): number;
get topLeftPoint(): Point;
get topRightPoint(): Point;
get bottomLeftPoint(): Point;
get bottomRightPoint(): Point;
get centerPoint(): Point;
get cornerPoints(): RectPoints;
get topCenterPoint(): Point;
get rightCenterPoint(): Point;
get bottomCenterPoint(): Point;
get leftCenterPoint(): Point;
get centerPoints(): RectPoints;
get isEmpty(): boolean;
get edges(): RectEdges;
getPoint(point: RectPoint): Point;
/**
* Updates the values for the rect
*/
set: (rect: Partial<RectValue>) => this;
/**
* Resets the rectangle to its initial values
*/
reset: () => this;
/**
* Returns the smallest rect that results from
* converting the source rect values to integers.
*/
toIntegral: () => Rect;
/**
* Returns the rect with values rounded to nearest pixel value.
*/
round: (decimal?: number | undefined) => this;
static isEqual: (a: Rect | undefined, b: Rect | undefined) => boolean;
static is: (value: any) => value is RectValue;
static cast: (value: Rect | RectValue) => Rect;
}
export declare type RectValue = PointValue & SizeValue;
export declare type RectPoints = [Point, Point, Point, Point];
declare type RectEdgePoints = [Point, Point];
export declare type RectEdge = "top" | "right" | "bottom" | "left";
export declare type RectPoint = "top-left" | "top-center" | "top-right" | "right-center" | "left-center" | "bottom-left" | "bottom-right" | "bottom-center" | "center";
export declare type RectEdges = Record<RectEdge, RectEdgePoints>;
export {};