@box2d/debug-draw
Version:
Debug drawing helper for @box2d
460 lines • 15.4 kB
TypeScript
import type { b2Readonly } from "./b2_readonly";
export declare const b2_pi_over_180: number;
export declare const b2_180_over_pi: number;
export declare const b2_two_pi: number;
export declare function b2Clamp(a: number, low: number, high: number): number;
export declare function b2DegToRad(degrees: number): number;
export declare function b2RadToDeg(radians: number): number;
/**
* "Next Largest Power of 2
* Given a binary integer value x, the next largest power of 2 can be computed by a SWAR algorithm
* that recursively "folds" the upper bits into the lower bits. This process yields a bit vector with
* the same most significant 1 as x, but all 1's below it. Adding 1 to that value yields the next
* largest power of 2. For a 32-bit value:"
*/
export declare function b2NextPowerOfTwo(x: number): number;
export declare function b2IsPowerOfTwo(x: number): boolean;
export declare function b2Random(): number;
export declare function b2RandomFloat(lo: number, hi: number): number;
export declare function b2RandomInt(lo: number, hi: number): number;
export interface XY {
x: number;
y: number;
}
/**
* A 2D column vector.
*/
export declare class b2Vec2 implements XY {
static readonly ZERO: b2Readonly<b2Vec2>;
static readonly UNITX: b2Readonly<b2Vec2>;
static readonly UNITY: b2Readonly<b2Vec2>;
static readonly s_t0: b2Vec2;
static readonly s_t1: b2Vec2;
static readonly s_t2: b2Vec2;
static readonly s_t3: b2Vec2;
x: number;
y: number;
constructor(x?: number, y?: number);
Clone(): b2Vec2;
/**
* Set this vector to all zeros.
*/
SetZero(): this;
/**
* Set this vector to some specified coordinates.
*/
Set(x: number, y: number): this;
Copy(other: Readonly<XY>): this;
/**
* Add a vector to this vector.
*/
Add(v: Readonly<XY>): this;
/**
* Add a vector to this vector.
*/
AddXY(x: number, y: number): this;
/**
* Subtract a vector from this vector.
*/
Subtract(v: Readonly<XY>): this;
/**
* Subtract a vector from this vector.
*/
SubtractXY(x: number, y: number): this;
/**
* Multiply this vector by a scalar.
*/
Scale(s: number): this;
AddScaled(s: number, v: Readonly<XY>): this;
SubtractScaled(s: number, v: Readonly<XY>): this;
/**
* Perform the dot product on two vectors.
*/
Dot(v: Readonly<XY>): number;
/**
* Perform the cross product on two vectors. In 2D this produces a scalar.
*/
Cross(v: Readonly<XY>): number;
/**
* Get the length of this vector (the norm).
*/
Length(): number;
/**
* Get the length squared. For performance, use this instead of
* b2Vec2::Length (if possible).
*/
LengthSquared(): number;
/**
* Convert this vector into a unit vector. Returns the length.
*/
Normalize(): number;
Rotate(radians: number): this;
RotateCosSin(c: number, s: number): this;
/**
* Does this vector contain finite coordinates?
*/
IsValid(): boolean;
Abs(): this;
GetAbs<T extends XY>(out: T): T;
/**
* Negate this vector.
*/
Negate(): this;
/**
* Skew this vector such that dot(skew_vec, other) == cross(vec, other)
*/
Skew(): this;
static Min<T extends XY>(a: Readonly<XY>, b: Readonly<XY>, out: T): T;
static Max<T extends XY>(a: Readonly<XY>, b: Readonly<XY>, out: T): T;
static Clamp<T extends XY>(v: Readonly<XY>, lo: Readonly<XY>, hi: Readonly<XY>, out: T): T;
static Rotate<T extends XY>(v: Readonly<XY>, radians: number, out: T): T;
/** Perform the dot product on two vectors. */
static Dot(a: Readonly<XY>, b: Readonly<XY>): number;
/** Perform the cross product on two vectors. In 2D this produces a scalar. */
static Cross(a: Readonly<XY>, b: Readonly<XY>): number;
/**
* Perform the cross product on a vector and a scalar. In 2D this produces
* a vector.
*/
static CrossVec2Scalar<T extends XY>(v: Readonly<XY>, s: number, out: T): T;
static CrossVec2One<T extends XY>(v: Readonly<XY>, out: T): T;
/**
* Perform the cross product on a scalar and a vector. In 2D this produces
* a vector.
*/
static CrossScalarVec2<T extends XY>(s: number, v: Readonly<XY>, out: T): T;
static CrossOneVec2<T extends XY>(v: Readonly<XY>, out: T): T;
/**
* Add two vectors component-wise.
*/
static Add<T extends XY>(a: Readonly<XY>, b: Readonly<XY>, out: T): T;
/**
* Subtract two vectors component-wise.
*/
static Subtract<T extends XY>(a: Readonly<XY>, b: Readonly<XY>, out: T): T;
static Scale<T extends XY>(s: number, v: Readonly<XY>, out: T): T;
static AddScaled<T extends XY>(a: Readonly<XY>, s: number, b: Readonly<XY>, out: T): T;
static SubtractScaled<T extends XY>(a: Readonly<XY>, s: number, b: Readonly<XY>, out: T): T;
static AddCrossScalarVec2<T extends XY>(a: Readonly<XY>, s: number, v: Readonly<XY>, out: T): T;
static Mid<T extends XY>(a: Readonly<XY>, b: Readonly<XY>, out: T): T;
static Extents<T extends XY>(a: Readonly<XY>, b: Readonly<XY>, out: T): T;
static Equals(a: Readonly<XY>, b: Readonly<XY>): boolean;
static Distance(a: Readonly<XY>, b: Readonly<XY>): number;
static DistanceSquared(a: Readonly<XY>, b: Readonly<XY>): number;
/**
* Negate a vector.
*/
static Negate<T extends XY>(v: Readonly<XY>, out: T): T;
static Normalize<T extends XY>(v: Readonly<XY>, out: T): T;
/**
* Skew a vector such that dot(skew_vec, other) == cross(vec, other)
*/
static Skew<T extends XY>(v: Readonly<XY>, out: T): T;
}
export interface XYZ extends XY {
z: number;
}
/**
* A 2D column vector with 3 elements.
*/
export declare class b2Vec3 implements XYZ {
static readonly ZERO: b2Readonly<b2Vec3>;
static readonly s_t0: b2Vec3;
x: number;
y: number;
z: number;
constructor(x?: number, y?: number, z?: number);
Clone(): b2Vec3;
/**
* Set this vector to all zeros.
*/
SetZero(): this;
/**
* Set this vector to some specified coordinates.
*/
Set(x: number, y: number, z: number): this;
Copy(other: Readonly<XYZ>): this;
/**
* Negate this vector.
*/
Negate(): this;
/**
* Add a vector to this vector.
*/
Add(v: Readonly<XYZ>): this;
/**
* Add a vector to this vector.
*/
AddXYZ(x: number, y: number, z: number): this;
/**
* Subtract a vector from this vector.
*/
Subtract(v: Readonly<XYZ>): this;
/**
* Subtract a vector from this vector.
*/
SubtractXYZ(x: number, y: number, z: number): this;
/**
* Multiply this vector by a scalar.
*/
Scale(s: number): this;
/**
* Perform the dot product on two vectors.
*/
static Dot(a: Readonly<XYZ>, b: Readonly<XYZ>): number;
/**
* Perform the cross product on two vectors.
*/
static Cross<T extends XYZ>(a: Readonly<XYZ>, b: Readonly<XYZ>, out: T): T;
}
/**
* A 2-by-2 matrix. Stored in column-major order.
*/
export declare class b2Mat22 {
static readonly IDENTITY: b2Readonly<b2Mat22>;
readonly ex: b2Vec2;
readonly ey: b2Vec2;
Clone(): b2Mat22;
/**
* Construct a matrix using columns.
*/
static FromColumns(c1: Readonly<XY>, c2: Readonly<XY>): b2Mat22;
/**
* Construct a matrix using scalars.
*/
static FromScalars(r1c1: number, r1c2: number, r2c1: number, r2c2: number): b2Mat22;
static FromAngle(radians: number): b2Mat22;
/**
* Set this matrix using scalars.
*/
SetScalars(r1c1: number, r1c2: number, r2c1: number, r2c2: number): this;
/**
* Initialize this matrix using columns.
*/
SetColumns(c1: Readonly<XY>, c2: Readonly<XY>): this;
SetAngle(radians: number): this;
Copy(other: b2Readonly<b2Mat22>): this;
/**
* Set this to the identity matrix.
*/
SetIdentity(): this;
/**
* Set this matrix to all zeros.
*/
SetZero(): this;
GetAngle(): number;
/**
* Solve A * x = b, where b is a column vector. This is more efficient
* than computing the inverse in one-shot cases.
*/
Solve<T extends XY>(b_x: number, b_y: number, out: T): T;
Abs(): this;
Inverse(): this;
Add(M: b2Readonly<b2Mat22>): this;
Subtract(M: b2Readonly<b2Mat22>): this;
GetInverse(out: b2Mat22): b2Mat22;
GetAbs(out: b2Mat22): b2Mat22;
/**
* Multiply a matrix times a vector. If a rotation matrix is provided,
* then this transforms the vector from one frame to another.
*/
static MultiplyVec2<T extends XY>(M: b2Readonly<b2Mat22>, v: Readonly<XY>, out: T): T;
/**
* Multiply a matrix transpose times a vector. If a rotation matrix is provided,
* then this transforms the vector from one frame to another (inverse transform).
*/
static TransposeMultiplyVec2<T extends XY>(M: b2Readonly<b2Mat22>, v: Readonly<XY>, out: T): T;
static Add(A: b2Readonly<b2Mat22>, B: b2Readonly<b2Mat22>, out: b2Mat22): b2Mat22;
/** A * B */
static Multiply(A: b2Readonly<b2Mat22>, B: b2Readonly<b2Mat22>, out: b2Mat22): b2Mat22;
/** A^T * B */
static TransposeMultiply(A: b2Readonly<b2Mat22>, B: b2Readonly<b2Mat22>, out: b2Mat22): b2Mat22;
}
/**
* A 3-by-3 matrix. Stored in column-major order.
*/
export declare class b2Mat33 {
static readonly IDENTITY: b2Readonly<b2Mat33>;
readonly ex: b2Vec3;
readonly ey: b2Vec3;
readonly ez: b2Vec3;
Clone(): b2Mat33;
/**
* Set this matrix using columns.
*/
SetColumns(c1: Readonly<XYZ>, c2: Readonly<XYZ>, c3: Readonly<XYZ>): this;
Copy(other: b2Readonly<b2Mat33>): this;
SetIdentity(): this;
/**
* Set this matrix to all zeros.
*/
SetZero(): this;
Add(M: b2Readonly<b2Mat33>): this;
/**
* Solve A * x = b, where b is a column vector. This is more efficient
* than computing the inverse in one-shot cases.
*/
Solve33<T extends XYZ>(b_x: number, b_y: number, b_z: number, out: T): T;
/**
* Solve A * x = b, where b is a column vector. This is more efficient
* than computing the inverse in one-shot cases. Solve only the upper
* 2-by-2 matrix equation.
*/
Solve22<T extends XY>(b_x: number, b_y: number, out: T): T;
/**
* Get the inverse of this matrix as a 2-by-2.
* Returns the zero matrix if singular.
*/
GetInverse22(M: b2Mat33): void;
/**
* Get the symmetric inverse of this matrix as a 3-by-3.
* Returns the zero matrix if singular.
*/
GetSymInverse33(M: b2Mat33): void;
/**
* Multiply a matrix times a vector.
*/
static MultiplyVec3<T extends XYZ>(A: b2Readonly<b2Mat33>, v: Readonly<XYZ>, out: T): T;
/**
* Multiply a matrix times a vector.
*/
static MultiplyVec2<T extends XY>(A: b2Readonly<b2Mat33>, v: Readonly<XY>, out: T): T;
}
/**
* Rotation
*/
export declare class b2Rot {
static readonly IDENTITY: b2Readonly<b2Rot>;
/** Sine */
s: number;
/** Cosine */
c: number;
/**
* Initialize from an angle in radians
*/
constructor(angle?: number);
Clone(): b2Rot;
Copy(other: b2Readonly<b2Rot>): this;
/**
* Set using an angle in radians.
*/
Set(angle: number): this;
/**
* Set to the identity rotation
*/
SetIdentity(): this;
/**
* Get the angle in radians
*/
GetAngle(): number;
/**
* Get the x-axis
*/
GetXAxis<T extends XY>(out: T): T;
/**
* Get the u-axis
*/
GetYAxis<T extends XY>(out: T): T;
/**
* Multiply two rotations: q * r
*/
static Multiply(q: b2Readonly<b2Rot>, r: b2Readonly<b2Rot>, out: b2Rot): b2Rot;
/**
* Transpose multiply two rotations: qT * r
*/
static TransposeMultiply(q: b2Readonly<b2Rot>, r: b2Readonly<b2Rot>, out: b2Rot): b2Rot;
/**
* Rotate a vector
*/
static MultiplyVec2<T extends XY>(q: b2Readonly<b2Rot>, v: Readonly<XY>, out: T): T;
/**
* Inverse rotate a vector
*/
static TransposeMultiplyVec2<T extends XY>(q: b2Readonly<b2Rot>, v: Readonly<XY>, out: T): T;
}
/**
* A transform contains translation and rotation. It is used to represent
* the position and orientation of rigid frames.
*/
export declare class b2Transform {
static readonly IDENTITY: b2Readonly<b2Transform>;
readonly p: b2Vec2;
readonly q: b2Rot;
Clone(): b2Transform;
Copy(other: b2Readonly<b2Transform>): this;
/**
* Set this to the identity transform.
*/
SetIdentity(): this;
/**
* Set this based on the position and rotation.
*/
SetPositionRotation(position: Readonly<XY>, q: b2Readonly<b2Rot>): this;
/**
* Set this based on the position and angle.
*/
SetPositionAngle(pos: Readonly<XY>, a: number): this;
SetPosition(position: Readonly<XY>): this;
SetPositionXY(x: number, y: number): this;
SetRotation(rotation: b2Readonly<b2Rot>): this;
SetRotationAngle(radians: number): this;
GetPosition(): b2Readonly<b2Vec2>;
GetRotation(): b2Readonly<b2Rot>;
GetAngle(): number;
static MultiplyVec2<T extends XY>(T: b2Readonly<b2Transform>, v: Readonly<XY>, out: T): T;
static TransposeMultiplyVec2<T extends XY>(T: b2Readonly<b2Transform>, v: Readonly<XY>, out: T): T;
/**
* v2 = A.q.Rot(B.q.Rot(v1) + B.p) + A.p
* = (A.q * B.q).Rot(v1) + A.q.Rot(B.p) + A.p
*/
static Multiply(A: b2Readonly<b2Transform>, B: b2Readonly<b2Transform>, out: b2Transform): b2Transform;
/**
* v2 = A.q' * (B.q * v1 + B.p - A.p)
* = A.q' * B.q * v1 + A.q' * (B.p - A.p)
*/
static TransposeMultiply(A: b2Readonly<b2Transform>, B: b2Readonly<b2Transform>, out: b2Transform): b2Transform;
}
/**
* This describes the motion of a body/shape for TOI computation.
* Shapes are defined with respect to the body origin, which may
* no coincide with the center of mass. However, to support dynamics
* we must interpolate the center of mass position.
*/
export declare class b2Sweep {
/** Local center of mass position */
readonly localCenter: b2Vec2;
/** Center world position at time 0 */
readonly c0: b2Vec2;
/** Center world position at time 1 */
readonly c: b2Vec2;
/** World angle at time 0 */
a0: number;
/** World angle at time 1 */
a: number;
/**
* Fraction of the current time step in the range [0,1]
* c0 and a0 are the positions at alpha0.
*/
alpha0: number;
Clone(): b2Sweep;
Copy(other: b2Sweep): this;
/**
* Get the interpolated transform at a specific time.
*
* @param transform The output transform
* @param beta Is a factor in [0,1], where 0 indicates alpha0.
* @see https://fgiesen.wordpress.com/2012/08/15/linear-interpolation-past-present-and-future/
*/
GetTransform(xf: b2Transform, beta: number): b2Transform;
/**
* Advance the sweep forward, yielding a new initial state.
*
* @param alpha The new initial time.
*/
Advance(alpha: number): void;
/**
* Normalize an angle in radians to be between -pi and pi
*/
Normalize(): void;
}
//# sourceMappingURL=b2_math.d.ts.map