UNPKG

4.24 kBTypeScriptView Raw
1import { Quaternion } from "./Quaternion.js";
2
3/**
4 * @see {@link https://github.com/mrdoob/three.js/blob/master/src/math/MathUtils.js|src/math/MathUtils.js}
5 */
6
7export const DEG2RAD: number;
8
9export const RAD2DEG: number;
10
11export function generateUUID(): string;
12
13/**
14 * Clamps the x to be between a and b.
15 *
16 * @param value Value to be clamped.
17 * @param min Minimum value.
18 * @param max Maximum value.
19 */
20export function clamp(value: number, min: number, max: number): number;
21
22export function euclideanModulo(n: number, m: number): number;
23
24/**
25 * Linear mapping of x from range [a1, a2] to range [b1, b2].
26 *
27 * @param x Value to be mapped.
28 * @param a1 Minimum value for range A.
29 * @param a2 Maximum value for range A.
30 * @param b1 Minimum value for range B.
31 * @param b2 Maximum value for range B.
32 */
33export function mapLinear(x: number, a1: number, a2: number, b1: number, b2: number): number;
34
35export function inverseLerp(x: number, y: number, t: number): number;
36
37/**
38 * Returns a value linearly interpolated from two known points based
39 * on the given interval - t = 0 will return x and t = 1 will return y.
40 *
41 * @param x Start point.
42 * @param y End point.
43 * @param t interpolation factor in the closed interval [0, 1]
44 */
45export function lerp(x: number, y: number, t: number): number;
46
47/**
48 * Smoothly interpolate a number from x toward y in a spring-like
49 * manner using the dt to maintain frame rate independent movement.
50 *
51 * @param x Current point.
52 * @param y Target point.
53 * @param lambda A higher lambda value will make the movement more sudden, and a lower value will make the movement more gradual.
54 * @param dt Delta time in seconds.
55 */
56export function damp(x: number, y: number, lambda: number, dt: number): number;
57
58/**
59 * Returns a value that alternates between 0 and length.
60 *
61 * @param x The value to pingpong.
62 * @param length The positive value the export function will pingpong to. Default is 1.
63 */
64export function pingpong(x: number, length?: number): number;
65
66export function smoothstep(x: number, min: number, max: number): number;
67
68export function smootherstep(x: number, min: number, max: number): number;
69
70/**
71 * Random integer from low to high interval.
72 */
73export function randInt(low: number, high: number): number;
74
75/**
76 * Random float from low to high interval.
77 */
78export function randFloat(low: number, high: number): number;
79
80/**
81 * Random float from - range / 2 to range / 2 interval.
82 */
83export function randFloatSpread(range: number): number;
84
85/**
86 * Deterministic pseudo-random float in the interval [ 0, 1 ].
87 */
88export function seededRandom(seed?: number): number;
89
90export function degToRad(degrees: number): number;
91
92export function radToDeg(radians: number): number;
93
94export function isPowerOfTwo(value: number): boolean;
95
96export function ceilPowerOfTwo(value: number): number;
97
98export function floorPowerOfTwo(value: number): number;
99
100export function setQuaternionFromProperEuler(q: Quaternion, a: number, b: number, c: number, order: string): void;
101
102export function denormalize(
103 value: number,
104 array: Float32Array | Uint32Array | Uint16Array | Uint8Array | Int32Array | Int16Array | Int8Array,
105): number;
106
107export function normalize(
108 value: number,
109 array: Float32Array | Uint32Array | Uint16Array | Uint8Array | Int32Array | Int16Array | Int8Array,
110): number;
111
112export const MathUtils: {
113 DEG2RAD: typeof DEG2RAD;
114 RAD2DEG: typeof RAD2DEG;
115 generateUUID: typeof generateUUID;
116 clamp: typeof clamp;
117 euclideanModulo: typeof euclideanModulo;
118 mapLinear: typeof mapLinear;
119 inverseLerp: typeof inverseLerp;
120 lerp: typeof lerp;
121 damp: typeof damp;
122 pingpong: typeof pingpong;
123 smoothstep: typeof smoothstep;
124 smootherstep: typeof smootherstep;
125 randInt: typeof randInt;
126 randFloat: typeof randFloat;
127 randFloatSpread: typeof randFloatSpread;
128 seededRandom: typeof seededRandom;
129 degToRad: typeof degToRad;
130 radToDeg: typeof radToDeg;
131 isPowerOfTwo: typeof isPowerOfTwo;
132 ceilPowerOfTwo: typeof ceilPowerOfTwo;
133 floorPowerOfTwo: typeof floorPowerOfTwo;
134 setQuaternionFromProperEuler: typeof setQuaternionFromProperEuler;
135 normalize: typeof normalize;
136 denormalize: typeof denormalize;
137};