@saber-usa/node-common 1.7.3 → 1.7.4

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.
@@ -1,71 +1,71 @@
1
- import {Vector3D} from "pious-squid";
2
-
3
- class NodeVector3D {
4
- constructor(x, y, z) {
5
- this.x = x;
6
- this.y = y;
7
- this.z = z;
8
- }
9
-
10
- add(vector) {
11
- return new NodeVector3D(this.x + vector.x, this.y + vector.y, this.z + vector.z);
12
- }
13
-
14
- subtract(vector) {
15
- return new NodeVector3D(this.x - vector.x, this.y - vector.y, this.z - vector.z);
16
- }
17
-
18
- dot(vector) {
19
- return this.x * vector.x + this.y * vector.y + this.z * vector.z;
20
- }
21
-
22
- cross(vector) {
23
- return new NodeVector3D(
24
- this.y * vector.z - this.z * vector.y,
25
- this.z * vector.x - this.x * vector.z,
26
- this.x * vector.y - this.y * vector.x,
27
- );
28
- }
29
-
30
- scale(scalar) {
31
- return new NodeVector3D(this.x * scalar, this.y * scalar, this.z * scalar);
32
- }
33
-
34
- negate() {
35
- return this.scale(-1);
36
- }
37
-
38
- magnitude() {
39
- return Math.sqrt(this.x ** 2 + this.y ** 2 + this.z ** 2);
40
- }
41
-
42
- distance(vector) {
43
- const dx = this.x - vector.x;
44
- const dy = this.y - vector.y;
45
- const dz = this.z - vector.z;
46
- return Math.sqrt(dx ** 2 + dy ** 2 + dz ** 2);
47
- }
48
-
49
- toString() {
50
- const xStr = this.x.toFixed(4);
51
- const yStr = this.y.toFixed(4);
52
- const zStr = this.z.toFixed(4);
53
- return `(${xStr}, ${yStr}, ${zStr})`;
54
- }
55
-
56
- normalized() {
57
- const mag = this.magnitude();
58
- if (mag === 0) {
59
- throw new Error("Cannot normalize a zero vector");
60
- }
61
- return new NodeVector3D(this.x / mag, this.y / mag, this.z / mag);
62
- }
63
-
64
- toSquid() {
65
- return new Vector3D(this.x, this.y, this.z);
66
- }
67
-
68
- // TODO: add angle and join operation methods
69
- }
70
-
71
- export {NodeVector3D};
1
+ import {Vector3D} from "pious-squid";
2
+
3
+ class NodeVector3D {
4
+ constructor(x, y, z) {
5
+ this.x = x;
6
+ this.y = y;
7
+ this.z = z;
8
+ }
9
+
10
+ add(vector) {
11
+ return new NodeVector3D(this.x + vector.x, this.y + vector.y, this.z + vector.z);
12
+ }
13
+
14
+ subtract(vector) {
15
+ return new NodeVector3D(this.x - vector.x, this.y - vector.y, this.z - vector.z);
16
+ }
17
+
18
+ dot(vector) {
19
+ return this.x * vector.x + this.y * vector.y + this.z * vector.z;
20
+ }
21
+
22
+ cross(vector) {
23
+ return new NodeVector3D(
24
+ this.y * vector.z - this.z * vector.y,
25
+ this.z * vector.x - this.x * vector.z,
26
+ this.x * vector.y - this.y * vector.x,
27
+ );
28
+ }
29
+
30
+ scale(scalar) {
31
+ return new NodeVector3D(this.x * scalar, this.y * scalar, this.z * scalar);
32
+ }
33
+
34
+ negate() {
35
+ return this.scale(-1);
36
+ }
37
+
38
+ magnitude() {
39
+ return Math.sqrt(this.x ** 2 + this.y ** 2 + this.z ** 2);
40
+ }
41
+
42
+ distance(vector) {
43
+ const dx = this.x - vector.x;
44
+ const dy = this.y - vector.y;
45
+ const dz = this.z - vector.z;
46
+ return Math.sqrt(dx ** 2 + dy ** 2 + dz ** 2);
47
+ }
48
+
49
+ toString() {
50
+ const xStr = this.x.toFixed(4);
51
+ const yStr = this.y.toFixed(4);
52
+ const zStr = this.z.toFixed(4);
53
+ return `(${xStr}, ${yStr}, ${zStr})`;
54
+ }
55
+
56
+ normalized() {
57
+ const mag = this.magnitude();
58
+ if (mag === 0) {
59
+ throw new Error("Cannot normalize a zero vector");
60
+ }
61
+ return new NodeVector3D(this.x / mag, this.y / mag, this.z / mag);
62
+ }
63
+
64
+ toSquid() {
65
+ return new Vector3D(this.x, this.y, this.z);
66
+ }
67
+
68
+ // TODO: add angle and join operation methods
69
+ }
70
+
71
+ export {NodeVector3D};