1 | import { BufferAttribute } from "../core/BufferAttribute.js";
|
2 | import { Matrix3 } from "./Matrix3.js";
|
3 |
|
4 | export type Vector2Tuple = [x: number, y: number];
|
5 |
|
6 | export interface Vector2Like {
|
7 | readonly x: number;
|
8 | readonly y: number;
|
9 | }
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | export class Vector2 {
|
15 | constructor(x?: number, y?: number);
|
16 |
|
17 | /**
|
18 | * @default 0
|
19 | */
|
20 | x: number;
|
21 |
|
22 | /**
|
23 | * @default 0
|
24 | */
|
25 | y: number;
|
26 | width: number;
|
27 | height: number;
|
28 | readonly isVector2: true;
|
29 |
|
30 | /**
|
31 | * Sets value of this vector.
|
32 | */
|
33 | set(x: number, y: number): this;
|
34 |
|
35 | /**
|
36 | * Sets the x and y values of this vector both equal to scalar.
|
37 | */
|
38 | setScalar(scalar: number): this;
|
39 |
|
40 | /**
|
41 | * Sets X component of this vector.
|
42 | */
|
43 | setX(x: number): this;
|
44 |
|
45 | /**
|
46 | * Sets Y component of this vector.
|
47 | */
|
48 | setY(y: number): this;
|
49 |
|
50 | /**
|
51 | * Sets a component of this vector.
|
52 | */
|
53 | setComponent(index: number, value: number): this;
|
54 |
|
55 | /**
|
56 | * Gets a component of this vector.
|
57 | */
|
58 | getComponent(index: number): number;
|
59 |
|
60 | /**
|
61 | * Returns a new Vector2 instance with the same `x` and `y` values.
|
62 | */
|
63 | clone(): this;
|
64 |
|
65 | /**
|
66 | * Copies value of v to this vector.
|
67 | */
|
68 | copy(v: Vector2Like): this;
|
69 |
|
70 | /**
|
71 | * Adds v to this vector.
|
72 | */
|
73 | add(v: Vector2Like): this;
|
74 |
|
75 | /**
|
76 | * Adds the scalar value s to this vector's x and y values.
|
77 | */
|
78 | addScalar(s: number): this;
|
79 |
|
80 | /**
|
81 | * Sets this vector to a + b.
|
82 | */
|
83 | addVectors(a: Vector2Like, b: Vector2Like): this;
|
84 |
|
85 | /**
|
86 | * Adds the multiple of v and s to this vector.
|
87 | */
|
88 | addScaledVector(v: Vector2Like, s: number): this;
|
89 |
|
90 | /**
|
91 | * Subtracts v from this vector.
|
92 | */
|
93 | sub(v: Vector2Like): this;
|
94 |
|
95 | /**
|
96 | * Subtracts s from this vector's x and y components.
|
97 | */
|
98 | subScalar(s: number): this;
|
99 |
|
100 | /**
|
101 | * Sets this vector to a - b.
|
102 | */
|
103 | subVectors(a: Vector2Like, b: Vector2Like): this;
|
104 |
|
105 | /**
|
106 | * Multiplies this vector by v.
|
107 | */
|
108 | multiply(v: Vector2Like): this;
|
109 |
|
110 | /**
|
111 | * Multiplies this vector by scalar s.
|
112 | */
|
113 | multiplyScalar(scalar: number): this;
|
114 |
|
115 | /**
|
116 | * Divides this vector by v.
|
117 | */
|
118 | divide(v: Vector2Like): this;
|
119 |
|
120 | /**
|
121 | * Divides this vector by scalar s.
|
122 | * Set vector to ( 0, 0 ) if s == 0.
|
123 | */
|
124 | divideScalar(s: number): this;
|
125 |
|
126 | /**
|
127 | * Multiplies this vector (with an implicit 1 as the 3rd component) by m.
|
128 | */
|
129 | applyMatrix3(m: Matrix3): this;
|
130 |
|
131 | /**
|
132 | * If this vector's x or y value is greater than v's x or y value, replace that value with the corresponding min value.
|
133 | */
|
134 | min(v: Vector2Like): this;
|
135 |
|
136 | /**
|
137 | * If this vector's x or y value is less than v's x or y value, replace that value with the corresponding max value.
|
138 | */
|
139 | max(v: Vector2Like): this;
|
140 |
|
141 | /**
|
142 | * If this vector's x or y value is greater than the max vector's x or y value, it is replaced by the corresponding value.
|
143 | * If this vector's x or y value is less than the min vector's x or y value, it is replaced by the corresponding value.
|
144 | * @param min the minimum x and y values.
|
145 | * @param max the maximum x and y values in the desired range.
|
146 | */
|
147 | clamp(min: Vector2Like, max: Vector2Like): this;
|
148 |
|
149 | /**
|
150 | * If this vector's x or y values are greater than the max value, they are replaced by the max value.
|
151 | * If this vector's x or y values are less than the min value, they are replaced by the min value.
|
152 | * @param min the minimum value the components will be clamped to.
|
153 | * @param max the maximum value the components will be clamped to.
|
154 | */
|
155 | clampScalar(min: number, max: number): this;
|
156 |
|
157 | /**
|
158 | * If this vector's length is greater than the max value, it is replaced by the max value.
|
159 | * If this vector's length is less than the min value, it is replaced by the min value.
|
160 | * @param min the minimum value the length will be clamped to.
|
161 | * @param max the maximum value the length will be clamped to.
|
162 | */
|
163 | clampLength(min: number, max: number): this;
|
164 |
|
165 | /**
|
166 | * The components of the vector are rounded down to the nearest integer value.
|
167 | */
|
168 | floor(): this;
|
169 |
|
170 | /**
|
171 | * The x and y components of the vector are rounded up to the nearest integer value.
|
172 | */
|
173 | ceil(): this;
|
174 |
|
175 | /**
|
176 | * The components of the vector are rounded to the nearest integer value.
|
177 | */
|
178 | round(): this;
|
179 |
|
180 | /**
|
181 | * The components of the vector are rounded towards zero (up if negative, down if positive) to an integer value.
|
182 | */
|
183 | roundToZero(): this;
|
184 |
|
185 | /**
|
186 | * Inverts this vector.
|
187 | */
|
188 | negate(): this;
|
189 |
|
190 | /**
|
191 | * Computes dot product of this vector and v.
|
192 | */
|
193 | dot(v: Vector2Like): number;
|
194 |
|
195 | /**
|
196 | * Computes cross product of this vector and v.
|
197 | */
|
198 | cross(v: Vector2Like): number;
|
199 |
|
200 | /**
|
201 | * Computes squared length of this vector.
|
202 | */
|
203 | lengthSq(): number;
|
204 |
|
205 | /**
|
206 | * Computes length of this vector.
|
207 | */
|
208 | length(): number;
|
209 |
|
210 | /**
|
211 | * Computes the Manhattan length of this vector.
|
212 | *
|
213 | * see {@link http:
|
214 | */
|
215 | manhattanLength(): number;
|
216 |
|
217 | |
218 |
|
219 |
|
220 | normalize(): this;
|
221 |
|
222 | |
223 |
|
224 |
|
225 | angle(): number;
|
226 |
|
227 | |
228 |
|
229 |
|
230 | angleTo(v: Vector2): number;
|
231 |
|
232 | |
233 |
|
234 |
|
235 | distanceTo(v: Vector2Like): number;
|
236 |
|
237 | |
238 |
|
239 |
|
240 | distanceToSquared(v: Vector2Like): number;
|
241 |
|
242 | |
243 |
|
244 |
|
245 |
|
246 |
|
247 | manhattanDistanceTo(v: Vector2Like): number;
|
248 |
|
249 | |
250 |
|
251 |
|
252 | setLength(length: number): this;
|
253 |
|
254 | |
255 |
|
256 |
|
257 |
|
258 |
|
259 | lerp(v: Vector2Like, alpha: number): this;
|
260 |
|
261 | |
262 |
|
263 |
|
264 |
|
265 |
|
266 |
|
267 | lerpVectors(v1: Vector2Like, v2: Vector2Like, alpha: number): this;
|
268 |
|
269 | |
270 |
|
271 |
|
272 | equals(v: Vector2Like): boolean;
|
273 |
|
274 | |
275 |
|
276 |
|
277 |
|
278 |
|
279 | fromArray(array: number[] | ArrayLike<number>, offset?: number): this;
|
280 |
|
281 | |
282 |
|
283 |
|
284 |
|
285 |
|
286 |
|
287 | toArray(array?: number[], offset?: number): number[];
|
288 | toArray(array?: Vector2Tuple, offset?: 0): Vector2Tuple;
|
289 |
|
290 | |
291 |
|
292 |
|
293 |
|
294 |
|
295 |
|
296 | toArray(array: ArrayLike<number>, offset?: number): ArrayLike<number>;
|
297 |
|
298 | |
299 |
|
300 |
|
301 |
|
302 |
|
303 | fromBufferAttribute(attribute: BufferAttribute, index: number): this;
|
304 |
|
305 | |
306 |
|
307 |
|
308 |
|
309 |
|
310 | rotateAround(center: Vector2Like, angle: number): this;
|
311 |
|
312 | |
313 |
|
314 |
|
315 | random(): this;
|
316 |
|
317 | |
318 |
|
319 |
|
320 | [Symbol.iterator](): Iterator<number>;
|
321 | }
|