UNPKG

@rpgjs/physic

Version:

A deterministic 2D top-down physics library for RPG, sandbox and MMO games

206 lines 5.33 kB
import { Vector2 } from './Vector2'; /** * Axis-Aligned Bounding Box (AABB) * * Represents a rectangular bounding box aligned with the coordinate axes. * Used for fast collision detection and spatial queries. * * @example * ```typescript * const box = new AABB(0, 0, 10, 10); * const point = new Vector2(5, 5); * if (box.contains(point)) { * // Point is inside the box * } * ``` */ export declare class AABB { /** * Minimum X coordinate (left edge) */ minX: number; /** * Minimum Y coordinate (bottom edge) */ minY: number; /** * Maximum X coordinate (right edge) */ maxX: number; /** * Maximum Y coordinate (top edge) */ maxY: number; /** * Creates a new AABB * * @param minX - Minimum X coordinate * @param minY - Minimum Y coordinate * @param maxX - Maximum X coordinate * @param maxY - Maximum Y coordinate */ constructor(minX: number, minY: number, maxX: number, maxY: number); /** * Creates an AABB from center and size * * @param centerX - Center X coordinate * @param centerY - Center Y coordinate * @param width - Width of the box * @param height - Height of the box * @returns New AABB */ static fromCenterSize(centerX: number, centerY: number, width: number, height: number): AABB; /** * Creates an AABB from a center point and size * * @param center - Center point * @param width - Width of the box * @param height - Height of the box * @returns New AABB */ static fromCenterSizeVector(center: Vector2, width: number, height: number): AABB; /** * Creates a copy of this AABB * * @returns New AABB with the same values */ clone(): AABB; /** * Copies values from another AABB * * @param other - AABB to copy from * @returns This AABB for chaining */ copyFrom(other: AABB): AABB; /** * Gets the width of the AABB * * @returns Width */ getWidth(): number; /** * Gets the height of the AABB * * @returns Height */ getHeight(): number; /** * Gets the center point of the AABB * * @returns Center point */ getCenter(): Vector2; /** * Gets the center X coordinate * * @returns Center X */ getCenterX(): number; /** * Gets the center Y coordinate * * @returns Center Y */ getCenterY(): number; /** * Gets the area of the AABB * * @returns Area */ getArea(): number; /** * Checks if a point is inside this AABB * * @param x - Point X coordinate * @param y - Point Y coordinate * @returns True if point is inside */ containsPoint(x: number, y: number): boolean; /** * Checks if a vector point is inside this AABB * * @param point - Point to check * @returns True if point is inside */ contains(point: Vector2): boolean; /** * Checks if another AABB is completely inside this AABB * * @param other - AABB to check * @returns True if other AABB is inside */ containsAABB(other: AABB): boolean; /** * Checks if this AABB intersects with another AABB * * @param other - AABB to check intersection with * @returns True if AABBs intersect */ intersects(other: AABB): boolean; /** * Calculates the intersection AABB with another AABB * * @param other - AABB to intersect with * @returns Intersection AABB, or null if no intersection */ intersection(other: AABB): AABB | null; /** * Calculates the union AABB with another AABB * * @param other - AABB to union with * @returns Union AABB */ union(other: AABB): AABB; /** * Expands this AABB by a given amount in all directions * * @param amount - Amount to expand by * @returns New expanded AABB */ expand(amount: number): AABB; /** * Expands this AABB by a given amount (in-place) * * @param amount - Amount to expand by * @returns This AABB for chaining */ expandInPlace(amount: number): AABB; /** * Translates this AABB by a given offset * * @param dx - X offset * @param dy - Y offset * @returns New translated AABB */ translate(dx: number, dy: number): AABB; /** * Translates this AABB by a given offset (in-place) * * @param dx - X offset * @param dy - Y offset * @returns This AABB for chaining */ translateInPlace(dx: number, dy: number): AABB; /** * Checks if this AABB equals another (with epsilon tolerance) * * @param other - AABB to compare * @param epsilon - Tolerance for comparison (default: 1e-5) * @returns True if AABBs are approximately equal */ equals(other: AABB, epsilon?: number): boolean; /** * Returns a string representation of this AABB * * @returns String representation */ toString(): string; /** * Clamps a point to be inside the AABB * * @param point - Point to clamp * @returns Clamped point */ clamp(point: Vector2): Vector2; } //# sourceMappingURL=AABB.d.ts.map