UNPKG

@rpgjs/physic

Version:

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

144 lines 4.04 kB
import { Vector2 } from './Vector2'; import { AABB } from './AABB'; /** * Geometric utility functions * * Collection of deterministic geometric operations for 2D physics. */ /** * Tolerance for floating-point comparisons */ export declare const EPSILON = 0.00001; /** * Checks if two numbers are approximately equal * * @param a - First number * @param b - Second number * @param epsilon - Tolerance (default: EPSILON) * @returns True if numbers are approximately equal * * @example * ```typescript * approximatelyEqual(0.1 + 0.2, 0.3); // true * ``` */ export declare function approximatelyEqual(a: number, b: number, epsilon?: number): boolean; /** * Clamps a value between min and max * * @param value - Value to clamp * @param min - Minimum value * @param max - Maximum value * @returns Clamped value * * @example * ```typescript * clamp(15, 0, 10); // 10 * ``` */ export declare function clamp(value: number, min: number, max: number): number; /** * Linearly interpolates between two values * * @param a - Start value * @param b - End value * @param t - Interpolation factor (0 to 1) * @returns Interpolated value * * @example * ```typescript * lerp(0, 10, 0.5); // 5 * ``` */ export declare function lerp(a: number, b: number, t: number): number; /** * Calculates the distance between two points * * @param x1 - First point X * @param y1 - First point Y * @param x2 - Second point X * @param y2 - Second point Y * @returns Distance */ export declare function distance(x1: number, y1: number, x2: number, y2: number): number; /** * Calculates the squared distance between two points (faster, avoids sqrt) * * @param x1 - First point X * @param y1 - First point Y * @param x2 - Second point X * @param y2 - Second point Y * @returns Squared distance */ export declare function distanceSquared(x1: number, y1: number, x2: number, y2: number): number; /** * Calculates the angle between two points in radians * * @param x1 - First point X * @param y1 - First point Y * @param x2 - Second point X * @param y2 - Second point Y * @returns Angle in radians */ export declare function angleBetween(x1: number, y1: number, x2: number, y2: number): number; /** * Normalizes an angle to the range [-π, π] * * @param angle - Angle in radians * @returns Normalized angle * * @example * ```typescript * normalizeAngle(Math.PI * 3); // -Math.PI * ``` */ export declare function normalizeAngle(angle: number): number; /** * Calculates the shortest angular distance between two angles * * @param from - Start angle in radians * @param to - End angle in radians * @returns Shortest angular distance in radians */ export declare function angularDistance(from: number, to: number): number; /** * Projects a point onto a line segment * * @param point - Point to project * @param lineStart - Line segment start point * @param lineEnd - Line segment end point * @returns Projected point on the line segment */ export declare function projectPointOnLineSegment(point: Vector2, lineStart: Vector2, lineEnd: Vector2): Vector2; /** * Calculates the closest point on an AABB to a given point * * @param point - Point to find closest point for * @param aabb - AABB to check against * @returns Closest point on the AABB */ export declare function closestPointOnAABB(point: Vector2, aabb: AABB): Vector2; /** * Checks if a point is inside a circle * * @param point - Point to check * @param center - Circle center * @param radius - Circle radius * @returns True if point is inside the circle */ export declare function pointInCircle(point: Vector2, center: Vector2, radius: number): boolean; /** * Converts degrees to radians * * @param degrees - Angle in degrees * @returns Angle in radians */ export declare function degToRad(degrees: number): number; /** * Converts radians to degrees * * @param radians - Angle in radians * @returns Angle in degrees */ export declare function radToDeg(radians: number): number; //# sourceMappingURL=utils.d.ts.map