@inglorious/utils 3.8.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/README.md +67 -3
  2. package/package.json +88 -12
  3. package/src/algorithms/decision-tree.js +3 -3
  4. package/src/algorithms/path-finding.js +6 -6
  5. package/src/data-structures/board.js +97 -15
  6. package/src/data-structures/index.js +1 -2
  7. package/src/data-structures/objects.js +352 -34
  8. package/src/data-structures/tree.js +1 -1
  9. package/src/functions/functions.js +168 -0
  10. package/src/functions/index.js +1 -4
  11. package/src/math/circle.js +5 -7
  12. package/src/math/index.js +0 -4
  13. package/src/math/line.js +3 -3
  14. package/src/math/point.js +10 -9
  15. package/src/math/quaternions.js +20 -4
  16. package/src/math/rectangle.js +4 -4
  17. package/src/math/segment.js +11 -5
  18. package/src/math/vectors.js +471 -65
  19. package/src/physics/acceleration.js +2 -3
  20. package/src/physics/friction.js +2 -2
  21. package/src/physics/gravity.js +2 -2
  22. package/src/physics/jump.js +0 -4
  23. package/src/physics/velocity.js +2 -3
  24. package/src/v.js +1 -1
  25. package/types/algorithms/decision-tree.d.ts +27 -0
  26. package/types/algorithms/index.d.ts +2 -0
  27. package/types/algorithms/path-finding.d.ts +69 -0
  28. package/types/data-structures/array.d.ts +56 -0
  29. package/types/data-structures/board.d.ts +121 -0
  30. package/types/data-structures/boolean.d.ts +4 -0
  31. package/types/data-structures/heap.d.ts +69 -0
  32. package/types/data-structures/index.d.ts +8 -0
  33. package/types/data-structures/objects.d.ts +237 -0
  34. package/types/data-structures/set.d.ts +4 -0
  35. package/types/data-structures/tree.d.ts +21 -0
  36. package/types/functions/functions.d.ts +57 -0
  37. package/types/functions/index.d.ts +1 -0
  38. package/types/index.d.ts +6 -4
  39. package/types/math/circle.d.ts +22 -0
  40. package/types/math/hitmask.d.ts +20 -0
  41. package/types/math/index.d.ts +14 -0
  42. package/types/math/line.d.ts +11 -0
  43. package/types/math/linear-interpolation.d.ts +2 -0
  44. package/types/math/numbers.d.ts +26 -0
  45. package/types/math/point.d.ts +25 -0
  46. package/types/math/quaternions.d.ts +10 -0
  47. package/types/math/rectangle.d.ts +36 -0
  48. package/types/math/rng.d.ts +14 -0
  49. package/types/math/segment.d.ts +23 -0
  50. package/types/math/statistics.d.ts +11 -0
  51. package/types/math/triangle.d.ts +5 -0
  52. package/types/math/trigonometry.d.ts +26 -0
  53. package/types/math/vectors.d.ts +190 -0
  54. package/types/physics/acceleration.d.ts +24 -0
  55. package/types/physics/friction.d.ts +11 -0
  56. package/types/physics/gravity.d.ts +20 -0
  57. package/types/physics/index.d.ts +5 -0
  58. package/types/physics/jump.d.ts +10 -0
  59. package/types/physics/velocity.d.ts +20 -0
  60. package/types/v.d.ts +7 -3
  61. package/src/data-structures/object.js +0 -320
  62. package/src/functions/function.js +0 -9
  63. package/src/math/quaternion.js +0 -22
  64. package/src/math/vector.js +0 -426
  65. package/types/algorithms.d.ts +0 -26
  66. package/types/data-structures.d.ts +0 -53
  67. package/types/math.d.ts +0 -90
@@ -0,0 +1 @@
1
+ export * from "./functions"
package/types/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
- export * from "./algorithms"
2
- export * from "./data-structures"
3
- export * from "./math"
4
- export * from "./v"
1
+ export * as algorithms from "./algorithms/index"
2
+ export * as dataStructures from "./data-structures/index"
3
+ export * as functions from "./functions/index"
4
+ export * as math from "./math/index"
5
+ export * as physics from "./physics/index"
6
+ export { v } from "./v"
@@ -0,0 +1,22 @@
1
+ import type { Point, PointInput } from "./point"
2
+ import type { Rectangle } from "./rectangle"
3
+
4
+ /** Represents a circle with a center and radius. */
5
+ export interface Circle {
6
+ /** The center of the circle. */
7
+ position: Point
8
+ /** The radius of the circle. */
9
+ radius: number
10
+ }
11
+
12
+ /** Checks whether a circle intersects a point. */
13
+ export function intersectsPoint(circle: Circle, point: PointInput): boolean
14
+
15
+ /** Checks whether two circles intersect. */
16
+ export function intersectsCircle(circle1: Circle, circle2: Circle): boolean
17
+
18
+ /** Checks whether a circle intersects a rectangle. */
19
+ export function intersectsRectangle(
20
+ circle: Circle,
21
+ rectangle: Rectangle,
22
+ ): boolean
@@ -0,0 +1,20 @@
1
+ import type { Point } from "./point"
2
+ import type { Platform } from "./rectangle"
3
+
4
+ /** Represents the width and depth of a hitmask tile. */
5
+ export type TileSize = readonly [width: number, depth: number]
6
+
7
+ /** Represents a tiled collision mask. */
8
+ export interface Hitmask {
9
+ /** The center of the hitmask. */
10
+ position: Point
11
+ /** The dimensions of each tile. */
12
+ tileSize: TileSize
13
+ /** The number of tile columns. */
14
+ columns: number
15
+ /** The height of each tile. */
16
+ heights: number[]
17
+ }
18
+
19
+ /** Checks whether a platform collides with a hitmask. */
20
+ export function findCollisions(hitmask: Hitmask, target: Platform): boolean
@@ -0,0 +1,14 @@
1
+ export * as circle from "./circle"
2
+ export * as hitmask from "./hitmask"
3
+ export * as line from "./line"
4
+ export * as linearInterpolation from "./linear-interpolation"
5
+ export * as numbers from "./numbers"
6
+ export * as point from "./point"
7
+ export * as quaternions from "./quaternions"
8
+ export * as rectangle from "./rectangle"
9
+ export * as rng from "./rng"
10
+ export * as segment from "./segment"
11
+ export * as statistics from "./statistics"
12
+ export * as triangle from "./triangle"
13
+ export * as trigonometry from "./trigonometry"
14
+ export * as vectors from "./vectors"
@@ -0,0 +1,11 @@
1
+ import type { Circle } from "./circle"
2
+ import type { Point } from "./point"
3
+
4
+ /** Represents a 2D line as `ax + bz + c = 0`. */
5
+ export type Line = readonly [a: number, b: number, c: number]
6
+
7
+ /** Calculates the shortest distance from a point to a line. */
8
+ export function distanceFromPoint(line: Line, point: Point): number
9
+
10
+ /** Checks whether a line intersects a circle. */
11
+ export function intersectsCircle(line: Line, circle: Circle): boolean
@@ -0,0 +1,2 @@
1
+ /** Linearly interpolates between two numbers. */
2
+ export function lerp(a: number, b: number, t: number): number
@@ -0,0 +1,26 @@
1
+ /** Returns the absolute value of a number. */
2
+ export function abs(num: number): number
3
+
4
+ /** Clamps a number to an inclusive range. */
5
+ export function clamp(num: number, min: number, max: number): number
6
+
7
+ /** Checks whether a number is within an inclusive range. */
8
+ export function isBetween(num: number, min: number, max: number): boolean
9
+
10
+ /** Checks whether two numbers are within a tolerance. */
11
+ export function isClose(num1: number, num2: number, tolerance?: number): boolean
12
+
13
+ /** Computes a positive modulus, returning the dividend for a zero divisor. */
14
+ export function mod(dividend: number, divisor: number): number
15
+
16
+ /** Snaps a number to the nearest multiple of a precision. */
17
+ export function snap(num: number, precision?: number): number
18
+
19
+ /** Alias for `mod`. */
20
+ export const remainder: typeof mod
21
+
22
+ /** Returns the sign of a number. */
23
+ export function sign(num: number): number
24
+
25
+ /** Computes the square root of a number. */
26
+ export function sqrt(num: number): number
@@ -0,0 +1,25 @@
1
+ import type { Vector3 } from "./vector"
2
+ import type { Circle } from "./circle"
3
+ import type { Line } from "./line"
4
+ import type { Rectangle } from "./rectangle"
5
+
6
+ /** Represents a point in 3D space. */
7
+ export type Point = readonly [x: number, y: number, z: number]
8
+
9
+ /** Accepts a 3D point, branded vector, or object with a point position. */
10
+ export type PointInput = Point | Vector3 | { position: Point | Vector3 }
11
+
12
+ /** Calculates the distance from a point to a line. */
13
+ export function getDistanceFromLine(point: Point, line: Line): number
14
+
15
+ /** Checks whether two points occupy the same position. */
16
+ export function intersectsPoint(point1: PointInput, point2: PointInput): boolean
17
+
18
+ /** Checks whether a point intersects a circle. */
19
+ export function intersectsCircle(point: PointInput, circle: Circle): boolean
20
+
21
+ /** Checks whether a point intersects a rectangle. */
22
+ export function intersectsRectangle(
23
+ point: PointInput,
24
+ rectangle: Rectangle,
25
+ ): boolean
@@ -0,0 +1,10 @@
1
+ import type { Vector, Vector3 } from "./vectors"
2
+
3
+ /** A quaternion represented as a four-dimensional vector. */
4
+ export type Quaternion = Vector<readonly [number, number, number, number]>
5
+
6
+ /** Combines two quaternions with the Hamilton product. */
7
+ export function combine(q1: Quaternion, q2: Quaternion): Quaternion
8
+
9
+ /** Creates a quaternion for a rotation around an axis. */
10
+ export function quaternion(angle?: number, axis?: Vector3): Quaternion
@@ -0,0 +1,36 @@
1
+ import type { Circle } from "./circle"
2
+ import type { Point, PointInput } from "./point"
3
+
4
+ /** Represents the dimensions of a 3D object. */
5
+ export type Size = readonly [width: number, height: number, depth: number]
6
+
7
+ /** Represents an axis-aligned rectangle. */
8
+ export interface Rectangle {
9
+ /** The center of the rectangle. */
10
+ position: Point
11
+ /** The dimensions of the rectangle. */
12
+ size: Size
13
+ }
14
+
15
+ /** Represents a rectangular platform. */
16
+ export interface Platform {
17
+ /** The center of the platform. */
18
+ position: Point
19
+ /** The dimensions of the platform. */
20
+ size: Size
21
+ }
22
+
23
+ /** Checks whether a rectangle intersects a point. */
24
+ export function intersectsPoint(
25
+ rectangle: Rectangle,
26
+ point: PointInput,
27
+ ): boolean
28
+
29
+ /** Checks whether a rectangle intersects a circle. */
30
+ export function intersectsCircle(rectangle: Rectangle, circle: Circle): boolean
31
+
32
+ /** Checks whether two rectangles intersect. */
33
+ export function intersectsRectangle(
34
+ rectangle1: Rectangle,
35
+ rectangle2: Rectangle,
36
+ ): boolean
@@ -0,0 +1,14 @@
1
+ /** Returns `undefined` when no values are supplied. */
2
+ export function choose(): undefined
3
+
4
+ /** Chooses a random supplied value. */
5
+ export function choose<T>(value: T, ...values: T[]): T
6
+
7
+ /** Generates a random number for the supplied bounds and step. */
8
+ export function random(): number
9
+ export function random(to: number): number
10
+ export function random(from: number, to: number): number
11
+ export function random(from: number, to: number, step: number): number
12
+
13
+ /** Generates a random value between two independent random values. */
14
+ export function randomBinomial(): number
@@ -0,0 +1,23 @@
1
+ import type { Circle } from "./circle"
2
+ import type { Line } from "./line"
3
+ import type { Point } from "./point"
4
+
5
+ /** Represents a line segment between two points. */
6
+ export interface Segment {
7
+ /** The starting point of the segment. */
8
+ from: Point
9
+ /** The ending point of the segment. */
10
+ to: Point
11
+ }
12
+
13
+ /** Calculates the coefficients of the line containing a segment. */
14
+ export function coefficients(segment: Segment): Line
15
+
16
+ /** Finds the closest point on a segment. */
17
+ export function closestPoint(segment: Segment, point: Point): Point
18
+
19
+ /** Calculates the shortest distance from a point to a segment. */
20
+ export function distanceFromPoint(segment: Segment, point: Point): number
21
+
22
+ /** Checks whether a segment intersects a circle. */
23
+ export function intersectsCircle(segment: Segment, circle: Circle): boolean
@@ -0,0 +1,11 @@
1
+ /** Calculates the arithmetic mean of the supplied numbers. */
2
+ export function mean(...numbers: number[]): number
3
+
4
+ /** Alias for `mean`. */
5
+ export const average: typeof mean
6
+
7
+ /** Calculates the median of the supplied numbers. */
8
+ export function median(...numbers: number[]): number
9
+
10
+ /** Finds the most frequent supplied value. */
11
+ export function mode(...values: unknown[]): string | undefined
@@ -0,0 +1,5 @@
1
+ /** Calculates the magnitude of the supplied numbers. */
2
+ export function hypothenuse(...nums: number[]): number
3
+
4
+ /** Alias for `hypothenuse`. */
5
+ export const pythagoras: typeof hypothenuse
@@ -0,0 +1,26 @@
1
+ /** Calculates the arctangent of a quotient in radians. */
2
+ export function atan2(y: number, x: number): number
3
+
4
+ /** Calculates the cosine of an angle in radians. */
5
+ export function cos(angle: number): number
6
+
7
+ /** Alias for `cos`. */
8
+ export const cosine: typeof cos
9
+
10
+ /** Returns pi. */
11
+ export function pi(): number
12
+
13
+ /** Calculates the sine of an angle in radians. */
14
+ export function sin(angle: number): number
15
+
16
+ /** Alias for `sin`. */
17
+ export const sine: typeof sin
18
+
19
+ /** Converts radians to degrees. */
20
+ export function toDegrees(radians: number): number
21
+
22
+ /** Converts degrees to radians. */
23
+ export function toRadians(degrees: number): number
24
+
25
+ /** Normalizes an angle to the range [-π, π]. */
26
+ export function toRange(angle: number): number
@@ -0,0 +1,190 @@
1
+ /** Identifies a value created by the vector factory. */
2
+ type IsVector = {
3
+ readonly __isVector__: true
4
+ }
5
+
6
+ /** A dynamically sized vector. */
7
+ export type Vector<Coordinates extends readonly number[] = readonly number[]> =
8
+ IsVector & Coordinates
9
+
10
+ /** A two-dimensional vector. */
11
+ export type Vector2 = Vector<readonly [number, number]>
12
+
13
+ /** A three-dimensional vector. */
14
+ export type Vector3 = Vector<readonly [number, number, number]>
15
+
16
+ /** A seven-dimensional vector. */
17
+ export type Vector7 = Vector<
18
+ readonly [number, number, number, number, number, number, number]
19
+ >
20
+
21
+ /** Returns the absolute value of each vector component. */
22
+ export function abs<T extends Vector>(vector: T): T
23
+
24
+ /** Alias for `sum`. */
25
+ export const add: typeof sum
26
+
27
+ /** Calculates the angle of a vector. */
28
+ export function angle<T extends Vector>(vector: T): number
29
+
30
+ /** Clamps a vector by scalar magnitude bounds. */
31
+ export function clamp<T extends Vector>(vector: T, min: number, max: number): T
32
+
33
+ /** Clamps a vector by component-wise vector bounds. */
34
+ export function clamp<T extends Vector>(
35
+ vector: T,
36
+ min: readonly number[],
37
+ max: readonly number[],
38
+ ): T
39
+
40
+ /** Returns the vector conjugate. */
41
+ export function conjugate<T extends Vector>(vector: T): T
42
+
43
+ /** Creates a 3D vector from a magnitude and angle. */
44
+ export function createVector(magnitude: number, angle: number): Vector3
45
+
46
+ /** Computes the cross product of same-width 3D or 7D vectors. */
47
+ export function cross<T extends Vector3 | Vector7>(...vectors: [T, ...T[]]): T
48
+
49
+ /** Computes the distance between same-width 2D or 3D vectors. */
50
+ export function distance<T extends Vector2 | Vector3>(
51
+ ...vectors: [T, ...T[]]
52
+ ): number
53
+
54
+ /** Divides same-width vectors component-wise. */
55
+ export function divide<T extends Vector2 | Vector3>(...vectors: [T, ...T[]]): T
56
+
57
+ /** Divides each vector component by a scalar. */
58
+ export function divide<T extends Vector2 | Vector3>(
59
+ vector: T,
60
+ scalar: number,
61
+ ): T
62
+
63
+ /** Divides a scalar by each vector component. */
64
+ export function divideBy<T extends Vector>(scalar: number, vector: T): T
65
+
66
+ /** Computes the dot product of same-width 2D or 3D vectors. */
67
+ export function dot<T extends Vector2 | Vector3>(
68
+ ...vectors: [T, ...T[]]
69
+ ): number
70
+
71
+ /** Converts a 2D vector to a 3D vector. */
72
+ export function from2D(vector: Vector2): Vector3
73
+
74
+ /** Creates a 3D unit vector from an angle. */
75
+ export function fromAngle(angle: number): Vector3
76
+
77
+ /** Alias for `multiply`. */
78
+ export const hadamard: typeof multiply
79
+
80
+ /** Checks whether a value is a vector. */
81
+ export function isVector<T>(value: T): value is T & Vector
82
+
83
+ /** Calculates a vector's magnitude. */
84
+ export function magnitude<T extends Vector>(vector: T): number
85
+
86
+ /** Alias for `magnitude`. */
87
+ export const length: typeof magnitude
88
+
89
+ /** Applies a component-wise modulus to same-width vectors. */
90
+ export function mod<T extends Vector2 | Vector3>(...vectors: [T, ...T[]]): T
91
+
92
+ /** Applies a modulus to each vector component. */
93
+ export function mod<T extends Vector2 | Vector3>(vector: T, divisor: number): T
94
+
95
+ /** Applies a scalar modulus to each vector component. */
96
+ export function modOf<T extends Vector>(scalar: number, vector: T): T
97
+
98
+ /** Multiplies same-width vectors component-wise. */
99
+ export function multiply<T extends Vector2 | Vector3>(
100
+ ...vectors: [T, ...T[]]
101
+ ): T
102
+
103
+ /** Multiplies each vector component by a scalar. */
104
+ export function multiply<T extends Vector2 | Vector3>(
105
+ vector: T,
106
+ scalar: number,
107
+ ): T
108
+
109
+ /** Normalizes a vector to unit magnitude. */
110
+ export function normalize<T extends Vector>(vector: T): T
111
+
112
+ /** Alias for `power`. */
113
+ export const pow: typeof power
114
+
115
+ /** Raises same-width vectors component-wise to powers. */
116
+ export function power<T extends Vector2 | Vector3>(...vectors: [T, ...T[]]): T
117
+
118
+ /** Raises each vector component to a power. */
119
+ export function power<T extends Vector2 | Vector3>(
120
+ vector: T,
121
+ exponent: number,
122
+ ): T
123
+
124
+ /** Raises a scalar to each vector component. */
125
+ export function powerOf<T extends Vector>(scalar: number, vector: T): T
126
+
127
+ /** Alias for `mod`. */
128
+ export const remainder: typeof mod
129
+
130
+ /** Rotates a 2D vector. */
131
+ export function rotate<T extends Vector2>(vector: T, angle: number): T
132
+
133
+ /** Rotates a 3D vector around the Y-axis. */
134
+ export function rotate<T extends Vector3>(vector: T, angle: number): T
135
+
136
+ /** Alias for `multiply`. */
137
+ export const scale: typeof multiply
138
+
139
+ /** Sets a vector's angle while preserving its magnitude. */
140
+ export function setAngle(vector: Vector, angle: number): Vector3
141
+
142
+ /** Alias for `setMagnitude`. */
143
+ export const setLength: typeof setMagnitude
144
+
145
+ /** Sets a vector's magnitude while preserving its direction. */
146
+ export function setMagnitude<T extends Vector>(vector: T, length: number): T
147
+
148
+ /** Rotates vector components by an index. */
149
+ export function shift<T extends Vector>(vector: T, index: number): T
150
+
151
+ /** Snaps each vector component to a precision. */
152
+ export function snap<T extends Vector>(vector: T, precision?: number): T
153
+
154
+ /** Subtracts same-width vectors component-wise. */
155
+ export function subtract<T extends Vector2 | Vector3>(
156
+ ...vectors: [T, ...T[]]
157
+ ): T
158
+
159
+ /** Sums same-width vectors component-wise. */
160
+ export function sum<T extends Vector2 | Vector3>(...vectors: [T, ...T[]]): T
161
+
162
+ /** Alias for `multiply`. */
163
+ export const times: typeof multiply
164
+
165
+ /** Converts a 3D vector to a 2D vector. */
166
+ export function to2D(vector: Vector3): Vector2
167
+
168
+ /** Converts 2D polar coordinates to Cartesian coordinates. */
169
+ export function toCartesian<T extends Vector2>(vector: T): T
170
+
171
+ /** Converts a 3D Cartesian vector to cylindrical coordinates. */
172
+ export function toCylindrical<T extends Vector3>(vector: T): T
173
+
174
+ /** Converts a 2D Cartesian vector to polar coordinates. */
175
+ export function toPolar<T extends Vector2>(vector: T): T
176
+
177
+ /** Formats a vector as a string. */
178
+ export function toString<T extends Vector>(vector: T, decimals?: number): string
179
+
180
+ /** Converts a 3D Cartesian vector to spherical coordinates. */
181
+ export function toSpherical<T extends Vector3>(vector: T): T
182
+
183
+ /** Creates a 3D unit vector. */
184
+ export function unit(angle?: number): Vector3
185
+
186
+ /** Alias for `cross`. */
187
+ export const vectorProduct: typeof cross
188
+
189
+ /** Creates a 3D zero vector. */
190
+ export function zero(): Vector3
@@ -0,0 +1,24 @@
1
+ import type { Vector3 } from "../math/vectors"
2
+
3
+ export interface AccelerationParams {
4
+ acceleration?: Vector3
5
+ friction?: number
6
+ maxAcceleration: number
7
+ maxSpeed: number
8
+ position?: Vector3
9
+ velocity?: Vector3
10
+ }
11
+
12
+ export interface AccelerationResult {
13
+ acceleration: Vector3
14
+ position: Vector3
15
+ velocity: Vector3
16
+ }
17
+
18
+ /**
19
+ * Applies acceleration to an object using Euler integration.
20
+ */
21
+ export function applyAcceleration(
22
+ params: AccelerationParams,
23
+ dt?: number,
24
+ ): AccelerationResult
@@ -0,0 +1,11 @@
1
+ import type { Vector3 } from "../math/vectors"
2
+
3
+ export interface FrictionParams {
4
+ friction: number
5
+ velocity?: Vector3
6
+ }
7
+
8
+ /**
9
+ * Applies friction to a velocity vector.
10
+ */
11
+ export function applyFriction(params: FrictionParams, dt?: number): Vector3
@@ -0,0 +1,20 @@
1
+ import type { Vector3 } from "../math/vectors"
2
+
3
+ export interface GravityParams {
4
+ maxJump?: number
5
+ maxLeap?: number
6
+ maxSpeed?: number
7
+ position?: Vector3
8
+ vy?: number
9
+ }
10
+
11
+ export interface GravityResult {
12
+ ay: number
13
+ position: Vector3
14
+ vy: number
15
+ }
16
+
17
+ /**
18
+ * Applies gravity to an object based on its current velocity and position.
19
+ */
20
+ export function applyGravity(params: GravityParams, dt?: number): GravityResult
@@ -0,0 +1,5 @@
1
+ export * as acceleration from "./acceleration"
2
+ export * as friction from "./friction"
3
+ export * as gravity from "./gravity"
4
+ export * as jump from "./jump"
5
+ export * as velocity from "./velocity"
@@ -0,0 +1,10 @@
1
+ export interface JumpParams {
2
+ maxJump?: number
3
+ maxLeap?: number
4
+ maxSpeed?: number
5
+ }
6
+
7
+ /**
8
+ * Calculates the vertical velocity of a jump.
9
+ */
10
+ export function jump(params: JumpParams): number
@@ -0,0 +1,20 @@
1
+ import type { Vector3 } from "../math/vectors"
2
+
3
+ export interface VelocityParams {
4
+ maxSpeed?: number
5
+ position?: Vector3
6
+ velocity?: Vector3
7
+ }
8
+
9
+ export interface VelocityResult {
10
+ position: Vector3
11
+ velocity: Vector3
12
+ }
13
+
14
+ /**
15
+ * Applies velocity to a position.
16
+ */
17
+ export function applyVelocity(
18
+ params: VelocityParams,
19
+ dt?: number,
20
+ ): VelocityResult
package/types/v.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Vector } from "./math"
1
+ import type { Vector } from "./math/vectors"
2
2
 
3
3
  /**
4
4
  * Ensures that a given value is a vector.
@@ -12,7 +12,9 @@ import { Vector } from "./math"
12
12
  * @param {T} value The value to check and potentially convert.
13
13
  * @returns {T extends number[] ? Vector : T} The value as a vector, or the original value if no conversion was needed.
14
14
  */
15
- export function ensureV<T>(value: T): T extends number[] ? Vector : T
15
+ export function ensureV<T>(
16
+ value: T,
17
+ ): T extends readonly number[] ? Vector<T> : T
16
18
 
17
19
  /**
18
20
  * A utility function to create a vector from a list of coordinates.
@@ -22,4 +24,6 @@ export function ensureV<T>(value: T): T extends number[] ? Vector : T
22
24
  * @param {...number} coords - The coordinates of the vector.
23
25
  * @returns {Vector} The created vector.
24
26
  */
25
- export function v(...coords: number[]): Vector
27
+ export function v<Coordinates extends number[]>(
28
+ ...coords: Coordinates
29
+ ): Vector<Coordinates>