UNPKG

gl2d

Version:

2D graphics package for WebGL

905 lines (904 loc) 30.9 kB
import { Point, PointLike } from "./point"; import { Vec2Like } from "./vec2"; import { Struct } from "gulp-structify/struct"; import { StructBuffer } from "gulp-structify/buffer"; /** * A rectangle with (left, top, right, bottom) boundaries. */ export declare class Rect { static ltrb(left: number, top: number, right: number, bottom: number): Rect; static lbrt(left: number, bottom: number, right: number, top: number): Rect; static lrbt(left: number, right: number, bottom: number, top: number): Rect; static ltwh(left: number, top: number, width: number, height: number): Rect; static lbwh(left: number, bottom: number, width: number, height: number): Rect; static unionOfPoints(points: PointLike[], offset?: number, count?: number): Rect; static unionOfPoints$(points: Float32Array, offset?: number, count?: number): Rect; static create(other: RectLike): Rect; /** * The left boundary of this Rect. */ left: number; /** * The top boundary of this Rect. */ top: number; /** * The right boundary of this Rect. */ right: number; /** * The bottom boundary of this Rect. */ bottom: number; /** * A rectangle with (left, top, right, bottom) boundaries. */ constructor(left?: number, top?: number, right?: number, bottom?: number); /** * Sets the boundaries of this Rect in left-top-right-bottom order. */ setLtrb(left: number, top: number, right: number, bottom: number): void; /** * Sets the boundaries of this Rect in left-bottom-right-top order. */ setLbrt(left: number, bottom: number, right: number, top: number): void; /** * Sets the boundaries of this Rect in left-right-bottom-top order. */ setLrbt(left: number, right: number, bottom: number, top: number): void; /** * Sets the dimensions of this rect in left-top-width-height order. */ setLtwh(left: number, top: number, width: number, height: number): void; /** * Sets the dimensions of this rect in left-bottom-width-height order. */ setLbwh(left: number, bottom: number, width: number, height: number): void; /** * Checks if this Rect is empty. True if left >= right or bottom >= top. */ isEmpty(): boolean; /** * Checks if the boundaries of this Rect represent a valid rectangle. True if right >= left and top >= bottom. */ isValid(): boolean; /** * Computes the width of this Rect. */ width(): number; /** * Computes the height of this Rect. */ height(): number; /** * Computes the area of this Rect. */ area(): number; /** * Finds the x-coordinate of the point at the center of this Rect. */ centerX(): number; /** * Finds the y-coordinate of the point at the center of this Rect. */ centerY(): number; /** * Gets the point at the center of this Rect */ center(): Point; /** * Gets the point between the top left and top right corners of this Rect. */ centerTop(): Point; /** * Gets the point between the bottom left and bottom right corners of this Rect. */ centerBottom(): Point; /** * Gets the point between the top and bottom left corners of this Rect. */ centerLeft(): Point; /** * Gets the point between the top and bottom right corners of this Rect. */ centerRight(): Point; /** * Gets the point at the bottom left corner of this Rect. */ bottomLeft(): Point; /** * Gets the point at the bottom right corner of this Rect. */ bottomRight(): Point; /** * Gets the point at the top left corner of this Rect. */ topLeft(): Point; /** * Gets the point at the top right corner of this Rect. */ topRight(): Point; /** * Gets the four corners of this Rect entered in CCW order beginning with the top left vertex. */ corners(): Point[]; /** * Sets this Rect to the empty rect (0,0,0,0). */ empty(): void; /** * Sets this Rect to the smallest rectangle containing the two specified points. */ setUnionOfPoints(points: PointLike[], offset?: number, count?: number): void; /** * Sets this Rect to the smallest rectangle containing a subset of points in the specified array. * @param points array of points entered as a series of (x,y) coordinates. * @param offset offset of the first point in the subset. * @param count number of points in the subset. */ setUnionOfPoints$(points: Float32Array, offset?: number, count?: number): void; /** * Checks if this Rect contains the other Rect. */ containsRect(other: RectLike): boolean; /** * Checks if this Rect contains the specified point. */ contains(p: PointLike): boolean; /** * Checks if this Rect contains the point (x,y). */ contains$(x: number, y: number): boolean; /** * Checks if this Rect intersects the other Rect. */ intersects(other: RectLike): boolean; /** * Sets this Rect to the intersection of itself with the other Rect. */ intersect(other: RectLike): void; /** * Expands this Rect to enclose the other Rect. */ union(other: RectLike): void; /** * Expands this Rect to enclose the specified point. */ unionPoint(p: PointLike): void; /** * Expands this Rect to enclose the point (x,y). */ unionPoint$(x: number, y: number): void; /** * Expands this Rect to enclose the specified points * @param points array of points. * @param offset offset of the first point in the subset. * @param count number of points in the subset. */ unionPoints(points: PointLike[], offset?: number, count?: number): void; /** * Expands this Rect to enclose the specified points * @param points array of points entered as a series of (x,y) coordinates. * @param offset offset of the first point in the subset. * @param count number of points in the subset. */ unionPoints$(points: Float32Array, offset?: number, count?: number): void; /** * Insets the boundaries of this Rect by the specified vector. */ inset(vec: Vec2Like): void; /** * Insets the boundaries of this Rect by the vector (dx,dy). */ inset$(dx: number, dy: number): void; /** * Offsets the boundaries of this Rect by the specified vector. */ offset(vec: Vec2Like): void; /** * Offsets the boundaries of this Rect by the vector (dx,dy). */ offset$(dx: number, dy: number): void; /** * Scales this Rect out from it's center by the specified (sx,sy) percentages. * @param r the Rect to scale. * @param sx the percentage by which to scale in the horizontal direction. * @param sy the percentage by which to scale in the vertical direction. */ scale(sx: number, sy: number): void; /** * Stretches this Rect out from it's center by the specified ratio, maintaining aspect. * @param ratio the percentage by which to stretch in all directions. */ stretch(ratio: number): void; /** * Shrinks this Rect to a square with the same center point. */ shrinkToSquare(): void; /** * Expands this Rect to a square with the same center point. */ expandToSquare(): void; /** * Swaps the top/bottom or left/right boundaries of this Rect if they are flipped, meaning left > right and/or top > bottom. */ sort(): void; /** * Sets each component of this Rect to that of the other Rect. */ set(other: RectLike): void; /** * Sets each component of this Rect. */ set$(left: number, top: number, right: number, bottom: number): void; /** * Sets each component of this Rect to the specified scalar. */ setScalar(k: number): void; /** * Adds the other Rect to this Rect componentwise. */ add(other: RectLike): void; /** * Adds the specified values to this Rect componentwise. */ add$(left: number, top: number, right: number, bottom: number): void; /** * Subtracts the other Rect from this Rect componentwise. */ subtract(other: RectLike): void; /** * Subtracts the specified values from this Rect componentwise. */ subtract$(left: number, top: number, right: number, bottom: number): void; /** * Multiplies each component of this Rect by the specified scalar. */ mulScalar(k: number): void; /** * Divides each component of this Rect by the specified scalar. */ divScalar(k: number): void; /** * Checks if each component of this Rect is exactly equal to that of the other Rect. */ equals(other: RectLike): boolean; /** * Checks if each component of this Rect is exactly equal to the specified scalar. */ equalsScalar(k: number): boolean; /** * Checks if each component of this Rect is approximately equal to that of the other Rect. */ epsilonEquals(other: RectLike, e: number): boolean; /** * Checks if each component of this Rect is approximately equal to the specified scalar. */ epsilonEqualsScalar(k: number, e: number): boolean; /** * Returns a string representation of this Rect. */ toString(): string; } /** * A rectangle with (left, top, right, bottom) boundaries. */ export interface RectLike { /** * The left boundary of this Rect. */ left: number; /** * The top boundary of this Rect. */ top: number; /** * The right boundary of this Rect. */ right: number; /** * The bottom boundary of this Rect. */ bottom: number; } /** * A Rect backed by a Float32Array. */ export declare class RectStruct extends Struct<Float32Array> { static ltrb(left: number, top: number, right: number, bottom: number): RectStruct; static lbrt(left: number, bottom: number, right: number, top: number): RectStruct; static lrbt(left: number, right: number, bottom: number, top: number): RectStruct; static ltwh(left: number, top: number, width: number, height: number): RectStruct; static lbwh(left: number, bottom: number, width: number, height: number): RectStruct; static unionOfPoints(points: PointLike[], offset?: number, count?: number): RectStruct; static unionOfPoints$(points: Float32Array, offset?: number, count?: number): RectStruct; static create(other: RectLike): RectStruct; static create$(left: number, top: number, right: number, bottom: number): RectStruct; /** * Sets the boundaries of this Rect in left-top-right-bottom order. */ setLtrb: (left: number, top: number, right: number, bottom: number) => void; /** * Sets the boundaries of this Rect in left-bottom-right-top order. */ setLbrt: (left: number, bottom: number, right: number, top: number) => void; /** * Sets the boundaries of this Rect in left-right-bottom-top order. */ setLrbt: (left: number, right: number, bottom: number, top: number) => void; /** * Sets the dimensions of this rect in left-top-width-height order. */ setLtwh: (left: number, top: number, width: number, height: number) => void; /** * Sets the dimensions of this rect in left-bottom-width-height order. */ setLbwh: (left: number, bottom: number, width: number, height: number) => void; /** * Checks if this Rect is empty. True if left >= right or bottom >= top. */ isEmpty: () => boolean; /** * Checks if the boundaries of this Rect represent a valid rectangle. True if right >= left and top >= bottom. */ isValid: () => boolean; /** * Computes the width of this Rect. */ width: () => number; /** * Computes the height of this Rect. */ height: () => number; /** * Computes the area of this Rect. */ area: () => number; /** * Finds the x-coordinate of the point at the center of this Rect. */ centerX: () => number; /** * Finds the y-coordinate of the point at the center of this Rect. */ centerY: () => number; /** * Gets the point at the center of this Rect */ center: () => Point; /** * Gets the point between the top left and top right corners of this Rect. */ centerTop: () => Point; /** * Gets the point between the bottom left and bottom right corners of this Rect. */ centerBottom: () => Point; /** * Gets the point between the top and bottom left corners of this Rect. */ centerLeft: () => Point; /** * Gets the point between the top and bottom right corners of this Rect. */ centerRight: () => Point; /** * Gets the point at the bottom left corner of this Rect. */ bottomLeft: () => Point; /** * Gets the point at the bottom right corner of this Rect. */ bottomRight: () => Point; /** * Gets the point at the top left corner of this Rect. */ topLeft: () => Point; /** * Gets the point at the top right corner of this Rect. */ topRight: () => Point; /** * Gets the four corners of this Rect entered in CCW order beginning with the top left vertex. */ corners: () => Point[]; /** * Sets this Rect to the empty rect (0,0,0,0). */ empty: () => void; /** * Sets this Rect to the smallest rectangle containing the two specified points. */ setUnionOfPoints: (points: PointLike[], offset?: number, count?: number) => void; /** * Sets this Rect to the smallest rectangle containing a subset of points in the specified array. * @param points array of points entered as a series of (x,y) coordinates. * @param offset offset of the first point in the subset. * @param count number of points in the subset. */ setUnionOfPoints$: (points: Float32Array, offset?: number, count?: number) => void; /** * Checks if this Rect contains the other Rect. */ containsRect: (other: RectLike) => boolean; /** * Checks if this Rect contains the specified point. */ contains: (p: PointLike) => boolean; /** * Checks if this Rect contains the point (x,y). */ contains$: (x: number, y: number) => boolean; /** * Checks if this Rect intersects the other Rect. */ intersects: (other: RectLike) => boolean; /** * Sets this Rect to the intersection of itself with the other Rect. */ intersect: (other: RectLike) => void; /** * Expands this Rect to enclose the other Rect. */ union: (other: RectLike) => void; /** * Expands this Rect to enclose the specified point. */ unionPoint: (p: PointLike) => void; /** * Expands this Rect to enclose the point (x,y). */ unionPoint$: (x: number, y: number) => void; /** * Expands this Rect to enclose the specified points * @param points array of points. * @param offset offset of the first point in the subset. * @param count number of points in the subset. */ unionPoints: (points: PointLike[], offset?: number, count?: number) => void; /** * Expands this Rect to enclose the specified points * @param points array of points entered as a series of (x,y) coordinates. * @param offset offset of the first point in the subset. * @param count number of points in the subset. */ unionPoints$: (points: Float32Array, offset?: number, count?: number) => void; /** * Insets the boundaries of this Rect by the specified vector. */ inset: (vec: Vec2Like) => void; /** * Insets the boundaries of this Rect by the vector (dx,dy). */ inset$: (dx: number, dy: number) => void; /** * Offsets the boundaries of this Rect by the specified vector. */ offset: (vec: Vec2Like) => void; /** * Offsets the boundaries of this Rect by the vector (dx,dy). */ offset$: (dx: number, dy: number) => void; /** * Scales this Rect out from it's center by the specified (sx,sy) percentages. * @param r the Rect to scale. * @param sx the percentage by which to scale in the horizontal direction. * @param sy the percentage by which to scale in the vertical direction. */ scale: (sx: number, sy: number) => void; /** * Stretches this Rect out from it's center by the specified ratio, maintaining aspect. * @param ratio the percentage by which to stretch in all directions. */ stretch: (ratio: number) => void; /** * Shrinks this Rect to a square with the same center point. */ shrinkToSquare: () => void; /** * Expands this Rect to a square with the same center point. */ expandToSquare: () => void; /** * Swaps the top/bottom or left/right boundaries of this Rect if they are flipped, meaning left > right and/or top > bottom. */ sort: () => void; /** * Sets each component of this Rect to that of the other Rect. */ set: (other: RectLike) => void; /** * Sets each component of this Rect. */ set$: (left: number, top: number, right: number, bottom: number) => void; /** * Sets each component of this Rect to the specified scalar. */ setScalar: (k: number) => void; /** * Adds the other Rect to this Rect componentwise. */ add: (other: RectLike) => void; /** * Adds the specified values to this Rect componentwise. */ add$: (left: number, top: number, right: number, bottom: number) => void; /** * Subtracts the other Rect from this Rect componentwise. */ subtract: (other: RectLike) => void; /** * Subtracts the specified values from this Rect componentwise. */ subtract$: (left: number, top: number, right: number, bottom: number) => void; /** * Multiplies each component of this Rect by the specified scalar. */ mulScalar: (k: number) => void; /** * Divides each component of this Rect by the specified scalar. */ divScalar: (k: number) => void; /** * Checks if each component of this Rect is exactly equal to that of the other Rect. */ equals: (other: RectLike) => boolean; /** * Checks if each component of this Rect is exactly equal to the specified scalar. */ equalsScalar: (k: number) => boolean; /** * Checks if each component of this Rect is approximately equal to that of the other Rect. */ epsilonEquals: (other: RectLike, e: number) => boolean; /** * Checks if each component of this Rect is approximately equal to the specified scalar. */ epsilonEqualsScalar: (k: number, e: number) => boolean; /** * Returns a string representation of this Rect. */ toString: () => string; /** * Creates a Rect struct backed by the specified data. */ constructor(data?: Float32Array); /** * The left boundary of this Rect. */ /** * The left boundary of this Rect. */ left: number; /** * The top boundary of this Rect. */ /** * The top boundary of this Rect. */ top: number; /** * The right boundary of this Rect. */ /** * The right boundary of this Rect. */ right: number; /** * The bottom boundary of this Rect. */ /** * The bottom boundary of this Rect. */ bottom: number; } /** * A Rect buffer backed by a Float32Array. */ export declare class RectBuffer extends StructBuffer<Float32Array> { /** * Creates an empty Rect buffer with the specified Rect capacity. */ static create(capacity: number): RectBuffer; /** * Sets the boundaries of this Rect in left-top-right-bottom order. */ setLtrb: (left: number, top: number, right: number, bottom: number) => void; /** * Sets the boundaries of this Rect in left-bottom-right-top order. */ setLbrt: (left: number, bottom: number, right: number, top: number) => void; /** * Sets the boundaries of this Rect in left-right-bottom-top order. */ setLrbt: (left: number, right: number, bottom: number, top: number) => void; /** * Sets the dimensions of this rect in left-top-width-height order. */ setLtwh: (left: number, top: number, width: number, height: number) => void; /** * Sets the dimensions of this rect in left-bottom-width-height order. */ setLbwh: (left: number, bottom: number, width: number, height: number) => void; /** * Checks if this Rect is empty. True if left >= right or bottom >= top. */ isEmpty: () => boolean; /** * Checks if the boundaries of this Rect represent a valid rectangle. True if right >= left and top >= bottom. */ isValid: () => boolean; /** * Computes the width of this Rect. */ width: () => number; /** * Computes the height of this Rect. */ height: () => number; /** * Computes the area of this Rect. */ area: () => number; /** * Finds the x-coordinate of the point at the center of this Rect. */ centerX: () => number; /** * Finds the y-coordinate of the point at the center of this Rect. */ centerY: () => number; /** * Gets the point at the center of this Rect */ center: () => Point; /** * Gets the point between the top left and top right corners of this Rect. */ centerTop: () => Point; /** * Gets the point between the bottom left and bottom right corners of this Rect. */ centerBottom: () => Point; /** * Gets the point between the top and bottom left corners of this Rect. */ centerLeft: () => Point; /** * Gets the point between the top and bottom right corners of this Rect. */ centerRight: () => Point; /** * Gets the point at the bottom left corner of this Rect. */ bottomLeft: () => Point; /** * Gets the point at the bottom right corner of this Rect. */ bottomRight: () => Point; /** * Gets the point at the top left corner of this Rect. */ topLeft: () => Point; /** * Gets the point at the top right corner of this Rect. */ topRight: () => Point; /** * Gets the four corners of this Rect entered in CCW order beginning with the top left vertex. */ corners: () => Point[]; /** * Sets this Rect to the empty rect (0,0,0,0). */ empty: () => void; /** * Sets this Rect to the smallest rectangle containing the two specified points. */ setUnionOfPoints: (points: PointLike[], offset?: number, count?: number) => void; /** * Sets this Rect to the smallest rectangle containing a subset of points in the specified array. * @param points array of points entered as a series of (x,y) coordinates. * @param offset offset of the first point in the subset. * @param count number of points in the subset. */ setUnionOfPoints$: (points: Float32Array, offset?: number, count?: number) => void; /** * Checks if this Rect contains the other Rect. */ containsRect: (other: RectLike) => boolean; /** * Checks if this Rect contains the specified point. */ contains: (p: PointLike) => boolean; /** * Checks if this Rect contains the point (x,y). */ contains$: (x: number, y: number) => boolean; /** * Checks if this Rect intersects the other Rect. */ intersects: (other: RectLike) => boolean; /** * Sets this Rect to the intersection of itself with the other Rect. */ intersect: (other: RectLike) => void; /** * Expands this Rect to enclose the other Rect. */ union: (other: RectLike) => void; /** * Expands this Rect to enclose the specified point. */ unionPoint: (p: PointLike) => void; /** * Expands this Rect to enclose the point (x,y). */ unionPoint$: (x: number, y: number) => void; /** * Expands this Rect to enclose the specified points * @param points array of points. * @param offset offset of the first point in the subset. * @param count number of points in the subset. */ unionPoints: (points: PointLike[], offset?: number, count?: number) => void; /** * Expands this Rect to enclose the specified points * @param points array of points entered as a series of (x,y) coordinates. * @param offset offset of the first point in the subset. * @param count number of points in the subset. */ unionPoints$: (points: Float32Array, offset?: number, count?: number) => void; /** * Insets the boundaries of this Rect by the specified vector. */ inset: (vec: Vec2Like) => void; /** * Insets the boundaries of this Rect by the vector (dx,dy). */ inset$: (dx: number, dy: number) => void; /** * Offsets the boundaries of this Rect by the specified vector. */ offset: (vec: Vec2Like) => void; /** * Offsets the boundaries of this Rect by the vector (dx,dy). */ offset$: (dx: number, dy: number) => void; /** * Scales this Rect out from it's center by the specified (sx,sy) percentages. * @param r the Rect to scale. * @param sx the percentage by which to scale in the horizontal direction. * @param sy the percentage by which to scale in the vertical direction. */ scale: (sx: number, sy: number) => void; /** * Stretches this Rect out from it's center by the specified ratio, maintaining aspect. * @param ratio the percentage by which to stretch in all directions. */ stretch: (ratio: number) => void; /** * Shrinks this Rect to a square with the same center point. */ shrinkToSquare: () => void; /** * Expands this Rect to a square with the same center point. */ expandToSquare: () => void; /** * Swaps the top/bottom or left/right boundaries of this Rect if they are flipped, meaning left > right and/or top > bottom. */ sort: () => void; /** * Sets each component of this Rect to that of the other Rect. */ set: (other: RectLike) => void; /** * Sets each component of this Rect. */ set$: (left: number, top: number, right: number, bottom: number) => void; /** * Sets each component of this Rect to the specified scalar. */ setScalar: (k: number) => void; /** * Adds the other Rect to this Rect componentwise. */ add: (other: RectLike) => void; /** * Adds the specified values to this Rect componentwise. */ add$: (left: number, top: number, right: number, bottom: number) => void; /** * Subtracts the other Rect from this Rect componentwise. */ subtract: (other: RectLike) => void; /** * Subtracts the specified values from this Rect componentwise. */ subtract$: (left: number, top: number, right: number, bottom: number) => void; /** * Multiplies each component of this Rect by the specified scalar. */ mulScalar: (k: number) => void; /** * Divides each component of this Rect by the specified scalar. */ divScalar: (k: number) => void; /** * Checks if each component of this Rect is exactly equal to that of the other Rect. */ equals: (other: RectLike) => boolean; /** * Checks if each component of this Rect is exactly equal to the specified scalar. */ equalsScalar: (k: number) => boolean; /** * Checks if each component of this Rect is approximately equal to that of the other Rect. */ epsilonEquals: (other: RectLike, e: number) => boolean; /** * Checks if each component of this Rect is approximately equal to the specified scalar. */ epsilonEqualsScalar: (k: number, e: number) => boolean; /** * Returns a string representation of this Rect. */ toString: () => string; /** * The left boundary of the current Rect. */ /** * The left boundary of the current Rect. */ left: number; /** * The top boundary of the current Rect. */ /** * The top boundary of the current Rect. */ top: number; /** * The right boundary of the current Rect. */ /** * The right boundary of the current Rect. */ right: number; /** * The bottom boundary of the current Rect. */ /** * The bottom boundary of the current Rect. */ bottom: number; /** * Gets the number of properties in a Rect, namely 4. */ structLength(): number; /** * Gets the components of the Rect at the specified position of this buffer. */ aget(position: number, dst?: RectLike): RectLike; /** * Gets the components of the current Rect, then moves to the next position of this buffer. */ rget(dst?: RectLike): RectLike; /** * Sets each component of the Rect at the specified position to that of the src Rect. */ aset(position: number, src: RectLike): void; /** * Sets each component of the Rect at the specified position. */ aset$(position: number, left: number, top: number, right: number, bottom: number): void; /** * Sets each component of the current Rect to that of the src Rect, then moves to the next position of this buffer. */ rset(src: RectLike): void; /** * Sets each component of the current Rect, then moves to the next position of this buffer. */ rset$(left: number, top: number, right: number, bottom: number): void; }