mathue 0.1.0 → 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.
- package/LICENSE +9 -9
- package/README.md +114 -88
- package/dist/index.d.ts +120 -51
- package/dist/mathue.cjs +1 -1
- package/dist/mathue.js +51 -31
- package/dist/mathue.umd.cjs +1 -1
- package/package.json +65 -56
package/LICENSE
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
The MIT License
|
|
2
|
-
|
|
3
|
-
Copyright 2025 SueueGunn
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
-
|
|
7
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
-
|
|
9
|
-
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright 2025 SueueGunn
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,88 +1,114 @@
|
|
|
1
|
-
<p align="center">
|
|
2
|
-
<img src="typedoc/favicon.ico" width="200">
|
|
3
|
-
</p>
|
|
4
|
-
<h1 align="center">mathue</h1>
|
|
5
|
-
|
|
6
|
-
[](https://github.com/sueuegunn/mathue/actions/workflows/test.yaml)
|
|
7
|
-
](https://opensource.org/licenses/MIT)
|
|
9
|
-
](https://github.com/sueuegunn/mathue/actions/workflows/test.yaml)
|
|
7
|
+

|
|
8
|
+
[](https://opensource.org/licenses/MIT)
|
|
9
|
+
[](https://www.npmjs.com/package/mathue)
|
|
10
|
+
|
|
11
|
+
**A high-performance TypeScript math library specially optimized for WebGL applications.**
|
|
12
|
+
|
|
13
|
+
Pronounced as **"Matthew"** ( mˈæθjuː ).
|
|
14
|
+
|
|
15
|
+
<br>
|
|
16
|
+
|
|
17
|
+
## 🔗 Links
|
|
18
|
+
|
|
19
|
+
* [Docs](https://sueuegunn.github.io/mathue/index.html)
|
|
20
|
+
* [npm](https://www.npmjs.com/package/mathue)
|
|
21
|
+
|
|
22
|
+
<br>
|
|
23
|
+
|
|
24
|
+
## 🚀 Why mathue?
|
|
25
|
+
|
|
26
|
+
Standard math libraries often create new objects for every calculation, causing Garbage Collection (GC) spikes that ruin the performance of real-time rendering loops (60fps+).
|
|
27
|
+
|
|
28
|
+
**mathue is designed to be "Zero-Allocation" by default.**
|
|
29
|
+
|
|
30
|
+
<br>
|
|
31
|
+
|
|
32
|
+
### Key Features
|
|
33
|
+
|
|
34
|
+
* **⚡ Zero-Allocation Design**: Minimizes GC overhead by using **mutable operations** (in-place modification) and reusing **static internal temporaries** for complex calculations.
|
|
35
|
+
* **🛠️ Flexible**: While optimized for mutation, every class implements `.clone()` and factory methods (e.g., `.identity()`, `.zero()`) for when you need immutable behavior.
|
|
36
|
+
* **⛓️ Method Chaining**: All mutable methods return `this`, allowing for concise and readable code similar to modern engines.
|
|
37
|
+
* **ts TypeScript First**: Built completely in TypeScript with full type definitions (`.d.ts`) included.
|
|
38
|
+
* **🟢 Standalone**: No external dependencies.
|
|
39
|
+
|
|
40
|
+
<br>
|
|
41
|
+
|
|
42
|
+
## 📦 Installation
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
npm install mathue
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
<br>
|
|
49
|
+
|
|
50
|
+
## 📖 Usage
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
// Applies matrix to vector
|
|
54
|
+
import {Vector3, Matrix4, Quaternion} from 'mathue';
|
|
55
|
+
|
|
56
|
+
const v = new Vector3(1, 2, 3);
|
|
57
|
+
|
|
58
|
+
const axis = new Vector3(0, 0, 1);
|
|
59
|
+
const angle = Math.PI / 3;
|
|
60
|
+
const q = Quaternion.fromAxisAndAngle(axis, angle);
|
|
61
|
+
|
|
62
|
+
const m = Matrix4.identity();
|
|
63
|
+
m.setQuaternion(q);
|
|
64
|
+
|
|
65
|
+
v.applyMatrix4(m);
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
// Calculates model matrix
|
|
70
|
+
const position = new Vector3(1, 2, 3);
|
|
71
|
+
const rotation = Quaternion.identity();
|
|
72
|
+
const scale = new Vector3(2, 2, 2);
|
|
73
|
+
|
|
74
|
+
const model = Matrix4.identity();
|
|
75
|
+
|
|
76
|
+
model.setIdentity()
|
|
77
|
+
.multiplyTranslation(position)
|
|
78
|
+
.multiplyRotation(rotation)
|
|
79
|
+
.multiplyScale(scale);
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
<br>
|
|
83
|
+
|
|
84
|
+
## 📚 API Overview
|
|
85
|
+
|
|
86
|
+
* Vector
|
|
87
|
+
* Vector1
|
|
88
|
+
* Vector2
|
|
89
|
+
* Vector3
|
|
90
|
+
* Vector4
|
|
91
|
+
* Matrix (Column-major order, WebGL compatible)
|
|
92
|
+
* Matrix3
|
|
93
|
+
* Matrix4
|
|
94
|
+
* PolarCoordinate3
|
|
95
|
+
* Quaternion (For rotation without gimbal lock)
|
|
96
|
+
|
|
97
|
+
See the [Full Documentation](https://sueuegunn.github.io/mathue/index.html) for details.
|
|
98
|
+
|
|
99
|
+
<br>
|
|
100
|
+
|
|
101
|
+
## 📄 License
|
|
102
|
+
|
|
103
|
+
MIT License
|
|
104
|
+
|
|
105
|
+
<br>
|
|
106
|
+
|
|
107
|
+
## 📐 Logo
|
|
108
|
+
|
|
109
|
+
<p align="center">
|
|
110
|
+
<img src="typedoc/favicon.ico" width="128">
|
|
111
|
+
</p>
|
|
112
|
+
|
|
113
|
+
The logo features **two upward vectors** arranged to form the letter "M".
|
|
114
|
+
Conceptually, the right vector represents the left vector transformed by a Matrix or Quaternion.
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,21 @@ export declare interface AdditiveGroup<T> {
|
|
|
3
3
|
subtract(other: T): T;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Options for transforming a 3D vector by a 4x4 matrix.
|
|
8
|
+
*/
|
|
9
|
+
export declare type ApplyMatrix4Options = {
|
|
10
|
+
/**
|
|
11
|
+
* Determines whether the vector is treated as a direction or a point.
|
|
12
|
+
*
|
|
13
|
+
* - `true`: Treated as a **direction** (w = 0).
|
|
14
|
+
* - `false` (default): Treated as a **point** (w = 1).
|
|
15
|
+
*
|
|
16
|
+
* @default false
|
|
17
|
+
*/
|
|
18
|
+
asDirection?: boolean;
|
|
19
|
+
};
|
|
20
|
+
|
|
6
21
|
export declare interface Clonable<T> {
|
|
7
22
|
clone(): T;
|
|
8
23
|
}
|
|
@@ -458,16 +473,52 @@ export declare class Matrix4 implements Matrix<4>, AdditiveGroup<Matrix4>, Parti
|
|
|
458
473
|
* ```
|
|
459
474
|
*/
|
|
460
475
|
setIdentity(): Matrix4;
|
|
476
|
+
/**
|
|
477
|
+
* Sets scale transformation matrix (mutates this)
|
|
478
|
+
* @param scale 3D scale vector
|
|
479
|
+
* @returns this instance, for method chaining
|
|
480
|
+
*
|
|
481
|
+
* @example
|
|
482
|
+
* ```ts
|
|
483
|
+
* const m = Matrix4.identity();
|
|
484
|
+
* const s = new Vector3(2, 3, 4);
|
|
485
|
+
* m.setScale(s);
|
|
486
|
+
* console.log(m.elements);
|
|
487
|
+
* // [ 2, 0, 0, 0,
|
|
488
|
+
* // 0, 3, 0, 0,
|
|
489
|
+
* // 0, 0, 4, 0,
|
|
490
|
+
* // 0, 0, 0, 1 ]
|
|
491
|
+
* ```
|
|
492
|
+
*/
|
|
493
|
+
setScale(scale: Vector3): Matrix4;
|
|
494
|
+
/**
|
|
495
|
+
* Sets translation transformation matrix (mutates this)
|
|
496
|
+
* @param translation translation vector
|
|
497
|
+
* @returns this instance, for method chaining
|
|
498
|
+
*
|
|
499
|
+
* @example
|
|
500
|
+
* ```ts
|
|
501
|
+
* const m = Matrix4.identity();
|
|
502
|
+
* const t = new Vector3(2, 3, 4);
|
|
503
|
+
* m.setTranslation(t);
|
|
504
|
+
* console.log(m.elements);
|
|
505
|
+
* // [ 1, 0, 0, 0,
|
|
506
|
+
* // 0, 1, 0, 0,
|
|
507
|
+
* // 0, 0, 1, 0,
|
|
508
|
+
* // 2, 3, 4, 1 ]
|
|
509
|
+
* ```
|
|
510
|
+
*/
|
|
511
|
+
setTranslation(translation: Vector3): Matrix4;
|
|
461
512
|
/**
|
|
462
513
|
* Sets rotation matrix from quaternion (mutates this)
|
|
463
|
-
* @param
|
|
514
|
+
* @param rotation
|
|
464
515
|
* @returns this instance, for method chaining
|
|
465
516
|
*
|
|
466
517
|
* @example
|
|
467
518
|
* ```ts
|
|
468
519
|
* const m = Matrix4.zero();
|
|
469
520
|
* const q = Quaternion.identity();
|
|
470
|
-
* m.
|
|
521
|
+
* m.setRotation(q);
|
|
471
522
|
* console.log(m.elements);
|
|
472
523
|
* // [ 0, 0, 0, 0,
|
|
473
524
|
* // 0, 0, 0, 0,
|
|
@@ -475,7 +526,7 @@ export declare class Matrix4 implements Matrix<4>, AdditiveGroup<Matrix4>, Parti
|
|
|
475
526
|
* // 0, 0, 0, 0 ]
|
|
476
527
|
* ```
|
|
477
528
|
*/
|
|
478
|
-
|
|
529
|
+
setRotation(rotation: Quaternion): Matrix4;
|
|
479
530
|
/**
|
|
480
531
|
* Adds by other matrix (mutates this)
|
|
481
532
|
* @param other other matrix
|
|
@@ -564,6 +615,24 @@ export declare class Matrix4 implements Matrix<4>, AdditiveGroup<Matrix4>, Parti
|
|
|
564
615
|
* ```
|
|
565
616
|
*/
|
|
566
617
|
multiply(other: Matrix4): Matrix4;
|
|
618
|
+
/**
|
|
619
|
+
* Multiplies scale matrix to this instance (mutates this)
|
|
620
|
+
* @param scale 3D scale vector
|
|
621
|
+
* @returns this instance, for method chaining
|
|
622
|
+
*/
|
|
623
|
+
multiplyScale(scale: Vector3): Matrix4;
|
|
624
|
+
/**
|
|
625
|
+
* Multiplies translation matrix to this instance (mutates this)
|
|
626
|
+
* @param position translation vector
|
|
627
|
+
* @returns this instance, for method chaining
|
|
628
|
+
*/
|
|
629
|
+
multiplyTranslation(position: Vector3): Matrix4;
|
|
630
|
+
/**
|
|
631
|
+
* Multiplies rotation matrix to this instance (mutates this)
|
|
632
|
+
* @param rotation rotation quaternion
|
|
633
|
+
* @returns this instance, for method chaining
|
|
634
|
+
*/
|
|
635
|
+
multiplyRotation(rotation: Quaternion): Matrix4;
|
|
567
636
|
/**
|
|
568
637
|
* Calculates determinant of this matrix (pure)
|
|
569
638
|
* @returns determinant of this matrix
|
|
@@ -585,42 +654,6 @@ export declare class Matrix4 implements Matrix<4>, AdditiveGroup<Matrix4>, Parti
|
|
|
585
654
|
* @returns `this` instance for method chaining if other is invertible, `null` otherwise
|
|
586
655
|
*/
|
|
587
656
|
divide(other: Matrix4): Matrix4 | null;
|
|
588
|
-
/**
|
|
589
|
-
* Sets scale transformation matrix (mutates this)
|
|
590
|
-
* @param scale 3D scale vector
|
|
591
|
-
* @returns this instance, for method chaining
|
|
592
|
-
*
|
|
593
|
-
* @example
|
|
594
|
-
* ```ts
|
|
595
|
-
* const m = Matrix4.identity();
|
|
596
|
-
* const s = new Vector3(2, 3, 4);
|
|
597
|
-
* m.scale(s);
|
|
598
|
-
* console.log(m.elements);
|
|
599
|
-
* // [ 2, 0, 0, 0,
|
|
600
|
-
* // 0, 3, 0, 0,
|
|
601
|
-
* // 0, 0, 4, 0,
|
|
602
|
-
* // 0, 0, 0, 1 ]
|
|
603
|
-
* ```
|
|
604
|
-
*/
|
|
605
|
-
scale(scale: Vector3): Matrix4;
|
|
606
|
-
/**
|
|
607
|
-
* Sets translation transformation matrix (mutates this)
|
|
608
|
-
* @param translation translation vector
|
|
609
|
-
* @returns this instance, for method chaining
|
|
610
|
-
*
|
|
611
|
-
* @example
|
|
612
|
-
* ```ts
|
|
613
|
-
* const m = Matrix4.identity();
|
|
614
|
-
* const t = new Vector3(2, 3, 4);
|
|
615
|
-
* m.translate(t);
|
|
616
|
-
* console.log(m.elements);
|
|
617
|
-
* // [ 1, 0, 0, 0,
|
|
618
|
-
* // 0, 1, 0, 0,
|
|
619
|
-
* // 0, 0, 1, 0,
|
|
620
|
-
* // 2, 3, 4, 1 ]
|
|
621
|
-
* ```
|
|
622
|
-
*/
|
|
623
|
-
translate(translation: Vector3): Matrix4;
|
|
624
657
|
/**
|
|
625
658
|
* Sets view transformation matrix (mutates this)
|
|
626
659
|
* @param position camera position
|
|
@@ -638,12 +671,25 @@ export declare class Matrix4 implements Matrix<4>, AdditiveGroup<Matrix4>, Parti
|
|
|
638
671
|
* ```
|
|
639
672
|
*/
|
|
640
673
|
lookAt(position: Vector3, target: Vector3, up: Vector3): Matrix4;
|
|
674
|
+
/**
|
|
675
|
+
* Sets projection matrix of orthographic camera (mutates this)
|
|
676
|
+
* @param left left boundary of the view frustum (negative X coordinate)
|
|
677
|
+
* @param right right boundary of the view frustum (positive X coordinate)
|
|
678
|
+
* @param bottom bottom boundary of the view frustum (negative Y coordinate)
|
|
679
|
+
* @param top top boundary of the view frustum (positive Y coordinate)
|
|
680
|
+
* @param near near clipping plane distance (positive value)
|
|
681
|
+
* @param far far clipping plane distance (positive value)
|
|
682
|
+
* @param options options for orthographic projection matrix
|
|
683
|
+
* @returns this instance, for method chaining
|
|
684
|
+
*/
|
|
685
|
+
orthographic(left: number, right: number, bottom: number, top: number, near: number, far: number, options?: ProjectionOptions): Matrix4;
|
|
641
686
|
/**
|
|
642
687
|
* Sets projection matrix of perspective camera (mutates this)
|
|
643
688
|
* @param verticalFov vertical field of view in radians
|
|
644
689
|
* @param near near clipping plane distance
|
|
645
690
|
* @param far far clipping plane distance
|
|
646
691
|
* @param aspect aspect ratio (width / height)
|
|
692
|
+
* @param options options for perspective projection matrix
|
|
647
693
|
* @returns this instance, for method chaining
|
|
648
694
|
*
|
|
649
695
|
* @example
|
|
@@ -653,10 +699,15 @@ export declare class Matrix4 implements Matrix<4>, AdditiveGroup<Matrix4>, Parti
|
|
|
653
699
|
* const near = 0.01;
|
|
654
700
|
* const far = 4.0;
|
|
655
701
|
* const aspect = 300 / 150;
|
|
702
|
+
*
|
|
703
|
+
* // for OpenGL, WebGL
|
|
656
704
|
* m.perspective(fov, near, far, aspect);
|
|
705
|
+
*
|
|
706
|
+
* // for WebGPU, Vulkan, DirectX, Metal
|
|
707
|
+
* m.perspective(fov, near, far, aspect, {depthZeroToOne: true});
|
|
657
708
|
* ```
|
|
658
709
|
*/
|
|
659
|
-
perspective(verticalFov: number, near: number, far: number, aspect: number): Matrix4;
|
|
710
|
+
perspective(verticalFov: number, near: number, far: number, aspect: number, options?: ProjectionOptions): Matrix4;
|
|
660
711
|
/** @ignore */
|
|
661
712
|
_applyVector(x: number, y: number, z: number, w: number): Vector4;
|
|
662
713
|
}
|
|
@@ -699,27 +750,27 @@ export declare class PolarCoordinate3 {
|
|
|
699
750
|
private _theta;
|
|
700
751
|
private _radius;
|
|
701
752
|
/**
|
|
702
|
-
* @param phi
|
|
703
|
-
* @param theta
|
|
753
|
+
* @param phi azimuthal angle theta in range [0, 2π] in radians
|
|
754
|
+
* @param theta polar angle phi in range [0, π] in radians
|
|
704
755
|
* @param radius radial distance from the origin, must be non-negative
|
|
705
756
|
*/
|
|
706
757
|
constructor(phi: number, theta: number, radius: number);
|
|
707
758
|
/**
|
|
708
|
-
* Gets
|
|
759
|
+
* Gets azimuthal angle theta in range [0, 2π] in radians, measured from the positive x-axis.
|
|
709
760
|
*/
|
|
710
761
|
get phi(): number;
|
|
711
762
|
/**
|
|
712
|
-
* Sets
|
|
713
|
-
* @param value
|
|
763
|
+
* Sets azimuthal angle theta in range [0, 2π] in radians, measured from the positive x-axis.
|
|
764
|
+
* @param value azimuthal angle in range [0, 2π]
|
|
714
765
|
*/
|
|
715
766
|
set phi(value: number);
|
|
716
767
|
/**
|
|
717
|
-
* Gets
|
|
768
|
+
* Gets polar angle phi in range [0, π] in radians, measured from positive z-axis.
|
|
718
769
|
*/
|
|
719
770
|
get theta(): number;
|
|
720
771
|
/**
|
|
721
|
-
* Sets
|
|
722
|
-
* @param value
|
|
772
|
+
* Sets polar angle phi in range [0, π] in radians, measured from positive z-axis.
|
|
773
|
+
* @param value polar angle in range [0, π]
|
|
723
774
|
*/
|
|
724
775
|
set theta(value: number);
|
|
725
776
|
/**
|
|
@@ -731,19 +782,36 @@ export declare class PolarCoordinate3 {
|
|
|
731
782
|
*/
|
|
732
783
|
set radius(value: number);
|
|
733
784
|
/**
|
|
734
|
-
* Converts polar coordinate to Vector3 and stores result in `out` vector.
|
|
785
|
+
* Converts polar coordinate to Vector3 and stores result in `out` vector. (mutates out)
|
|
735
786
|
* @param out vector instance to receive result
|
|
736
787
|
* @returns {void}
|
|
737
788
|
*/
|
|
738
789
|
toVector3(out: Vector3): void;
|
|
739
790
|
/**
|
|
740
|
-
* Converts to tangent vector pointing positive z-axis direction, and sotres result in `out` vector.
|
|
791
|
+
* Converts to tangent vector pointing positive z-axis direction, and sotres result in `out` vector. (mutates out)
|
|
741
792
|
* @param out vector instance to receive result
|
|
742
793
|
* @returns {void}
|
|
743
794
|
*/
|
|
744
795
|
toTangentZ(out: Vector3): void;
|
|
745
796
|
}
|
|
746
797
|
|
|
798
|
+
/**
|
|
799
|
+
* Options for generating a projection matrix.
|
|
800
|
+
*/
|
|
801
|
+
export declare type ProjectionOptions = {
|
|
802
|
+
/**
|
|
803
|
+
* Determines the normalized device coordinate (NDC) Z range for the clip planes. [1, 2]
|
|
804
|
+
*
|
|
805
|
+
* - `false` (default): Corresponds to a Z range of **[-1, 1]**, which matches the clip volume
|
|
806
|
+
* requirements for **WebGL and OpenGL**. [1]
|
|
807
|
+
* - `true`: Corresponds to a Z range of ****, which matches the clip volume
|
|
808
|
+
* requirements for modern APIs such as **WebGPU, Vulkan, DirectX, and Metal**. [2]
|
|
809
|
+
*
|
|
810
|
+
* @default false
|
|
811
|
+
*/
|
|
812
|
+
depthZeroToOne?: boolean;
|
|
813
|
+
};
|
|
814
|
+
|
|
747
815
|
/**
|
|
748
816
|
* Represents a quaternion using Hamilton's notation: q = a + bi + cj + dk
|
|
749
817
|
*/
|
|
@@ -1907,9 +1975,10 @@ export declare class Vector3 implements Vector<3>, AdditiveGroup<Vector3>, Scala
|
|
|
1907
1975
|
/**
|
|
1908
1976
|
* Applies matrix to this vector (mutates this)
|
|
1909
1977
|
* @param matrix
|
|
1978
|
+
* @param options
|
|
1910
1979
|
* @returns this instance, for method chaining
|
|
1911
1980
|
*/
|
|
1912
|
-
applyMatrix4(matrix: Matrix4): Vector3;
|
|
1981
|
+
applyMatrix4(matrix: Matrix4, options?: ApplyMatrix4Options): Vector3;
|
|
1913
1982
|
/**
|
|
1914
1983
|
* Applies quaternion to this vector (mutates this)
|
|
1915
1984
|
* @param quaternion
|
package/dist/mathue.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function*e(e,t){let n=t?.start??0,r=t?.step??1;if(r!==0&&!(r>0&&n>e)&&!(r<0&&n<e))for(let t=n;r>0?t<e:t>e;t+=r)yield t}function t(e){let t=0;for(let n of e)t+=n;return t}function n(e,t){let n=0;for(let r of e)n+=t(r)??0;return n}var r=0,i=1,a=2,o=3,s=class e{dimension=4;elements;static _tmpMatrix4;static get tmpMatrix4(){return this._tmpMatrix4||=l.identity(),this._tmpMatrix4}constructor(e,t,n,r){this.elements=[e,t,n,r]}get x(){return this.elements[r]}set x(e){this.elements[r]=e}get y(){return this.elements[i]}set y(e){this.elements[i]=e}get z(){return this.elements[a]}set z(e){this.elements[a]=e}get w(){return this.elements[o]}set w(e){this.elements[o]=e}static zero(){return new e(0,0,0,0)}static one(){return new e(1,1,1,1)}clone(){let{x:t,y:n,z:r,w:i}=this;return new e(t,n,r,i)}isZero(){let{x:e,y:t,z:n,w:r}=this;return e===0&&t===0&&n===0&&r===0}set(e,t,n,r){this.x=e,this.y=t,this.z=n,this.w=r}copy(e){let{x:t,y:n,z:r,w:i}=e;this.set(t,n,r,i)}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this}subtract(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this}divideScalar(e){return this.x/=e,this.y/=e,this.z/=e,this.w/=e,this}length(){let{x:e,y:t,z:n,w:r}=this;return Math.sqrt(e**2+t**2+n**2+r**2)}normalize(){let e=this.length();return e<=0?this:this.divideScalar(e)}applyMatrix4(t){let{tmpMatrix4:n}=e;n.copy(t);let{x:r,y:i,z:a,w:o}=this,s=n._applyVector(r,i,a,o);return this.copy(s),this}applyQuaternion(t){let{tmpMatrix4:n}=e;n.setQuaternion(t);let{x:r,y:i,z:a,w:o}=this,s=n._applyVector(r,i,a,o);return this.copy(s),this}},c=1e-8,l=class t{order=4;elements;static _tmpMatrix;static get tmpMatrix(){return this._tmpMatrix||=t.identity(),this._tmpMatrix}static _tmpVector;static get tmpVector(){return this._tmpVector||=s.zero(),this._tmpVector}constructor(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h){this.elements=Float32Array.of(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h)}static identity(){return t.zero().setIdentity()}static zero(){return new t(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}clone(){let[e,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g]=this.elements;return new t(e,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g)}set(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h){return this.elements[0]=e,this.elements[1]=t,this.elements[2]=n,this.elements[3]=r,this.elements[4]=i,this.elements[5]=a,this.elements[6]=o,this.elements[7]=s,this.elements[8]=c,this.elements[9]=l,this.elements[10]=u,this.elements[11]=d,this.elements[12]=f,this.elements[13]=p,this.elements[14]=m,this.elements[15]=h,this}copy(e){let[t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g]=e.elements;this.set(t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g)}setIdentity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}setQuaternion(e){let{a:t,b:n,c:r,d:i}=e,a=2/e.squaredNorm(),o=n**2,s=r**2,c=i**2,l=t*n,u=t*r,d=t*i,f=n*r,p=n*i,m=r*i;return this.set(1-a*(s+c),a*(f-d),a*(p+u),0,a*(f+d),1-a*(o+c),a*(m-l),0,a*(p-u),a*(m+l),1-a*(o+s),0,0,0,0,1),this}add(t){let{order:n}=this;for(let r of e(n**2))this.elements[r]+=t.elements[r];return this}subtract(t){let{order:n}=this;for(let r of e(n**2))this.elements[r]-=t.elements[r];return this}multiplyScalar(t){let{order:n}=this;for(let r of e(n**2))this.elements[r]*=t;return this}divideScalar(t){let{order:n}=this;for(let r of e(n**2))this.elements[r]/=t;return this}multiply(e){let[t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g]=this.elements,[_,v,y,b,x,S,C,w,T,E,D,O,k,A,j,M]=e.elements;return this.elements[0]=_*t+v*a+y*l+b*p,this.elements[1]=_*n+v*o+y*u+b*m,this.elements[2]=_*r+v*s+y*d+b*h,this.elements[3]=_*i+v*c+y*f+b*g,this.elements[4]=x*t+S*a+C*l+w*p,this.elements[5]=x*n+S*o+C*u+w*m,this.elements[6]=x*r+S*s+C*d+w*h,this.elements[7]=x*i+S*c+C*f+w*g,this.elements[8]=T*t+E*a+D*l+O*p,this.elements[9]=T*n+E*o+D*u+O*m,this.elements[10]=T*r+E*s+D*d+O*h,this.elements[11]=T*i+E*c+D*f+O*g,this.elements[12]=k*t+A*a+j*l+M*p,this.elements[13]=k*n+A*o+j*u+M*m,this.elements[14]=k*r+A*s+j*d+M*h,this.elements[15]=k*i+A*c+j*f+M*g,this}determinant(){let[e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h]=this.elements;return e*(a*(u*h-d*m)-o*(l*h-d*p)+s*(l*m-u*p))-t*(i*(u*h-d*m)-o*(c*h-d*f)+s*(c*m-u*f))+n*(i*(l*h-d*p)-a*(c*h-d*f)+s*(c*p-l*f))-r*(i*(l*m-u*p)-a*(c*m-u*f)+o*(c*p-l*f))}invert(){let e=this.determinant();if(Math.abs(e)<c)return null;let[t,n,r,i,a,o,s,l,u,d,f,p,m,h,g,_]=this.elements,v=f*_-p*g,y=d*_-p*h,b=d*g-f*h,x=s*_-l*g,S=o*_-l*h,C=o*g-s*h,w=s*p-l*f,T=o*p-l*d,E=o*f-s*d,D=u*_-p*m,O=u*g-f*m,k=a*_-l*m,A=a*g-s*m,j=a*p-l*u,M=a*f-s*u,N=u*h-d*m,P=a*h-o*m,F=a*d-o*u;return this.elements[0]=(o*v-s*y+l*b)/e,this.elements[1]=-(n*v-r*y+i*b)/e,this.elements[2]=(n*x-r*S+i*C)/e,this.elements[3]=-(n*w-r*T+i*E)/e,this.elements[4]=-(a*v-s*D+l*O)/e,this.elements[5]=(t*v-r*D+i*O)/e,this.elements[6]=-(t*x-r*k+i*A)/e,this.elements[7]=(t*w-r*j+i*M)/e,this.elements[8]=(a*y-o*D+l*N)/e,this.elements[9]=-(t*y-n*D+i*N)/e,this.elements[10]=(t*S-n*k+i*P)/e,this.elements[11]=-(t*T-n*j+i*F)/e,this.elements[12]=-(a*b-o*O+s*N)/e,this.elements[13]=(t*b-n*O+r*N)/e,this.elements[14]=-(t*C-n*A+r*P)/e,this.elements[15]=(t*E-n*M+r*F)/e,this}transpose(){let[e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h]=this.elements;return this.elements[1]=i,this.elements[2]=c,this.elements[3]=f,this.elements[4]=t,this.elements[6]=l,this.elements[7]=p,this.elements[8]=n,this.elements[9]=o,this.elements[11]=m,this.elements[12]=r,this.elements[13]=s,this.elements[14]=d,this}divide(e){let{tmpMatrix:n}=t;return n.copy(e),n.invert()?this.multiply(n):null}scale(t){let{order:n}=this;for(let r of e(n)){let i=r===n-1?1:t.elements[r];for(let t of e(n)){let e=r*n+t;this.elements[e]*=i}}return this}translate(e){let{x:t,y:n,z:r}=e,[i,a,o,s,c,l,u,d,f,p,m,h,g,_,v,y]=this.elements;return this.elements[12]=i*t+c*n+f*r+g,this.elements[13]=a*t+l*n+p*r+_,this.elements[14]=o*t+u*n+m*r+v,this.elements[15]=s*t+d*n+h*r+y,this}lookAt(e,t,n){let{x:r,y:i,z:a}=e,{x:o,y:s,z:l}=n,u=e.x-t.x,d=e.y-t.y,f=e.z-t.z,p=Math.sqrt(u**2+d**2+f**2);if(p<c)return this;u/=p,d/=p,f/=p;let m=s*f-l*d,h=l*u-o*f,g=o*d-s*u,_=Math.sqrt(m**2+h**2+g**2);_>0&&(m/=_,h/=_,g/=_);let v=d*g-f*h,y=f*m-u*g,b=u*h-d*m,x=Math.sqrt(v**2+y**2+b**2);x>0&&(v/=x,y/=x,b/=x);let S=-(m*r+h*i+g*a),C=-(v*r+y*i+b*a),w=-(u*r+d*i+f*a);return this.set(m,v,u,0,h,y,d,0,g,b,f,0,S,C,w,1),this}perspective(e,t,n,r){let i=1/Math.tan(e/2);return this.set(i/r,0,0,0,0,i,0,0,0,0,1,-1,0,0,1,0),n===1/0?(this.elements[10]=-1,this.elements[14]=-2*t):(this.elements[10]=-(n+t)/(n-t),this.elements[14]=-2*n*t/(n-t)),this}_applyVector(e,n,r,i){let{tmpVector:a}=t;a.set(e,n,r,i);let[o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,x]=this.elements,S=o*e+u*n+m*r+v*i,C=s*e+d*n+h*r+y*i,w=c*e+f*n+g*r+b*i,T=l*e+p*n+_*r+x*i;return a.set(S,C,w,T),a}},u=0,d=1,f=2,p=class e{dimension=3;elements;static _tmpMatrix3;static get tmpMatrix3(){return this._tmpMatrix3||=h.identity(),this._tmpMatrix3}static _tmpMatrix4;static get tmpMatrix4(){return this._tmpMatrix4||=l.identity(),this._tmpMatrix4}constructor(e,t,n){this.elements=[e,t,n]}get x(){return this.elements[u]}set x(e){this.elements[u]=e}get y(){return this.elements[d]}set y(e){this.elements[d]=e}get z(){return this.elements[f]}set z(e){this.elements[f]=e}static zero(){return new e(0,0,0)}static one(){return new e(1,1,1)}clone(){let{x:t,y:n,z:r}=this;return new e(t,n,r)}isZero(){let{x:e,y:t,z:n}=this;return e===0&&t===0&&n===0}set(e,t,n){return this.x=e,this.y=t,this.z=n,this}copy(e){let{x:t,y:n,z:r}=e;return this.set(t,n,r)}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}subtract(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}divideScalar(e){return this.x/=e,this.y/=e,this.z/=e,this}length(){let{x:e,y:t,z:n}=this;return Math.sqrt(e**2+t**2+n**2)}normalize(){let e=this.length();return e<=0?this:this.divideScalar(e)}cross(e){let{x:t,y:n,z:r}=this,{x:i,y:a,z:o}=e,s=n*o-r*a,c=r*i-t*o,l=t*a-n*i;return this.set(s,c,l)}crossTo(e,t){return t.copy(this),t.cross(e)}applyMatrix3(t){let{tmpMatrix3:n}=e;n.copy(t);let{x:r,y:i,z:a}=n._applyVector(this.x,this.y,this.z);return this.set(r,i,a),this}applyMatrix4(t){let{tmpMatrix4:n}=e;n.copy(t);let{x:r,y:i,z:a}=n._applyVector(this.x,this.y,this.z,0);return this.set(r,i,a),this}applyQuaternion(t){let{tmpMatrix4:n}=e;n.setQuaternion(t);let{x:r,y:i,z:a}=n._applyVector(this.x,this.y,this.z,0);return this.set(r,i,a),this}},m=1e-8,h=class t{order=3;elements;static _tmpMatrix;static get tmpMatrix(){return this._tmpMatrix||=t.identity(),this._tmpMatrix}static _tmpVector;static get tmpVector(){return this._tmpVector||=p.zero(),this._tmpVector}constructor(e,t,n,r,i,a,o,s,c){this.elements=Float32Array.of(e,t,n,r,i,a,o,s,c)}static identity(){return t.zero().setIdentity()}static zero(){return new t(0,0,0,0,0,0,0,0,0)}clone(){let[e,n,r,i,a,o,s,c,l]=this.elements;return new t(e,n,r,i,a,o,s,c,l)}set(e,t,n,r,i,a,o,s,c){return this.elements[0]=e,this.elements[1]=t,this.elements[2]=n,this.elements[3]=r,this.elements[4]=i,this.elements[5]=a,this.elements[6]=o,this.elements[7]=s,this.elements[8]=c,this}copy(e){let[t,n,r,i,a,o,s,c,l]=e.elements;this.set(t,n,r,i,a,o,s,c,l)}setIdentity(){return this.set(1,0,0,0,1,0,0,0,1),this}add(t){let{order:n}=this;for(let r of e(n**2))this.elements[r]+=t.elements[r];return this}subtract(t){let{order:n}=this;for(let r of e(n**2))this.elements[r]-=t.elements[r];return this}multiplyScalar(t){let{order:n}=this;for(let r of e(n**2))this.elements[r]*=t;return this}divideScalar(t){let{order:n}=this;for(let r of e(n**2))this.elements[r]/=t;return this}multiply(e){let[t,n,r,i,a,o,s,c,l]=this.elements,[u,d,f,p,m,h,g,_,v]=e.elements;return this.elements[0]=u*t+d*i+f*s,this.elements[1]=u*n+d*a+f*c,this.elements[2]=u*r+d*o+f*l,this.elements[3]=p*t+m*i+h*s,this.elements[4]=p*n+m*a+h*c,this.elements[5]=p*r+m*o+h*l,this.elements[6]=g*t+_*i+v*s,this.elements[7]=g*n+_*a+v*c,this.elements[8]=g*r+_*o+v*l,this}determinant(){let[e,t,n,r,i,a,o,s,c]=this.elements;return e*(c*i-a*s)+t*(-c*r+a*o)+n*(s*r-i*o)}invert(){let e=this.determinant();if(Math.abs(e)<m)return null;let[t,n,r,i,a,o,s,c,l]=this.elements,u=l*a-o*c,d=-l*i+o*s,f=c*i-a*s;return this.elements[0]=u/e,this.elements[1]=(-l*n+r*c)/e,this.elements[2]=(o*n-r*a)/e,this.elements[3]=d/e,this.elements[4]=(l*t-r*s)/e,this.elements[5]=(-o*t+r*i)/e,this.elements[6]=f/e,this.elements[7]=(-c*t+n*s)/e,this.elements[8]=(a*t-n*i)/e,this}transpose(){let[e,t,n,r,i,a,o,s,c]=this.elements;return this.elements[1]=r,this.elements[2]=o,this.elements[3]=t,this.elements[5]=s,this.elements[6]=n,this.elements[7]=a,this}divide(e){let{tmpMatrix:n}=t;return n.copy(e),n.invert()?this.multiply(n):null}_applyVector(e,n,r){let{tmpVector:i}=t;i.set(e,n,r);let[a,o,s,c,l,u,d,f,p]=this.elements,m=a*e+c*n+d*r,h=o*e+l*n+f*r,g=s*e+u*n+p*r;return i.set(m,h,g),i}},g=class{_phi;_theta;_radius;constructor(e,t,n){this._phi=e,this._theta=t,this._radius=n}get phi(){return this._phi}set phi(e){this._phi=e}get theta(){return this._theta}set theta(e){this._theta=e}get radius(){return this._radius}set radius(e){this._radius=e}toVector3(e){let{phi:t,theta:n,radius:r}=this,{cos:i,sin:a}=Math,o=a(n),s=r*o*i(t),c=r*o*a(t),l=r*i(n);e.set(s,c,l)}toTangentZ(e){let{phi:t,theta:n}=this,{cos:r,sin:i}=Math,a=r(n),o=-a*r(t),s=-a*i(t),c=i(n);e.set(o,s,c)}},_=class e{_a;_b;_c;_d;static temporary=e.identity();constructor(e,t,n,r){this._a=e,this._b=t,this._c=n,this._d=r}get a(){return this._a}get b(){return this._b}get c(){return this._c}get d(){return this._d}static identity(){return new e(1,0,0,0)}static fromAxisAndAngle(t,n){let r=e.identity();return r.setAxisAndAngle(t,n),r}clone(){let{a:t,b:n,c:r,d:i}=this;return new e(t,n,r,i)}set(e,t,n,r){return this._a=e,this._b=t,this._c=n,this._d=r,this}copy(e){let{a:t,b:n,c:r,d:i}=e;return this.set(t,n,r,i)}setIdentity(){this.set(1,0,0,0)}setAxisAndAngle(e,t){if(e.isZero())return this.setIdentity();e.normalize();let{x:n,y:r,z:i}=e,a=Math.sin(t/2);this.set(Math.cos(t/2),n*a,r*a,i*a)}squaredNorm(){let{a:e,b:t,c:n,d:r}=this;return e**2+t**2+n**2+r**2}norm(){return Math.sqrt(this.squaredNorm())}conjugate(){return this._b*=-1,this._c*=-1,this._d*=-1,this}add(e){let{a:t,b:n,c:r,d:i}=e;return this._a+=t,this._b+=n,this._c+=r,this._d+=i,this}subtract(e){let{a:t,b:n,c:r,d:i}=e;return this._a-=t,this._b-=n,this._c-=r,this._d-=i,this}multiply(e){let{a:t,b:n,c:r,d:i}=this,{a,b:o,c:s,d:c}=e;return this._a=t*a-n*o-r*s-i*c,this._b=t*o+n*a+r*c-i*s,this._c=t*s-n*c+r*a+i*o,this._d=t*c+n*s-r*o+i*a,this}invert(){let e=this.squaredNorm();return e<=0?null:this.conjugate().divideScalar(e)}divide(t){let{temporary:n}=e;return n.copy(t),n.invert()?this.multiply(n):null}multiplyScalar(e){return this._a*=e,this._b*=e,this._c*=e,this._d*=e,this}divideScalar(e){return this._a/=e,this._b/=e,this._c/=e,this._d/=e,this}rotateX(t){let{temporary:n}=e;return n.setIdentity(),n.setAxisAndAngle(new p(1,0,0),t),this.multiply(n)}rotateY(t){let{temporary:n}=e;return n.setIdentity(),n.setAxisAndAngle(new p(0,1,0),t),this.multiply(n)}rotateZ(t){let{temporary:n}=e;return n.setIdentity(),n.setAxisAndAngle(new p(0,0,1),t),this.multiply(n)}},v=0,y=class e{dimension=1;elements;static _tmpMatrix3;static get tmpMatrix3(){return this._tmpMatrix3||=h.identity(),this._tmpMatrix3}static _tmpMatrix4;static get tmpMatrix4(){return this._tmpMatrix4||=l.identity(),this._tmpMatrix4}constructor(e){this.elements=[e]}get x(){return this.elements[v]}set x(e){this.elements[v]=e}static zero(){return new e(0)}static one(){return new e(1)}clone(){let{x:t}=this;return new e(t)}isZero(){return this.x===0}set(e){return this.x=e,this}copy(e){return this.x=e.x,this}add(e){return this.x+=e.x,this}subtract(e){return this.x-=e.x,this}multiplyScalar(e){return this.x*=e,this}divideScalar(e){return this.x/=e,this}length(){return Math.abs(this.x)}normalize(){return this.x/=this.length(),this}applyMatrix3(t){let{tmpMatrix3:n}=e;n.copy(t);let{x:r}=n._applyVector(this.x,0,0);return this.set(r),this}applyMatrix4(t){let{tmpMatrix4:n}=e;n.copy(t);let{x:r}=n._applyVector(this.x,0,0,0);return this.set(r),this}applyQuaternion(t){let{tmpMatrix4:n}=e;n.setQuaternion(t);let{x:r}=n._applyVector(this.x,0,0,0);return this.set(r),this}},b=0,x=1,S=class e{dimension=2;elements;static _tmpMatrix3;static get tmpMatrix3(){return this._tmpMatrix3||=h.identity(),this._tmpMatrix3}static _tmpMatrix4;static get tmpMatrix4(){return this._tmpMatrix4||=l.identity(),this._tmpMatrix4}constructor(e,t){this.elements=[e,t]}get x(){return this.elements[b]}set x(e){this.elements[b]=e}get y(){return this.elements[x]}set y(e){this.elements[x]=e}static zero(){return new e(0,0)}static one(){return new e(1,1)}clone(){let{x:t,y:n}=this;return new e(t,n)}isZero(){let{x:e,y:t}=this;return e===0&&t===0}set(e,t){return this.x=e,this.y=t,this}copy(e){let{x:t,y:n}=e;return this.set(t,n)}add(e){return this.x+=e.x,this.y+=e.y,this}subtract(e){return this.x-=e.x,this.y-=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}divideScalar(e){return this.x/=e,this.y/=e,this}length(){let{x:e,y:t}=this;return Math.sqrt(e**2+t**2)}normalize(){let e=this.length();return e<=0?this:this.divideScalar(e)}rotate(e){let{cos:t,sin:n}=Math,r=this.x*t(e)-this.y*n(e),i=this.x*n(e)+this.y*t(e);return this.x=r,this.y=i,this}applyMatrix3(t){let{tmpMatrix3:n}=e;n.copy(t);let{x:r,y:i}=n._applyVector(this.x,this.y,0);return this.set(r,i),this}applyMatrix4(t){let{tmpMatrix4:n}=e;n.copy(t);let{x:r,y:i}=n._applyVector(this.x,this.y,0,0);return this.set(r,i),this}applyQuaternion(t){let{tmpMatrix4:n}=e;n.setQuaternion(t);let{x:r,y:i}=n._applyVector(this.x,this.y,0,0);return this.set(r,i),this}};exports.Matrix3=h,exports.Matrix4=l,exports.PolarCoordinate3=g,exports.Quaternion=_,exports.Vector1=y,exports.Vector2=S,exports.Vector3=p,exports.Vector4=s,exports.range=e,exports.sum=t,exports.sumMap=n;
|
|
1
|
+
function*e(e,t){let n=t?.start??0,r=t?.step??1;if(r!==0&&!(r>0&&n>e)&&!(r<0&&n<e))for(let t=n;r>0?t<e:t>e;t+=r)yield t}function t(e){let t=0;for(let n of e)t+=n;return t}function n(e,t){let n=0;for(let r of e)n+=t(r)??0;return n}var r=0,i=1,a=2,o=3,s=class e{dimension=4;elements;static _tmpMatrix4;static get tmpMatrix4(){return this._tmpMatrix4||=u.identity(),this._tmpMatrix4}constructor(e,t,n,r){this.elements=[e,t,n,r]}get x(){return this.elements[r]}set x(e){this.elements[r]=e}get y(){return this.elements[i]}set y(e){this.elements[i]=e}get z(){return this.elements[a]}set z(e){this.elements[a]=e}get w(){return this.elements[o]}set w(e){this.elements[o]=e}static zero(){return new e(0,0,0,0)}static one(){return new e(1,1,1,1)}clone(){let{x:t,y:n,z:r,w:i}=this;return new e(t,n,r,i)}isZero(){let{x:e,y:t,z:n,w:r}=this;return e===0&&t===0&&n===0&&r===0}set(e,t,n,r){this.x=e,this.y=t,this.z=n,this.w=r}copy(e){let{x:t,y:n,z:r,w:i}=e;this.set(t,n,r,i)}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this}subtract(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this}divideScalar(e){return this.x/=e,this.y/=e,this.z/=e,this.w/=e,this}length(){let{x:e,y:t,z:n,w:r}=this;return Math.sqrt(e**2+t**2+n**2+r**2)}normalize(){let e=this.length();return e<=0?this:this.divideScalar(e)}applyMatrix4(t){let{tmpMatrix4:n}=e;n.copy(t);let{x:r,y:i,z:a,w:o}=this,s=n._applyVector(r,i,a,o);return this.copy(s),this}applyQuaternion(t){let{tmpMatrix4:n}=e;n.setRotation(t);let{x:r,y:i,z:a,w:o}=this,s=n._applyVector(r,i,a,o);return this.copy(s),this}},c=1e-8,l=!1,u=class t{order=4;elements;static _tmpMatrix;static get tmpMatrix(){return this._tmpMatrix||=t.identity(),this._tmpMatrix}static _tmpVector;static get tmpVector(){return this._tmpVector||=s.zero(),this._tmpVector}constructor(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h){this.elements=Float32Array.of(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h)}static identity(){return t.zero().setIdentity()}static zero(){return new t(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}clone(){let[e,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g]=this.elements;return new t(e,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g)}set(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h){return this.elements[0]=e,this.elements[1]=t,this.elements[2]=n,this.elements[3]=r,this.elements[4]=i,this.elements[5]=a,this.elements[6]=o,this.elements[7]=s,this.elements[8]=c,this.elements[9]=l,this.elements[10]=u,this.elements[11]=d,this.elements[12]=f,this.elements[13]=p,this.elements[14]=m,this.elements[15]=h,this}copy(e){let[t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g]=e.elements;this.set(t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g)}setIdentity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}setScale(t){this.setIdentity();let{order:n}=this;for(let r of e(n)){let i=r===n-1?1:t.elements[r];for(let t of e(n)){let e=r*n+t;this.elements[e]*=i}}return this}setTranslation(e){let{x:t,y:n,z:r}=e;return this.setIdentity(),this.elements[12]=t,this.elements[13]=n,this.elements[14]=r,this}setRotation(e){let{a:t,b:n,c:r,d:i}=e,a=2/e.squaredNorm(),o=n**2,s=r**2,c=i**2,l=t*n,u=t*r,d=t*i,f=n*r,p=n*i,m=r*i;return this.set(1-a*(s+c),-a*(f-d),-a*(p+u),0,-a*(f+d),1-a*(o+c),-a*(m-l),0,-a*(p-u),-a*(m+l),1-a*(o+s),0,0,0,0,1),this}add(t){let{order:n}=this;for(let r of e(n**2))this.elements[r]+=t.elements[r];return this}subtract(t){let{order:n}=this;for(let r of e(n**2))this.elements[r]-=t.elements[r];return this}multiplyScalar(t){let{order:n}=this;for(let r of e(n**2))this.elements[r]*=t;return this}divideScalar(t){let{order:n}=this;for(let r of e(n**2))this.elements[r]/=t;return this}multiply(e){let[t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g]=this.elements,[_,v,y,b,x,S,C,w,T,E,D,O,k,A,j,M]=e.elements;return this.elements[0]=_*t+v*a+y*l+b*p,this.elements[1]=_*n+v*o+y*u+b*m,this.elements[2]=_*r+v*s+y*d+b*h,this.elements[3]=_*i+v*c+y*f+b*g,this.elements[4]=x*t+S*a+C*l+w*p,this.elements[5]=x*n+S*o+C*u+w*m,this.elements[6]=x*r+S*s+C*d+w*h,this.elements[7]=x*i+S*c+C*f+w*g,this.elements[8]=T*t+E*a+D*l+O*p,this.elements[9]=T*n+E*o+D*u+O*m,this.elements[10]=T*r+E*s+D*d+O*h,this.elements[11]=T*i+E*c+D*f+O*g,this.elements[12]=k*t+A*a+j*l+M*p,this.elements[13]=k*n+A*o+j*u+M*m,this.elements[14]=k*r+A*s+j*d+M*h,this.elements[15]=k*i+A*c+j*f+M*g,this}multiplyScale(e){return this.multiply(t.tmpMatrix.setScale(e))}multiplyTranslation(e){return this.multiply(t.tmpMatrix.setTranslation(e))}multiplyRotation(e){return this.multiply(t.tmpMatrix.setRotation(e))}determinant(){let[e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h]=this.elements;return e*(a*(u*h-d*m)-o*(l*h-d*p)+s*(l*m-u*p))-t*(i*(u*h-d*m)-o*(c*h-d*f)+s*(c*m-u*f))+n*(i*(l*h-d*p)-a*(c*h-d*f)+s*(c*p-l*f))-r*(i*(l*m-u*p)-a*(c*m-u*f)+o*(c*p-l*f))}invert(){let e=this.determinant();if(Math.abs(e)<c)return null;let[t,n,r,i,a,o,s,l,u,d,f,p,m,h,g,_]=this.elements,v=f*_-p*g,y=d*_-p*h,b=d*g-f*h,x=s*_-l*g,S=o*_-l*h,C=o*g-s*h,w=s*p-l*f,T=o*p-l*d,E=o*f-s*d,D=u*_-p*m,O=u*g-f*m,k=a*_-l*m,A=a*g-s*m,j=a*p-l*u,M=a*f-s*u,N=u*h-d*m,P=a*h-o*m,F=a*d-o*u;return this.elements[0]=(o*v-s*y+l*b)/e,this.elements[1]=-(n*v-r*y+i*b)/e,this.elements[2]=(n*x-r*S+i*C)/e,this.elements[3]=-(n*w-r*T+i*E)/e,this.elements[4]=-(a*v-s*D+l*O)/e,this.elements[5]=(t*v-r*D+i*O)/e,this.elements[6]=-(t*x-r*k+i*A)/e,this.elements[7]=(t*w-r*j+i*M)/e,this.elements[8]=(a*y-o*D+l*N)/e,this.elements[9]=-(t*y-n*D+i*N)/e,this.elements[10]=(t*S-n*k+i*P)/e,this.elements[11]=-(t*T-n*j+i*F)/e,this.elements[12]=-(a*b-o*O+s*N)/e,this.elements[13]=(t*b-n*O+r*N)/e,this.elements[14]=-(t*C-n*A+r*P)/e,this.elements[15]=(t*E-n*M+r*F)/e,this}transpose(){let[e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h]=this.elements;return this.elements[1]=i,this.elements[2]=c,this.elements[3]=f,this.elements[4]=t,this.elements[6]=l,this.elements[7]=p,this.elements[8]=n,this.elements[9]=o,this.elements[11]=m,this.elements[12]=r,this.elements[13]=s,this.elements[14]=d,this}divide(e){let{tmpMatrix:n}=t;return n.copy(e),n.invert()?this.multiply(n):null}lookAt(e,t,n){let{x:r,y:i,z:a}=e,{x:o,y:s,z:l}=n,u=e.x-t.x,d=e.y-t.y,f=e.z-t.z,p=Math.sqrt(u**2+d**2+f**2);if(p<c)return this;u/=p,d/=p,f/=p;let m=s*f-l*d,h=l*u-o*f,g=o*d-s*u,_=Math.sqrt(m**2+h**2+g**2);_>0&&(m/=_,h/=_,g/=_);let v=d*g-f*h,y=f*m-u*g,b=u*h-d*m,x=Math.sqrt(v**2+y**2+b**2);x>0&&(v/=x,y/=x,b/=x);let S=-(m*r+h*i+g*a),C=-(v*r+y*i+b*a),w=-(u*r+d*i+f*a);return this.set(m,v,u,0,h,y,d,0,g,b,f,0,S,C,w,1),this}orthographic(e,t,n,r,i,a,o){let s=o?.depthZeroToOne??l,c=t-e,u=r-n,d=a-i,f=(s?-1:-2)/d,p=-(t+e)/c,m=-(r+n)/u,h=(s?-i:-(a+i))/d;return this.set(2/c,0,0,0,0,2/u,0,0,0,0,f,0,p,m,h,1),this}perspective(e,t,n,r,i){let a=1/Math.tan(e/2);this.set(a/r,0,0,0,0,a,0,0,0,0,1,-1,0,0,1,0);let o=i?.depthZeroToOne??l,s=o?1:2;if(n!==1/0){let e=o?n:n+t;this.elements[10]=-e/(n-t),this.elements[14]=-s*n*t/(n-t)}else this.elements[10]=-1,this.elements[14]=-s*t;return this}_applyVector(e,n,r,i){let{tmpVector:a}=t;a.set(e,n,r,i);let[o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,x]=this.elements,S=o*e+u*n+m*r+v*i,C=s*e+d*n+h*r+y*i,w=c*e+f*n+g*r+b*i,T=l*e+p*n+_*r+x*i;return a.set(S,C,w,T),a}},d=0,f=1,p=2,m=!1,h=class e{dimension=3;elements;static _tmpMatrix3;static get tmpMatrix3(){return this._tmpMatrix3||=_.identity(),this._tmpMatrix3}static _tmpMatrix4;static get tmpMatrix4(){return this._tmpMatrix4||=u.identity(),this._tmpMatrix4}constructor(e,t,n){this.elements=[e,t,n]}get x(){return this.elements[d]}set x(e){this.elements[d]=e}get y(){return this.elements[f]}set y(e){this.elements[f]=e}get z(){return this.elements[p]}set z(e){this.elements[p]=e}static zero(){return new e(0,0,0)}static one(){return new e(1,1,1)}clone(){let{x:t,y:n,z:r}=this;return new e(t,n,r)}isZero(){let{x:e,y:t,z:n}=this;return e===0&&t===0&&n===0}set(e,t,n){return this.x=e,this.y=t,this.z=n,this}copy(e){let{x:t,y:n,z:r}=e;return this.set(t,n,r)}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}subtract(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}divideScalar(e){return this.x/=e,this.y/=e,this.z/=e,this}length(){let{x:e,y:t,z:n}=this;return Math.sqrt(e**2+t**2+n**2)}normalize(){let e=this.length();return e<=0?this:this.divideScalar(e)}cross(e){let{x:t,y:n,z:r}=this,{x:i,y:a,z:o}=e,s=n*o-r*a,c=r*i-t*o,l=t*a-n*i;return this.set(s,c,l)}crossTo(e,t){return t.copy(this),t.cross(e)}applyMatrix3(t){let{tmpMatrix3:n}=e;n.copy(t);let{x:r,y:i,z:a}=n._applyVector(this.x,this.y,this.z);return this.set(r,i,a),this}applyMatrix4(t,n){let{tmpMatrix4:r}=e;r.copy(t);let i=n?.asDirection??m,a=i?0:1,{x:o,y:s,z:c,w:l}=r._applyVector(this.x,this.y,this.z,a),u=i||l===0?o:o/l,d=i||l===0?s:s/l,f=i||l===0?c:c/l;return this.set(u,d,f),this}applyQuaternion(t){let{tmpMatrix4:n}=e;n.setRotation(t);let{x:r,y:i,z:a}=n._applyVector(this.x,this.y,this.z,0);return this.set(r,i,a),this}},g=1e-8,_=class t{order=3;elements;static _tmpMatrix;static get tmpMatrix(){return this._tmpMatrix||=t.identity(),this._tmpMatrix}static _tmpVector;static get tmpVector(){return this._tmpVector||=h.zero(),this._tmpVector}constructor(e,t,n,r,i,a,o,s,c){this.elements=Float32Array.of(e,t,n,r,i,a,o,s,c)}static identity(){return t.zero().setIdentity()}static zero(){return new t(0,0,0,0,0,0,0,0,0)}clone(){let[e,n,r,i,a,o,s,c,l]=this.elements;return new t(e,n,r,i,a,o,s,c,l)}set(e,t,n,r,i,a,o,s,c){return this.elements[0]=e,this.elements[1]=t,this.elements[2]=n,this.elements[3]=r,this.elements[4]=i,this.elements[5]=a,this.elements[6]=o,this.elements[7]=s,this.elements[8]=c,this}copy(e){let[t,n,r,i,a,o,s,c,l]=e.elements;this.set(t,n,r,i,a,o,s,c,l)}setIdentity(){return this.set(1,0,0,0,1,0,0,0,1),this}add(t){let{order:n}=this;for(let r of e(n**2))this.elements[r]+=t.elements[r];return this}subtract(t){let{order:n}=this;for(let r of e(n**2))this.elements[r]-=t.elements[r];return this}multiplyScalar(t){let{order:n}=this;for(let r of e(n**2))this.elements[r]*=t;return this}divideScalar(t){let{order:n}=this;for(let r of e(n**2))this.elements[r]/=t;return this}multiply(e){let[t,n,r,i,a,o,s,c,l]=this.elements,[u,d,f,p,m,h,g,_,v]=e.elements;return this.elements[0]=u*t+d*i+f*s,this.elements[1]=u*n+d*a+f*c,this.elements[2]=u*r+d*o+f*l,this.elements[3]=p*t+m*i+h*s,this.elements[4]=p*n+m*a+h*c,this.elements[5]=p*r+m*o+h*l,this.elements[6]=g*t+_*i+v*s,this.elements[7]=g*n+_*a+v*c,this.elements[8]=g*r+_*o+v*l,this}determinant(){let[e,t,n,r,i,a,o,s,c]=this.elements;return e*(c*i-a*s)+t*(-c*r+a*o)+n*(s*r-i*o)}invert(){let e=this.determinant();if(Math.abs(e)<g)return null;let[t,n,r,i,a,o,s,c,l]=this.elements,u=l*a-o*c,d=-l*i+o*s,f=c*i-a*s;return this.elements[0]=u/e,this.elements[1]=(-l*n+r*c)/e,this.elements[2]=(o*n-r*a)/e,this.elements[3]=d/e,this.elements[4]=(l*t-r*s)/e,this.elements[5]=(-o*t+r*i)/e,this.elements[6]=f/e,this.elements[7]=(-c*t+n*s)/e,this.elements[8]=(a*t-n*i)/e,this}transpose(){let[e,t,n,r,i,a,o,s,c]=this.elements;return this.elements[1]=r,this.elements[2]=o,this.elements[3]=t,this.elements[5]=s,this.elements[6]=n,this.elements[7]=a,this}divide(e){let{tmpMatrix:n}=t;return n.copy(e),n.invert()?this.multiply(n):null}_applyVector(e,n,r){let{tmpVector:i}=t;i.set(e,n,r);let[a,o,s,c,l,u,d,f,p]=this.elements,m=a*e+c*n+d*r,h=o*e+l*n+f*r,g=s*e+u*n+p*r;return i.set(m,h,g),i}},v=class{_phi;_theta;_radius;constructor(e,t,n){this._phi=e,this._theta=t,this._radius=n}get phi(){return this._phi}set phi(e){this._phi=e}get theta(){return this._theta}set theta(e){this._theta=e}get radius(){return this._radius}set radius(e){this._radius=e}toVector3(e){let{phi:t,theta:n,radius:r}=this,{cos:i,sin:a}=Math,o=a(n),s=r*o*i(t),c=r*o*a(t),l=r*i(n);e.set(s,c,l)}toTangentZ(e){let{phi:t,theta:n}=this,{cos:r,sin:i}=Math,a=r(n),o=-a*r(t),s=-a*i(t),c=i(n);e.set(o,s,c)}},y=class e{_a;_b;_c;_d;static temporary=e.identity();constructor(e,t,n,r){this._a=e,this._b=t,this._c=n,this._d=r}get a(){return this._a}get b(){return this._b}get c(){return this._c}get d(){return this._d}static identity(){return new e(1,0,0,0)}static fromAxisAndAngle(t,n){let r=e.identity();return r.setAxisAndAngle(t,n),r}clone(){let{a:t,b:n,c:r,d:i}=this;return new e(t,n,r,i)}set(e,t,n,r){return this._a=e,this._b=t,this._c=n,this._d=r,this}copy(e){let{a:t,b:n,c:r,d:i}=e;return this.set(t,n,r,i)}setIdentity(){this.set(1,0,0,0)}setAxisAndAngle(e,t){if(e.isZero())return this.setIdentity();e.normalize();let{x:n,y:r,z:i}=e,a=Math.sin(t/2);this.set(Math.cos(t/2),n*a,r*a,i*a)}squaredNorm(){let{a:e,b:t,c:n,d:r}=this;return e**2+t**2+n**2+r**2}norm(){return Math.sqrt(this.squaredNorm())}conjugate(){return this._b*=-1,this._c*=-1,this._d*=-1,this}add(e){let{a:t,b:n,c:r,d:i}=e;return this._a+=t,this._b+=n,this._c+=r,this._d+=i,this}subtract(e){let{a:t,b:n,c:r,d:i}=e;return this._a-=t,this._b-=n,this._c-=r,this._d-=i,this}multiply(e){let{a:t,b:n,c:r,d:i}=this,{a,b:o,c:s,d:c}=e;return this._a=t*a-n*o-r*s-i*c,this._b=t*o+n*a+r*c-i*s,this._c=t*s-n*c+r*a+i*o,this._d=t*c+n*s-r*o+i*a,this}invert(){let e=this.squaredNorm();return e<=0?null:this.conjugate().divideScalar(e)}divide(t){let{temporary:n}=e;return n.copy(t),n.invert()?this.multiply(n):null}multiplyScalar(e){return this._a*=e,this._b*=e,this._c*=e,this._d*=e,this}divideScalar(e){return this._a/=e,this._b/=e,this._c/=e,this._d/=e,this}rotateX(t){let{temporary:n}=e;return n.setIdentity(),n.setAxisAndAngle(new h(1,0,0),t),this.multiply(n)}rotateY(t){let{temporary:n}=e;return n.setIdentity(),n.setAxisAndAngle(new h(0,1,0),t),this.multiply(n)}rotateZ(t){let{temporary:n}=e;return n.setIdentity(),n.setAxisAndAngle(new h(0,0,1),t),this.multiply(n)}},b=0,x=class e{dimension=1;elements;static _tmpMatrix3;static get tmpMatrix3(){return this._tmpMatrix3||=_.identity(),this._tmpMatrix3}static _tmpMatrix4;static get tmpMatrix4(){return this._tmpMatrix4||=u.identity(),this._tmpMatrix4}constructor(e){this.elements=[e]}get x(){return this.elements[b]}set x(e){this.elements[b]=e}static zero(){return new e(0)}static one(){return new e(1)}clone(){let{x:t}=this;return new e(t)}isZero(){return this.x===0}set(e){return this.x=e,this}copy(e){return this.x=e.x,this}add(e){return this.x+=e.x,this}subtract(e){return this.x-=e.x,this}multiplyScalar(e){return this.x*=e,this}divideScalar(e){return this.x/=e,this}length(){return Math.abs(this.x)}normalize(){return this.x/=this.length(),this}applyMatrix3(t){let{tmpMatrix3:n}=e;n.copy(t);let{x:r}=n._applyVector(this.x,0,0);return this.set(r),this}applyMatrix4(t){let{tmpMatrix4:n}=e;n.copy(t);let{x:r}=n._applyVector(this.x,0,0,0);return this.set(r),this}applyQuaternion(t){let{tmpMatrix4:n}=e;n.setRotation(t);let{x:r}=n._applyVector(this.x,0,0,0);return this.set(r),this}},S=0,C=1,w=class e{dimension=2;elements;static _tmpMatrix3;static get tmpMatrix3(){return this._tmpMatrix3||=_.identity(),this._tmpMatrix3}static _tmpMatrix4;static get tmpMatrix4(){return this._tmpMatrix4||=u.identity(),this._tmpMatrix4}constructor(e,t){this.elements=[e,t]}get x(){return this.elements[S]}set x(e){this.elements[S]=e}get y(){return this.elements[C]}set y(e){this.elements[C]=e}static zero(){return new e(0,0)}static one(){return new e(1,1)}clone(){let{x:t,y:n}=this;return new e(t,n)}isZero(){let{x:e,y:t}=this;return e===0&&t===0}set(e,t){return this.x=e,this.y=t,this}copy(e){let{x:t,y:n}=e;return this.set(t,n)}add(e){return this.x+=e.x,this.y+=e.y,this}subtract(e){return this.x-=e.x,this.y-=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}divideScalar(e){return this.x/=e,this.y/=e,this}length(){let{x:e,y:t}=this;return Math.sqrt(e**2+t**2)}normalize(){let e=this.length();return e<=0?this:this.divideScalar(e)}rotate(e){let{cos:t,sin:n}=Math,r=this.x*t(e)-this.y*n(e),i=this.x*n(e)+this.y*t(e);return this.x=r,this.y=i,this}applyMatrix3(t){let{tmpMatrix3:n}=e;n.copy(t);let{x:r,y:i}=n._applyVector(this.x,this.y,0);return this.set(r,i),this}applyMatrix4(t){let{tmpMatrix4:n}=e;n.copy(t);let{x:r,y:i}=n._applyVector(this.x,this.y,0,0);return this.set(r,i),this}applyQuaternion(t){let{tmpMatrix4:n}=e;n.setRotation(t);let{x:r,y:i}=n._applyVector(this.x,this.y,0,0);return this.set(r,i),this}};exports.Matrix3=_,exports.Matrix4=u,exports.PolarCoordinate3=v,exports.Quaternion=y,exports.Vector1=x,exports.Vector2=w,exports.Vector3=h,exports.Vector4=s,exports.range=e,exports.sum=t,exports.sumMap=n;
|
package/dist/mathue.js
CHANGED
|
@@ -100,11 +100,11 @@ var INDEX_X$3 = 0, INDEX_Y$2 = 1, INDEX_Z$1 = 2, INDEX_W = 3, Vector4 = class e
|
|
|
100
100
|
}
|
|
101
101
|
applyQuaternion(t) {
|
|
102
102
|
let { tmpMatrix4: n } = e;
|
|
103
|
-
n.
|
|
103
|
+
n.setRotation(t);
|
|
104
104
|
let { x: r, y: i, z: a, w: o } = this, s = n._applyVector(r, i, a, o);
|
|
105
105
|
return this.copy(s), this;
|
|
106
106
|
}
|
|
107
|
-
}, EPSILON$1 = 1e-8, Matrix4 = class t {
|
|
107
|
+
}, EPSILON$1 = 1e-8, DEFAULT_DEPTH_ZERO_TO_ONE = !1, Matrix4 = class t {
|
|
108
108
|
order = 4;
|
|
109
109
|
elements;
|
|
110
110
|
static _tmpMatrix;
|
|
@@ -138,9 +138,25 @@ var INDEX_X$3 = 0, INDEX_Y$2 = 1, INDEX_Z$1 = 2, INDEX_W = 3, Vector4 = class e
|
|
|
138
138
|
setIdentity() {
|
|
139
139
|
return this.set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1), this;
|
|
140
140
|
}
|
|
141
|
-
|
|
141
|
+
setScale(t) {
|
|
142
|
+
this.setIdentity();
|
|
143
|
+
let { order: n } = this;
|
|
144
|
+
for (let r of range(n)) {
|
|
145
|
+
let i = r === n - 1 ? 1 : t.elements[r];
|
|
146
|
+
for (let t of range(n)) {
|
|
147
|
+
let e = r * n + t;
|
|
148
|
+
this.elements[e] *= i;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return this;
|
|
152
|
+
}
|
|
153
|
+
setTranslation(e) {
|
|
154
|
+
let { x: t, y: n, z: r } = e;
|
|
155
|
+
return this.setIdentity(), this.elements[12] = t, this.elements[13] = n, this.elements[14] = r, this;
|
|
156
|
+
}
|
|
157
|
+
setRotation(e) {
|
|
142
158
|
let { a: t, b: n, c: r, d: i } = e, a = 2 / e.squaredNorm(), o = n ** 2, s = r ** 2, c = i ** 2, l = t * n, u = t * r, d = t * i, f = n * r, p = n * i, m = r * i;
|
|
143
|
-
return this.set(1 - a * (s + c), a * (f - d), a * (p + u), 0, a * (f + d), 1 - a * (o + c), a * (m - l), 0, a * (p - u), a * (m + l), 1 - a * (o + s), 0, 0, 0, 0, 1), this;
|
|
159
|
+
return this.set(1 - a * (s + c), -a * (f - d), -a * (p + u), 0, -a * (f + d), 1 - a * (o + c), -a * (m - l), 0, -a * (p - u), -a * (m + l), 1 - a * (o + s), 0, 0, 0, 0, 1), this;
|
|
144
160
|
}
|
|
145
161
|
add(t) {
|
|
146
162
|
let { order: n } = this;
|
|
@@ -166,6 +182,15 @@ var INDEX_X$3 = 0, INDEX_Y$2 = 1, INDEX_Z$1 = 2, INDEX_W = 3, Vector4 = class e
|
|
|
166
182
|
let [t, n, r, i, a, o, s, c, l, u, d, f, p, m, h, g] = this.elements, [_, v, y, b, x, S, C, w, T, E, D, O, k, A, j, M] = e.elements;
|
|
167
183
|
return this.elements[0] = _ * t + v * a + y * l + b * p, this.elements[1] = _ * n + v * o + y * u + b * m, this.elements[2] = _ * r + v * s + y * d + b * h, this.elements[3] = _ * i + v * c + y * f + b * g, this.elements[4] = x * t + S * a + C * l + w * p, this.elements[5] = x * n + S * o + C * u + w * m, this.elements[6] = x * r + S * s + C * d + w * h, this.elements[7] = x * i + S * c + C * f + w * g, this.elements[8] = T * t + E * a + D * l + O * p, this.elements[9] = T * n + E * o + D * u + O * m, this.elements[10] = T * r + E * s + D * d + O * h, this.elements[11] = T * i + E * c + D * f + O * g, this.elements[12] = k * t + A * a + j * l + M * p, this.elements[13] = k * n + A * o + j * u + M * m, this.elements[14] = k * r + A * s + j * d + M * h, this.elements[15] = k * i + A * c + j * f + M * g, this;
|
|
168
184
|
}
|
|
185
|
+
multiplyScale(e) {
|
|
186
|
+
return this.multiply(t.tmpMatrix.setScale(e));
|
|
187
|
+
}
|
|
188
|
+
multiplyTranslation(e) {
|
|
189
|
+
return this.multiply(t.tmpMatrix.setTranslation(e));
|
|
190
|
+
}
|
|
191
|
+
multiplyRotation(e) {
|
|
192
|
+
return this.multiply(t.tmpMatrix.setRotation(e));
|
|
193
|
+
}
|
|
169
194
|
determinant() {
|
|
170
195
|
let [e, t, n, r, i, a, o, s, c, l, u, d, f, p, m, h] = this.elements;
|
|
171
196
|
return e * (a * (u * h - d * m) - o * (l * h - d * p) + s * (l * m - u * p)) - t * (i * (u * h - d * m) - o * (c * h - d * f) + s * (c * m - u * f)) + n * (i * (l * h - d * p) - a * (c * h - d * f) + s * (c * p - l * f)) - r * (i * (l * m - u * p) - a * (c * m - u * f) + o * (c * p - l * f));
|
|
@@ -184,21 +209,6 @@ var INDEX_X$3 = 0, INDEX_Y$2 = 1, INDEX_Z$1 = 2, INDEX_W = 3, Vector4 = class e
|
|
|
184
209
|
let { tmpMatrix: n } = t;
|
|
185
210
|
return n.copy(e), n.invert() ? this.multiply(n) : null;
|
|
186
211
|
}
|
|
187
|
-
scale(t) {
|
|
188
|
-
let { order: n } = this;
|
|
189
|
-
for (let r of range(n)) {
|
|
190
|
-
let i = r === n - 1 ? 1 : t.elements[r];
|
|
191
|
-
for (let t of range(n)) {
|
|
192
|
-
let e = r * n + t;
|
|
193
|
-
this.elements[e] *= i;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
return this;
|
|
197
|
-
}
|
|
198
|
-
translate(e) {
|
|
199
|
-
let { x: t, y: n, z: r } = e, [i, a, o, s, c, l, u, d, f, p, m, h, g, _, v, y] = this.elements;
|
|
200
|
-
return this.elements[12] = i * t + c * n + f * r + g, this.elements[13] = a * t + l * n + p * r + _, this.elements[14] = o * t + u * n + m * r + v, this.elements[15] = s * t + d * n + h * r + y, this;
|
|
201
|
-
}
|
|
202
212
|
lookAt(e, t, n) {
|
|
203
213
|
let { x: r, y: i, z: a } = e, { x: o, y: s, z: l } = n, u = e.x - t.x, d = e.y - t.y, f = e.z - t.z, p = Math.sqrt(u ** 2 + d ** 2 + f ** 2);
|
|
204
214
|
if (p < EPSILON$1) return this;
|
|
@@ -210,9 +220,19 @@ var INDEX_X$3 = 0, INDEX_Y$2 = 1, INDEX_Z$1 = 2, INDEX_W = 3, Vector4 = class e
|
|
|
210
220
|
let S = -(m * r + h * i + g * a), C = -(v * r + y * i + b * a), w = -(u * r + d * i + f * a);
|
|
211
221
|
return this.set(m, v, u, 0, h, y, d, 0, g, b, f, 0, S, C, w, 1), this;
|
|
212
222
|
}
|
|
213
|
-
|
|
214
|
-
let i = 1 /
|
|
215
|
-
return this.set(
|
|
223
|
+
orthographic(e, t, n, r, i, a, o) {
|
|
224
|
+
let s = o?.depthZeroToOne ?? DEFAULT_DEPTH_ZERO_TO_ONE, c = t - e, u = r - n, d = a - i, f = (s ? -1 : -2) / d, p = -(t + e) / c, m = -(r + n) / u, h = (s ? -i : -(a + i)) / d;
|
|
225
|
+
return this.set(2 / c, 0, 0, 0, 0, 2 / u, 0, 0, 0, 0, f, 0, p, m, h, 1), this;
|
|
226
|
+
}
|
|
227
|
+
perspective(e, t, n, r, i) {
|
|
228
|
+
let a = 1 / Math.tan(e / 2);
|
|
229
|
+
this.set(a / r, 0, 0, 0, 0, a, 0, 0, 0, 0, 1, -1, 0, 0, 1, 0);
|
|
230
|
+
let o = i?.depthZeroToOne ?? DEFAULT_DEPTH_ZERO_TO_ONE, s = o ? 1 : 2;
|
|
231
|
+
if (n !== Infinity) {
|
|
232
|
+
let e = o ? n : n + t;
|
|
233
|
+
this.elements[10] = -e / (n - t), this.elements[14] = -s * n * t / (n - t);
|
|
234
|
+
} else this.elements[10] = -1, this.elements[14] = -s * t;
|
|
235
|
+
return this;
|
|
216
236
|
}
|
|
217
237
|
_applyVector(e, n, r, i) {
|
|
218
238
|
let { tmpVector: a } = t;
|
|
@@ -220,7 +240,7 @@ var INDEX_X$3 = 0, INDEX_Y$2 = 1, INDEX_Z$1 = 2, INDEX_W = 3, Vector4 = class e
|
|
|
220
240
|
let [o, s, c, l, u, d, f, p, m, h, g, _, v, y, b, x] = this.elements, S = o * e + u * n + m * r + v * i, C = s * e + d * n + h * r + y * i, w = c * e + f * n + g * r + b * i, T = l * e + p * n + _ * r + x * i;
|
|
221
241
|
return a.set(S, C, w, T), a;
|
|
222
242
|
}
|
|
223
|
-
}, INDEX_X$2 = 0, INDEX_Y$1 = 1, INDEX_Z = 2, Vector3 = class e {
|
|
243
|
+
}, INDEX_X$2 = 0, INDEX_Y$1 = 1, INDEX_Z = 2, DEFAULT_AS_DIRECTION = !1, Vector3 = class e {
|
|
224
244
|
dimension = 3;
|
|
225
245
|
elements;
|
|
226
246
|
static _tmpMatrix3;
|
|
@@ -310,15 +330,15 @@ var INDEX_X$3 = 0, INDEX_Y$2 = 1, INDEX_Z$1 = 2, INDEX_W = 3, Vector4 = class e
|
|
|
310
330
|
let { x: r, y: i, z: a } = n._applyVector(this.x, this.y, this.z);
|
|
311
331
|
return this.set(r, i, a), this;
|
|
312
332
|
}
|
|
313
|
-
applyMatrix4(t) {
|
|
314
|
-
let { tmpMatrix4:
|
|
315
|
-
|
|
316
|
-
let { x:
|
|
317
|
-
return this.set(
|
|
333
|
+
applyMatrix4(t, n) {
|
|
334
|
+
let { tmpMatrix4: r } = e;
|
|
335
|
+
r.copy(t);
|
|
336
|
+
let i = n?.asDirection ?? DEFAULT_AS_DIRECTION, a = i ? 0 : 1, { x: o, y: s, z: c, w: l } = r._applyVector(this.x, this.y, this.z, a), u = i || l === 0 ? o : o / l, d = i || l === 0 ? s : s / l, f = i || l === 0 ? c : c / l;
|
|
337
|
+
return this.set(u, d, f), this;
|
|
318
338
|
}
|
|
319
339
|
applyQuaternion(t) {
|
|
320
340
|
let { tmpMatrix4: n } = e;
|
|
321
|
-
n.
|
|
341
|
+
n.setRotation(t);
|
|
322
342
|
let { x: r, y: i, z: a } = n._applyVector(this.x, this.y, this.z, 0);
|
|
323
343
|
return this.set(r, i, a), this;
|
|
324
344
|
}
|
|
@@ -604,7 +624,7 @@ var INDEX_X$3 = 0, INDEX_Y$2 = 1, INDEX_Z$1 = 2, INDEX_W = 3, Vector4 = class e
|
|
|
604
624
|
}
|
|
605
625
|
applyQuaternion(t) {
|
|
606
626
|
let { tmpMatrix4: n } = e;
|
|
607
|
-
n.
|
|
627
|
+
n.setRotation(t);
|
|
608
628
|
let { x: r } = n._applyVector(this.x, 0, 0, 0);
|
|
609
629
|
return this.set(r), this;
|
|
610
630
|
}
|
|
@@ -693,7 +713,7 @@ var INDEX_X$3 = 0, INDEX_Y$2 = 1, INDEX_Z$1 = 2, INDEX_W = 3, Vector4 = class e
|
|
|
693
713
|
}
|
|
694
714
|
applyQuaternion(t) {
|
|
695
715
|
let { tmpMatrix4: n } = e;
|
|
696
|
-
n.
|
|
716
|
+
n.setRotation(t);
|
|
697
717
|
let { x: r, y: i } = n._applyVector(this.x, this.y, 0, 0);
|
|
698
718
|
return this.set(r, i), this;
|
|
699
719
|
}
|
package/dist/mathue.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.mathue={}))})(this,function(e){function*t(e,t){let n=t?.start??0,r=t?.step??1;if(r!==0&&!(r>0&&n>e)&&!(r<0&&n<e))for(let t=n;r>0?t<e:t>e;t+=r)yield t}function n(e){let t=0;for(let n of e)t+=n;return t}function r(e,t){let n=0;for(let r of e)n+=t(r)??0;return n}var i=0,a=1,o=2,s=3,c=class e{dimension=4;elements;static _tmpMatrix4;static get tmpMatrix4(){return this._tmpMatrix4||=u.identity(),this._tmpMatrix4}constructor(e,t,n,r){this.elements=[e,t,n,r]}get x(){return this.elements[i]}set x(e){this.elements[i]=e}get y(){return this.elements[a]}set y(e){this.elements[a]=e}get z(){return this.elements[o]}set z(e){this.elements[o]=e}get w(){return this.elements[s]}set w(e){this.elements[s]=e}static zero(){return new e(0,0,0,0)}static one(){return new e(1,1,1,1)}clone(){let{x:t,y:n,z:r,w:i}=this;return new e(t,n,r,i)}isZero(){let{x:e,y:t,z:n,w:r}=this;return e===0&&t===0&&n===0&&r===0}set(e,t,n,r){this.x=e,this.y=t,this.z=n,this.w=r}copy(e){let{x:t,y:n,z:r,w:i}=e;this.set(t,n,r,i)}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this}subtract(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this}divideScalar(e){return this.x/=e,this.y/=e,this.z/=e,this.w/=e,this}length(){let{x:e,y:t,z:n,w:r}=this;return Math.sqrt(e**2+t**2+n**2+r**2)}normalize(){let e=this.length();return e<=0?this:this.divideScalar(e)}applyMatrix4(t){let{tmpMatrix4:n}=e;n.copy(t);let{x:r,y:i,z:a,w:o}=this,s=n._applyVector(r,i,a,o);return this.copy(s),this}applyQuaternion(t){let{tmpMatrix4:n}=e;n.setQuaternion(t);let{x:r,y:i,z:a,w:o}=this,s=n._applyVector(r,i,a,o);return this.copy(s),this}},l=1e-8,u=class e{order=4;elements;static _tmpMatrix;static get tmpMatrix(){return this._tmpMatrix||=e.identity(),this._tmpMatrix}static _tmpVector;static get tmpVector(){return this._tmpVector||=c.zero(),this._tmpVector}constructor(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h){this.elements=Float32Array.of(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h)}static identity(){return e.zero().setIdentity()}static zero(){return new e(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}clone(){let[t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g]=this.elements;return new e(t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g)}set(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h){return this.elements[0]=e,this.elements[1]=t,this.elements[2]=n,this.elements[3]=r,this.elements[4]=i,this.elements[5]=a,this.elements[6]=o,this.elements[7]=s,this.elements[8]=c,this.elements[9]=l,this.elements[10]=u,this.elements[11]=d,this.elements[12]=f,this.elements[13]=p,this.elements[14]=m,this.elements[15]=h,this}copy(e){let[t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g]=e.elements;this.set(t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g)}setIdentity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}setQuaternion(e){let{a:t,b:n,c:r,d:i}=e,a=2/e.squaredNorm(),o=n**2,s=r**2,c=i**2,l=t*n,u=t*r,d=t*i,f=n*r,p=n*i,m=r*i;return this.set(1-a*(s+c),a*(f-d),a*(p+u),0,a*(f+d),1-a*(o+c),a*(m-l),0,a*(p-u),a*(m+l),1-a*(o+s),0,0,0,0,1),this}add(e){let{order:n}=this;for(let r of t(n**2))this.elements[r]+=e.elements[r];return this}subtract(e){let{order:n}=this;for(let r of t(n**2))this.elements[r]-=e.elements[r];return this}multiplyScalar(e){let{order:n}=this;for(let r of t(n**2))this.elements[r]*=e;return this}divideScalar(e){let{order:n}=this;for(let r of t(n**2))this.elements[r]/=e;return this}multiply(e){let[t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g]=this.elements,[_,v,y,b,x,S,C,w,T,E,D,O,k,A,j,M]=e.elements;return this.elements[0]=_*t+v*a+y*l+b*p,this.elements[1]=_*n+v*o+y*u+b*m,this.elements[2]=_*r+v*s+y*d+b*h,this.elements[3]=_*i+v*c+y*f+b*g,this.elements[4]=x*t+S*a+C*l+w*p,this.elements[5]=x*n+S*o+C*u+w*m,this.elements[6]=x*r+S*s+C*d+w*h,this.elements[7]=x*i+S*c+C*f+w*g,this.elements[8]=T*t+E*a+D*l+O*p,this.elements[9]=T*n+E*o+D*u+O*m,this.elements[10]=T*r+E*s+D*d+O*h,this.elements[11]=T*i+E*c+D*f+O*g,this.elements[12]=k*t+A*a+j*l+M*p,this.elements[13]=k*n+A*o+j*u+M*m,this.elements[14]=k*r+A*s+j*d+M*h,this.elements[15]=k*i+A*c+j*f+M*g,this}determinant(){let[e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h]=this.elements;return e*(a*(u*h-d*m)-o*(l*h-d*p)+s*(l*m-u*p))-t*(i*(u*h-d*m)-o*(c*h-d*f)+s*(c*m-u*f))+n*(i*(l*h-d*p)-a*(c*h-d*f)+s*(c*p-l*f))-r*(i*(l*m-u*p)-a*(c*m-u*f)+o*(c*p-l*f))}invert(){let e=this.determinant();if(Math.abs(e)<l)return null;let[t,n,r,i,a,o,s,c,u,d,f,p,m,h,g,_]=this.elements,v=f*_-p*g,y=d*_-p*h,b=d*g-f*h,x=s*_-c*g,S=o*_-c*h,C=o*g-s*h,w=s*p-c*f,T=o*p-c*d,E=o*f-s*d,D=u*_-p*m,O=u*g-f*m,k=a*_-c*m,A=a*g-s*m,j=a*p-c*u,M=a*f-s*u,N=u*h-d*m,P=a*h-o*m,F=a*d-o*u;return this.elements[0]=(o*v-s*y+c*b)/e,this.elements[1]=-(n*v-r*y+i*b)/e,this.elements[2]=(n*x-r*S+i*C)/e,this.elements[3]=-(n*w-r*T+i*E)/e,this.elements[4]=-(a*v-s*D+c*O)/e,this.elements[5]=(t*v-r*D+i*O)/e,this.elements[6]=-(t*x-r*k+i*A)/e,this.elements[7]=(t*w-r*j+i*M)/e,this.elements[8]=(a*y-o*D+c*N)/e,this.elements[9]=-(t*y-n*D+i*N)/e,this.elements[10]=(t*S-n*k+i*P)/e,this.elements[11]=-(t*T-n*j+i*F)/e,this.elements[12]=-(a*b-o*O+s*N)/e,this.elements[13]=(t*b-n*O+r*N)/e,this.elements[14]=-(t*C-n*A+r*P)/e,this.elements[15]=(t*E-n*M+r*F)/e,this}transpose(){let[e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h]=this.elements;return this.elements[1]=i,this.elements[2]=c,this.elements[3]=f,this.elements[4]=t,this.elements[6]=l,this.elements[7]=p,this.elements[8]=n,this.elements[9]=o,this.elements[11]=m,this.elements[12]=r,this.elements[13]=s,this.elements[14]=d,this}divide(t){let{tmpMatrix:n}=e;return n.copy(t),n.invert()?this.multiply(n):null}scale(e){let{order:n}=this;for(let r of t(n)){let i=r===n-1?1:e.elements[r];for(let e of t(n)){let t=r*n+e;this.elements[t]*=i}}return this}translate(e){let{x:t,y:n,z:r}=e,[i,a,o,s,c,l,u,d,f,p,m,h,g,_,v,y]=this.elements;return this.elements[12]=i*t+c*n+f*r+g,this.elements[13]=a*t+l*n+p*r+_,this.elements[14]=o*t+u*n+m*r+v,this.elements[15]=s*t+d*n+h*r+y,this}lookAt(e,t,n){let{x:r,y:i,z:a}=e,{x:o,y:s,z:c}=n,u=e.x-t.x,d=e.y-t.y,f=e.z-t.z,p=Math.sqrt(u**2+d**2+f**2);if(p<l)return this;u/=p,d/=p,f/=p;let m=s*f-c*d,h=c*u-o*f,g=o*d-s*u,_=Math.sqrt(m**2+h**2+g**2);_>0&&(m/=_,h/=_,g/=_);let v=d*g-f*h,y=f*m-u*g,b=u*h-d*m,x=Math.sqrt(v**2+y**2+b**2);x>0&&(v/=x,y/=x,b/=x);let S=-(m*r+h*i+g*a),C=-(v*r+y*i+b*a),w=-(u*r+d*i+f*a);return this.set(m,v,u,0,h,y,d,0,g,b,f,0,S,C,w,1),this}perspective(e,t,n,r){let i=1/Math.tan(e/2);return this.set(i/r,0,0,0,0,i,0,0,0,0,1,-1,0,0,1,0),n===1/0?(this.elements[10]=-1,this.elements[14]=-2*t):(this.elements[10]=-(n+t)/(n-t),this.elements[14]=-2*n*t/(n-t)),this}_applyVector(t,n,r,i){let{tmpVector:a}=e;a.set(t,n,r,i);let[o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,x]=this.elements,S=o*t+u*n+m*r+v*i,C=s*t+d*n+h*r+y*i,w=c*t+f*n+g*r+b*i,T=l*t+p*n+_*r+x*i;return a.set(S,C,w,T),a}},d=0,f=1,p=2,m=class e{dimension=3;elements;static _tmpMatrix3;static get tmpMatrix3(){return this._tmpMatrix3||=g.identity(),this._tmpMatrix3}static _tmpMatrix4;static get tmpMatrix4(){return this._tmpMatrix4||=u.identity(),this._tmpMatrix4}constructor(e,t,n){this.elements=[e,t,n]}get x(){return this.elements[d]}set x(e){this.elements[d]=e}get y(){return this.elements[f]}set y(e){this.elements[f]=e}get z(){return this.elements[p]}set z(e){this.elements[p]=e}static zero(){return new e(0,0,0)}static one(){return new e(1,1,1)}clone(){let{x:t,y:n,z:r}=this;return new e(t,n,r)}isZero(){let{x:e,y:t,z:n}=this;return e===0&&t===0&&n===0}set(e,t,n){return this.x=e,this.y=t,this.z=n,this}copy(e){let{x:t,y:n,z:r}=e;return this.set(t,n,r)}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}subtract(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}divideScalar(e){return this.x/=e,this.y/=e,this.z/=e,this}length(){let{x:e,y:t,z:n}=this;return Math.sqrt(e**2+t**2+n**2)}normalize(){let e=this.length();return e<=0?this:this.divideScalar(e)}cross(e){let{x:t,y:n,z:r}=this,{x:i,y:a,z:o}=e,s=n*o-r*a,c=r*i-t*o,l=t*a-n*i;return this.set(s,c,l)}crossTo(e,t){return t.copy(this),t.cross(e)}applyMatrix3(t){let{tmpMatrix3:n}=e;n.copy(t);let{x:r,y:i,z:a}=n._applyVector(this.x,this.y,this.z);return this.set(r,i,a),this}applyMatrix4(t){let{tmpMatrix4:n}=e;n.copy(t);let{x:r,y:i,z:a}=n._applyVector(this.x,this.y,this.z,0);return this.set(r,i,a),this}applyQuaternion(t){let{tmpMatrix4:n}=e;n.setQuaternion(t);let{x:r,y:i,z:a}=n._applyVector(this.x,this.y,this.z,0);return this.set(r,i,a),this}},h=1e-8,g=class e{order=3;elements;static _tmpMatrix;static get tmpMatrix(){return this._tmpMatrix||=e.identity(),this._tmpMatrix}static _tmpVector;static get tmpVector(){return this._tmpVector||=m.zero(),this._tmpVector}constructor(e,t,n,r,i,a,o,s,c){this.elements=Float32Array.of(e,t,n,r,i,a,o,s,c)}static identity(){return e.zero().setIdentity()}static zero(){return new e(0,0,0,0,0,0,0,0,0)}clone(){let[t,n,r,i,a,o,s,c,l]=this.elements;return new e(t,n,r,i,a,o,s,c,l)}set(e,t,n,r,i,a,o,s,c){return this.elements[0]=e,this.elements[1]=t,this.elements[2]=n,this.elements[3]=r,this.elements[4]=i,this.elements[5]=a,this.elements[6]=o,this.elements[7]=s,this.elements[8]=c,this}copy(e){let[t,n,r,i,a,o,s,c,l]=e.elements;this.set(t,n,r,i,a,o,s,c,l)}setIdentity(){return this.set(1,0,0,0,1,0,0,0,1),this}add(e){let{order:n}=this;for(let r of t(n**2))this.elements[r]+=e.elements[r];return this}subtract(e){let{order:n}=this;for(let r of t(n**2))this.elements[r]-=e.elements[r];return this}multiplyScalar(e){let{order:n}=this;for(let r of t(n**2))this.elements[r]*=e;return this}divideScalar(e){let{order:n}=this;for(let r of t(n**2))this.elements[r]/=e;return this}multiply(e){let[t,n,r,i,a,o,s,c,l]=this.elements,[u,d,f,p,m,h,g,_,v]=e.elements;return this.elements[0]=u*t+d*i+f*s,this.elements[1]=u*n+d*a+f*c,this.elements[2]=u*r+d*o+f*l,this.elements[3]=p*t+m*i+h*s,this.elements[4]=p*n+m*a+h*c,this.elements[5]=p*r+m*o+h*l,this.elements[6]=g*t+_*i+v*s,this.elements[7]=g*n+_*a+v*c,this.elements[8]=g*r+_*o+v*l,this}determinant(){let[e,t,n,r,i,a,o,s,c]=this.elements;return e*(c*i-a*s)+t*(-c*r+a*o)+n*(s*r-i*o)}invert(){let e=this.determinant();if(Math.abs(e)<h)return null;let[t,n,r,i,a,o,s,c,l]=this.elements,u=l*a-o*c,d=-l*i+o*s,f=c*i-a*s;return this.elements[0]=u/e,this.elements[1]=(-l*n+r*c)/e,this.elements[2]=(o*n-r*a)/e,this.elements[3]=d/e,this.elements[4]=(l*t-r*s)/e,this.elements[5]=(-o*t+r*i)/e,this.elements[6]=f/e,this.elements[7]=(-c*t+n*s)/e,this.elements[8]=(a*t-n*i)/e,this}transpose(){let[e,t,n,r,i,a,o,s,c]=this.elements;return this.elements[1]=r,this.elements[2]=o,this.elements[3]=t,this.elements[5]=s,this.elements[6]=n,this.elements[7]=a,this}divide(t){let{tmpMatrix:n}=e;return n.copy(t),n.invert()?this.multiply(n):null}_applyVector(t,n,r){let{tmpVector:i}=e;i.set(t,n,r);let[a,o,s,c,l,u,d,f,p]=this.elements,m=a*t+c*n+d*r,h=o*t+l*n+f*r,g=s*t+u*n+p*r;return i.set(m,h,g),i}},_=class{_phi;_theta;_radius;constructor(e,t,n){this._phi=e,this._theta=t,this._radius=n}get phi(){return this._phi}set phi(e){this._phi=e}get theta(){return this._theta}set theta(e){this._theta=e}get radius(){return this._radius}set radius(e){this._radius=e}toVector3(e){let{phi:t,theta:n,radius:r}=this,{cos:i,sin:a}=Math,o=a(n),s=r*o*i(t),c=r*o*a(t),l=r*i(n);e.set(s,c,l)}toTangentZ(e){let{phi:t,theta:n}=this,{cos:r,sin:i}=Math,a=r(n),o=-a*r(t),s=-a*i(t),c=i(n);e.set(o,s,c)}},v=class e{_a;_b;_c;_d;static temporary=e.identity();constructor(e,t,n,r){this._a=e,this._b=t,this._c=n,this._d=r}get a(){return this._a}get b(){return this._b}get c(){return this._c}get d(){return this._d}static identity(){return new e(1,0,0,0)}static fromAxisAndAngle(t,n){let r=e.identity();return r.setAxisAndAngle(t,n),r}clone(){let{a:t,b:n,c:r,d:i}=this;return new e(t,n,r,i)}set(e,t,n,r){return this._a=e,this._b=t,this._c=n,this._d=r,this}copy(e){let{a:t,b:n,c:r,d:i}=e;return this.set(t,n,r,i)}setIdentity(){this.set(1,0,0,0)}setAxisAndAngle(e,t){if(e.isZero())return this.setIdentity();e.normalize();let{x:n,y:r,z:i}=e,a=Math.sin(t/2);this.set(Math.cos(t/2),n*a,r*a,i*a)}squaredNorm(){let{a:e,b:t,c:n,d:r}=this;return e**2+t**2+n**2+r**2}norm(){return Math.sqrt(this.squaredNorm())}conjugate(){return this._b*=-1,this._c*=-1,this._d*=-1,this}add(e){let{a:t,b:n,c:r,d:i}=e;return this._a+=t,this._b+=n,this._c+=r,this._d+=i,this}subtract(e){let{a:t,b:n,c:r,d:i}=e;return this._a-=t,this._b-=n,this._c-=r,this._d-=i,this}multiply(e){let{a:t,b:n,c:r,d:i}=this,{a,b:o,c:s,d:c}=e;return this._a=t*a-n*o-r*s-i*c,this._b=t*o+n*a+r*c-i*s,this._c=t*s-n*c+r*a+i*o,this._d=t*c+n*s-r*o+i*a,this}invert(){let e=this.squaredNorm();return e<=0?null:this.conjugate().divideScalar(e)}divide(t){let{temporary:n}=e;return n.copy(t),n.invert()?this.multiply(n):null}multiplyScalar(e){return this._a*=e,this._b*=e,this._c*=e,this._d*=e,this}divideScalar(e){return this._a/=e,this._b/=e,this._c/=e,this._d/=e,this}rotateX(t){let{temporary:n}=e;return n.setIdentity(),n.setAxisAndAngle(new m(1,0,0),t),this.multiply(n)}rotateY(t){let{temporary:n}=e;return n.setIdentity(),n.setAxisAndAngle(new m(0,1,0),t),this.multiply(n)}rotateZ(t){let{temporary:n}=e;return n.setIdentity(),n.setAxisAndAngle(new m(0,0,1),t),this.multiply(n)}},y=0,b=class e{dimension=1;elements;static _tmpMatrix3;static get tmpMatrix3(){return this._tmpMatrix3||=g.identity(),this._tmpMatrix3}static _tmpMatrix4;static get tmpMatrix4(){return this._tmpMatrix4||=u.identity(),this._tmpMatrix4}constructor(e){this.elements=[e]}get x(){return this.elements[y]}set x(e){this.elements[y]=e}static zero(){return new e(0)}static one(){return new e(1)}clone(){let{x:t}=this;return new e(t)}isZero(){return this.x===0}set(e){return this.x=e,this}copy(e){return this.x=e.x,this}add(e){return this.x+=e.x,this}subtract(e){return this.x-=e.x,this}multiplyScalar(e){return this.x*=e,this}divideScalar(e){return this.x/=e,this}length(){return Math.abs(this.x)}normalize(){return this.x/=this.length(),this}applyMatrix3(t){let{tmpMatrix3:n}=e;n.copy(t);let{x:r}=n._applyVector(this.x,0,0);return this.set(r),this}applyMatrix4(t){let{tmpMatrix4:n}=e;n.copy(t);let{x:r}=n._applyVector(this.x,0,0,0);return this.set(r),this}applyQuaternion(t){let{tmpMatrix4:n}=e;n.setQuaternion(t);let{x:r}=n._applyVector(this.x,0,0,0);return this.set(r),this}},x=0,S=1,C=class e{dimension=2;elements;static _tmpMatrix3;static get tmpMatrix3(){return this._tmpMatrix3||=g.identity(),this._tmpMatrix3}static _tmpMatrix4;static get tmpMatrix4(){return this._tmpMatrix4||=u.identity(),this._tmpMatrix4}constructor(e,t){this.elements=[e,t]}get x(){return this.elements[x]}set x(e){this.elements[x]=e}get y(){return this.elements[S]}set y(e){this.elements[S]=e}static zero(){return new e(0,0)}static one(){return new e(1,1)}clone(){let{x:t,y:n}=this;return new e(t,n)}isZero(){let{x:e,y:t}=this;return e===0&&t===0}set(e,t){return this.x=e,this.y=t,this}copy(e){let{x:t,y:n}=e;return this.set(t,n)}add(e){return this.x+=e.x,this.y+=e.y,this}subtract(e){return this.x-=e.x,this.y-=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}divideScalar(e){return this.x/=e,this.y/=e,this}length(){let{x:e,y:t}=this;return Math.sqrt(e**2+t**2)}normalize(){let e=this.length();return e<=0?this:this.divideScalar(e)}rotate(e){let{cos:t,sin:n}=Math,r=this.x*t(e)-this.y*n(e),i=this.x*n(e)+this.y*t(e);return this.x=r,this.y=i,this}applyMatrix3(t){let{tmpMatrix3:n}=e;n.copy(t);let{x:r,y:i}=n._applyVector(this.x,this.y,0);return this.set(r,i),this}applyMatrix4(t){let{tmpMatrix4:n}=e;n.copy(t);let{x:r,y:i}=n._applyVector(this.x,this.y,0,0);return this.set(r,i),this}applyQuaternion(t){let{tmpMatrix4:n}=e;n.setQuaternion(t);let{x:r,y:i}=n._applyVector(this.x,this.y,0,0);return this.set(r,i),this}};e.Matrix3=g,e.Matrix4=u,e.PolarCoordinate3=_,e.Quaternion=v,e.Vector1=b,e.Vector2=C,e.Vector3=m,e.Vector4=c,e.range=t,e.sum=n,e.sumMap=r});
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.mathue={}))})(this,function(e){function*t(e,t){let n=t?.start??0,r=t?.step??1;if(r!==0&&!(r>0&&n>e)&&!(r<0&&n<e))for(let t=n;r>0?t<e:t>e;t+=r)yield t}function n(e){let t=0;for(let n of e)t+=n;return t}function r(e,t){let n=0;for(let r of e)n+=t(r)??0;return n}var i=0,a=1,o=2,s=3,c=class e{dimension=4;elements;static _tmpMatrix4;static get tmpMatrix4(){return this._tmpMatrix4||=d.identity(),this._tmpMatrix4}constructor(e,t,n,r){this.elements=[e,t,n,r]}get x(){return this.elements[i]}set x(e){this.elements[i]=e}get y(){return this.elements[a]}set y(e){this.elements[a]=e}get z(){return this.elements[o]}set z(e){this.elements[o]=e}get w(){return this.elements[s]}set w(e){this.elements[s]=e}static zero(){return new e(0,0,0,0)}static one(){return new e(1,1,1,1)}clone(){let{x:t,y:n,z:r,w:i}=this;return new e(t,n,r,i)}isZero(){let{x:e,y:t,z:n,w:r}=this;return e===0&&t===0&&n===0&&r===0}set(e,t,n,r){this.x=e,this.y=t,this.z=n,this.w=r}copy(e){let{x:t,y:n,z:r,w:i}=e;this.set(t,n,r,i)}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this}subtract(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this}divideScalar(e){return this.x/=e,this.y/=e,this.z/=e,this.w/=e,this}length(){let{x:e,y:t,z:n,w:r}=this;return Math.sqrt(e**2+t**2+n**2+r**2)}normalize(){let e=this.length();return e<=0?this:this.divideScalar(e)}applyMatrix4(t){let{tmpMatrix4:n}=e;n.copy(t);let{x:r,y:i,z:a,w:o}=this,s=n._applyVector(r,i,a,o);return this.copy(s),this}applyQuaternion(t){let{tmpMatrix4:n}=e;n.setRotation(t);let{x:r,y:i,z:a,w:o}=this,s=n._applyVector(r,i,a,o);return this.copy(s),this}},l=1e-8,u=!1,d=class e{order=4;elements;static _tmpMatrix;static get tmpMatrix(){return this._tmpMatrix||=e.identity(),this._tmpMatrix}static _tmpVector;static get tmpVector(){return this._tmpVector||=c.zero(),this._tmpVector}constructor(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h){this.elements=Float32Array.of(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h)}static identity(){return e.zero().setIdentity()}static zero(){return new e(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}clone(){let[t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g]=this.elements;return new e(t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g)}set(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h){return this.elements[0]=e,this.elements[1]=t,this.elements[2]=n,this.elements[3]=r,this.elements[4]=i,this.elements[5]=a,this.elements[6]=o,this.elements[7]=s,this.elements[8]=c,this.elements[9]=l,this.elements[10]=u,this.elements[11]=d,this.elements[12]=f,this.elements[13]=p,this.elements[14]=m,this.elements[15]=h,this}copy(e){let[t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g]=e.elements;this.set(t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g)}setIdentity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}setScale(e){this.setIdentity();let{order:n}=this;for(let r of t(n)){let i=r===n-1?1:e.elements[r];for(let e of t(n)){let t=r*n+e;this.elements[t]*=i}}return this}setTranslation(e){let{x:t,y:n,z:r}=e;return this.setIdentity(),this.elements[12]=t,this.elements[13]=n,this.elements[14]=r,this}setRotation(e){let{a:t,b:n,c:r,d:i}=e,a=2/e.squaredNorm(),o=n**2,s=r**2,c=i**2,l=t*n,u=t*r,d=t*i,f=n*r,p=n*i,m=r*i;return this.set(1-a*(s+c),-a*(f-d),-a*(p+u),0,-a*(f+d),1-a*(o+c),-a*(m-l),0,-a*(p-u),-a*(m+l),1-a*(o+s),0,0,0,0,1),this}add(e){let{order:n}=this;for(let r of t(n**2))this.elements[r]+=e.elements[r];return this}subtract(e){let{order:n}=this;for(let r of t(n**2))this.elements[r]-=e.elements[r];return this}multiplyScalar(e){let{order:n}=this;for(let r of t(n**2))this.elements[r]*=e;return this}divideScalar(e){let{order:n}=this;for(let r of t(n**2))this.elements[r]/=e;return this}multiply(e){let[t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g]=this.elements,[_,v,y,b,x,S,C,w,T,E,D,O,k,A,j,M]=e.elements;return this.elements[0]=_*t+v*a+y*l+b*p,this.elements[1]=_*n+v*o+y*u+b*m,this.elements[2]=_*r+v*s+y*d+b*h,this.elements[3]=_*i+v*c+y*f+b*g,this.elements[4]=x*t+S*a+C*l+w*p,this.elements[5]=x*n+S*o+C*u+w*m,this.elements[6]=x*r+S*s+C*d+w*h,this.elements[7]=x*i+S*c+C*f+w*g,this.elements[8]=T*t+E*a+D*l+O*p,this.elements[9]=T*n+E*o+D*u+O*m,this.elements[10]=T*r+E*s+D*d+O*h,this.elements[11]=T*i+E*c+D*f+O*g,this.elements[12]=k*t+A*a+j*l+M*p,this.elements[13]=k*n+A*o+j*u+M*m,this.elements[14]=k*r+A*s+j*d+M*h,this.elements[15]=k*i+A*c+j*f+M*g,this}multiplyScale(t){return this.multiply(e.tmpMatrix.setScale(t))}multiplyTranslation(t){return this.multiply(e.tmpMatrix.setTranslation(t))}multiplyRotation(t){return this.multiply(e.tmpMatrix.setRotation(t))}determinant(){let[e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h]=this.elements;return e*(a*(u*h-d*m)-o*(l*h-d*p)+s*(l*m-u*p))-t*(i*(u*h-d*m)-o*(c*h-d*f)+s*(c*m-u*f))+n*(i*(l*h-d*p)-a*(c*h-d*f)+s*(c*p-l*f))-r*(i*(l*m-u*p)-a*(c*m-u*f)+o*(c*p-l*f))}invert(){let e=this.determinant();if(Math.abs(e)<l)return null;let[t,n,r,i,a,o,s,c,u,d,f,p,m,h,g,_]=this.elements,v=f*_-p*g,y=d*_-p*h,b=d*g-f*h,x=s*_-c*g,S=o*_-c*h,C=o*g-s*h,w=s*p-c*f,T=o*p-c*d,E=o*f-s*d,D=u*_-p*m,O=u*g-f*m,k=a*_-c*m,A=a*g-s*m,j=a*p-c*u,M=a*f-s*u,N=u*h-d*m,P=a*h-o*m,F=a*d-o*u;return this.elements[0]=(o*v-s*y+c*b)/e,this.elements[1]=-(n*v-r*y+i*b)/e,this.elements[2]=(n*x-r*S+i*C)/e,this.elements[3]=-(n*w-r*T+i*E)/e,this.elements[4]=-(a*v-s*D+c*O)/e,this.elements[5]=(t*v-r*D+i*O)/e,this.elements[6]=-(t*x-r*k+i*A)/e,this.elements[7]=(t*w-r*j+i*M)/e,this.elements[8]=(a*y-o*D+c*N)/e,this.elements[9]=-(t*y-n*D+i*N)/e,this.elements[10]=(t*S-n*k+i*P)/e,this.elements[11]=-(t*T-n*j+i*F)/e,this.elements[12]=-(a*b-o*O+s*N)/e,this.elements[13]=(t*b-n*O+r*N)/e,this.elements[14]=-(t*C-n*A+r*P)/e,this.elements[15]=(t*E-n*M+r*F)/e,this}transpose(){let[e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h]=this.elements;return this.elements[1]=i,this.elements[2]=c,this.elements[3]=f,this.elements[4]=t,this.elements[6]=l,this.elements[7]=p,this.elements[8]=n,this.elements[9]=o,this.elements[11]=m,this.elements[12]=r,this.elements[13]=s,this.elements[14]=d,this}divide(t){let{tmpMatrix:n}=e;return n.copy(t),n.invert()?this.multiply(n):null}lookAt(e,t,n){let{x:r,y:i,z:a}=e,{x:o,y:s,z:c}=n,u=e.x-t.x,d=e.y-t.y,f=e.z-t.z,p=Math.sqrt(u**2+d**2+f**2);if(p<l)return this;u/=p,d/=p,f/=p;let m=s*f-c*d,h=c*u-o*f,g=o*d-s*u,_=Math.sqrt(m**2+h**2+g**2);_>0&&(m/=_,h/=_,g/=_);let v=d*g-f*h,y=f*m-u*g,b=u*h-d*m,x=Math.sqrt(v**2+y**2+b**2);x>0&&(v/=x,y/=x,b/=x);let S=-(m*r+h*i+g*a),C=-(v*r+y*i+b*a),w=-(u*r+d*i+f*a);return this.set(m,v,u,0,h,y,d,0,g,b,f,0,S,C,w,1),this}orthographic(e,t,n,r,i,a,o){let s=o?.depthZeroToOne??u,c=t-e,l=r-n,d=a-i,f=(s?-1:-2)/d,p=-(t+e)/c,m=-(r+n)/l,h=(s?-i:-(a+i))/d;return this.set(2/c,0,0,0,0,2/l,0,0,0,0,f,0,p,m,h,1),this}perspective(e,t,n,r,i){let a=1/Math.tan(e/2);this.set(a/r,0,0,0,0,a,0,0,0,0,1,-1,0,0,1,0);let o=i?.depthZeroToOne??u,s=o?1:2;if(n!==1/0){let e=o?n:n+t;this.elements[10]=-e/(n-t),this.elements[14]=-s*n*t/(n-t)}else this.elements[10]=-1,this.elements[14]=-s*t;return this}_applyVector(t,n,r,i){let{tmpVector:a}=e;a.set(t,n,r,i);let[o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,x]=this.elements,S=o*t+u*n+m*r+v*i,C=s*t+d*n+h*r+y*i,w=c*t+f*n+g*r+b*i,T=l*t+p*n+_*r+x*i;return a.set(S,C,w,T),a}},f=0,p=1,m=2,h=!1,g=class e{dimension=3;elements;static _tmpMatrix3;static get tmpMatrix3(){return this._tmpMatrix3||=v.identity(),this._tmpMatrix3}static _tmpMatrix4;static get tmpMatrix4(){return this._tmpMatrix4||=d.identity(),this._tmpMatrix4}constructor(e,t,n){this.elements=[e,t,n]}get x(){return this.elements[f]}set x(e){this.elements[f]=e}get y(){return this.elements[p]}set y(e){this.elements[p]=e}get z(){return this.elements[m]}set z(e){this.elements[m]=e}static zero(){return new e(0,0,0)}static one(){return new e(1,1,1)}clone(){let{x:t,y:n,z:r}=this;return new e(t,n,r)}isZero(){let{x:e,y:t,z:n}=this;return e===0&&t===0&&n===0}set(e,t,n){return this.x=e,this.y=t,this.z=n,this}copy(e){let{x:t,y:n,z:r}=e;return this.set(t,n,r)}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}subtract(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}divideScalar(e){return this.x/=e,this.y/=e,this.z/=e,this}length(){let{x:e,y:t,z:n}=this;return Math.sqrt(e**2+t**2+n**2)}normalize(){let e=this.length();return e<=0?this:this.divideScalar(e)}cross(e){let{x:t,y:n,z:r}=this,{x:i,y:a,z:o}=e,s=n*o-r*a,c=r*i-t*o,l=t*a-n*i;return this.set(s,c,l)}crossTo(e,t){return t.copy(this),t.cross(e)}applyMatrix3(t){let{tmpMatrix3:n}=e;n.copy(t);let{x:r,y:i,z:a}=n._applyVector(this.x,this.y,this.z);return this.set(r,i,a),this}applyMatrix4(t,n){let{tmpMatrix4:r}=e;r.copy(t);let i=n?.asDirection??h,a=i?0:1,{x:o,y:s,z:c,w:l}=r._applyVector(this.x,this.y,this.z,a),u=i||l===0?o:o/l,d=i||l===0?s:s/l,f=i||l===0?c:c/l;return this.set(u,d,f),this}applyQuaternion(t){let{tmpMatrix4:n}=e;n.setRotation(t);let{x:r,y:i,z:a}=n._applyVector(this.x,this.y,this.z,0);return this.set(r,i,a),this}},_=1e-8,v=class e{order=3;elements;static _tmpMatrix;static get tmpMatrix(){return this._tmpMatrix||=e.identity(),this._tmpMatrix}static _tmpVector;static get tmpVector(){return this._tmpVector||=g.zero(),this._tmpVector}constructor(e,t,n,r,i,a,o,s,c){this.elements=Float32Array.of(e,t,n,r,i,a,o,s,c)}static identity(){return e.zero().setIdentity()}static zero(){return new e(0,0,0,0,0,0,0,0,0)}clone(){let[t,n,r,i,a,o,s,c,l]=this.elements;return new e(t,n,r,i,a,o,s,c,l)}set(e,t,n,r,i,a,o,s,c){return this.elements[0]=e,this.elements[1]=t,this.elements[2]=n,this.elements[3]=r,this.elements[4]=i,this.elements[5]=a,this.elements[6]=o,this.elements[7]=s,this.elements[8]=c,this}copy(e){let[t,n,r,i,a,o,s,c,l]=e.elements;this.set(t,n,r,i,a,o,s,c,l)}setIdentity(){return this.set(1,0,0,0,1,0,0,0,1),this}add(e){let{order:n}=this;for(let r of t(n**2))this.elements[r]+=e.elements[r];return this}subtract(e){let{order:n}=this;for(let r of t(n**2))this.elements[r]-=e.elements[r];return this}multiplyScalar(e){let{order:n}=this;for(let r of t(n**2))this.elements[r]*=e;return this}divideScalar(e){let{order:n}=this;for(let r of t(n**2))this.elements[r]/=e;return this}multiply(e){let[t,n,r,i,a,o,s,c,l]=this.elements,[u,d,f,p,m,h,g,_,v]=e.elements;return this.elements[0]=u*t+d*i+f*s,this.elements[1]=u*n+d*a+f*c,this.elements[2]=u*r+d*o+f*l,this.elements[3]=p*t+m*i+h*s,this.elements[4]=p*n+m*a+h*c,this.elements[5]=p*r+m*o+h*l,this.elements[6]=g*t+_*i+v*s,this.elements[7]=g*n+_*a+v*c,this.elements[8]=g*r+_*o+v*l,this}determinant(){let[e,t,n,r,i,a,o,s,c]=this.elements;return e*(c*i-a*s)+t*(-c*r+a*o)+n*(s*r-i*o)}invert(){let e=this.determinant();if(Math.abs(e)<_)return null;let[t,n,r,i,a,o,s,c,l]=this.elements,u=l*a-o*c,d=-l*i+o*s,f=c*i-a*s;return this.elements[0]=u/e,this.elements[1]=(-l*n+r*c)/e,this.elements[2]=(o*n-r*a)/e,this.elements[3]=d/e,this.elements[4]=(l*t-r*s)/e,this.elements[5]=(-o*t+r*i)/e,this.elements[6]=f/e,this.elements[7]=(-c*t+n*s)/e,this.elements[8]=(a*t-n*i)/e,this}transpose(){let[e,t,n,r,i,a,o,s,c]=this.elements;return this.elements[1]=r,this.elements[2]=o,this.elements[3]=t,this.elements[5]=s,this.elements[6]=n,this.elements[7]=a,this}divide(t){let{tmpMatrix:n}=e;return n.copy(t),n.invert()?this.multiply(n):null}_applyVector(t,n,r){let{tmpVector:i}=e;i.set(t,n,r);let[a,o,s,c,l,u,d,f,p]=this.elements,m=a*t+c*n+d*r,h=o*t+l*n+f*r,g=s*t+u*n+p*r;return i.set(m,h,g),i}},y=class{_phi;_theta;_radius;constructor(e,t,n){this._phi=e,this._theta=t,this._radius=n}get phi(){return this._phi}set phi(e){this._phi=e}get theta(){return this._theta}set theta(e){this._theta=e}get radius(){return this._radius}set radius(e){this._radius=e}toVector3(e){let{phi:t,theta:n,radius:r}=this,{cos:i,sin:a}=Math,o=a(n),s=r*o*i(t),c=r*o*a(t),l=r*i(n);e.set(s,c,l)}toTangentZ(e){let{phi:t,theta:n}=this,{cos:r,sin:i}=Math,a=r(n),o=-a*r(t),s=-a*i(t),c=i(n);e.set(o,s,c)}},b=class e{_a;_b;_c;_d;static temporary=e.identity();constructor(e,t,n,r){this._a=e,this._b=t,this._c=n,this._d=r}get a(){return this._a}get b(){return this._b}get c(){return this._c}get d(){return this._d}static identity(){return new e(1,0,0,0)}static fromAxisAndAngle(t,n){let r=e.identity();return r.setAxisAndAngle(t,n),r}clone(){let{a:t,b:n,c:r,d:i}=this;return new e(t,n,r,i)}set(e,t,n,r){return this._a=e,this._b=t,this._c=n,this._d=r,this}copy(e){let{a:t,b:n,c:r,d:i}=e;return this.set(t,n,r,i)}setIdentity(){this.set(1,0,0,0)}setAxisAndAngle(e,t){if(e.isZero())return this.setIdentity();e.normalize();let{x:n,y:r,z:i}=e,a=Math.sin(t/2);this.set(Math.cos(t/2),n*a,r*a,i*a)}squaredNorm(){let{a:e,b:t,c:n,d:r}=this;return e**2+t**2+n**2+r**2}norm(){return Math.sqrt(this.squaredNorm())}conjugate(){return this._b*=-1,this._c*=-1,this._d*=-1,this}add(e){let{a:t,b:n,c:r,d:i}=e;return this._a+=t,this._b+=n,this._c+=r,this._d+=i,this}subtract(e){let{a:t,b:n,c:r,d:i}=e;return this._a-=t,this._b-=n,this._c-=r,this._d-=i,this}multiply(e){let{a:t,b:n,c:r,d:i}=this,{a,b:o,c:s,d:c}=e;return this._a=t*a-n*o-r*s-i*c,this._b=t*o+n*a+r*c-i*s,this._c=t*s-n*c+r*a+i*o,this._d=t*c+n*s-r*o+i*a,this}invert(){let e=this.squaredNorm();return e<=0?null:this.conjugate().divideScalar(e)}divide(t){let{temporary:n}=e;return n.copy(t),n.invert()?this.multiply(n):null}multiplyScalar(e){return this._a*=e,this._b*=e,this._c*=e,this._d*=e,this}divideScalar(e){return this._a/=e,this._b/=e,this._c/=e,this._d/=e,this}rotateX(t){let{temporary:n}=e;return n.setIdentity(),n.setAxisAndAngle(new g(1,0,0),t),this.multiply(n)}rotateY(t){let{temporary:n}=e;return n.setIdentity(),n.setAxisAndAngle(new g(0,1,0),t),this.multiply(n)}rotateZ(t){let{temporary:n}=e;return n.setIdentity(),n.setAxisAndAngle(new g(0,0,1),t),this.multiply(n)}},x=0,S=class e{dimension=1;elements;static _tmpMatrix3;static get tmpMatrix3(){return this._tmpMatrix3||=v.identity(),this._tmpMatrix3}static _tmpMatrix4;static get tmpMatrix4(){return this._tmpMatrix4||=d.identity(),this._tmpMatrix4}constructor(e){this.elements=[e]}get x(){return this.elements[x]}set x(e){this.elements[x]=e}static zero(){return new e(0)}static one(){return new e(1)}clone(){let{x:t}=this;return new e(t)}isZero(){return this.x===0}set(e){return this.x=e,this}copy(e){return this.x=e.x,this}add(e){return this.x+=e.x,this}subtract(e){return this.x-=e.x,this}multiplyScalar(e){return this.x*=e,this}divideScalar(e){return this.x/=e,this}length(){return Math.abs(this.x)}normalize(){return this.x/=this.length(),this}applyMatrix3(t){let{tmpMatrix3:n}=e;n.copy(t);let{x:r}=n._applyVector(this.x,0,0);return this.set(r),this}applyMatrix4(t){let{tmpMatrix4:n}=e;n.copy(t);let{x:r}=n._applyVector(this.x,0,0,0);return this.set(r),this}applyQuaternion(t){let{tmpMatrix4:n}=e;n.setRotation(t);let{x:r}=n._applyVector(this.x,0,0,0);return this.set(r),this}},C=0,w=1,T=class e{dimension=2;elements;static _tmpMatrix3;static get tmpMatrix3(){return this._tmpMatrix3||=v.identity(),this._tmpMatrix3}static _tmpMatrix4;static get tmpMatrix4(){return this._tmpMatrix4||=d.identity(),this._tmpMatrix4}constructor(e,t){this.elements=[e,t]}get x(){return this.elements[C]}set x(e){this.elements[C]=e}get y(){return this.elements[w]}set y(e){this.elements[w]=e}static zero(){return new e(0,0)}static one(){return new e(1,1)}clone(){let{x:t,y:n}=this;return new e(t,n)}isZero(){let{x:e,y:t}=this;return e===0&&t===0}set(e,t){return this.x=e,this.y=t,this}copy(e){let{x:t,y:n}=e;return this.set(t,n)}add(e){return this.x+=e.x,this.y+=e.y,this}subtract(e){return this.x-=e.x,this.y-=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}divideScalar(e){return this.x/=e,this.y/=e,this}length(){let{x:e,y:t}=this;return Math.sqrt(e**2+t**2)}normalize(){let e=this.length();return e<=0?this:this.divideScalar(e)}rotate(e){let{cos:t,sin:n}=Math,r=this.x*t(e)-this.y*n(e),i=this.x*n(e)+this.y*t(e);return this.x=r,this.y=i,this}applyMatrix3(t){let{tmpMatrix3:n}=e;n.copy(t);let{x:r,y:i}=n._applyVector(this.x,this.y,0);return this.set(r,i),this}applyMatrix4(t){let{tmpMatrix4:n}=e;n.copy(t);let{x:r,y:i}=n._applyVector(this.x,this.y,0,0);return this.set(r,i),this}applyQuaternion(t){let{tmpMatrix4:n}=e;n.setRotation(t);let{x:r,y:i}=n._applyVector(this.x,this.y,0,0);return this.set(r,i),this}};e.Matrix3=v,e.Matrix4=d,e.PolarCoordinate3=y,e.Quaternion=b,e.Vector1=S,e.Vector2=T,e.Vector3=g,e.Vector4=c,e.range=t,e.sum=n,e.sumMap=r});
|
package/package.json
CHANGED
|
@@ -1,56 +1,65 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "mathue",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
},
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
|
|
56
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "mathue",
|
|
3
|
+
"description": "TypeScript math library",
|
|
4
|
+
"version": "0.1.2",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"main": "dist/mathue.js",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/mathue.js",
|
|
16
|
+
"require": "./dist/mathue.cjs"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://sueuegunn.github.io/mathue",
|
|
20
|
+
"repository": {
|
|
21
|
+
"url": "https://github.com/sueuegunn/mathue"
|
|
22
|
+
},
|
|
23
|
+
"funding": {
|
|
24
|
+
"type": "github",
|
|
25
|
+
"url": "https://github.com/sponsors/sueuegunn"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"math",
|
|
29
|
+
"mathematics",
|
|
30
|
+
"linear-algebra",
|
|
31
|
+
"vector",
|
|
32
|
+
"matrix",
|
|
33
|
+
"quaternion",
|
|
34
|
+
"webgl",
|
|
35
|
+
"webgpu",
|
|
36
|
+
"graphics",
|
|
37
|
+
"3d",
|
|
38
|
+
"typescript",
|
|
39
|
+
"zero-allocation",
|
|
40
|
+
"performance"
|
|
41
|
+
],
|
|
42
|
+
"scripts": {
|
|
43
|
+
"dev": "vite",
|
|
44
|
+
"build": "tsc --noEmit && vite build",
|
|
45
|
+
"preview": "vite preview",
|
|
46
|
+
"test": "vitest run",
|
|
47
|
+
"test:cov": "vitest run --coverage",
|
|
48
|
+
"docs": "typedoc",
|
|
49
|
+
"version:major": "npm version major --git-tag-version false",
|
|
50
|
+
"version:minor": "npm version minor --git-tag-version false",
|
|
51
|
+
"version:patch": "npm version patch --git-tag-version false"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@types/node": "^24.9.2",
|
|
55
|
+
"@vitest/coverage-v8": "^4.0.6",
|
|
56
|
+
"typedoc": "^0.28.15",
|
|
57
|
+
"typescript": "~5.9.3",
|
|
58
|
+
"vite": "npm:rolldown-vite@7.1.14",
|
|
59
|
+
"vite-plugin-dts": "^4.5.4",
|
|
60
|
+
"vitest": "^4.0.6"
|
|
61
|
+
},
|
|
62
|
+
"overrides": {
|
|
63
|
+
"vite": "npm:rolldown-vite@7.1.14"
|
|
64
|
+
}
|
|
65
|
+
}
|