UNPKG

@esengine/nova-ecs-math

Version:

Comprehensive fixed-point mathematics library for deterministic calculations in games and simulations

1,227 lines (1,218 loc) 36.2 kB
import { Component } from '@esengine/nova-ecs'; export { Component, ComponentPool } from '@esengine/nova-ecs'; /** * Fixed-point number implementation for deterministic arithmetic * 用于确定性算术的定点数实现 */ declare class Fixed { private static readonly SCALE; private _value; private static readonly _cache; private static readonly MAX_CACHE_SIZE; /** * Create a new Fixed-point number * 创建新的定点数 * * @param value - The value to convert to fixed-point */ constructor(value: number | string | Fixed); /** * Create a Fixed number from raw internal value * 从原始内部值创建定点数 */ static fromRaw(rawValue: number): Fixed; /** * Create a cached Fixed number for commonly used values * 为常用值创建缓存的定点数 */ static cached(value: number): Fixed; /** * Add two fixed-point numbers * 两个定点数相加 */ add(other: Fixed): Fixed; /** * Add in place (modifies this instance for better performance) * 就地相加(修改当前实例以提高性能) */ addInPlace(other: Fixed): Fixed; /** * Subtract two fixed-point numbers * 两个定点数相减 */ subtract(other: Fixed): Fixed; /** * Subtract in place (modifies this instance for better performance) * 就地相减(修改当前实例以提高性能) */ subtractInPlace(other: Fixed): Fixed; /** * Multiply two fixed-point numbers * 两个定点数相乘 */ multiply(other: Fixed): Fixed; /** * Multiply in place (modifies this instance for better performance) * 就地相乘(修改当前实例以提高性能) */ multiplyInPlace(other: Fixed): Fixed; /** * Divide two fixed-point numbers * 两个定点数相除 */ divide(other: Fixed): Fixed; /** * Divide in place (modifies this instance for better performance) * 就地相除(修改当前实例以提高性能) */ divideInPlace(other: Fixed): Fixed; /** * Get the absolute value * 获取绝对值 */ abs(): Fixed; /** * Negate the value * 取负值 */ negate(): Fixed; /** * Calculate square root using Newton's method for deterministic results * 使用牛顿迭代法计算平方根,确保确定性结果 */ sqrt(): Fixed; /** * Static square root method * 静态平方根方法 */ static sqrt(value: Fixed): Fixed; /** * Normalize angle to [-π, π] range for trigonometric functions * 将角度标准化到[-π, π]范围用于三角函数 */ private static normalizeAngle; /** * Calculate sine using Taylor series for deterministic results * 使用泰勒级数计算正弦值,确保确定性结果 */ sin(): Fixed; /** * Static sine function using Taylor series * 使用泰勒级数的静态正弦函数 */ static sin(angle: Fixed): Fixed; /** * Calculate cosine using the identity cos(x) = sin(x + π/2) * 使用恒等式 cos(x) = sin(x + π/2) 计算余弦值 */ cos(): Fixed; /** * Static cosine function using cos(x) = sin(x + π/2) * 使用 cos(x) = sin(x + π/2) 的静态余弦函数 */ static cos(angle: Fixed): Fixed; /** * Calculate tangent * 计算正切值 */ tan(): Fixed; /** * Static tangent function * 静态正切函数 */ static tan(angle: Fixed): Fixed; /** * Calculate arcsine using Newton's method * 使用牛顿法计算反正弦值 */ asin(): Fixed; /** * Calculate arccosine * 计算反余弦值 */ acos(): Fixed; /** * Calculate arctangent using CORDIC algorithm * 使用CORDIC算法计算反正切值 */ atan(): Fixed; /** * Calculate atan2 for vector angles * 计算atan2用于向量角度 */ static atan2(y: Fixed, x: Fixed): Fixed; /** * Convert to regular number * 转换为普通数字 */ toNumber(): number; /** * Convert to string representation * 转换为字符串表示 */ toString(): string; /** * Check equality with another Fixed number * 检查与另一个定点数是否相等 */ equals(other: Fixed): boolean; /** * Check if this number is less than another * 检查是否小于另一个数 */ lessThan(other: Fixed): boolean; /** * Check if this number is less than or equal to another * 检查是否小于或等于另一个数 */ lessThanOrEqual(other: Fixed): boolean; /** * Check if this number is greater than another * 检查是否大于另一个数 */ greaterThan(other: Fixed): boolean; /** * Check if this number is greater than or equal to another * 检查是否大于或等于另一个数 */ greaterThanOrEqual(other: Fixed): boolean; /** * Get the raw internal value (for advanced usage) * 获取原始内部值(高级用法) */ get rawValue(): number; /** * Get the scale factor used for fixed-point arithmetic * 获取用于定点算术的比例因子 */ static get scale(): number; /** * Floor function - largest integer less than or equal to this value * 向下取整函数 */ floor(): Fixed; /** * Ceiling function - smallest integer greater than or equal to this value * 向上取整函数 */ ceil(): Fixed; /** * Round to nearest integer * 四舍五入到最近整数 */ round(): Fixed; /** * Get fractional part * 获取小数部分 */ frac(): Fixed; /** * Power function using exponentiation by squaring * 使用平方求幂的幂函数 */ pow(exponent: Fixed): Fixed; /** * Natural logarithm using Taylor series * 使用泰勒级数计算自然对数 */ ln(): Fixed; /** * Exponential function using Taylor series * 使用泰勒级数计算指数函数 */ exp(): Fixed; /** * Minimum of two values * 两个值的最小值 */ static min(a: Fixed, b: Fixed): Fixed; /** * Maximum of two values * 两个值的最大值 */ static max(a: Fixed, b: Fixed): Fixed; /** * Clamp value between min and max * 将值限制在最小值和最大值之间 */ clamp(min: Fixed, max: Fixed): Fixed; /** * Modulo operation - returns the remainder after division * 模运算 - 返回除法后的余数 */ mod(divisor: Fixed): Fixed; /** * Linear interpolation between two values * 两个值之间的线性插值 */ static lerp(a: Fixed, b: Fixed, t: Fixed): Fixed; static readonly ZERO: Fixed; static readonly ONE: Fixed; static readonly PI: Fixed; static readonly E: Fixed; static readonly HALF: Fixed; static readonly TWO: Fixed; static readonly PI_2: Fixed; static readonly PI_HALF: Fixed; static readonly PI_4: Fixed; static readonly PI_QUARTER: Fixed; static readonly TWO_PI: Fixed; static readonly PI_TWO: Fixed; static readonly DEG_TO_RAD: Fixed; static readonly RAD_TO_DEG: Fixed; private static readonly FACTORIALS; private static readonly SIN_TABLE; } /** * 2D Vector using fixed-point arithmetic for deterministic calculations * 使用定点算术的2D向量,用于确定性计算 */ declare class FixedVector2 { x: Fixed; y: Fixed; /** * Create a new 2D fixed-point vector * 创建新的2D定点向量 * * @param x - X component (can be Fixed or number) * @param y - Y component (can be Fixed or number) */ constructor(x?: Fixed | number, y?: Fixed | number); /** * Add two vectors * 两个向量相加 */ add(other: FixedVector2): FixedVector2; /** * Add in place (modifies this instance for better performance) * 就地相加(修改当前实例以提高性能) */ addInPlace(other: FixedVector2): FixedVector2; /** * Subtract two vectors * 两个向量相减 */ subtract(other: FixedVector2): FixedVector2; /** * Subtract in place (modifies this instance for better performance) * 就地相减(修改当前实例以提高性能) */ subtractInPlace(other: FixedVector2): FixedVector2; /** * Multiply vector by a scalar * 向量乘以标量 */ multiply(scalar: Fixed | number): FixedVector2; /** * Multiply in place (modifies this instance for better performance) * 就地相乘(修改当前实例以提高性能) */ multiplyInPlace(scalar: Fixed | number): FixedVector2; /** * Divide vector by a scalar * 向量除以标量 */ divide(scalar: Fixed | number): FixedVector2; /** * Divide in place (modifies this instance for better performance) * 就地相除(修改当前实例以提高性能) */ divideInPlace(scalar: Fixed | number): FixedVector2; /** * Calculate the magnitude (length) of the vector * 计算向量的大小(长度) */ magnitude(): Fixed; /** * Calculate the squared magnitude (more efficient than magnitude) * 计算平方大小(比magnitude更高效) */ sqrMagnitude(): Fixed; /** * Normalize the vector (make it unit length) * 归一化向量(使其长度为1) */ normalize(): FixedVector2; /** * Calculate dot product with another vector * 计算与另一个向量的点积 */ dot(other: FixedVector2): Fixed; /** * Calculate cross product with another vector (returns scalar for 2D) * 计算与另一个向量的叉积(2D返回标量) */ cross(other: FixedVector2): Fixed; /** * Calculate distance to another vector * 计算到另一个向量的距离 */ distance(other: FixedVector2): Fixed; /** * Calculate squared distance to another vector (more efficient) * 计算到另一个向量的平方距离(更高效) */ sqrDistance(other: FixedVector2): Fixed; /** * Negate the vector * 取向量的负值 */ negate(): FixedVector2; /** * Get the absolute values of components * 获取分量的绝对值 */ abs(): FixedVector2; /** * Check equality with another vector * 检查与另一个向量是否相等 */ equals(other: FixedVector2): boolean; /** * Convert to string representation * 转换为字符串表示 */ toString(): string; /** * Convert to array [x, y] * 转换为数组 [x, y] */ toArray(): [number, number]; /** * Create a copy of this vector * 创建此向量的副本 */ clone(): FixedVector2; /** * Set this vector's components from another vector (for reusing objects) * 从另一个向量设置此向量的分量(用于重用对象) */ setFrom(other: FixedVector2): FixedVector2; /** * Set this vector's components from coordinates (for reusing objects) * 从坐标设置此向量的分量(用于重用对象) */ set(x: Fixed | number, y: Fixed | number): FixedVector2; /** * Reset this vector to zero (for object pooling) * 将此向量重置为零(用于对象池) */ reset(): FixedVector2; static readonly ZERO: FixedVector2; static readonly ONE: FixedVector2; static readonly UP: FixedVector2; static readonly DOWN: FixedVector2; static readonly LEFT: FixedVector2; static readonly RIGHT: FixedVector2; /** * Linear interpolation between two vectors * 两个向量之间的线性插值 */ static lerp(a: FixedVector2, b: FixedVector2, t: Fixed | number): FixedVector2; /** * Calculate angle between two vectors in radians using deterministic math * 使用确定性数学计算两个向量之间的角度(弧度) */ static angle(a: FixedVector2, b: FixedVector2): Fixed; /** * Get the angle of this vector from the positive X axis * 获取此向量相对于正X轴的角度 */ angle(): Fixed; /** * Reflect this vector across a normal vector * 沿法向量反射此向量 * * @param normal - The normal vector to reflect across (should be normalized) * @returns The reflected vector */ reflect(normal: FixedVector2): FixedVector2; /** * Project this vector onto another vector * 将此向量投影到另一个向量上 * * @param onto - The vector to project onto * @returns The projected vector */ project(onto: FixedVector2): FixedVector2; /** * Get the component of this vector perpendicular to another vector * 获取此向量垂直于另一个向量的分量 * * @param onto - The vector to get the perpendicular component relative to * @returns The perpendicular component */ reject(onto: FixedVector2): FixedVector2; /** * Rotate this vector by the given angle in radians * 将此向量按给定角度(弧度)旋转 * * @param angle - Angle in radians * @returns The rotated vector */ rotate(angle: Fixed | number): FixedVector2; /** * Get a vector perpendicular to this one (rotated 90 degrees counter-clockwise) * 获取垂直于此向量的向量(逆时针旋转90度) */ perpendicular(): FixedVector2; /** * Get the right perpendicular vector (rotated 90 degrees clockwise) * 获取右垂直向量(顺时针旋转90度) */ perpendicularRight(): FixedVector2; /** * Create a vector from angle and magnitude * 从角度和大小创建向量 */ static fromAngle(angle: Fixed, magnitude?: Fixed): FixedVector2; } /** * 2x2 Matrix using fixed-point arithmetic for deterministic calculations * 使用定点算术的2x2矩阵,用于确定性计算 * * Matrix layout: * | m00 m01 | * | m10 m11 | */ declare class FixedMatrix2x2 { m00: Fixed; m01: Fixed; m10: Fixed; m11: Fixed; /** * Create a new 2x2 fixed-point matrix * 创建新的2x2定点矩阵 * * @param m00 - Element at row 0, column 0 * @param m01 - Element at row 0, column 1 * @param m10 - Element at row 1, column 0 * @param m11 - Element at row 1, column 1 */ constructor(m00?: Fixed | number, m01?: Fixed | number, m10?: Fixed | number, m11?: Fixed | number); /** * Create an identity matrix * 创建单位矩阵 */ static identity(): FixedMatrix2x2; /** * Create a zero matrix * 创建零矩阵 */ static zero(): FixedMatrix2x2; /** * Create a rotation matrix * 创建旋转矩阵 * * @param angle - Rotation angle in radians */ static rotation(angle: Fixed): FixedMatrix2x2; /** * Create a scaling matrix * 创建缩放矩阵 * * @param scaleX - Scale factor for X axis * @param scaleY - Scale factor for Y axis (defaults to scaleX for uniform scaling) */ static scaling(scaleX: Fixed, scaleY?: Fixed): FixedMatrix2x2; /** * Create a shear matrix * 创建剪切矩阵 * * @param shearX - Shear factor for X axis * @param shearY - Shear factor for Y axis */ static shear(shearX: Fixed, shearY: Fixed): FixedMatrix2x2; /** * Create a matrix from an array [m00, m01, m10, m11] * 从数组创建矩阵 [m00, m01, m10, m11] */ static fromArray(array: number[]): FixedMatrix2x2; /** * Add two matrices * 两个矩阵相加 */ add(other: FixedMatrix2x2): FixedMatrix2x2; /** * Add in place (modifies this instance for better performance) * 就地相加(修改当前实例以提高性能) */ addInPlace(other: FixedMatrix2x2): FixedMatrix2x2; /** * Subtract two matrices * 两个矩阵相减 */ subtract(other: FixedMatrix2x2): FixedMatrix2x2; /** * Subtract in place (modifies this instance for better performance) * 就地相减(修改当前实例以提高性能) */ subtractInPlace(other: FixedMatrix2x2): FixedMatrix2x2; /** * Multiply two matrices * 两个矩阵相乘 */ multiply(other: FixedMatrix2x2): FixedMatrix2x2; /** * Multiply matrix by a scalar * 矩阵乘以标量 */ multiplyScalar(scalar: Fixed): FixedMatrix2x2; /** * Multiply matrix by a scalar in place * 就地矩阵乘以标量 */ multiplyScalarInPlace(scalar: Fixed): FixedMatrix2x2; /** * Transform a vector by this matrix * 使用此矩阵变换向量 */ transformVector(vector: FixedVector2): FixedVector2; /** * Calculate the determinant of this matrix * 计算此矩阵的行列式 */ determinant(): Fixed; /** * Calculate the inverse of this matrix * 计算此矩阵的逆矩阵 */ inverse(): FixedMatrix2x2; /** * Transpose this matrix * 转置此矩阵 */ transpose(): FixedMatrix2x2; /** * Calculate the trace (sum of diagonal elements) of this matrix * 计算此矩阵的迹(对角线元素之和) */ trace(): Fixed; /** * Check if this matrix equals another matrix * 检查此矩阵是否等于另一个矩阵 */ equals(other: FixedMatrix2x2): boolean; /** * Check if this matrix is the identity matrix * 检查此矩阵是否为单位矩阵 */ isIdentity(): boolean; /** * Create a copy of this matrix * 创建此矩阵的副本 */ clone(): FixedMatrix2x2; /** * Convert to a regular number array [m00, m01, m10, m11] * 转换为普通数字数组 [m00, m01, m10, m11] */ toArray(): number[]; /** * Convert to string representation * 转换为字符串表示 */ toString(): string; static readonly IDENTITY: FixedMatrix2x2; static readonly ZERO: FixedMatrix2x2; } /** * Rectangle using fixed-point arithmetic for deterministic calculations * 使用定点算术的矩形,用于确定性计算 */ declare class FixedRect { x: Fixed; y: Fixed; width: Fixed; height: Fixed; /** * Create a new fixed-point rectangle * 创建新的定点矩形 * * @param x - X coordinate of the top-left corner * @param y - Y coordinate of the top-left corner * @param width - Width of the rectangle * @param height - Height of the rectangle */ constructor(x?: Fixed | number, y?: Fixed | number, width?: Fixed | number, height?: Fixed | number); /** * Get the left edge X coordinate * 获取左边缘X坐标 */ get left(): Fixed; /** * Get the right edge X coordinate * 获取右边缘X坐标 */ get right(): Fixed; /** * Get the top edge Y coordinate * 获取顶边Y坐标 */ get top(): Fixed; /** * Get the bottom edge Y coordinate * 获取底边Y坐标 */ get bottom(): Fixed; /** * Get the center point of the rectangle * 获取矩形的中心点 */ get center(): FixedVector2; /** * Get the top-left corner as a vector * 获取左上角作为向量 */ get topLeft(): FixedVector2; /** * Get the top-right corner as a vector * 获取右上角作为向量 */ get topRight(): FixedVector2; /** * Get the bottom-left corner as a vector * 获取左下角作为向量 */ get bottomLeft(): FixedVector2; /** * Get the bottom-right corner as a vector * 获取右下角作为向量 */ get bottomRight(): FixedVector2; /** * Check if a point is inside this rectangle * 检查点是否在此矩形内 */ contains(point: FixedVector2): boolean; /** * Check if a point is inside this rectangle (inclusive of edges) * 检查点是否在此矩形内(包含边缘) */ containsInclusive(point: FixedVector2): boolean; /** * Check if this rectangle intersects with another rectangle * 检查此矩形是否与另一个矩形相交 */ intersects(other: FixedRect): boolean; /** * Get the intersection rectangle with another rectangle * 获取与另一个矩形的交集矩形 */ intersection(other: FixedRect): FixedRect | null; /** * Get the union rectangle with another rectangle * 获取与另一个矩形的并集矩形 */ union(other: FixedRect): FixedRect; /** * Expand the rectangle by the given amount in all directions * 在所有方向上按给定量扩展矩形 */ expand(amount: Fixed | number): FixedRect; /** * Shrink the rectangle by the given amount in all directions * 在所有方向上按给定量收缩矩形 */ shrink(amount: Fixed | number): FixedRect; /** * Move the rectangle by the given offset * 按给定偏移量移动矩形 */ translate(offset: FixedVector2): FixedRect; /** * Create a copy of this rectangle * 创建此矩形的副本 */ clone(): FixedRect; /** * Check if this rectangle equals another rectangle * 检查此矩形是否等于另一个矩形 */ equals(other: FixedRect): boolean; /** * Get the area of the rectangle * 获取矩形的面积 */ area(): Fixed; /** * Get the perimeter of the rectangle * 获取矩形的周长 */ perimeter(): Fixed; /** * Check if the rectangle is empty (zero or negative area) * 检查矩形是否为空(零或负面积) */ isEmpty(): boolean; /** * Convert to string representation * 转换为字符串表示 */ toString(): string; /** * Convert to a regular number array [x, y, width, height] * 转换为普通数字数组 [x, y, width, height] */ toArray(): number[]; /** * Create a rectangle from an array [x, y, width, height] * 从数组创建矩形 [x, y, width, height] */ static fromArray(array: number[]): FixedRect; /** * Create a rectangle from two corner points * 从两个角点创建矩形 */ static fromCorners(corner1: FixedVector2, corner2: FixedVector2): FixedRect; /** * Create a rectangle centered at the given point * 创建以给定点为中心的矩形 */ static centered(center: FixedVector2, width: Fixed | number, height: Fixed | number): FixedRect; static readonly ZERO: FixedRect; static readonly UNIT: FixedRect; } /** * Circle using fixed-point arithmetic for deterministic calculations * 使用定点算术的圆形,用于确定性计算 */ declare class FixedCircle { center: FixedVector2; radius: Fixed; /** * Create a new fixed-point circle * 创建新的定点圆形 * * @param center - Center point of the circle * @param radius - Radius of the circle */ constructor(center: FixedVector2, radius: Fixed | number); constructor(x: Fixed | number, y: Fixed | number, radius: Fixed | number); /** * Get the X coordinate of the center * 获取中心点的X坐标 */ get x(): Fixed; /** * Set the X coordinate of the center * 设置中心点的X坐标 */ set x(value: Fixed | number); /** * Get the Y coordinate of the center * 获取中心点的Y坐标 */ get y(): Fixed; /** * Set the Y coordinate of the center * 设置中心点的Y坐标 */ set y(value: Fixed | number); /** * Get the diameter of the circle * 获取圆的直径 */ get diameter(): Fixed; /** * Set the diameter of the circle (updates radius) * 设置圆的直径(更新半径) */ set diameter(value: Fixed | number); /** * Check if a point is inside this circle * 检查点是否在此圆内 */ contains(point: FixedVector2): boolean; /** * Check if a point is inside this circle (inclusive of edge) * 检查点是否在此圆内(包含边缘) */ containsInclusive(point: FixedVector2): boolean; /** * Check if this circle intersects with another circle * 检查此圆是否与另一个圆相交 */ intersects(other: FixedCircle): boolean; /** * Check if this circle intersects with a rectangle * 检查此圆是否与矩形相交 */ intersectsRect(rect: FixedRect): boolean; /** * Check if this circle completely contains another circle * 检查此圆是否完全包含另一个圆 */ containsCircle(other: FixedCircle): boolean; /** * Check if this circle is completely contained within another circle * 检查此圆是否完全被另一个圆包含 */ isContainedBy(other: FixedCircle): boolean; /** * Get the area of the circle * 获取圆的面积 */ area(): Fixed; /** * Get the circumference of the circle * 获取圆的周长 */ circumference(): Fixed; /** * Get the bounding rectangle of the circle * 获取圆的边界矩形 */ getBounds(): FixedRect; /** * Move the circle by the given offset * 按给定偏移量移动圆 */ translate(offset: FixedVector2): FixedCircle; /** * Scale the circle by the given factor * 按给定因子缩放圆 */ scale(factor: Fixed | number): FixedCircle; /** * Get the closest point on the circle to the given point * 获取圆上距离给定点最近的点 */ closestPointTo(point: FixedVector2): FixedVector2; /** * Get the distance from the circle edge to the given point * 获取从圆边缘到给定点的距离 */ distanceToPoint(point: FixedVector2): Fixed; /** * Get a point on the circle at the given angle * 获取圆上给定角度的点 * * @param angle - Angle in radians (0 = right, π/2 = up) */ pointAtAngle(angle: Fixed | number): FixedVector2; /** * Get the angle from the center to the given point * 获取从中心到给定点的角度 */ angleToPoint(point: FixedVector2): Fixed; /** * Create a copy of this circle * 创建此圆的副本 */ clone(): FixedCircle; /** * Check if this circle equals another circle * 检查此圆是否等于另一个圆 */ equals(other: FixedCircle): boolean; /** * Convert to string representation * 转换为字符串表示 */ toString(): string; /** * Convert to a regular number array [x, y, radius] * 转换为普通数字数组 [x, y, radius] */ toArray(): number[]; /** * Create a circle from an array [x, y, radius] * 从数组创建圆 [x, y, radius] */ static fromArray(array: number[]): FixedCircle; /** * Create a circle that encompasses the given points * 创建包含给定点的圆 */ static fromPoints(points: FixedVector2[]): FixedCircle; /** * Create a circle from a bounding rectangle (inscribed circle) * 从边界矩形创建圆(内接圆) */ static inscribedInRect(rect: FixedRect): FixedCircle; /** * Create a circle from a bounding rectangle (circumscribed circle) * 从边界矩形创建圆(外接圆) */ static circumscribedAroundRect(rect: FixedRect): FixedCircle; static readonly ZERO: FixedCircle; static readonly UNIT: FixedCircle; } /** * Utility functions for geometric calculations using fixed-point arithmetic * 使用定点算术进行几何计算的实用函数 */ declare class GeometryUtils { /** * Calculate the distance between two points * 计算两点之间的距离 */ static distance(point1: FixedVector2, point2: FixedVector2): Fixed; /** * Calculate the squared distance between two points (faster than distance) * 计算两点之间的距离平方(比距离计算更快) */ static distanceSquared(point1: FixedVector2, point2: FixedVector2): Fixed; /** * Check if a point is inside a triangle * 检查点是否在三角形内 */ static pointInTriangle(point: FixedVector2, a: FixedVector2, b: FixedVector2, c: FixedVector2): boolean; /** * Calculate the area of a triangle * 计算三角形的面积 */ static triangleArea(a: FixedVector2, b: FixedVector2, c: FixedVector2): Fixed; /** * Calculate the centroid of a triangle * 计算三角形的重心 */ static triangleCentroid(a: FixedVector2, b: FixedVector2, c: FixedVector2): FixedVector2; /** * Check if two line segments intersect * 检查两条线段是否相交 */ static lineSegmentsIntersect(p1: FixedVector2, q1: FixedVector2, p2: FixedVector2, q2: FixedVector2): boolean; /** * Find the intersection point of two lines (not segments) * 找到两条直线(非线段)的交点 */ static lineIntersection(p1: FixedVector2, p2: FixedVector2, p3: FixedVector2, p4: FixedVector2): FixedVector2 | null; /** * Calculate the closest point on a line segment to a given point * 计算线段上距离给定点最近的点 */ static closestPointOnLineSegment(point: FixedVector2, lineStart: FixedVector2, lineEnd: FixedVector2): FixedVector2; /** * Check if a point is inside a polygon (using ray casting algorithm) * 检查点是否在多边形内(使用射线投射算法) */ static pointInPolygon(point: FixedVector2, polygon: FixedVector2[]): boolean; /** * Calculate the area of a polygon * 计算多边形的面积 */ static polygonArea(polygon: FixedVector2[]): Fixed; /** * Calculate the centroid of a polygon * 计算多边形的重心 */ static polygonCentroid(polygon: FixedVector2[]): FixedVector2; /** * Check if two rectangles intersect * 检查两个矩形是否相交 */ static rectanglesIntersect(rect1: FixedRect, rect2: FixedRect): boolean; /** * Check if two circles intersect * 检查两个圆是否相交 */ static circlesIntersect(circle1: FixedCircle, circle2: FixedCircle): boolean; /** * Check if a circle and rectangle intersect * 检查圆和矩形是否相交 */ static circleRectangleIntersect(circle: FixedCircle, rect: FixedRect): boolean; /** * Calculate the angle between two vectors * 计算两个向量之间的角度 */ static angleBetween(v1: FixedVector2, v2: FixedVector2): Fixed; /** * Clamp a point to be within a rectangle * 将点限制在矩形内 */ static clampPointToRect(point: FixedVector2, rect: FixedRect): FixedVector2; /** * Get the bounding rectangle of a set of points * 获取一组点的边界矩形 */ static getBoundingRect(points: FixedVector2[]): FixedRect; /** * Get the bounding circle of a set of points * 获取一组点的边界圆 */ static getBoundingCircle(points: FixedVector2[]): FixedCircle; } /** * Position component using fixed-point arithmetic * 使用定点算术的位置组件 */ declare class FixedPositionComponent extends Component { position: FixedVector2; /** * Create a new fixed-point position component * 创建新的定点位置组件 * * @param x - X coordinate (can be Fixed or number) * @param y - Y coordinate (can be Fixed or number) */ constructor(x?: Fixed | number, y?: Fixed | number); /** * Get X coordinate * 获取X坐标 */ get x(): Fixed; /** * Set X coordinate * 设置X坐标 */ set x(value: Fixed | number); /** * Get Y coordinate * 获取Y坐标 */ get y(): Fixed; /** * Set Y coordinate * 设置Y坐标 */ set y(value: Fixed | number); /** * Set position from coordinates * 从坐标设置位置 */ setPosition(x: Fixed | number, y: Fixed | number): void; /** * Set position from vector * 从向量设置位置 */ setPositionFromVector(vector: FixedVector2): void; /** * Reset component state * 重置组件状态 */ reset(): void; /** * Get serializable properties * 获取可序列化属性 */ getSerializableProperties(): Record<string, unknown>; /** * Set serializable properties * 设置可序列化属性 */ setSerializableProperties(properties: Record<string, unknown>): void; } /** * Velocity component using fixed-point arithmetic * 使用定点算术的速度组件 */ declare class FixedVelocityComponent extends Component { velocity: FixedVector2; /** * Create a new fixed-point velocity component * 创建新的定点速度组件 * * @param x - X velocity (can be Fixed or number) * @param y - Y velocity (can be Fixed or number) */ constructor(x?: Fixed | number, y?: Fixed | number); /** * Get X velocity * 获取X速度 */ get x(): Fixed; /** * Set X velocity * 设置X速度 */ set x(value: Fixed | number); /** * Get Y velocity * 获取Y速度 */ get y(): Fixed; /** * Set Y velocity * 设置Y速度 */ set y(value: Fixed | number); /** * Set velocity from coordinates * 从坐标设置速度 */ setVelocity(x: Fixed | number, y: Fixed | number): void; /** * Set velocity from vector * 从向量设置速度 */ setVelocityFromVector(vector: FixedVector2): void; /** * Reset component state * 重置组件状态 */ reset(): void; /** * Get serializable properties * 获取可序列化属性 */ getSerializableProperties(): Record<string, unknown>; /** * Set serializable properties * 设置可序列化属性 */ setSerializableProperties(properties: Record<string, unknown>): void; } /** * Acceleration component using fixed-point arithmetic * 使用定点算术的加速度组件 */ declare class FixedAccelerationComponent extends Component { acceleration: FixedVector2; /** * Create a new fixed-point acceleration component * 创建新的定点加速度组件 * * @param x - X acceleration (can be Fixed or number) * @param y - Y acceleration (can be Fixed or number) */ constructor(x?: Fixed | number, y?: Fixed | number); /** * Get X acceleration * 获取X加速度 */ get x(): Fixed; /** * Set X acceleration * 设置X加速度 */ set x(value: Fixed | number); /** * Get Y acceleration * 获取Y加速度 */ get y(): Fixed; /** * Set Y acceleration * 设置Y加速度 */ set y(value: Fixed | number); /** * Set acceleration from coordinates * 从坐标设置加速度 */ setAcceleration(x: Fixed | number, y: Fixed | number): void; /** * Set acceleration from vector * 从向量设置加速度 */ setAccelerationFromVector(vector: FixedVector2): void; /** * Reset component state * 重置组件状态 */ reset(): void; /** * Get serializable properties * 获取可序列化属性 */ getSerializableProperties(): Record<string, unknown>; /** * Set serializable properties * 设置可序列化属性 */ setSerializableProperties(properties: Record<string, unknown>): void; } export { Fixed, FixedAccelerationComponent, FixedCircle, FixedMatrix2x2, FixedPositionComponent, FixedRect, FixedVector2, FixedVelocityComponent, GeometryUtils };