UNPKG

ecspresso

Version:

A minimal Entity-Component-System library for typescript and javascript.

132 lines (131 loc) 4.01 kB
/** * Shared vector math utilities for ECSpresso bundles. * All functions are pure — they return new vectors, never mutate inputs. */ /** * A 2D vector with x and y components. */ export interface Vector2D { x: number; y: number; } /** * Create a Vector2D from x and y components. */ export declare function vec2(x: number, y: number): Vector2D; /** * Return a zero vector {x: 0, y: 0}. */ export declare function vec2Zero(): Vector2D; /** * Add two vectors component-wise. */ export declare function vec2Add(a: Vector2D, b: Vector2D): Vector2D; /** * Subtract b from a component-wise. */ export declare function vec2Sub(a: Vector2D, b: Vector2D): Vector2D; /** * Scale a vector by a scalar. */ export declare function vec2Scale(v: Vector2D, scalar: number): Vector2D; /** * Negate a vector (flip both components). */ export declare function vec2Negate(v: Vector2D): Vector2D; /** * Compute the dot product of two vectors. */ export declare function vec2Dot(a: Vector2D, b: Vector2D): number; /** * Compute the 2D cross product (scalar z-component of the 3D cross product). */ export declare function vec2Cross(a: Vector2D, b: Vector2D): number; /** * Compute the squared length of a vector. Avoids sqrt when only comparing magnitudes. */ export declare function vec2LengthSq(v: Vector2D): number; /** * Compute the length (magnitude) of a vector. */ export declare function vec2Length(v: Vector2D): number; /** * Return a unit vector in the same direction. Returns zero vector if input is zero-length. */ export declare function vec2Normalize(v: Vector2D): Vector2D; /** * Compute the squared distance between two points. Avoids sqrt when only comparing. */ export declare function vec2DistanceSq(a: Vector2D, b: Vector2D): number; /** * Compute the distance between two points. */ export declare function vec2Distance(a: Vector2D, b: Vector2D): number; /** * Check if two vectors are approximately equal within an epsilon tolerance. */ export declare function vec2Equals(a: Vector2D, b: Vector2D, epsilon?: number): boolean; /** * A 3D vector with x, y, and z components. */ export interface Vector3D { x: number; y: number; z: number; } /** * Create a Vector3D from x, y, and z components. */ export declare function vec3(x: number, y: number, z: number): Vector3D; /** * Return a zero vector {x: 0, y: 0, z: 0}. */ export declare function vec3Zero(): Vector3D; /** * Add two vectors component-wise. */ export declare function vec3Add(a: Vector3D, b: Vector3D): Vector3D; /** * Subtract b from a component-wise. */ export declare function vec3Sub(a: Vector3D, b: Vector3D): Vector3D; /** * Scale a vector by a scalar. */ export declare function vec3Scale(v: Vector3D, scalar: number): Vector3D; /** * Negate a vector (flip all components). */ export declare function vec3Negate(v: Vector3D): Vector3D; /** * Compute the dot product of two vectors. */ export declare function vec3Dot(a: Vector3D, b: Vector3D): number; /** * Compute the cross product of two vectors. */ export declare function vec3Cross(a: Vector3D, b: Vector3D): Vector3D; /** * Compute the squared length of a vector. Avoids sqrt when only comparing magnitudes. */ export declare function vec3LengthSq(v: Vector3D): number; /** * Compute the length (magnitude) of a vector. */ export declare function vec3Length(v: Vector3D): number; /** * Return a unit vector in the same direction. Returns zero vector if input is zero-length. */ export declare function vec3Normalize(v: Vector3D): Vector3D; /** * Compute the squared distance between two points. Avoids sqrt when only comparing. */ export declare function vec3DistanceSq(a: Vector3D, b: Vector3D): number; /** * Compute the distance between two points. */ export declare function vec3Distance(a: Vector3D, b: Vector3D): number; /** * Check if two vectors are approximately equal within an epsilon tolerance. */ export declare function vec3Equals(a: Vector3D, b: Vector3D, epsilon?: number): boolean;