@itwin/core-react
Version:
A react component library of iTwin.js UI general purpose components
146 lines • 5.59 kB
TypeScript
/** @packageDocumentation
* @module Utilities
*/
import { Point } from "./Point.js";
import type { PointProps } from "./PointProps.js";
import type { SizeProps } from "./Size.js";
/** Describes 2d bounds.
* @public
* @deprecated in 4.16.0. Use {@link @itwin/appui-react#RectangleProps} instead.
*/
export interface RectangleProps {
readonly left: number;
readonly top: number;
readonly right: number;
readonly bottom: number;
}
/** Available corners of [[Rectangle]].
* @internal
*/
export declare enum Corner {
TopLeft = 0,
TopRight = 1,
BottomRight = 2,
BottomLeft = 3
}
/** Describes and provides methods to work with 2d bounds.
* @internal
*/
export declare class Rectangle implements RectangleProps {
readonly left: number;
readonly top: number;
readonly right: number;
readonly bottom: number;
/** Creates rectangle from [[RectangleProps]]. */
static create(props: RectangleProps): Rectangle;
/** Creates rectangle from [[SizeProps]]. */
static createFromSize(size: SizeProps): Rectangle;
/** Create a rectangle with 2 pairs of xy candidates. Theses are compared and shuffled as needed for the rectangle. */
static createXYXY(xA: number, yA: number, xB: number, yB: number): Rectangle;
/** Creates rectangle with specified bounds. */
constructor(left?: number, top?: number, right?: number, bottom?: number);
/** @returns Size of this rectangle. */
getSize(): SizeProps;
/** @returns Width of this rectangle. */
getWidth(): number;
/** @returns Height of this rectangle. */
getHeight(): number;
/** @returns Position of specified corner. */
getCorner(corner: Corner): Point;
/**
* Inset the bounds of this rectangle.
* @note Negative arguments will increase the size of rectangle.
* @returns New [[Rectangle]] with modified bounds.
*/
inset(left: number, top: number, right: number, bottom: number): Rectangle;
/**
* Offsets the rectangle along the X and Y axes.
* @returns New [[Rectangle]] with modified position.
*/
offset(offset: PointProps): Rectangle;
/**
* Offsets the rectangle along the X axis.
* @returns New [[Rectangle]] with modified position along X axis.
*/
offsetX(offset: number): Rectangle;
/**
* Offsets the rectangle along the Y axis.
* @returns New [[Rectangle]] with modified position along Y axis.
*/
offsetY(offset: number): Rectangle;
/**
* Moves the top left corner of rectangle to specified point.
* @returns New [[Rectangle]] with modified position.
*/
setPosition(position: PointProps): Rectangle;
/**
* Sets the height of the rectangle.
* @note Only [[Edge.Bottom]] is subject to change.
* @returns New [[Rectangle]] with modified height.
*/
setHeight(height: number): Rectangle;
/**
* Sets the width of the rectangle.
* @note Only [[Edge.Right]] is subject to change.
* @returns New [[Rectangle]] with modified width.
*/
setWidth(width: number): Rectangle;
/**
* Sets the height and width of the rectangle.
* @note Only [[Edge.Bottom]] and [[Edge.Right]] are subjects to change.
* @returns New [[Rectangle]] with modified height.
*/
setSize(size: SizeProps): Rectangle;
/** Checks if bounds of two rectangles match. */
equals(other: RectangleProps): boolean;
/**
* Checks if point is within bounds of the rectangle.
* @note Inclusive.
*/
containsPoint(point: PointProps): boolean;
/**
* Checks if a point given as x,y is within the rectangle.
* @note Inclusive.
*/
containsXY(x: number, y: number): boolean;
/**
* @returns true if this rectangle contains other rectangle.
* @note Inclusive.
*/
contains(other: RectangleProps): boolean;
/** @returns New [[Rectangle]] which is contained in other rectangle. */
containIn(other: RectangleProps): Rectangle;
/** @returns New [[Rectangle]] which is vertically contained in other rectangle. */
containVerticallyIn(other: RectangleProps): Rectangle;
/** @returns New [[Rectangle]] which is horizontally contained in other rectangle. */
containHorizontallyIn(other: RectangleProps): Rectangle;
/** @returns [[Corner.TopLeft]] position of this rectangle. */
topLeft(): Point;
/** @returns Center point position of this rectangle. */
center(): Point;
/** @returns true if this rectangle intersects other rectangle. */
intersects(other: RectangleProps): boolean;
/**
* Merges outer edges of this and other rectangles.
* @returns New [[Rectangle]] with merged bounds.
*/
outerMergeWith(other: RectangleProps): Rectangle;
/**
* Vertically divides this rectangle into specified number of equal height segments.
* @returns Vertical rectangle segment.
*/
getVerticalSegmentBounds(segmentId: number, numberOfSegments: number): Rectangle;
/**
* Horizontally divides this rectangle into specified number of equal width segments.
* @returns Horizontal rectangle segment.
*/
getHorizontalSegmentBounds(segmentId: number, numberOfSegments: number): Rectangle;
/**
* Calculates the shortest distance between this rectangle and a given point.
* @returns The shortest distance to a point.
*/
getShortestDistanceToPoint(point: PointProps): number;
/** @returns [[RectangleProps]] object for this rectangle. */
toProps(): RectangleProps;
}
//# sourceMappingURL=Rectangle.d.ts.map