vec3 0.1.7 → 0.1.8

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.
@@ -0,0 +1,7 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: npm
4
+ directory: "/"
5
+ schedule:
6
+ interval: daily
7
+ open-pull-requests-limit: 10
@@ -13,13 +13,20 @@ jobs:
13
13
  - name: Set up Node.js
14
14
  uses: actions/setup-node@master
15
15
  with:
16
- node-version: 10.0.0
17
- - name: Publish if version has been updated
18
- uses: pascalgn/npm-publish-action@4f4bf159e299f65d21cd1cbd96fc5d53228036df
19
- with: # All of theses inputs are optional
20
- tag_name: "%s"
21
- tag_message: "%s"
22
- commit_pattern: "^Release (\\S+)"
23
- env: # More info about the environment variables in the README
24
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Leave this as is, it's automatically generated
25
- NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} # You need to set this in your repo settings
16
+ node-version: 14.0.0
17
+ - id: publish
18
+ uses: JS-DevTools/npm-publish@v1
19
+ with:
20
+ token: ${{ secrets.NPM_AUTH_TOKEN }}
21
+ - name: Create Release
22
+ if: steps.publish.outputs.type != 'none'
23
+ id: create_release
24
+ uses: actions/create-release@v1
25
+ env:
26
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27
+ with:
28
+ tag_name: ${{ steps.publish.outputs.version }}
29
+ release_name: Release ${{ steps.publish.outputs.version }}
30
+ body: ${{ steps.publish.outputs.version }}
31
+ draft: false
32
+ prerelease: false
package/HISTORY.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.1.8
2
+
3
+ * fix some typescript stuff
4
+ * new methods: rounded, round, multiply, and divide
5
+
1
6
  ## 0.1.7
2
7
  * fix standard not being a dev dependency
3
8
 
package/README.md CHANGED
@@ -39,6 +39,8 @@ v()
39
39
  ✓ invalid deserialize
40
40
 
41
41
  vec3
42
+ ✓ rounded
43
+ ✓ round
42
44
  ✓ floored
43
45
  ✓ floor
44
46
  ✓ offset
@@ -53,6 +55,8 @@ v()
53
55
  ✓ clone
54
56
  ✓ add
55
57
  ✓ subtract
58
+ ✓ multiply
59
+ ✓ divide
56
60
  ✓ set
57
61
  ✓ modulus
58
62
  ✓ volume
@@ -80,4 +84,4 @@ More functions welcome in the form of pull requests.
80
84
 
81
85
  ## History
82
86
 
83
- See [History](History.md)
87
+ See [History](HISTORY.md)
package/index.d.ts CHANGED
@@ -1,79 +1,205 @@
1
1
  export class Vec3 {
2
- constructor(x: number, y: number, z: number);
3
-
4
- x: number;
5
- y: number;
6
- z: number;
7
-
8
- set(x: number, y: number, z: number): this;
9
-
10
- update(other: Vec3): this;
11
-
12
- floored(): Vec3;
13
-
14
- floor(): this;
15
-
16
- offset(dx: number, dy: number, dz: number): Vec3;
17
-
18
- translate(dx: number, dy: number, dz: number): this;
19
-
20
- add(other: Vec3): this;
21
-
22
- subtract(other: Vec3): this;
23
-
24
- plus(other: Vec3): Vec3;
25
-
26
- minus(other: Vec3): Vec3;
27
-
28
- scaled(scalar: number): Vec3;
29
-
30
- abs(): Vec3;
31
-
32
- volume(): number;
33
-
34
- modulus(other: Vec3): Vec3;
35
-
36
- distanceTo(other: Vec3): number;
37
-
38
- distanceSquared(other: Vec3): number;
39
-
40
- equals(other: Vec3): boolean;
41
-
42
- toString(): string;
43
-
44
- clone(): Vec3;
45
-
46
- min(other: Vec3): Vec3;
47
-
48
- max(other: Vec3): Vec3;
49
-
50
- dot(other: Vec3): number;
51
-
52
- cross(other: Vec3): Vec3;
53
-
54
- norm(): number;
55
-
56
- unit(): Vec3;
57
-
58
- normalize(): Vec3;
59
-
60
- scale(scalar: number): this;
61
-
62
- xyDistanceTo(other: Vec3): number;
63
-
64
- xzDistanceTo(other: Vec3): number;
65
-
66
- yzDistanceTo(other: Vec3): number;
67
-
68
- innerProduct(other: Vec3): number;
69
-
70
- manhattanDistanceTo(other: Vec3): number;
71
-
72
- toArray(): Array<number>;
2
+ constructor(x: number, y: number, z: number);
3
+
4
+ x: number;
5
+ y: number;
6
+ z: number;
7
+
8
+ /**
9
+ * Set own values to given x y z
10
+ */
11
+ set(x: number, y: number, z: number): this;
12
+
13
+ /**
14
+ * Set own values to values given by other
15
+ */
16
+ update(other: Vec3): this;
17
+
18
+ /**
19
+ * Return a new instance with copied values that are rounded
20
+ */
21
+ rounded(): Vec3;
22
+
23
+ /**
24
+ * Round own values to nearest integer
25
+ */
26
+ round(): this;
27
+
28
+ /**
29
+ * Return a new instance with copied values that are floored
30
+ */
31
+ floored(): Vec3;
32
+
33
+ /**
34
+ * Floor own values
35
+ */
36
+ floor(): this;
37
+
38
+ /**
39
+ * Return a new instance with copied values that are offset by dx dy and dz
40
+ */
41
+ offset(dx: number, dy: number, dz: number): Vec3;
42
+
43
+ /**
44
+ * Translate own values by dx dy and dz
45
+ */
46
+ translate(dx: number, dy: number, dz: number): this;
47
+
48
+ /**
49
+ * Add to own values by vector
50
+ */
51
+ add(other: Vec3): this;
52
+
53
+ /**
54
+ * Subtract own values by vector
55
+ */
56
+ subtract(other: Vec3): this;
57
+
58
+ /**
59
+ * Multiply own values by value from vector
60
+ */
61
+ multiply(other: Vec3): this;
62
+
63
+ /**
64
+ * Divide own values by value from vector
65
+ */
66
+ divide(other: Vec3): this;
67
+
68
+ /**
69
+ * Return a new instance with copied values that are added to by vector
70
+ */
71
+ plus(other: Vec3): Vec3;
72
+
73
+ /**
74
+ * Return a new instance with copied values that are subtracted by vector
75
+ */
76
+ minus(other: Vec3): Vec3;
77
+
78
+ /**
79
+ * Return a new instance with copied values that are scaled by number
80
+ */
81
+ scaled(scalar: number): Vec3;
82
+
83
+ /**
84
+ * Return a new instance with copied values that are absolute
85
+ */
86
+ abs(): Vec3;
87
+
88
+ /**
89
+ * Return the volume off the vector
90
+ */
91
+ volume(): number;
92
+
93
+ /**
94
+ * Return a new instance with copied values that are modulated by value from a vector
95
+ */
96
+ modulus(other: Vec3): Vec3;
97
+
98
+ /**
99
+ * Return the euclidean distance to another vector
100
+ */
101
+ distanceTo(other: Vec3): number;
102
+
103
+ /**
104
+ * Return the squared euclidean distance to another vector
105
+ */
106
+ distanceSquared(other: Vec3): number;
107
+
108
+ /**
109
+ * Returns true when all values match with the values off the other vector
110
+ */
111
+ equals(other: Vec3): boolean;
112
+
113
+ /**
114
+ * Converts own values to a string representation in the format `(x, y, z)`
115
+ */
116
+ toString(): string;
117
+
118
+ /**
119
+ * Return a new instance with the same values
120
+ */
121
+ clone(): Vec3;
122
+
123
+ /**
124
+ * Return a new instance with the min values by value compared to another vector
125
+ */
126
+ min(other: Vec3): Vec3;
127
+
128
+ /**
129
+ * Return a new instance with the max values by value compared to another vector
130
+ */
131
+ max(other: Vec3): Vec3;
132
+
133
+ /**
134
+ * Returns its own euclidean norm
135
+ */
136
+ norm(): number;
137
+
138
+ /**
139
+ * Returns the dot product with another vector
140
+ */
141
+ dot(other: Vec3): number;
142
+
143
+ /**
144
+ * Returns a new instance off the cross product to another vector
145
+ */
146
+ cross(other: Vec3): Vec3;
147
+
148
+ /**
149
+ * Returns a new instance with copied values normed to the unit vector
150
+ */
151
+ unit(): Vec3;
152
+
153
+ /**
154
+ * Normalize own values
155
+ */
156
+ normalize(): Vec3;
157
+
158
+ /**
159
+ * Scale own values by a number
160
+ */
161
+ scale(scalar: number): this;
162
+
163
+ /**
164
+ * Returns the xy distance to another vector
165
+ */
166
+ xyDistanceTo(other: Vec3): number;
167
+
168
+ /**
169
+ * Returns the xz distance to another vector
170
+ */
171
+ xzDistanceTo(other: Vec3): number;
172
+
173
+ /**
174
+ * Returns the yz distance to another vector
175
+ */
176
+ yzDistanceTo(other: Vec3): number;
177
+
178
+ /**
179
+ * Returns the inner product to another vector
180
+ */
181
+ innerProduct(other: Vec3): number;
182
+
183
+ /**
184
+ * Returns the manhattan distance to another vector
185
+ */
186
+ manhattanDistanceTo(other: Vec3): number;
187
+
188
+ /**
189
+ * Returns an array with x y z in array form ie [x, y, z]
190
+ */
191
+ toArray(): [number, number, number];
73
192
  }
74
193
 
75
194
  export default function v(
76
- x: null | Array<number | string> | {x: number | string, y: number | string, z: number | string} | string,
77
- y?: number | string,
78
- z?: number | string
195
+ coordinates:
196
+ | null
197
+ | string
198
+ | [number | string, number | string, number | string]
199
+ | { x: number | string; y: number | string; z: number | string }
200
+ ): Vec3;
201
+ export default function v(
202
+ x: number | string,
203
+ y: number | string,
204
+ z: number | string
79
205
  ): Vec3;
package/index.js CHANGED
@@ -21,6 +21,17 @@ class Vec3 {
21
21
  return this
22
22
  }
23
23
 
24
+ rounded () {
25
+ return new Vec3(Math.round(this.x), Math.round(this.y), Math.round(this.z))
26
+ }
27
+
28
+ round () {
29
+ this.x = Math.round(this.x)
30
+ this.y = Math.round(this.y)
31
+ this.z = Math.round(this.z)
32
+ return this
33
+ }
34
+
24
35
  floored () {
25
36
  return new Vec3(Math.floor(this.x), Math.floor(this.y), Math.floor(this.z))
26
37
  }
@@ -57,6 +68,20 @@ class Vec3 {
57
68
  return this
58
69
  }
59
70
 
71
+ multiply (other) {
72
+ this.x *= other.x
73
+ this.y *= other.y
74
+ this.z *= other.z
75
+ return this
76
+ }
77
+
78
+ divide (other) {
79
+ this.x /= other.x
80
+ this.y /= other.y
81
+ this.z /= other.z
82
+ return this
83
+ }
84
+
60
85
  plus (other) {
61
86
  return this.offset(other.x, other.y, other.z)
62
87
  }
@@ -85,16 +110,16 @@ class Vec3 {
85
110
  }
86
111
 
87
112
  distanceTo (other) {
88
- var dx = other.x - this.x
89
- var dy = other.y - this.y
90
- var dz = other.z - this.z
113
+ const dx = other.x - this.x
114
+ const dy = other.y - this.y
115
+ const dz = other.z - this.z
91
116
  return Math.sqrt(dx * dx + dy * dy + dz * dz)
92
117
  }
93
118
 
94
119
  distanceSquared (other) {
95
- var dx = other.x - this.x
96
- var dy = other.y - this.y
97
- var dz = other.z - this.z
120
+ const dx = other.x - this.x
121
+ const dy = other.y - this.y
122
+ const dz = other.z - this.z
98
123
  return dx * dx + dy * dy + dz * dz
99
124
  }
100
125
 
@@ -157,20 +182,20 @@ class Vec3 {
157
182
  }
158
183
 
159
184
  xyDistanceTo (other) {
160
- var dx = other.x - this.x
161
- var dy = other.y - this.y
185
+ const dx = other.x - this.x
186
+ const dy = other.y - this.y
162
187
  return Math.sqrt(dx * dx + dy * dy)
163
188
  }
164
189
 
165
190
  xzDistanceTo (other) {
166
- var dx = other.x - this.x
167
- var dz = other.z - this.z
191
+ const dx = other.x - this.x
192
+ const dz = other.z - this.z
168
193
  return Math.sqrt(dx * dx + dz * dz)
169
194
  }
170
195
 
171
196
  yzDistanceTo (other) {
172
- var dy = other.y - this.y
173
- var dz = other.z - this.z
197
+ const dy = other.y - this.y
198
+ const dz = other.z - this.z
174
199
  return Math.sqrt(dy * dy + dz * dz)
175
200
  }
176
201
 
@@ -191,26 +216,26 @@ function v (x, y, z) {
191
216
  if (x == null) {
192
217
  return new Vec3(0, 0, 0)
193
218
  } else if (Array.isArray(x)) {
194
- return new Vec3(parseFloat(x[0], 10), parseFloat(x[1], 10), parseFloat(x[2], 10))
219
+ return new Vec3(parseFloat(x[0]), parseFloat(x[1]), parseFloat(x[2]))
195
220
  } else if (typeof x === 'object') {
196
- return new Vec3(parseFloat(x.x, 10), parseFloat(x.y, 10), parseFloat(x.z, 10))
221
+ return new Vec3(parseFloat(x.x), parseFloat(x.y), parseFloat(x.z))
197
222
  } else if (typeof x === 'string' && y == null) {
198
- var match = x.match(re)
223
+ const match = x.match(re)
199
224
  if (match) {
200
225
  return new Vec3(
201
- parseFloat(match[1], 10),
202
- parseFloat(match[2], 10),
203
- parseFloat(match[3], 10))
226
+ parseFloat(match[1]),
227
+ parseFloat(match[2]),
228
+ parseFloat(match[3]))
204
229
  } else {
205
230
  throw new Error('vec3: cannot parse: ' + x)
206
231
  }
207
232
  } else {
208
- return new Vec3(parseFloat(x, 10), parseFloat(y, 10), parseFloat(z, 10))
233
+ return new Vec3(parseFloat(x), parseFloat(y), parseFloat(z))
209
234
  }
210
235
  }
211
236
 
212
237
  function euclideanMod (numerator, denominator) {
213
- var result = numerator % denominator
238
+ const result = numerator % denominator
214
239
  return result < 0 ? result + denominator : result
215
240
  }
216
241
 
package/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "vec3",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "3d vector math with good unit tests",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
7
7
  "scripts": {
8
- "test": "mocha --reporter spec",
8
+ "test": "npm run test-js && npm run test-types",
9
+ "test-js": "mocha --reporter spec",
10
+ "test-types": "tsd",
9
11
  "pretest": "npm run lint",
10
12
  "lint": "standard",
11
13
  "fix": "standard --fix"
@@ -13,12 +15,23 @@
13
15
  "keywords": [
14
16
  "point"
15
17
  ],
18
+ "exports": {
19
+ "require": "./index.js",
20
+ "import": "./wrapper.mjs"
21
+ },
16
22
  "author": "Andrew Kelley",
17
23
  "license": "BSD",
18
24
  "devDependencies": {
19
- "mocha": "^7.2.0",
20
- "standard": "^14.3.4"
25
+ "mocha": "^10.0.0",
26
+ "standard": "^17.0.0",
27
+ "tsd": "^0.25.0"
28
+ },
29
+ "dependencies": {},
30
+ "tsd": {
31
+ "directory": "test"
21
32
  },
22
- "dependencies": {
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "https://github.com/PrismarineJS/node-vec3.git"
23
36
  }
24
37
  }
@@ -0,0 +1,54 @@
1
+ import { expectType } from "tsd";
2
+ import vec3, { Vec3 } from "..";
3
+
4
+ const vec = vec3([1, 2, 3]);
5
+ expectType<Vec3>(vec);
6
+ expectType<Vec3>(vec3([1, 2, 3]));
7
+ expectType<Vec3>(vec3({ x: 1, y: 2, z: 3 }));
8
+ expectType<Vec3>(vec3("1, 2, 3"));
9
+ expectType<Vec3>(vec3(1, 2, 3));
10
+ expectType<Vec3>(new Vec3(1,2,3));
11
+ // @ts-expect-error
12
+ vec3(1, 2);
13
+ // @ts-expect-error
14
+ vec3("1", 2);
15
+
16
+ expectType<number>(vec.x);
17
+ expectType<number>(vec.y);
18
+ expectType<number>(vec.z);
19
+
20
+ expectType<Vec3>(vec.set(4, 5, 6));
21
+ expectType<Vec3>(vec.update(vec));
22
+ expectType<Vec3>(vec.floored());
23
+ expectType<Vec3>(vec.floor());
24
+ expectType<Vec3>(vec.offset(0, 0, 0));
25
+ expectType<Vec3>(vec.translate(0, 0, 0));
26
+ expectType<Vec3>(vec.add(vec));
27
+ expectType<Vec3>(vec.subtract(vec));
28
+ expectType<Vec3>(vec.multiply(vec));
29
+ expectType<Vec3>(vec.divide(vec));
30
+ expectType<Vec3>(vec.plus(vec));
31
+ expectType<Vec3>(vec.minus(vec));
32
+ expectType<Vec3>(vec.scaled(2));
33
+ expectType<Vec3>(vec.abs());
34
+ expectType<number>(vec.volume());
35
+ expectType<Vec3>(vec.modulus(vec));
36
+ expectType<number>(vec.distanceTo(vec));
37
+ expectType<number>(vec.distanceSquared(vec));
38
+ expectType<boolean>(vec.equals(vec));
39
+ expectType<string>(vec.toString());
40
+ expectType<Vec3>(vec.clone());
41
+ expectType<Vec3>(vec.min(vec));
42
+ expectType<Vec3>(vec.max(vec));
43
+ expectType<number>(vec.norm());
44
+ expectType<number>(vec.dot(vec));
45
+ expectType<Vec3>(vec.cross(vec));
46
+ expectType<Vec3>(vec.unit());
47
+ expectType<Vec3>(vec.normalize());
48
+ expectType<Vec3>(vec.scale(2));
49
+ expectType<number>(vec.xyDistanceTo(vec));
50
+ expectType<number>(vec.xzDistanceTo(vec));
51
+ expectType<number>(vec.yzDistanceTo(vec));
52
+ expectType<number>(vec.innerProduct(vec));
53
+ expectType<number>(vec.manhattanDistanceTo(vec));
54
+ expectType<[number, number, number]>(vec.toArray());
package/test/test.js CHANGED
@@ -1,49 +1,49 @@
1
1
  /* eslint-env mocha */
2
2
 
3
- var v = require('../')
4
- var Vec3 = v.Vec3
5
- var assert = require('assert')
3
+ const v = require('../')
4
+ const Vec3 = v.Vec3
5
+ const assert = require('assert')
6
6
 
7
7
  describe('v()', function () {
8
8
  it('no args', function () {
9
- var v1 = v()
9
+ const v1 = v()
10
10
  assert.strictEqual(v1.x, 0)
11
11
  assert.strictEqual(v1.y, 0)
12
12
  assert.strictEqual(v1.z, 0)
13
13
  })
14
14
  it('x, y, z', function () {
15
- var v1 = v(-1, 5, 10.10)
15
+ const v1 = v(-1, 5, 10.10)
16
16
  assert.strictEqual(v1.x, -1)
17
17
  assert.strictEqual(v1.y, 5)
18
18
  assert.strictEqual(v1.z, 10.10)
19
19
  })
20
20
  it('array', function () {
21
- var v1 = v([4, 5, 6])
21
+ const v1 = v([4, 5, 6])
22
22
  assert.strictEqual(v1.x, 4)
23
23
  assert.strictEqual(v1.y, 5)
24
24
  assert.strictEqual(v1.z, 6)
25
25
  })
26
26
  it('object', function () {
27
- var v1 = v({ x: 9, y: 8, z: 7 })
27
+ const v1 = v({ x: 9, y: 8, z: 7 })
28
28
  assert.strictEqual(v1.x, 9)
29
29
  assert.strictEqual(v1.y, 8)
30
30
  assert.strictEqual(v1.z, 7)
31
31
  })
32
32
  it('string coords', function () {
33
- var v1 = v('1', '1.5', '-30.2')
33
+ const v1 = v('1', '1.5', '-30.2')
34
34
  assert.strictEqual(v1.x, 1)
35
35
  assert.strictEqual(v1.y, 1.5)
36
36
  assert.strictEqual(v1.z, -30.2)
37
37
  })
38
38
  it('deserialize', function () {
39
- var v1 = v(v(1, -3.5, 0).toString())
39
+ const v1 = v(v(1, -3.5, 0).toString())
40
40
  assert.strictEqual(v1.x, 1)
41
41
  assert.strictEqual(v1.y, -3.5)
42
42
  assert.strictEqual(v1.z, 0)
43
- var v2 = v(v(-111, 222, 9876543210.123456789).toString())
43
+ const v2 = v(v(-111, 222, 9876543210.12345).toString())
44
44
  assert.strictEqual(v2.x, -111)
45
45
  assert.strictEqual(v2.y, 222)
46
- assert.strictEqual(v2.z, 9876543210.123456789)
46
+ assert.strictEqual(v2.z, 9876543210.12345)
47
47
  })
48
48
  it('invalid deserialize', function () {
49
49
  assert.throws(function () {
@@ -52,41 +52,57 @@ describe('v()', function () {
52
52
  })
53
53
  })
54
54
  describe('vec3', function () {
55
+ it('rounded', function () {
56
+ const v1 = new Vec3(1.1, -1.5, 1.9)
57
+ const v2 = v1.rounded()
58
+ v1.x = 10
59
+ assert.strictEqual(v2.x, 1)
60
+ assert.strictEqual(v2.y, -1)
61
+ assert.strictEqual(v2.z, 2)
62
+ })
63
+ it('round', function () {
64
+ const v1 = new Vec3(1.1, -1.5, 1.9)
65
+ const v2 = v1.round()
66
+ assert.strictEqual(v2, v1)
67
+ assert.strictEqual(v1.x, 1)
68
+ assert.strictEqual(v1.y, -1)
69
+ assert.strictEqual(v1.z, 2)
70
+ })
55
71
  it('floored', function () {
56
- var v1 = new Vec3(1.1, -1.5, 1.9)
57
- var v2 = v1.floored()
72
+ const v1 = new Vec3(1.1, -1.5, 1.9)
73
+ const v2 = v1.floored()
58
74
  v1.x = 10
59
75
  assert.strictEqual(v2.x, 1)
60
76
  assert.strictEqual(v2.y, -2)
61
77
  assert.strictEqual(v2.z, 1)
62
78
  })
63
79
  it('floor', function () {
64
- var v1 = new Vec3(1.1, -1.5, 1.9)
65
- var v2 = v1.floor()
80
+ const v1 = new Vec3(1.1, -1.5, 1.9)
81
+ const v2 = v1.floor()
66
82
  assert.strictEqual(v2, v1)
67
83
  assert.strictEqual(v1.x, 1)
68
84
  assert.strictEqual(v1.y, -2)
69
85
  assert.strictEqual(v1.z, 1)
70
86
  })
71
87
  it('offset', function () {
72
- var v1 = new Vec3(1, 2, 3)
73
- var v2 = v1.offset(10, -10, 20)
88
+ const v1 = new Vec3(1, 2, 3)
89
+ const v2 = v1.offset(10, -10, 20)
74
90
  v1.x = -100
75
91
  assert.strictEqual(v2.x, 11)
76
92
  assert.strictEqual(v2.y, -8)
77
93
  assert.strictEqual(v2.z, 23)
78
94
  })
79
95
  it('translate', function () {
80
- var v1 = new Vec3(1, 2, 3)
96
+ const v1 = new Vec3(1, 2, 3)
81
97
  v1.translate(10, -10, 20)
82
98
  assert.strictEqual(v1.x, 11)
83
99
  assert.strictEqual(v1.y, -8)
84
100
  assert.strictEqual(v1.z, 23)
85
101
  })
86
102
  it('plus', function () {
87
- var v1 = new Vec3(1, 2, 3)
88
- var v2 = new Vec3(-1, 0, 1)
89
- var v3 = v1.plus(v2)
103
+ const v1 = new Vec3(1, 2, 3)
104
+ const v2 = new Vec3(-1, 0, 1)
105
+ const v3 = v1.plus(v2)
90
106
  assert.strictEqual(v1.x, 1)
91
107
  assert.strictEqual(v1.y, 2)
92
108
  assert.strictEqual(v1.z, 3)
@@ -98,9 +114,9 @@ describe('vec3', function () {
98
114
  assert.strictEqual(v3.z, 4)
99
115
  })
100
116
  it('minus', function () {
101
- var v1 = new Vec3(1, 2, 3)
102
- var v2 = new Vec3(-1, 0, 1)
103
- var v3 = v1.minus(v2)
117
+ const v1 = new Vec3(1, 2, 3)
118
+ const v2 = new Vec3(-1, 0, 1)
119
+ const v3 = v1.minus(v2)
104
120
  assert.strictEqual(v1.x, 1)
105
121
  assert.strictEqual(v1.y, 2)
106
122
  assert.strictEqual(v1.z, 3)
@@ -112,8 +128,8 @@ describe('vec3', function () {
112
128
  assert.strictEqual(v3.z, 2)
113
129
  })
114
130
  it('scaled', function () {
115
- var v1 = new Vec3(1, 2, 3)
116
- var v2 = v1.scaled(2)
131
+ const v1 = new Vec3(1, 2, 3)
132
+ const v2 = v1.scaled(2)
117
133
  assert.strictEqual(v1.x, 1)
118
134
  assert.strictEqual(v1.y, 2)
119
135
  assert.strictEqual(v1.z, 3)
@@ -122,44 +138,44 @@ describe('vec3', function () {
122
138
  assert.strictEqual(v2.z, 6)
123
139
  })
124
140
  it('abs', function () {
125
- var v1 = new Vec3(1.1, -1.5, 1.9)
126
- var v2 = v1.abs()
141
+ const v1 = new Vec3(1.1, -1.5, 1.9)
142
+ const v2 = v1.abs()
127
143
  v1.x = 10
128
144
  assert.strictEqual(v2.x, 1.1)
129
145
  assert.strictEqual(v2.y, 1.5)
130
146
  assert.strictEqual(v2.z, 1.9)
131
147
  })
132
148
  it('distanceTo', function () {
133
- var v1 = new Vec3(1, 1, 1)
134
- var v2 = new Vec3(2, 2, 2)
135
- var dist1 = v1.distanceTo(v2)
136
- var dist2 = v2.distanceTo(v1)
137
- var expected = 1.7320508075688772
149
+ const v1 = new Vec3(1, 1, 1)
150
+ const v2 = new Vec3(2, 2, 2)
151
+ const dist1 = v1.distanceTo(v2)
152
+ const dist2 = v2.distanceTo(v1)
153
+ const expected = 1.7320508075688772
138
154
  assert.strictEqual(dist1, dist2)
139
155
  assert.strictEqual(Math.round(dist1 * 100000), Math.round(expected * 100000))
140
156
  })
141
157
  it('distanceSquared', function () {
142
- var v1 = new Vec3(1, 1, 1)
143
- var v2 = new Vec3(2, 2, 2)
144
- var dist1 = v1.distanceSquared(v2)
145
- var dist2 = v2.distanceSquared(v1)
146
- var expected = 3
158
+ const v1 = new Vec3(1, 1, 1)
159
+ const v2 = new Vec3(2, 2, 2)
160
+ const dist1 = v1.distanceSquared(v2)
161
+ const dist2 = v2.distanceSquared(v1)
162
+ const expected = 3
147
163
  assert.strictEqual(dist1, dist2)
148
164
  assert.strictEqual(Math.round(dist1 * 100000), Math.round(expected * 100000))
149
165
  })
150
166
  it('equals', function () {
151
- var v1 = new Vec3(1, 2, 3)
152
- var v2 = v1.scaled(0.23424)
153
- var v3 = v1.scaled(0.23424)
167
+ const v1 = new Vec3(1, 2, 3)
168
+ const v2 = v1.scaled(0.23424)
169
+ const v3 = v1.scaled(0.23424)
154
170
  assert.ok(v2.equals(v3))
155
171
  })
156
172
  it('toString', function () {
157
- var v1 = new Vec3(1, -1, 3.14)
173
+ const v1 = new Vec3(1, -1, 3.14)
158
174
  assert.strictEqual(v1.toString(), '(1, -1, 3.14)')
159
175
  })
160
176
  it('clone', function () {
161
- var v1 = new Vec3(1, 2, 3)
162
- var v2 = v1.clone()
177
+ const v1 = new Vec3(1, 2, 3)
178
+ const v2 = v1.clone()
163
179
  v2.x = 10
164
180
  assert.strictEqual(v1.x, 1)
165
181
  assert.strictEqual(v1.y, 2)
@@ -169,35 +185,53 @@ describe('vec3', function () {
169
185
  assert.strictEqual(v2.z, 3)
170
186
  })
171
187
  it('add', function () {
172
- var v1 = new Vec3(1, 2, 3)
173
- var v2 = new Vec3(-1, -2, -3)
174
- var v3 = v1.add(v2)
188
+ const v1 = new Vec3(1, 2, 3)
189
+ const v2 = new Vec3(-1, -2, -3)
190
+ const v3 = v1.add(v2)
175
191
  assert.strictEqual(v3, v1)
176
192
  assert.strictEqual(v1.x, 0)
177
193
  assert.strictEqual(v1.y, 0)
178
194
  assert.strictEqual(v1.z, 0)
179
195
  })
180
196
  it('subtract', function () {
181
- var v1 = new Vec3(1, 2, 3)
182
- var v2 = new Vec3(-1, -2, -3)
183
- var v3 = v1.subtract(v2)
197
+ const v1 = new Vec3(1, 2, 3)
198
+ const v2 = new Vec3(-1, -2, -3)
199
+ const v3 = v1.subtract(v2)
184
200
  assert.strictEqual(v3, v1)
185
201
  assert.strictEqual(v1.x, 2)
186
202
  assert.strictEqual(v1.y, 4)
187
203
  assert.strictEqual(v1.z, 6)
188
204
  })
205
+ it('multiply', function () {
206
+ const v1 = new Vec3(1, 2, 3)
207
+ const v2 = new Vec3(-1, -2, -5)
208
+ const v3 = v1.multiply(v2)
209
+ assert.strictEqual(v3, v1)
210
+ assert.strictEqual(v1.x, -1)
211
+ assert.strictEqual(v1.y, -4)
212
+ assert.strictEqual(v1.z, -15)
213
+ })
214
+ it('divide', function () {
215
+ const v1 = new Vec3(10, 20, 30)
216
+ const v2 = new Vec3(2, 5, 3)
217
+ const v3 = v1.divide(v2)
218
+ assert.strictEqual(v3, v1)
219
+ assert.strictEqual(v1.x, 5)
220
+ assert.strictEqual(v1.y, 4)
221
+ assert.strictEqual(v1.z, 10)
222
+ })
189
223
  it('set', function () {
190
- var v1 = new Vec3(12, 32, 46)
191
- var v2 = v1.set(0, 10, 100)
224
+ const v1 = new Vec3(12, 32, 46)
225
+ const v2 = v1.set(0, 10, 100)
192
226
  assert.strictEqual(v1, v2)
193
227
  assert.strictEqual(v1.x, 0)
194
228
  assert.strictEqual(v1.y, 10)
195
229
  assert.strictEqual(v1.z, 100)
196
230
  })
197
231
  it('modulus', function () {
198
- var v1 = new Vec3(12, 32, -1)
199
- var v2 = new Vec3(14, 32, 16)
200
- var v3 = v1.modulus(v2)
232
+ const v1 = new Vec3(12, 32, -1)
233
+ const v2 = new Vec3(14, 32, 16)
234
+ const v3 = v1.modulus(v2)
201
235
  assert.strictEqual(v1.x, 12)
202
236
  assert.strictEqual(v1.y, 32)
203
237
  assert.strictEqual(v1.z, -1)
@@ -209,29 +243,29 @@ describe('vec3', function () {
209
243
  assert.strictEqual(v3.z, 15)
210
244
  })
211
245
  it('volume', function () {
212
- var v1 = new Vec3(3, 4, 5)
246
+ const v1 = new Vec3(3, 4, 5)
213
247
  assert.strictEqual(v1.volume(), 60)
214
248
  })
215
249
  it('min', function () {
216
- var v1 = new Vec3(-1, 0, 1)
217
- var v2 = new Vec3(10, -10, 1.1)
218
- var v3 = v1.min(v2)
250
+ const v1 = new Vec3(-1, 0, 1)
251
+ const v2 = new Vec3(10, -10, 1.1)
252
+ const v3 = v1.min(v2)
219
253
  assert.strictEqual(v3.x, -1)
220
254
  assert.strictEqual(v3.y, -10)
221
255
  assert.strictEqual(v3.z, 1)
222
256
  })
223
257
  it('max', function () {
224
- var v1 = new Vec3(-1, 0, 1)
225
- var v2 = new Vec3(10, -10, 1.1)
226
- var v3 = v1.max(v2)
258
+ const v1 = new Vec3(-1, 0, 1)
259
+ const v2 = new Vec3(10, -10, 1.1)
260
+ const v3 = v1.max(v2)
227
261
  assert.strictEqual(v3.x, 10)
228
262
  assert.strictEqual(v3.y, 0)
229
263
  assert.strictEqual(v3.z, 1.1)
230
264
  })
231
265
  it('update', function () {
232
- var v1 = new Vec3(-1, 0, 1)
233
- var v2 = new Vec3(10, -10, 1.1)
234
- var v3 = v1.update(v2)
266
+ const v1 = new Vec3(-1, 0, 1)
267
+ const v2 = new Vec3(10, -10, 1.1)
268
+ const v3 = v1.update(v2)
235
269
  assert.strictEqual(v3, v1)
236
270
  assert.strictEqual(v1.x, 10)
237
271
  assert.strictEqual(v1.y, -10)
@@ -241,97 +275,97 @@ describe('vec3', function () {
241
275
  assert.strictEqual(v2.z, 1.1)
242
276
  })
243
277
  it('norm', function () {
244
- var v1 = new Vec3(-10, 0, 10)
245
- assert.strictEqual(Math.round(v1.norm() * 100000), Math.round(14.142135623730950 * 100000))
278
+ const v1 = new Vec3(-10, 0, 10)
279
+ assert.strictEqual(Math.round(v1.norm() * 100000), Math.round(14.1421356237 * 100000))
246
280
  })
247
281
  it('dot', function () {
248
- var v1 = new Vec3(-1, -1, -1)
249
- var v2 = new Vec3(1, 1, 1)
282
+ const v1 = new Vec3(-1, -1, -1)
283
+ const v2 = new Vec3(1, 1, 1)
250
284
  assert.strictEqual(v1.dot(v2), -3)
251
285
  })
252
286
  it('cross', function () {
253
- var v1 = new Vec3(1, 0, 0)
254
- var v2 = new Vec3(0, 1, 0)
255
- var v3 = new Vec3(0, 0, 1)
287
+ const v1 = new Vec3(1, 0, 0)
288
+ const v2 = new Vec3(0, 1, 0)
289
+ const v3 = new Vec3(0, 0, 1)
256
290
  assert.ok(v1.cross(v2).equals(v3))
257
291
  })
258
292
  it('unit', function () {
259
- var v1 = new Vec3(10, -10, 1.1)
260
- var v2 = v1.unit()
261
- assert.strictEqual(Math.round(v2.x * 100000), Math.round(0.7049774402016568 * 100000))
262
- assert.strictEqual(Math.round(v2.y * 100000), Math.round(-0.704977440201656 * 100000))
263
- assert.strictEqual(Math.round(v2.z * 100000), Math.round(0.07754751842218225 * 100000))
264
- var v3 = new Vec3(0, 0, 0)
265
- var v4 = v3.unit()
293
+ const v1 = new Vec3(10, -10, 1.1)
294
+ const v2 = v1.unit()
295
+ assert.strictEqual(Math.round(v2.x * 100000), Math.round(0.70497744020 * 100000))
296
+ assert.strictEqual(Math.round(v2.y * 100000), Math.round(-0.7049774402 * 100000))
297
+ assert.strictEqual(Math.round(v2.z * 100000), Math.round(0.07754751842 * 100000))
298
+ const v3 = new Vec3(0, 0, 0)
299
+ const v4 = v3.unit()
266
300
  assert.strictEqual(v4.x, 0)
267
301
  assert.strictEqual(v4.y, 0)
268
302
  assert.strictEqual(v4.z, 0)
269
303
  })
270
304
  it('normalize', function () {
271
- var v1 = new Vec3(10, -10, 1.1)
272
- var v2 = v1.normalize()
273
- assert.strictEqual(Math.round(v2.x * 100000), Math.round(0.7049774402016568 * 100000))
274
- assert.strictEqual(Math.round(v2.y * 100000), Math.round(-0.704977440201656 * 100000))
275
- assert.strictEqual(Math.round(v2.z * 100000), Math.round(0.07754751842218225 * 100000))
276
- var v3 = new Vec3(0, 0, 0)
277
- var v4 = v3.normalize()
305
+ const v1 = new Vec3(10, -10, 1.1)
306
+ const v2 = v1.normalize()
307
+ assert.strictEqual(Math.round(v2.x * 100000), Math.round(0.70497744020 * 100000))
308
+ assert.strictEqual(Math.round(v2.y * 100000), Math.round(-0.7049774402 * 100000))
309
+ assert.strictEqual(Math.round(v2.z * 100000), Math.round(0.07754751842 * 100000))
310
+ const v3 = new Vec3(0, 0, 0)
311
+ const v4 = v3.normalize()
278
312
  assert.strictEqual(v4.x, 0)
279
313
  assert.strictEqual(v4.y, 0)
280
314
  assert.strictEqual(v4.z, 0)
281
315
  })
282
316
  it('scale', function () {
283
- var v1 = new Vec3(10, -10, 1.1)
284
- var v2 = v1.scale(1.5)
317
+ const v1 = new Vec3(10, -10, 1.1)
318
+ const v2 = v1.scale(1.5)
285
319
  assert.strictEqual(v2.x, 15)
286
320
  assert.strictEqual(v2.y, -15)
287
321
  assert.strictEqual(Math.round(v2.z * 100000), Math.round(1.65 * 100000))
288
322
  })
289
323
  it('xyDistanceTo', function () {
290
- var v1 = new Vec3(1, 1, 1)
291
- var v2 = new Vec3(2, 2, 2)
292
- var dist1 = v1.xyDistanceTo(v2)
293
- var dist2 = v2.xyDistanceTo(v1)
294
- var expected = 1.4142135623730950
324
+ const v1 = new Vec3(1, 1, 1)
325
+ const v2 = new Vec3(2, 2, 2)
326
+ const dist1 = v1.xyDistanceTo(v2)
327
+ const dist2 = v2.xyDistanceTo(v1)
328
+ const expected = 1.414213562
295
329
  assert.strictEqual(dist1, dist2)
296
330
  assert.strictEqual(Math.round(dist1 * 100000), Math.round(expected * 100000))
297
331
  })
298
332
  it('xzDistanceTo', function () {
299
- var v1 = new Vec3(1, 1, 1)
300
- var v2 = new Vec3(2, 2, 2)
301
- var dist1 = v1.xzDistanceTo(v2)
302
- var dist2 = v2.xzDistanceTo(v1)
303
- var expected = 1.4142135623730950
333
+ const v1 = new Vec3(1, 1, 1)
334
+ const v2 = new Vec3(2, 2, 2)
335
+ const dist1 = v1.xzDistanceTo(v2)
336
+ const dist2 = v2.xzDistanceTo(v1)
337
+ const expected = 1.41421356237
304
338
  assert.strictEqual(dist1, dist2)
305
339
  assert.strictEqual(Math.round(dist1 * 100000), Math.round(expected * 100000))
306
340
  })
307
341
  it('yzDistanceTo', function () {
308
- var v1 = new Vec3(1, 1, 1)
309
- var v2 = new Vec3(2, 2, 2)
310
- var dist1 = v1.yzDistanceTo(v2)
311
- var dist2 = v2.yzDistanceTo(v1)
312
- var expected = 1.4142135623730950
342
+ const v1 = new Vec3(1, 1, 1)
343
+ const v2 = new Vec3(2, 2, 2)
344
+ const dist1 = v1.yzDistanceTo(v2)
345
+ const dist2 = v2.yzDistanceTo(v1)
346
+ const expected = 1.41421356237
313
347
  assert.strictEqual(dist1, dist2)
314
348
  assert.strictEqual(Math.round(dist1 * 100000), Math.round(expected * 100000))
315
349
  })
316
350
  it('innerProduct', function () {
317
- var v1 = new Vec3(-1, 0, 1)
318
- var v2 = new Vec3(0, 1, 0)
319
- var ip1 = v1.innerProduct(v2)
320
- var ip2 = v2.innerProduct(v1)
351
+ const v1 = new Vec3(-1, 0, 1)
352
+ const v2 = new Vec3(0, 1, 0)
353
+ const ip1 = v1.innerProduct(v2)
354
+ const ip2 = v2.innerProduct(v1)
321
355
  assert.strictEqual(ip1, ip2)
322
356
  assert.strictEqual(ip1, 0)
323
357
  })
324
358
  it('manhattanDistanceTo', function () {
325
- var v1 = new Vec3(-1, 0, 1)
326
- var v2 = new Vec3(10, -10, 1.1)
327
- var dist1 = v1.manhattanDistanceTo(v2)
328
- var dist2 = v2.manhattanDistanceTo(v1)
359
+ const v1 = new Vec3(-1, 0, 1)
360
+ const v2 = new Vec3(10, -10, 1.1)
361
+ const dist1 = v1.manhattanDistanceTo(v2)
362
+ const dist2 = v2.manhattanDistanceTo(v1)
329
363
  assert.strictEqual(dist1, dist2)
330
364
  assert.strictEqual(dist1, 21.1)
331
365
  })
332
366
  it('toArray', function () {
333
- var v1 = new Vec3(1, -1, 3.14)
334
- var array = v1.toArray()
367
+ const v1 = new Vec3(1, -1, 3.14)
368
+ const array = v1.toArray()
335
369
  assert.strictEqual(v1.x, array[0])
336
370
  assert.strictEqual(v1.y, array[1])
337
371
  assert.strictEqual(v1.z, array[2])
package/wrapper.mjs ADDED
@@ -0,0 +1,4 @@
1
+ import mod from './index.js'
2
+
3
+ export default mod
4
+ export const Vec3 = mod.Vec3