cavi 0.1.1 → 0.1.2

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 (4) hide show
  1. package/cavi.d.ts +195 -0
  2. package/cavi.js +1619 -8
  3. package/package.json +1 -3
  4. package/cavi_bg.js +0 -1517
package/cavi.js CHANGED
@@ -1,9 +1,1620 @@
1
1
  /* @ts-self-types="./cavi.d.ts" */
2
- import * as wasm from "./cavi_bg.wasm";
3
- import { __wbg_set_wasm } from "./cavi_bg.js";
4
-
5
- __wbg_set_wasm(wasm);
6
- wasm.__wbindgen_start();
7
- export {
8
- WasmNode, WasmPoint, WasmPosition, WasmWire, WasmWorld
9
- } from "./cavi_bg.js";
2
+
3
+ export class WasmNode {
4
+ static __wrap(ptr) {
5
+ const obj = Object.create(WasmNode.prototype);
6
+ obj.__wbg_ptr = ptr;
7
+ WasmNodeFinalization.register(obj, obj.__wbg_ptr, obj);
8
+ return obj;
9
+ }
10
+ __destroy_into_raw() {
11
+ const ptr = this.__wbg_ptr;
12
+ this.__wbg_ptr = 0;
13
+ WasmNodeFinalization.unregister(this);
14
+ return ptr;
15
+ }
16
+ free() {
17
+ const ptr = this.__destroy_into_raw();
18
+ wasm.__wbg_wasmnode_free(ptr, 0);
19
+ }
20
+ /**
21
+ * @returns {boolean}
22
+ */
23
+ get fixed() {
24
+ const ret = wasm.__wbg_get_wasmnode_fixed(this.__wbg_ptr);
25
+ return ret !== 0;
26
+ }
27
+ /**
28
+ * @returns {WasmPosition}
29
+ */
30
+ get position() {
31
+ const ret = wasm.__wbg_get_wasmnode_position(this.__wbg_ptr);
32
+ return WasmPosition.__wrap(ret);
33
+ }
34
+ /**
35
+ * @returns {WasmPoint}
36
+ */
37
+ get velocity() {
38
+ const ret = wasm.__wbg_get_wasmnode_velocity(this.__wbg_ptr);
39
+ return WasmPoint.__wrap(ret);
40
+ }
41
+ /**
42
+ * @param {boolean} arg0
43
+ */
44
+ set fixed(arg0) {
45
+ wasm.__wbg_set_wasmnode_fixed(this.__wbg_ptr, arg0);
46
+ }
47
+ /**
48
+ * @param {WasmPosition} arg0
49
+ */
50
+ set position(arg0) {
51
+ _assertClass(arg0, WasmPosition);
52
+ var ptr0 = arg0.__destroy_into_raw();
53
+ wasm.__wbg_set_wasmnode_position(this.__wbg_ptr, ptr0);
54
+ }
55
+ /**
56
+ * @param {WasmPoint} arg0
57
+ */
58
+ set velocity(arg0) {
59
+ _assertClass(arg0, WasmPoint);
60
+ var ptr0 = arg0.__destroy_into_raw();
61
+ wasm.__wbg_set_wasmnode_velocity(this.__wbg_ptr, ptr0);
62
+ }
63
+ /**
64
+ * Applies a force to the node (changes velocity)
65
+ * @param {number} fx
66
+ * @param {number} fy
67
+ */
68
+ apply_force(fx, fy) {
69
+ wasm.wasmnode_apply_force(this.__wbg_ptr, fx, fy);
70
+ }
71
+ /**
72
+ * Applies a force from a Point
73
+ * @param {WasmPoint} force
74
+ */
75
+ apply_force_point(force) {
76
+ _assertClass(force, WasmPoint);
77
+ var ptr0 = force.__destroy_into_raw();
78
+ wasm.wasmnode_apply_force_point(this.__wbg_ptr, ptr0);
79
+ }
80
+ /**
81
+ * Returns the squared distance to another node (faster)
82
+ * @param {WasmNode} other
83
+ * @returns {number}
84
+ */
85
+ distance_squared_to(other) {
86
+ _assertClass(other, WasmNode);
87
+ const ret = wasm.wasmnode_distance_squared_to(this.__wbg_ptr, other.__wbg_ptr);
88
+ return ret;
89
+ }
90
+ /**
91
+ * Returns the distance to another node
92
+ * @param {WasmNode} other
93
+ * @returns {number}
94
+ */
95
+ distance_to(other) {
96
+ _assertClass(other, WasmNode);
97
+ const ret = wasm.wasmnode_distance_to(this.__wbg_ptr, other.__wbg_ptr);
98
+ return ret;
99
+ }
100
+ /**
101
+ * Returns the fixed value (0.0 = movable, 1.0 = fixed)
102
+ * @returns {boolean}
103
+ */
104
+ get_fixed() {
105
+ const ret = wasm.wasmnode_get_fixed(this.__wbg_ptr);
106
+ return ret !== 0;
107
+ }
108
+ /**
109
+ * Returns the current position as a Point
110
+ * @returns {WasmPoint}
111
+ */
112
+ get_position() {
113
+ const ret = wasm.wasmnode_get_position(this.__wbg_ptr);
114
+ return WasmPoint.__wrap(ret);
115
+ }
116
+ /**
117
+ * Returns the speed (magnitude of velocity)
118
+ * @returns {number}
119
+ */
120
+ get_speed() {
121
+ const ret = wasm.wasmnode_get_speed(this.__wbg_ptr);
122
+ return ret;
123
+ }
124
+ /**
125
+ * Returns the velocity as a Point
126
+ * @returns {WasmPoint}
127
+ */
128
+ get_velocity() {
129
+ const ret = wasm.wasmnode_get_velocity(this.__wbg_ptr);
130
+ return WasmPoint.__wrap(ret);
131
+ }
132
+ /**
133
+ * Returns the velocity x component
134
+ * @returns {number}
135
+ */
136
+ get_velocity_x() {
137
+ const ret = wasm.wasmnode_get_velocity_x(this.__wbg_ptr);
138
+ return ret;
139
+ }
140
+ /**
141
+ * Returns the velocity y component
142
+ * @returns {number}
143
+ */
144
+ get_velocity_y() {
145
+ const ret = wasm.wasmnode_get_velocity_y(this.__wbg_ptr);
146
+ return ret;
147
+ }
148
+ /**
149
+ * Returns the current x position
150
+ * @returns {number}
151
+ */
152
+ get_x() {
153
+ const ret = wasm.wasmnode_get_x(this.__wbg_ptr);
154
+ return ret;
155
+ }
156
+ /**
157
+ * Returns the current y position
158
+ * @returns {number}
159
+ */
160
+ get_y() {
161
+ const ret = wasm.wasmnode_get_y(this.__wbg_ptr);
162
+ return ret;
163
+ }
164
+ /**
165
+ * Returns true if the node is fixed
166
+ * @returns {boolean}
167
+ */
168
+ is_fixed() {
169
+ const ret = wasm.wasmnode_is_fixed(this.__wbg_ptr);
170
+ return ret !== 0;
171
+ }
172
+ /**
173
+ * Returns true if the node is movable
174
+ * @returns {boolean}
175
+ */
176
+ is_movable() {
177
+ const ret = wasm.wasmnode_is_movable(this.__wbg_ptr);
178
+ return ret !== 0;
179
+ }
180
+ /**
181
+ * Makes the node fixed (immovable)
182
+ */
183
+ make_fixed() {
184
+ wasm.wasmnode_make_fixed(this.__wbg_ptr);
185
+ }
186
+ /**
187
+ * Makes the node movable
188
+ */
189
+ make_movable() {
190
+ wasm.wasmnode_make_movable(this.__wbg_ptr);
191
+ }
192
+ /**
193
+ * @param {WasmPosition} pos
194
+ * @param {WasmPoint} vel
195
+ * @param {boolean} fix
196
+ */
197
+ constructor(pos, vel, fix) {
198
+ _assertClass(pos, WasmPosition);
199
+ var ptr0 = pos.__destroy_into_raw();
200
+ _assertClass(vel, WasmPoint);
201
+ var ptr1 = vel.__destroy_into_raw();
202
+ const ret = wasm.wasmnode_new(ptr0, ptr1, fix);
203
+ this.__wbg_ptr = ret;
204
+ WasmNodeFinalization.register(this, this.__wbg_ptr, this);
205
+ return this;
206
+ }
207
+ /**
208
+ * Creates a fixed Node at the given position
209
+ * @param {number} x
210
+ * @param {number} y
211
+ * @returns {WasmNode}
212
+ */
213
+ static new_fixed(x, y) {
214
+ const ret = wasm.wasmnode_new_fixed(x, y);
215
+ return WasmNode.__wrap(ret);
216
+ }
217
+ /**
218
+ * Creates a Node with no initial velocity
219
+ * @param {number} x
220
+ * @param {number} y
221
+ * @param {boolean} fix
222
+ * @returns {WasmNode}
223
+ */
224
+ static new_no_vel(x, y, fix) {
225
+ const ret = wasm.wasmnode_new_no_vel(x, y, fix);
226
+ return WasmNode.__wrap(ret);
227
+ }
228
+ /**
229
+ * Converts to a string representation
230
+ * @returns {string}
231
+ */
232
+ print() {
233
+ let deferred1_0;
234
+ let deferred1_1;
235
+ try {
236
+ const ret = wasm.wasmnode_print(this.__wbg_ptr);
237
+ deferred1_0 = ret[0];
238
+ deferred1_1 = ret[1];
239
+ return getStringFromWasm0(ret[0], ret[1]);
240
+ } finally {
241
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
242
+ }
243
+ }
244
+ /**
245
+ * Resets the velocity to zero
246
+ */
247
+ reset_velocity() {
248
+ wasm.wasmnode_reset_velocity(this.__wbg_ptr);
249
+ }
250
+ /**
251
+ * Sets whether the node is fixed
252
+ * @param {boolean} fixed
253
+ */
254
+ set_fixed(fixed) {
255
+ wasm.wasmnode_set_fixed(this.__wbg_ptr, fixed);
256
+ }
257
+ /**
258
+ * Sets the current position
259
+ * @param {number} x
260
+ * @param {number} y
261
+ */
262
+ set_position(x, y) {
263
+ wasm.wasmnode_set_position(this.__wbg_ptr, x, y);
264
+ }
265
+ /**
266
+ * Sets the velocity
267
+ * @param {number} vx
268
+ * @param {number} vy
269
+ */
270
+ set_velocity(vx, vy) {
271
+ wasm.wasmnode_set_velocity(this.__wbg_ptr, vx, vy);
272
+ }
273
+ /**
274
+ * Moves the node by a delta amount
275
+ * @param {number} dx
276
+ * @param {number} dy
277
+ */
278
+ translate(dx, dy) {
279
+ wasm.wasmnode_translate(this.__wbg_ptr, dx, dy);
280
+ }
281
+ /**
282
+ * Updates the position based on velocity and acceleration
283
+ * @param {number} dt
284
+ * @param {number} friction
285
+ * @param {WasmPoint} acceleration
286
+ */
287
+ update_position(dt, friction, acceleration) {
288
+ _assertClass(acceleration, WasmPoint);
289
+ var ptr0 = acceleration.__destroy_into_raw();
290
+ wasm.wasmnode_update_position(this.__wbg_ptr, dt, friction, ptr0);
291
+ }
292
+ /**
293
+ * Updates position with custom acceleration
294
+ * @param {WasmPoint} acceleration
295
+ * @param {number} dt
296
+ * @param {number} friction
297
+ */
298
+ update_with_acceleration(acceleration, dt, friction) {
299
+ _assertClass(acceleration, WasmPoint);
300
+ var ptr0 = acceleration.__destroy_into_raw();
301
+ wasm.wasmnode_update_with_acceleration(this.__wbg_ptr, ptr0, dt, friction);
302
+ }
303
+ /**
304
+ * Creates a Node at origin with no velocity
305
+ * @returns {WasmNode}
306
+ */
307
+ static zero() {
308
+ const ret = wasm.wasmnode_zero();
309
+ return WasmNode.__wrap(ret);
310
+ }
311
+ }
312
+ if (Symbol.dispose) WasmNode.prototype[Symbol.dispose] = WasmNode.prototype.free;
313
+
314
+ export class WasmPoint {
315
+ static __wrap(ptr) {
316
+ const obj = Object.create(WasmPoint.prototype);
317
+ obj.__wbg_ptr = ptr;
318
+ WasmPointFinalization.register(obj, obj.__wbg_ptr, obj);
319
+ return obj;
320
+ }
321
+ __destroy_into_raw() {
322
+ const ptr = this.__wbg_ptr;
323
+ this.__wbg_ptr = 0;
324
+ WasmPointFinalization.unregister(this);
325
+ return ptr;
326
+ }
327
+ free() {
328
+ const ptr = this.__destroy_into_raw();
329
+ wasm.__wbg_wasmpoint_free(ptr, 0);
330
+ }
331
+ /**
332
+ * @returns {number}
333
+ */
334
+ get x() {
335
+ const ret = wasm.__wbg_get_wasmpoint_x(this.__wbg_ptr);
336
+ return ret;
337
+ }
338
+ /**
339
+ * @returns {number}
340
+ */
341
+ get y() {
342
+ const ret = wasm.__wbg_get_wasmpoint_y(this.__wbg_ptr);
343
+ return ret;
344
+ }
345
+ /**
346
+ * @param {number} arg0
347
+ */
348
+ set x(arg0) {
349
+ wasm.__wbg_set_wasmpoint_x(this.__wbg_ptr, arg0);
350
+ }
351
+ /**
352
+ * @param {number} arg0
353
+ */
354
+ set y(arg0) {
355
+ wasm.__wbg_set_wasmpoint_y(this.__wbg_ptr, arg0);
356
+ }
357
+ /**
358
+ * Returns the angle of this vector in radians
359
+ * @returns {number}
360
+ */
361
+ angle() {
362
+ const ret = wasm.wasmpoint_angle(this.__wbg_ptr);
363
+ return ret;
364
+ }
365
+ /**
366
+ * Returns the angle to another point in radians
367
+ * @param {WasmPoint} other
368
+ * @returns {number}
369
+ */
370
+ angle_to(other) {
371
+ _assertClass(other, WasmPoint);
372
+ const ret = wasm.wasmpoint_angle_to(this.__wbg_ptr, other.__wbg_ptr);
373
+ return ret;
374
+ }
375
+ /**
376
+ * Returns true if this point is approximately equal to another
377
+ * @param {WasmPoint} other
378
+ * @param {number} epsilon
379
+ * @returns {boolean}
380
+ */
381
+ approx_equal(other, epsilon) {
382
+ _assertClass(other, WasmPoint);
383
+ const ret = wasm.wasmpoint_approx_equal(this.__wbg_ptr, other.__wbg_ptr, epsilon);
384
+ return ret !== 0;
385
+ }
386
+ /**
387
+ * Clamps the length of the vector to a maximum value
388
+ * @param {number} max_length
389
+ * @returns {WasmPoint}
390
+ */
391
+ clamped(max_length) {
392
+ const ret = wasm.wasmpoint_clamped(this.__wbg_ptr, max_length);
393
+ return WasmPoint.__wrap(ret);
394
+ }
395
+ /**
396
+ * Returns the cross product (z component) with another point
397
+ * @param {WasmPoint} other
398
+ * @returns {number}
399
+ */
400
+ cross(other) {
401
+ _assertClass(other, WasmPoint);
402
+ const ret = wasm.wasmpoint_cross(this.__wbg_ptr, other.__wbg_ptr);
403
+ return ret;
404
+ }
405
+ /**
406
+ * Returns the squared distance to another point (avoids sqrt)
407
+ * @param {WasmPoint} other
408
+ * @returns {number}
409
+ */
410
+ distance_squared_to(other) {
411
+ _assertClass(other, WasmPoint);
412
+ const ret = wasm.wasmpoint_distance_squared_to(this.__wbg_ptr, other.__wbg_ptr);
413
+ return ret;
414
+ }
415
+ /**
416
+ * Returns the distance to another point
417
+ * @param {WasmPoint} other
418
+ * @returns {number}
419
+ */
420
+ distance_to(other) {
421
+ _assertClass(other, WasmPoint);
422
+ const ret = wasm.wasmpoint_distance_to(this.__wbg_ptr, other.__wbg_ptr);
423
+ return ret;
424
+ }
425
+ /**
426
+ * Returns the dot product with another point
427
+ * @param {WasmPoint} other
428
+ * @returns {number}
429
+ */
430
+ dot(other) {
431
+ _assertClass(other, WasmPoint);
432
+ const ret = wasm.wasmpoint_dot(this.__wbg_ptr, other.__wbg_ptr);
433
+ return ret;
434
+ }
435
+ /**
436
+ * Returns the length (magnitude) of the vector
437
+ * @returns {number}
438
+ */
439
+ length() {
440
+ const ret = wasm.wasmpoint_length(this.__wbg_ptr);
441
+ return ret;
442
+ }
443
+ /**
444
+ * Returns the squared length (avoids sqrt for performance)
445
+ * @returns {number}
446
+ */
447
+ length_squared() {
448
+ const ret = wasm.wasmpoint_length_squared(this.__wbg_ptr);
449
+ return ret;
450
+ }
451
+ /**
452
+ * Linear interpolation between this point and another
453
+ * @param {WasmPoint} other
454
+ * @param {number} t
455
+ * @returns {WasmPoint}
456
+ */
457
+ lerp(other, t) {
458
+ _assertClass(other, WasmPoint);
459
+ const ret = wasm.wasmpoint_lerp(this.__wbg_ptr, other.__wbg_ptr, t);
460
+ return WasmPoint.__wrap(ret);
461
+ }
462
+ /**
463
+ * @param {number} x
464
+ * @param {number} y
465
+ */
466
+ constructor(x, y) {
467
+ const ret = wasm.wasmpoint_new(x, y);
468
+ this.__wbg_ptr = ret;
469
+ WasmPointFinalization.register(this, this.__wbg_ptr, this);
470
+ return this;
471
+ }
472
+ /**
473
+ * Normalizes this point in place
474
+ */
475
+ normalize() {
476
+ wasm.wasmpoint_normalize(this.__wbg_ptr);
477
+ }
478
+ /**
479
+ * Returns a normalized version of this point (unit vector)
480
+ * @returns {WasmPoint}
481
+ */
482
+ normalized() {
483
+ const ret = wasm.wasmpoint_normalized(this.__wbg_ptr);
484
+ return WasmPoint.__wrap(ret);
485
+ }
486
+ /**
487
+ * Returns a point with both components set to 1
488
+ * @returns {WasmPoint}
489
+ */
490
+ static one() {
491
+ const ret = wasm.wasmpoint_one();
492
+ return WasmPoint.__wrap(ret);
493
+ }
494
+ /**
495
+ * Returns a perpendicular vector (rotated 90 degrees CCW)
496
+ * @returns {WasmPoint}
497
+ */
498
+ perpendicular() {
499
+ const ret = wasm.wasmpoint_perpendicular(this.__wbg_ptr);
500
+ return WasmPoint.__wrap(ret);
501
+ }
502
+ /**
503
+ * Reflects this vector across a normal vector
504
+ * @param {WasmPoint} normal
505
+ * @returns {WasmPoint}
506
+ */
507
+ reflect(normal) {
508
+ _assertClass(normal, WasmPoint);
509
+ const ret = wasm.wasmpoint_reflect(this.__wbg_ptr, normal.__wbg_ptr);
510
+ return WasmPoint.__wrap(ret);
511
+ }
512
+ /**
513
+ * Rotates this point in place by the given angle (in radians)
514
+ * @param {number} angle
515
+ */
516
+ rotate(angle) {
517
+ wasm.wasmpoint_rotate(this.__wbg_ptr, angle);
518
+ }
519
+ /**
520
+ * Returns a point rotated by the given angle (in radians)
521
+ * @param {number} angle
522
+ * @returns {WasmPoint}
523
+ */
524
+ rotated(angle) {
525
+ const ret = wasm.wasmpoint_rotated(this.__wbg_ptr, angle);
526
+ return WasmPoint.__wrap(ret);
527
+ }
528
+ /**
529
+ * Returns a unit point in the X direction (1, 0)
530
+ * @returns {WasmPoint}
531
+ */
532
+ static unit_x() {
533
+ const ret = wasm.wasmpoint_unit_x();
534
+ return WasmPoint.__wrap(ret);
535
+ }
536
+ /**
537
+ * Returns a unit point in the Y direction (0, 1)
538
+ * @returns {WasmPoint}
539
+ */
540
+ static unit_y() {
541
+ const ret = wasm.wasmpoint_unit_y();
542
+ return WasmPoint.__wrap(ret);
543
+ }
544
+ /**
545
+ * Returns a zero point (0, 0)
546
+ * @returns {WasmPoint}
547
+ */
548
+ static zero() {
549
+ const ret = wasm.wasmpoint_zero();
550
+ return WasmPoint.__wrap(ret);
551
+ }
552
+ }
553
+ if (Symbol.dispose) WasmPoint.prototype[Symbol.dispose] = WasmPoint.prototype.free;
554
+
555
+ export class WasmPosition {
556
+ static __wrap(ptr) {
557
+ const obj = Object.create(WasmPosition.prototype);
558
+ obj.__wbg_ptr = ptr;
559
+ WasmPositionFinalization.register(obj, obj.__wbg_ptr, obj);
560
+ return obj;
561
+ }
562
+ __destroy_into_raw() {
563
+ const ptr = this.__wbg_ptr;
564
+ this.__wbg_ptr = 0;
565
+ WasmPositionFinalization.unregister(this);
566
+ return ptr;
567
+ }
568
+ free() {
569
+ const ptr = this.__destroy_into_raw();
570
+ wasm.__wbg_wasmposition_free(ptr, 0);
571
+ }
572
+ /**
573
+ * @returns {WasmPoint}
574
+ */
575
+ get curr() {
576
+ const ret = wasm.__wbg_get_wasmposition_curr(this.__wbg_ptr);
577
+ return WasmPoint.__wrap(ret);
578
+ }
579
+ /**
580
+ * @returns {WasmPoint}
581
+ */
582
+ get old() {
583
+ const ret = wasm.__wbg_get_wasmposition_old(this.__wbg_ptr);
584
+ return WasmPoint.__wrap(ret);
585
+ }
586
+ /**
587
+ * @param {WasmPoint} arg0
588
+ */
589
+ set curr(arg0) {
590
+ _assertClass(arg0, WasmPoint);
591
+ var ptr0 = arg0.__destroy_into_raw();
592
+ wasm.__wbg_set_wasmposition_curr(this.__wbg_ptr, ptr0);
593
+ }
594
+ /**
595
+ * @param {WasmPoint} arg0
596
+ */
597
+ set old(arg0) {
598
+ _assertClass(arg0, WasmPoint);
599
+ var ptr0 = arg0.__destroy_into_raw();
600
+ wasm.__wbg_set_wasmposition_old(this.__wbg_ptr, ptr0);
601
+ }
602
+ /**
603
+ * Applies a constraint by moving the current position
604
+ * @param {WasmPoint} target
605
+ */
606
+ constrain(target) {
607
+ _assertClass(target, WasmPoint);
608
+ var ptr0 = target.__destroy_into_raw();
609
+ wasm.wasmposition_constrain(this.__wbg_ptr, ptr0);
610
+ }
611
+ /**
612
+ * Returns the distance between current and old positions
613
+ * @returns {number}
614
+ */
615
+ displacement() {
616
+ const ret = wasm.wasmposition_displacement(this.__wbg_ptr);
617
+ return ret;
618
+ }
619
+ /**
620
+ * Creates a Position from two Points
621
+ * @param {WasmPoint} curr
622
+ * @param {WasmPoint} old
623
+ * @returns {WasmPosition}
624
+ */
625
+ static from_points(curr, old) {
626
+ _assertClass(curr, WasmPoint);
627
+ var ptr0 = curr.__destroy_into_raw();
628
+ _assertClass(old, WasmPoint);
629
+ var ptr1 = old.__destroy_into_raw();
630
+ const ret = wasm.wasmposition_from_points(ptr0, ptr1);
631
+ return WasmPosition.__wrap(ret);
632
+ }
633
+ /**
634
+ * Returns the current position as a Point
635
+ * @returns {WasmPoint}
636
+ */
637
+ get_curr() {
638
+ const ret = wasm.wasmposition_get_curr(this.__wbg_ptr);
639
+ return WasmPoint.__wrap(ret);
640
+ }
641
+ /**
642
+ * Returns the current x coordinate
643
+ * @returns {number}
644
+ */
645
+ get_curr_x() {
646
+ const ret = wasm.wasmposition_get_curr_x(this.__wbg_ptr);
647
+ return ret;
648
+ }
649
+ /**
650
+ * Returns the current y coordinate
651
+ * @returns {number}
652
+ */
653
+ get_curr_y() {
654
+ const ret = wasm.wasmposition_get_curr_y(this.__wbg_ptr);
655
+ return ret;
656
+ }
657
+ /**
658
+ * Returns the old position as a Point
659
+ * @returns {WasmPoint}
660
+ */
661
+ get_old() {
662
+ const ret = wasm.wasmposition_get_old(this.__wbg_ptr);
663
+ return WasmPoint.__wrap(ret);
664
+ }
665
+ /**
666
+ * Returns the old x coordinate
667
+ * @returns {number}
668
+ */
669
+ get_old_x() {
670
+ const ret = wasm.wasmposition_get_old_x(this.__wbg_ptr);
671
+ return ret;
672
+ }
673
+ /**
674
+ * Returns the old y coordinate
675
+ * @returns {number}
676
+ */
677
+ get_old_y() {
678
+ const ret = wasm.wasmposition_get_old_y(this.__wbg_ptr);
679
+ return ret;
680
+ }
681
+ /**
682
+ * Integrates the position using Verlet integration
683
+ * new_pos = curr + (curr - old) * damping + acceleration * dt^2
684
+ * @param {WasmPoint} acceleration
685
+ * @param {number} dt
686
+ * @param {number} damping
687
+ */
688
+ integrate(acceleration, dt, damping) {
689
+ _assertClass(acceleration, WasmPoint);
690
+ var ptr0 = acceleration.__destroy_into_raw();
691
+ wasm.wasmposition_integrate(this.__wbg_ptr, ptr0, dt, damping);
692
+ }
693
+ /**
694
+ * @param {number} x
695
+ * @param {number} y
696
+ */
697
+ constructor(x, y) {
698
+ const ret = wasm.wasmposition_new(x, y);
699
+ this.__wbg_ptr = ret;
700
+ WasmPositionFinalization.register(this, this.__wbg_ptr, this);
701
+ return this;
702
+ }
703
+ /**
704
+ * Creates a Position with different current and old positions
705
+ * @param {number} curr_x
706
+ * @param {number} curr_y
707
+ * @param {number} old_x
708
+ * @param {number} old_y
709
+ * @returns {WasmPosition}
710
+ */
711
+ static new_with_old(curr_x, curr_y, old_x, old_y) {
712
+ const ret = wasm.wasmposition_new_with_old(curr_x, curr_y, old_x, old_y);
713
+ return WasmPosition.__wrap(ret);
714
+ }
715
+ /**
716
+ * Resets old position to match current (stops motion)
717
+ */
718
+ reset_velocity() {
719
+ wasm.wasmposition_reset_velocity(this.__wbg_ptr);
720
+ }
721
+ /**
722
+ * Sets the current position
723
+ * @param {number} x
724
+ * @param {number} y
725
+ */
726
+ set_curr(x, y) {
727
+ wasm.wasmposition_set_curr(this.__wbg_ptr, x, y);
728
+ }
729
+ /**
730
+ * Sets the current position from a Point
731
+ * @param {WasmPoint} point
732
+ */
733
+ set_curr_point(point) {
734
+ _assertClass(point, WasmPoint);
735
+ var ptr0 = point.__destroy_into_raw();
736
+ wasm.wasmposition_set_curr_point(this.__wbg_ptr, ptr0);
737
+ }
738
+ /**
739
+ * Sets the old position
740
+ * @param {number} x
741
+ * @param {number} y
742
+ */
743
+ set_old(x, y) {
744
+ wasm.wasmposition_set_old(this.__wbg_ptr, x, y);
745
+ }
746
+ /**
747
+ * Sets the old position from a Point
748
+ * @param {WasmPoint} point
749
+ */
750
+ set_old_point(point) {
751
+ _assertClass(point, WasmPoint);
752
+ var ptr0 = point.__destroy_into_raw();
753
+ wasm.wasmposition_set_old_point(this.__wbg_ptr, ptr0);
754
+ }
755
+ /**
756
+ * Returns the speed (magnitude of velocity)
757
+ * @returns {number}
758
+ */
759
+ speed() {
760
+ const ret = wasm.wasmposition_speed(this.__wbg_ptr);
761
+ return ret;
762
+ }
763
+ /**
764
+ * Updates the position: stores current as old, then sets new current
765
+ * @param {number} x
766
+ * @param {number} y
767
+ */
768
+ update(x, y) {
769
+ wasm.wasmposition_update(this.__wbg_ptr, x, y);
770
+ }
771
+ /**
772
+ * Updates the position from a Point
773
+ * @param {WasmPoint} point
774
+ */
775
+ update_point(point) {
776
+ _assertClass(point, WasmPoint);
777
+ var ptr0 = point.__destroy_into_raw();
778
+ wasm.wasmposition_update_point(this.__wbg_ptr, ptr0);
779
+ }
780
+ /**
781
+ * Returns the velocity (difference between current and old positions)
782
+ * @returns {WasmPoint}
783
+ */
784
+ velocity() {
785
+ const ret = wasm.wasmposition_velocity(this.__wbg_ptr);
786
+ return WasmPoint.__wrap(ret);
787
+ }
788
+ }
789
+ if (Symbol.dispose) WasmPosition.prototype[Symbol.dispose] = WasmPosition.prototype.free;
790
+
791
+ export class WasmWire {
792
+ static __wrap(ptr) {
793
+ const obj = Object.create(WasmWire.prototype);
794
+ obj.__wbg_ptr = ptr;
795
+ WasmWireFinalization.register(obj, obj.__wbg_ptr, obj);
796
+ return obj;
797
+ }
798
+ __destroy_into_raw() {
799
+ const ptr = this.__wbg_ptr;
800
+ this.__wbg_ptr = 0;
801
+ WasmWireFinalization.unregister(this);
802
+ return ptr;
803
+ }
804
+ free() {
805
+ const ptr = this.__destroy_into_raw();
806
+ wasm.__wbg_wasmwire_free(ptr, 0);
807
+ }
808
+ /**
809
+ * @returns {number}
810
+ */
811
+ get iterations() {
812
+ const ret = wasm.__wbg_get_wasmwire_iterations(this.__wbg_ptr);
813
+ return ret >>> 0;
814
+ }
815
+ /**
816
+ * @returns {number}
817
+ */
818
+ get link_target_distance() {
819
+ const ret = wasm.__wbg_get_wasmwire_link_target_distance(this.__wbg_ptr);
820
+ return ret;
821
+ }
822
+ /**
823
+ * @returns {number}
824
+ */
825
+ get radius() {
826
+ const ret = wasm.__wbg_get_wasmwire_radius(this.__wbg_ptr);
827
+ return ret;
828
+ }
829
+ /**
830
+ * @returns {number}
831
+ */
832
+ get render_type() {
833
+ const ret = wasm.__wbg_get_wasmwire_render_type(this.__wbg_ptr);
834
+ return ret;
835
+ }
836
+ /**
837
+ * @param {number} arg0
838
+ */
839
+ set iterations(arg0) {
840
+ wasm.__wbg_set_wasmwire_iterations(this.__wbg_ptr, arg0);
841
+ }
842
+ /**
843
+ * @param {number} arg0
844
+ */
845
+ set link_target_distance(arg0) {
846
+ wasm.__wbg_set_wasmwire_link_target_distance(this.__wbg_ptr, arg0);
847
+ }
848
+ /**
849
+ * @param {number} arg0
850
+ */
851
+ set radius(arg0) {
852
+ wasm.__wbg_set_wasmwire_radius(this.__wbg_ptr, arg0);
853
+ }
854
+ /**
855
+ * @param {number} arg0
856
+ */
857
+ set render_type(arg0) {
858
+ wasm.__wbg_set_wasmwire_render_type(this.__wbg_ptr, arg0);
859
+ }
860
+ /**
861
+ * Adds a new node at the specified position
862
+ * @param {number} x
863
+ * @param {number} y
864
+ * @param {boolean} fixed
865
+ */
866
+ add_node(x, y, fixed) {
867
+ wasm.wasmwire_add_node(this.__wbg_ptr, x, y, fixed);
868
+ }
869
+ /**
870
+ * Adds a new node at a specific index
871
+ * @param {number} index
872
+ * @param {number} x
873
+ * @param {number} y
874
+ * @param {boolean} fixed
875
+ */
876
+ add_node_at(index, x, y, fixed) {
877
+ wasm.wasmwire_add_node_at(this.__wbg_ptr, index, x, y, fixed);
878
+ }
879
+ /**
880
+ * Checks collision with a point and adjusts nodes
881
+ * @param {WasmPoint} point
882
+ * @param {number} pointer_radius
883
+ */
884
+ check_collision(point, pointer_radius) {
885
+ _assertClass(point, WasmPoint);
886
+ wasm.wasmwire_check_collision(this.__wbg_ptr, point.__wbg_ptr, pointer_radius);
887
+ }
888
+ /**
889
+ * Checks collision with mouse/pointer position
890
+ * @param {WasmPoint} mouse
891
+ * @param {number} mouse_radius
892
+ */
893
+ check_mouse_collision(mouse, mouse_radius) {
894
+ _assertClass(mouse, WasmPoint);
895
+ var ptr0 = mouse.__destroy_into_raw();
896
+ wasm.wasmwire_check_mouse_collision(this.__wbg_ptr, ptr0, mouse_radius);
897
+ }
898
+ /**
899
+ * Checks for collisions between wire elements
900
+ * @param {number} response_coef
901
+ */
902
+ check_wire_elements_collisions(response_coef) {
903
+ wasm.wasmwire_check_wire_elements_collisions(this.__wbg_ptr, response_coef);
904
+ }
905
+ /**
906
+ * Gets the end point of the wire
907
+ * @returns {WasmPoint}
908
+ */
909
+ get_end() {
910
+ const ret = wasm.wasmwire_get_end(this.__wbg_ptr);
911
+ return WasmPoint.__wrap(ret);
912
+ }
913
+ /**
914
+ * Gets a specific node by index
915
+ * @param {number} index
916
+ * @returns {WasmNode | undefined}
917
+ */
918
+ get_node(index) {
919
+ const ret = wasm.wasmwire_get_node(this.__wbg_ptr, index);
920
+ return ret === 0 ? undefined : WasmNode.__wrap(ret);
921
+ }
922
+ /**
923
+ * Gets the x coordinate of a node at the given index
924
+ * @param {number} index
925
+ * @returns {number}
926
+ */
927
+ get_node_x(index) {
928
+ const ret = wasm.wasmwire_get_node_x(this.__wbg_ptr, index);
929
+ return ret;
930
+ }
931
+ /**
932
+ * Gets the y coordinate of a node at the given index
933
+ * @param {number} index
934
+ * @returns {number}
935
+ */
936
+ get_node_y(index) {
937
+ const ret = wasm.wasmwire_get_node_y(this.__wbg_ptr, index);
938
+ return ret;
939
+ }
940
+ /**
941
+ * @returns {number}
942
+ */
943
+ get_radius() {
944
+ const ret = wasm.wasmwire_get_radius(this.__wbg_ptr);
945
+ return ret;
946
+ }
947
+ /**
948
+ * Gets the render type (0 = segments, 1 = bezier)
949
+ * @returns {number}
950
+ */
951
+ get_render_type() {
952
+ const ret = wasm.wasmwire_get_render_type(this.__wbg_ptr);
953
+ return ret;
954
+ }
955
+ /**
956
+ * Gets the start point of the wire
957
+ * @returns {WasmPoint}
958
+ */
959
+ get_start() {
960
+ const ret = wasm.wasmwire_get_start(this.__wbg_ptr);
961
+ return WasmPoint.__wrap(ret);
962
+ }
963
+ /**
964
+ * Resets the iteration counter
965
+ */
966
+ invalidate() {
967
+ wasm.wasmwire_invalidate(this.__wbg_ptr);
968
+ }
969
+ /**
970
+ * Returns the length of the wire (sum of all segment distances)
971
+ * @returns {number}
972
+ */
973
+ length() {
974
+ const ret = wasm.wasmwire_length(this.__wbg_ptr);
975
+ return ret;
976
+ }
977
+ constructor() {
978
+ const ret = wasm.wasmwire_new();
979
+ this.__wbg_ptr = ret;
980
+ WasmWireFinalization.register(this, this.__wbg_ptr, this);
981
+ return this;
982
+ }
983
+ /**
984
+ * Creates a wire between two points with specified radius
985
+ * @param {number} xs
986
+ * @param {number} ys
987
+ * @param {number} xe
988
+ * @param {number} ye
989
+ * @param {number} radius
990
+ * @returns {WasmWire}
991
+ */
992
+ static new_wire(xs, ys, xe, ye, radius) {
993
+ const ret = wasm.wasmwire_new_wire(xs, ys, xe, ye, radius);
994
+ return WasmWire.__wrap(ret);
995
+ }
996
+ /**
997
+ * Creates a wire with specific node count and link target distance
998
+ * @param {number} xs
999
+ * @param {number} ys
1000
+ * @param {number} xe
1001
+ * @param {number} ye
1002
+ * @param {number} node_count
1003
+ * @param {number} link_target
1004
+ * @param {number} radius
1005
+ * @param {number} render_type
1006
+ * @returns {WasmWire}
1007
+ */
1008
+ static new_with_count(xs, ys, xe, ye, node_count, link_target, radius, render_type) {
1009
+ const ret = wasm.wasmwire_new_with_count(xs, ys, xe, ye, node_count, link_target, radius, render_type);
1010
+ return WasmWire.__wrap(ret);
1011
+ }
1012
+ /**
1013
+ * Returns the number of nodes in the wire
1014
+ * @returns {number}
1015
+ */
1016
+ node_count() {
1017
+ const ret = wasm.wasmwire_node_count(this.__wbg_ptr);
1018
+ return ret >>> 0;
1019
+ }
1020
+ /**
1021
+ * @param {WasmPoint} start
1022
+ * @param {WasmPoint} end
1023
+ * @param {number} node_radius
1024
+ * @returns {number}
1025
+ */
1026
+ static optimal_length(start, end, node_radius) {
1027
+ _assertClass(start, WasmPoint);
1028
+ var ptr0 = start.__destroy_into_raw();
1029
+ _assertClass(end, WasmPoint);
1030
+ var ptr1 = end.__destroy_into_raw();
1031
+ const ret = wasm.wasmwire_optimal_length(ptr0, ptr1, node_radius);
1032
+ return ret >>> 0;
1033
+ }
1034
+ /**
1035
+ * Removes a node at the specified index
1036
+ * @param {number} index
1037
+ * @returns {boolean}
1038
+ */
1039
+ remove_node(index) {
1040
+ const ret = wasm.wasmwire_remove_node(this.__wbg_ptr, index);
1041
+ return ret !== 0;
1042
+ }
1043
+ /**
1044
+ * Sets the end point position (if it's fixed)
1045
+ * @param {number} x
1046
+ * @param {number} y
1047
+ */
1048
+ set_end(x, y) {
1049
+ wasm.wasmwire_set_end(this.__wbg_ptr, x, y);
1050
+ }
1051
+ /**
1052
+ * Sets the number of nodes in the wire
1053
+ * Redistributes nodes evenly between start and end points
1054
+ * @param {number} new_count
1055
+ */
1056
+ set_node_count(new_count) {
1057
+ wasm.wasmwire_set_node_count(this.__wbg_ptr, new_count);
1058
+ }
1059
+ /**
1060
+ * Sets the fixed state of a specific node
1061
+ * @param {number} node_idx
1062
+ * @param {boolean} fixed
1063
+ */
1064
+ set_node_fixed(node_idx, fixed) {
1065
+ wasm.wasmwire_set_node_fixed(this.__wbg_ptr, node_idx, fixed);
1066
+ }
1067
+ /**
1068
+ * Sets the position of a specific node
1069
+ * @param {number} node_idx
1070
+ * @param {number} x
1071
+ * @param {number} y
1072
+ */
1073
+ set_node_position(node_idx, x, y) {
1074
+ wasm.wasmwire_set_node_position(this.__wbg_ptr, node_idx, x, y);
1075
+ }
1076
+ /**
1077
+ * Sets the radius of the wire
1078
+ * @param {number} radius
1079
+ */
1080
+ set_radius(radius) {
1081
+ wasm.wasmwire_set_radius(this.__wbg_ptr, radius);
1082
+ }
1083
+ /**
1084
+ * Sets the render type (0 = segments, 1 = bezier)
1085
+ * @param {number} render_type
1086
+ */
1087
+ set_render_type(render_type) {
1088
+ wasm.wasmwire_set_render_type(this.__wbg_ptr, render_type);
1089
+ }
1090
+ /**
1091
+ * Sets the start point position (if it's fixed)
1092
+ * @param {number} x
1093
+ * @param {number} y
1094
+ */
1095
+ set_start(x, y) {
1096
+ wasm.wasmwire_set_start(this.__wbg_ptr, x, y);
1097
+ }
1098
+ /**
1099
+ * Updates the wire physics simulation
1100
+ * @param {number} dt
1101
+ * @param {number} friction
1102
+ * @param {WasmPoint} acceleration
1103
+ */
1104
+ update(dt, friction, acceleration) {
1105
+ _assertClass(acceleration, WasmPoint);
1106
+ var ptr0 = acceleration.__destroy_into_raw();
1107
+ wasm.wasmwire_update(this.__wbg_ptr, dt, friction, ptr0);
1108
+ }
1109
+ }
1110
+ if (Symbol.dispose) WasmWire.prototype[Symbol.dispose] = WasmWire.prototype.free;
1111
+
1112
+ export class WasmWorld {
1113
+ __destroy_into_raw() {
1114
+ const ptr = this.__wbg_ptr;
1115
+ this.__wbg_ptr = 0;
1116
+ WasmWorldFinalization.unregister(this);
1117
+ return ptr;
1118
+ }
1119
+ free() {
1120
+ const ptr = this.__destroy_into_raw();
1121
+ wasm.__wbg_wasmworld_free(ptr, 0);
1122
+ }
1123
+ /**
1124
+ * Adds a wire between two points with specified radius
1125
+ * @param {number} xs
1126
+ * @param {number} ys
1127
+ * @param {number} xe
1128
+ * @param {number} ye
1129
+ * @param {number} radius
1130
+ */
1131
+ add_wire(xs, ys, xe, ye, radius) {
1132
+ wasm.wasmworld_add_wire(this.__wbg_ptr, xs, ys, xe, ye, radius);
1133
+ }
1134
+ /**
1135
+ * Adds a default wire to the world
1136
+ */
1137
+ add_wire_debug() {
1138
+ wasm.wasmworld_add_wire_debug(this.__wbg_ptr);
1139
+ }
1140
+ /**
1141
+ * Adds a node to a specific wire
1142
+ * @param {number} wire_idx
1143
+ * @param {number} x
1144
+ * @param {number} y
1145
+ * @param {boolean} fixed
1146
+ */
1147
+ add_wire_node(wire_idx, x, y, fixed) {
1148
+ wasm.wasmworld_add_wire_node(this.__wbg_ptr, wire_idx, x, y, fixed);
1149
+ }
1150
+ /**
1151
+ * Adds a node to a specific wire at a specific index
1152
+ * @param {number} wire_idx
1153
+ * @param {number} node_idx
1154
+ * @param {number} x
1155
+ * @param {number} y
1156
+ * @param {boolean} fixed
1157
+ */
1158
+ add_wire_node_at(wire_idx, node_idx, x, y, fixed) {
1159
+ wasm.wasmworld_add_wire_node_at(this.__wbg_ptr, wire_idx, node_idx, x, y, fixed);
1160
+ }
1161
+ /**
1162
+ * Adds a wire with specific node count and link target distance
1163
+ * @param {number} xs
1164
+ * @param {number} ys
1165
+ * @param {number} xe
1166
+ * @param {number} ye
1167
+ * @param {number} node_count
1168
+ * @param {number} link_target
1169
+ * @param {number} radius
1170
+ * @param {number} render_type
1171
+ */
1172
+ add_wire_with_count(xs, ys, xe, ye, node_count, link_target, radius, render_type) {
1173
+ wasm.wasmworld_add_wire_with_count(this.__wbg_ptr, xs, ys, xe, ye, node_count, link_target, radius, render_type);
1174
+ }
1175
+ /**
1176
+ * Deletes a wire by index
1177
+ * @param {number} index
1178
+ * @returns {boolean}
1179
+ */
1180
+ delete_wire(index) {
1181
+ const ret = wasm.wasmworld_delete_wire(this.__wbg_ptr, index);
1182
+ return ret !== 0;
1183
+ }
1184
+ /**
1185
+ * Gets the acceleration vector
1186
+ * @returns {WasmPoint}
1187
+ */
1188
+ get_acceleration() {
1189
+ const ret = wasm.wasmworld_get_acceleration(this.__wbg_ptr);
1190
+ return WasmPoint.__wrap(ret);
1191
+ }
1192
+ /**
1193
+ * Gets the x component of acceleration
1194
+ * @returns {number}
1195
+ */
1196
+ get_acceleration_x() {
1197
+ const ret = wasm.wasmworld_get_acceleration_x(this.__wbg_ptr);
1198
+ return ret;
1199
+ }
1200
+ /**
1201
+ * Gets the y component of acceleration
1202
+ * @returns {number}
1203
+ */
1204
+ get_acceleration_y() {
1205
+ const ret = wasm.wasmworld_get_acceleration_y(this.__wbg_ptr);
1206
+ return ret;
1207
+ }
1208
+ /**
1209
+ * Gets the friction coefficient
1210
+ * @returns {number}
1211
+ */
1212
+ get_friction() {
1213
+ const ret = wasm.wasmworld_get_friction(this.__wbg_ptr);
1214
+ return ret;
1215
+ }
1216
+ /**
1217
+ * Gets the mouse interaction radius
1218
+ * @returns {number}
1219
+ */
1220
+ get_mouse_radius() {
1221
+ const ret = wasm.wasmworld_get_mouse_radius(this.__wbg_ptr);
1222
+ return ret;
1223
+ }
1224
+ /**
1225
+ * Gets the pointer collision radius
1226
+ * @returns {number}
1227
+ */
1228
+ get_pointer_radius() {
1229
+ const ret = wasm.wasmworld_get_pointer_radius(this.__wbg_ptr);
1230
+ return ret;
1231
+ }
1232
+ /**
1233
+ * Gets the collision response coefficient
1234
+ * @returns {number}
1235
+ */
1236
+ get_response_coef() {
1237
+ const ret = wasm.wasmworld_get_response_coef(this.__wbg_ptr);
1238
+ return ret;
1239
+ }
1240
+ /**
1241
+ * Gets a specific wire by index
1242
+ * @param {number} index
1243
+ * @returns {WasmWire | undefined}
1244
+ */
1245
+ get_wire(index) {
1246
+ const ret = wasm.wasmworld_get_wire(this.__wbg_ptr, index);
1247
+ return ret === 0 ? undefined : WasmWire.__wrap(ret);
1248
+ }
1249
+ /**
1250
+ * Gets a node from a specific wire
1251
+ * @param {number} wire_idx
1252
+ * @param {number} node_idx
1253
+ * @returns {WasmNode | undefined}
1254
+ */
1255
+ get_wire_node(wire_idx, node_idx) {
1256
+ const ret = wasm.wasmworld_get_wire_node(this.__wbg_ptr, wire_idx, node_idx);
1257
+ return ret === 0 ? undefined : WasmNode.__wrap(ret);
1258
+ }
1259
+ /**
1260
+ * Gets the number of nodes in a specific wire
1261
+ * @param {number} wire_idx
1262
+ * @returns {number}
1263
+ */
1264
+ get_wire_node_count(wire_idx) {
1265
+ const ret = wasm.wasmworld_get_wire_node_count(this.__wbg_ptr, wire_idx);
1266
+ return ret >>> 0;
1267
+ }
1268
+ /**
1269
+ * Gets x coordinate of a node in a wire
1270
+ * @param {number} wire_idx
1271
+ * @param {number} node_idx
1272
+ * @returns {number}
1273
+ */
1274
+ get_wire_node_x(wire_idx, node_idx) {
1275
+ const ret = wasm.wasmworld_get_wire_node_x(this.__wbg_ptr, wire_idx, node_idx);
1276
+ return ret;
1277
+ }
1278
+ /**
1279
+ * Gets y coordinate of a node in a wire
1280
+ * @param {number} wire_idx
1281
+ * @param {number} node_idx
1282
+ * @returns {number}
1283
+ */
1284
+ get_wire_node_y(wire_idx, node_idx) {
1285
+ const ret = wasm.wasmworld_get_wire_node_y(this.__wbg_ptr, wire_idx, node_idx);
1286
+ return ret;
1287
+ }
1288
+ /**
1289
+ * @param {number} wire_idx
1290
+ * @returns {number}
1291
+ */
1292
+ get_wire_radius(wire_idx) {
1293
+ const ret = wasm.wasmworld_get_wire_radius(this.__wbg_ptr, wire_idx);
1294
+ return ret;
1295
+ }
1296
+ constructor() {
1297
+ const ret = wasm.wasmworld_new();
1298
+ this.__wbg_ptr = ret;
1299
+ WasmWorldFinalization.register(this, this.__wbg_ptr, this);
1300
+ return this;
1301
+ }
1302
+ /**
1303
+ * Removes a node from a specific wire
1304
+ * @param {number} wire_idx
1305
+ * @param {number} node_idx
1306
+ * @returns {boolean}
1307
+ */
1308
+ remove_wire_node(wire_idx, node_idx) {
1309
+ const ret = wasm.wasmworld_remove_wire_node(this.__wbg_ptr, wire_idx, node_idx);
1310
+ return ret !== 0;
1311
+ }
1312
+ /**
1313
+ * Sets the acceleration vector
1314
+ * @param {number} x
1315
+ * @param {number} y
1316
+ */
1317
+ set_acceleration(x, y) {
1318
+ wasm.wasmworld_set_acceleration(this.__wbg_ptr, x, y);
1319
+ }
1320
+ /**
1321
+ * Sets the friction coefficient
1322
+ * @param {number} friction
1323
+ */
1324
+ set_friction(friction) {
1325
+ wasm.wasmworld_set_friction(this.__wbg_ptr, friction);
1326
+ }
1327
+ /**
1328
+ * Sets the mouse position
1329
+ * @param {number} x
1330
+ * @param {number} y
1331
+ */
1332
+ set_mouse(x, y) {
1333
+ wasm.wasmworld_set_mouse(this.__wbg_ptr, x, y);
1334
+ }
1335
+ /**
1336
+ * Sets the mouse interaction radius
1337
+ * @param {number} radius
1338
+ */
1339
+ set_mouse_radius(radius) {
1340
+ wasm.wasmworld_set_mouse_radius(this.__wbg_ptr, radius);
1341
+ }
1342
+ /**
1343
+ * Sets the pointer collision radius
1344
+ * @param {number} radius
1345
+ */
1346
+ set_pointer_radius(radius) {
1347
+ wasm.wasmworld_set_pointer_radius(this.__wbg_ptr, radius);
1348
+ }
1349
+ /**
1350
+ * Sets the collision response coefficient
1351
+ * @param {number} coef
1352
+ */
1353
+ set_response_coef(coef) {
1354
+ wasm.wasmworld_set_response_coef(this.__wbg_ptr, coef);
1355
+ }
1356
+ /**
1357
+ * Sets the position of the last node (end) of a wire
1358
+ * @param {number} wire_idx
1359
+ * @param {number} x
1360
+ * @param {number} y
1361
+ */
1362
+ set_wire_end(wire_idx, x, y) {
1363
+ wasm.wasmworld_set_wire_end(this.__wbg_ptr, wire_idx, x, y);
1364
+ }
1365
+ /**
1366
+ * Sets the number of nodes in a specific wire
1367
+ * @param {number} wire_idx
1368
+ * @param {number} node_count
1369
+ */
1370
+ set_wire_node_count(wire_idx, node_count) {
1371
+ wasm.wasmworld_set_wire_node_count(this.__wbg_ptr, wire_idx, node_count);
1372
+ }
1373
+ /**
1374
+ * Sets the fixed state of a specific node in a wire
1375
+ * @param {number} wire_idx
1376
+ * @param {number} node_idx
1377
+ * @param {boolean} fixed
1378
+ */
1379
+ set_wire_node_fixed(wire_idx, node_idx, fixed) {
1380
+ wasm.wasmworld_set_wire_node_fixed(this.__wbg_ptr, wire_idx, node_idx, fixed);
1381
+ }
1382
+ /**
1383
+ * Sets the position of a specific node in a wire
1384
+ * @param {number} wire_idx
1385
+ * @param {number} node_idx
1386
+ * @param {number} x
1387
+ * @param {number} y
1388
+ */
1389
+ set_wire_node_position(wire_idx, node_idx, x, y) {
1390
+ wasm.wasmworld_set_wire_node_position(this.__wbg_ptr, wire_idx, node_idx, x, y);
1391
+ }
1392
+ /**
1393
+ * Sets the radius of a specific wire
1394
+ * @param {number} wire_idx
1395
+ * @param {number} radius
1396
+ */
1397
+ set_wire_radius(wire_idx, radius) {
1398
+ wasm.wasmworld_set_wire_radius(this.__wbg_ptr, wire_idx, radius);
1399
+ }
1400
+ /**
1401
+ * Sets the position of the first node (start) of a wire
1402
+ * @param {number} wire_idx
1403
+ * @param {number} x
1404
+ * @param {number} y
1405
+ */
1406
+ set_wire_start(wire_idx, x, y) {
1407
+ wasm.wasmworld_set_wire_start(this.__wbg_ptr, wire_idx, x, y);
1408
+ }
1409
+ /**
1410
+ * Updates all wires in the world
1411
+ */
1412
+ update() {
1413
+ wasm.wasmworld_update(this.__wbg_ptr);
1414
+ }
1415
+ /**
1416
+ * Returns the number of wires
1417
+ * @returns {number}
1418
+ */
1419
+ wire_count() {
1420
+ const ret = wasm.wasmworld_wire_count(this.__wbg_ptr);
1421
+ return ret >>> 0;
1422
+ }
1423
+ /**
1424
+ * Returns the length of the wire data buffer
1425
+ * @returns {number}
1426
+ */
1427
+ wire_data_len() {
1428
+ const ret = wasm.wasmworld_wire_data_len(this.__wbg_ptr);
1429
+ return ret >>> 0;
1430
+ }
1431
+ /**
1432
+ * Returns the pointer to the wire data buffer
1433
+ * Buffer format per wire: [node_count, radius, render_type, path_length, ...path_data]
1434
+ * @returns {number}
1435
+ */
1436
+ wire_data_ptr() {
1437
+ const ret = wasm.wasmworld_wire_data_ptr(this.__wbg_ptr);
1438
+ return ret >>> 0;
1439
+ }
1440
+ /**
1441
+ * Calculates the default node count for a wire based on distance and link target
1442
+ * @param {number} start_x
1443
+ * @param {number} start_y
1444
+ * @param {number} end_x
1445
+ * @param {number} end_y
1446
+ * @param {number} radius
1447
+ * @returns {number}
1448
+ */
1449
+ static wire_optimal_length(start_x, start_y, end_x, end_y, radius) {
1450
+ const ret = wasm.wasmworld_wire_optimal_length(start_x, start_y, end_x, end_y, radius);
1451
+ return ret >>> 0;
1452
+ }
1453
+ }
1454
+ if (Symbol.dispose) WasmWorld.prototype[Symbol.dispose] = WasmWorld.prototype.free;
1455
+ function __wbg_get_imports() {
1456
+ const import0 = {
1457
+ __proto__: null,
1458
+ __wbg___wbindgen_throw_bb96b2010945f0bc: function(arg0, arg1) {
1459
+ throw new Error(getStringFromWasm0(arg0, arg1));
1460
+ },
1461
+ __wbindgen_init_externref_table: function() {
1462
+ const table = wasm.__wbindgen_externrefs;
1463
+ const offset = table.grow(4);
1464
+ table.set(0, undefined);
1465
+ table.set(offset + 0, undefined);
1466
+ table.set(offset + 1, null);
1467
+ table.set(offset + 2, true);
1468
+ table.set(offset + 3, false);
1469
+ },
1470
+ };
1471
+ return {
1472
+ __proto__: null,
1473
+ "./cavi_bg.js": import0,
1474
+ };
1475
+ }
1476
+
1477
+ const WasmNodeFinalization = (typeof FinalizationRegistry === 'undefined')
1478
+ ? { register: () => {}, unregister: () => {} }
1479
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmnode_free(ptr, 1));
1480
+ const WasmPointFinalization = (typeof FinalizationRegistry === 'undefined')
1481
+ ? { register: () => {}, unregister: () => {} }
1482
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmpoint_free(ptr, 1));
1483
+ const WasmPositionFinalization = (typeof FinalizationRegistry === 'undefined')
1484
+ ? { register: () => {}, unregister: () => {} }
1485
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmposition_free(ptr, 1));
1486
+ const WasmWireFinalization = (typeof FinalizationRegistry === 'undefined')
1487
+ ? { register: () => {}, unregister: () => {} }
1488
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmwire_free(ptr, 1));
1489
+ const WasmWorldFinalization = (typeof FinalizationRegistry === 'undefined')
1490
+ ? { register: () => {}, unregister: () => {} }
1491
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmworld_free(ptr, 1));
1492
+
1493
+ function _assertClass(instance, klass) {
1494
+ if (!(instance instanceof klass)) {
1495
+ throw new Error(`expected instance of ${klass.name}`);
1496
+ }
1497
+ }
1498
+
1499
+ function getStringFromWasm0(ptr, len) {
1500
+ return decodeText(ptr >>> 0, len);
1501
+ }
1502
+
1503
+ let cachedUint8ArrayMemory0 = null;
1504
+ function getUint8ArrayMemory0() {
1505
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
1506
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
1507
+ }
1508
+ return cachedUint8ArrayMemory0;
1509
+ }
1510
+
1511
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
1512
+ cachedTextDecoder.decode();
1513
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
1514
+ let numBytesDecoded = 0;
1515
+ function decodeText(ptr, len) {
1516
+ numBytesDecoded += len;
1517
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
1518
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
1519
+ cachedTextDecoder.decode();
1520
+ numBytesDecoded = len;
1521
+ }
1522
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
1523
+ }
1524
+
1525
+ let wasmModule, wasmInstance, wasm;
1526
+ function __wbg_finalize_init(instance, module) {
1527
+ wasmInstance = instance;
1528
+ wasm = instance.exports;
1529
+ wasmModule = module;
1530
+ cachedUint8ArrayMemory0 = null;
1531
+ wasm.__wbindgen_start();
1532
+ return wasm;
1533
+ }
1534
+
1535
+ async function __wbg_load(module, imports) {
1536
+ if (typeof Response === 'function' && module instanceof Response) {
1537
+ if (!module.ok) {
1538
+ throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
1539
+ }
1540
+
1541
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
1542
+ try {
1543
+ return await WebAssembly.instantiateStreaming(module, imports);
1544
+ } catch (e) {
1545
+ const validResponse = expectedResponseType(module.type);
1546
+
1547
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
1548
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
1549
+
1550
+ } else { throw e; }
1551
+ }
1552
+ }
1553
+
1554
+ const bytes = await module.arrayBuffer();
1555
+ return await WebAssembly.instantiate(bytes, imports);
1556
+ } else {
1557
+ const instance = await WebAssembly.instantiate(module, imports);
1558
+
1559
+ if (instance instanceof WebAssembly.Instance) {
1560
+ return { instance, module };
1561
+ } else {
1562
+ return instance;
1563
+ }
1564
+ }
1565
+
1566
+ function expectedResponseType(type) {
1567
+ switch (type) {
1568
+ case 'basic': case 'cors': case 'default': return true;
1569
+ }
1570
+ return false;
1571
+ }
1572
+ }
1573
+
1574
+ function initSync(module) {
1575
+ if (wasm !== undefined) return wasm;
1576
+
1577
+
1578
+ if (module !== undefined) {
1579
+ if (Object.getPrototypeOf(module) === Object.prototype) {
1580
+ ({module} = module)
1581
+ } else {
1582
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
1583
+ }
1584
+ }
1585
+
1586
+ const imports = __wbg_get_imports();
1587
+ if (!(module instanceof WebAssembly.Module)) {
1588
+ module = new WebAssembly.Module(module);
1589
+ }
1590
+ const instance = new WebAssembly.Instance(module, imports);
1591
+ return __wbg_finalize_init(instance, module);
1592
+ }
1593
+
1594
+ async function __wbg_init(module_or_path) {
1595
+ if (wasm !== undefined) return wasm;
1596
+
1597
+
1598
+ if (module_or_path !== undefined) {
1599
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
1600
+ ({module_or_path} = module_or_path)
1601
+ } else {
1602
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
1603
+ }
1604
+ }
1605
+
1606
+ if (module_or_path === undefined) {
1607
+ module_or_path = new URL('cavi_bg.wasm', import.meta.url);
1608
+ }
1609
+ const imports = __wbg_get_imports();
1610
+
1611
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
1612
+ module_or_path = fetch(module_or_path);
1613
+ }
1614
+
1615
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
1616
+
1617
+ return __wbg_finalize_init(instance, module);
1618
+ }
1619
+
1620
+ export { initSync, __wbg_init as default };