tav-media
Version:
Cross platform media editing framework
248 lines (247 loc) • 9.6 kB
TypeScript
import { tav } from "../tav";
import { Point } from "./types";
/**
* Rect holds four float coordinates describing the upper and lower bounds of a rectangle. Rect may
* be created from outer bounds or from position, width, and height. Rect describes an area; if its
* right is less than or equal to its left, or if its bottom is less than or equal to its top, it is
* considered empty.
*/
export declare class Rect {
private _nativeRect;
/**
* Make new constructed Rect set to (0, 0, 0, 0), or create from an existing Rect.
* @param nativeRect Existing native rect object.
*/
constructor(nativeRect?: tav.TAVRect);
/**
* Returns constructed Rect set to (0, 0, 0, 0).
*/
static MakeEmpty(): Rect;
/**
* Returns constructed Rect set to float values (0, 0, w, h). Does not validate input; w or h may
* be negative.
*/
static MakeWH(width: number, height: number): Rect;
/**
* Returns constructed Rect set to (l, t, r, b). Does not sort input; Rect may result in left
* greater than right, or top greater than bottom.
*/
static MakeLTRB(left: number, top: number, right: number, bottom: number): Rect;
/**
* Returns constructed Rect set to (x, y, x + w, y + h). Does not validate input; w or h may be
* negative.
*/
static MakeXYWH(x: number, y: number, width: number, height: number): Rect;
/**
* Returns true if a intersects b. Returns false if either a or b is empty, or do not intersect.
*/
static Intersects(a: Rect, b: Rect): boolean;
/**
* smaller x-axis bounds.
*/
get left(): number;
/**
* smaller y-axis bounds.
*/
get top(): number;
/**
* larger x-axis bounds.
*/
get right(): number;
/**
* larger y-axis bounds.
*/
get bottom(): number;
build(): tav.TAVRect;
/**
* Returns true if left is equal to or greater than right, or if top is equal to or greater
* than bottom. Call sort() to reverse rectangles with negative width() or height().
*/
isEmpty(): boolean;
/**
* Returns true if left is equal to or less than right, or if top is equal to or less than
* bottom. Call sort() to reverse rectangles with negative width() or height().
*/
isSorted(): boolean;
/**
* Returns left edge of Rect, if sorted. Call isSorted() to see if Rect is valid. Call sort() to
* reverse left and right if needed.
*/
x(): number;
/**
* Returns top edge of Rect, if sorted. Call isEmpty() to see if Rect may be invalid, and sort()
* to reverse top and bottom if needed.
*/
y(): number;
/**
* Returns span on the x-axis. This does not check if Rect is sorted, or if result fits in 32-bit
* float; result may be negative or infinity.
*/
width(): number;
/**
* Returns span on the y-axis. This does not check if Rect is sorted, or if result fits in 32-bit
* float; result may be negative or infinity.
*/
height(): number;
/**
* Returns average of left edge and right edge. Result does not change if Rect is sorted.
*/
centerX(): number;
/**
* Returns average of top edge and bottom edge. Result does not change if Rect is sorted.
*/
centerY(): number;
/**
* Sets Rect to (0, 0, 0, 0).
*/
setEmpty(): void;
/**
* Sets Rect to (left, top, right, bottom). left and right are not sorted; left is not necessarily
* less than right. top and bottom are not sorted; top is not necessarily less than bottom.
*/
setLTRB(left: number, top: number, right: number, bottom: number): void;
/**
* Sets to bounds of Point array with count entries. Returns false if count is zero or smaller, or
* if Point array contains an infinity or NaN; in these cases sets Rect to (0, 0, 0, 0).
* Result is either empty or sorted: left is less than or equal to right, and top is less than
* or equal to bottom.
*/
setBounds(pts: Point[]): void;
/**
* Sets Rect to (x, y, x + width, y + height). Does not validate input; width or height may be
* negative.
*/
setXYWH(x: number, y: number, width: number, height: number): void;
/**
* Sets Rect to (0, 0, width, height). Does not validate input, width or height may be negative.
*/
setWH(width: number, height: number): void;
/**
* Returns Rect offset by (dx, dy).
* If dx is negative, Rect returned is moved to the left.
* If dx is positive, Rect returned is moved to the right.
* If dy is negative, Rect returned is moved upward.
* If dy is positive, Rect returned is moved downward.
*/
makeOffset(dx: number, dy: number): Rect;
/**
* Returns Rect, inset by (dx, dy).
* If dx is negative, Rect returned is wider.
* If dx is positive, Rect returned is narrower.
* If dy is negative, Rect returned is taller.
* If dy is positive, Rect returned is shorter.
*/
makeInset(dx: number, dy: number): Rect;
/**
* Returns Rect, outset by (dx, dy).
* If dx is negative, Rect returned is narrower.
* If dx is positive, Rect returned is wider.
* If dy is negative, Rect returned is shorter.
* If dy is positive, Rect returned is taller.
*/
makeOutset(dx: number, dy: number): Rect;
/**
* Offsets Rect by adding dx to left, right; and by adding dy to top, bottom.
* If dx is negative, moves Rect to the left.
* If dx is positive, moves Rect to the right.
* If dy is negative, moves Rect upward.
* If dy is positive, moves Rect downward.
*/
offset(dx: number, dy: number): void;
/**
* Offsets Rect by adding delta.x to left, right; and by adding delta.y to top, bottom.
* If delta.x is negative, moves Rect to the left.
* If delta.x is positive, moves Rect to the right.
* If delta.y is negative, moves Rect upward.
* If delta.y is positive, moves Rect downward.
*/
offsetPoint(delta: Point): void;
/**
* Offsets Rect so that left equals newX, and top equals newY. width and height are unchanged.
*/
offsetTo(x: number, y: number): void;
/**
* Insets Rect by (dx, dy).
* If dx is positive, makes Rect narrower.
* If dx is negative, makes Rect wider.
* If dy is positive, makes Rect shorter.
* If dy is negative, makes Rect taller.
*/
inset(dx: number, dy: number): void;
/**
* Outsets Rect by (dx, dy).
* If dx is positive, makes Rect wider.
* If dx is negative, makes Rect narrower.
* If dy is positive, makes Rect taller.
* If dy is negative, makes Rect shorter.
*/
outset(dx: number, dy: number): void;
/**
* Scale the rectangle by scaleX and scaleY.
*/
scale(scaleX: number, scaleY: number): void;
/**
* Constructs Rect to intersect from (left, top, right, bottom). Does not sort construction.
* Returns true if Rect intersects construction, and sets Rect to intersection.
* Returns false if Rect does not intersect construction, and leaves Rect unchanged.
* Returns false if either construction or Rect is empty, leaving Rect unchanged.
*/
intersect(l: number, t: number, r: number, b: number): boolean;
/**
* Returns true if Rect intersects r, and sets Rect to intersection. Returns false if Rect does
* not intersect r, and leaves Rect unchanged. Returns false if either r or Rect is empty, leaving
* Rect unchanged.
*/
intersectRect(r: Rect): boolean;
/**
* Returns true if Rect intersects r. Returns false if either r or Rect is empty, or do not
* intersect.
*/
intersects(l: number, t: number, r: number, b: number): boolean;
/**
* Returns true if Rect intersects r. Returns false if either r or Rect is empty, or do not
* intersect.
*/
intersectsRect(r: Rect): boolean;
/**
* Constructs Rect to intersect from (left, top, right, bottom). Does not sort construction.
* Sets Rect to the union of itself and the construction. Has no effect if construction is empty.
* Otherwise, if Rect is empty, sets Rect to construction.
*/
join(l: number, t: number, r: number, b: number): void;
/**
* Sets Rect to the union of itself and r. Has no effect if r is empty. Otherwise, if Rect is
* empty, sets Rect to r.
*/
joinRect(a: Rect, b: Rect): void;
/**
* Returns true if: left <= x < right && top <= y < bottom. Returns false if Rect is empty.
*/
contains(x: number, y: number): boolean;
/**
* Returns true if Rect contains r. Returns false if Rect is empty or r is empty. Rect contains r
* when Rect area completely includes r area.
*/
containsRect(r: Rect): boolean;
/**
* Sets Rect by rounding of left, top, right and bottom.
*/
round(): void;
/**
* Sets Rect by discarding the fractional portion of left and top; and rounding up right and
* bottom.
*/
roundOut(): void;
/**
* Swaps left and right if left is greater than right; and swaps top and bottom if top is
* greater than bottom. Result may be empty; and width() and height() will be zero or positive.
*/
sort(): void;
/**
* Returns Rect with left and right swapped if left is greater than right, and with top and
* bottom swapped if top is greater than bottom. Result may be empty, and width() and height()
* will be zero or positive.
*/
makeSorted(): Rect;
private makeNativeRect;
}