vec3 0.1.8 → 0.1.9

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.
@@ -13,7 +13,7 @@ jobs:
13
13
 
14
14
  strategy:
15
15
  matrix:
16
- node-version: [12.x]
16
+ node-version: [18.x]
17
17
 
18
18
  steps:
19
19
  - uses: actions/checkout@v2
@@ -0,0 +1,22 @@
1
+ name: Repo Commands
2
+
3
+ on:
4
+ issue_comment: # Handle comment commands
5
+ types: [created]
6
+ pull_request: # Handle renamed PRs
7
+ types: [edited]
8
+
9
+ jobs:
10
+ comment-trigger:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - name: Check out repository
14
+ uses: actions/checkout@v3
15
+ - name: Run command handlers
16
+ uses: PrismarineJS/prismarine-repo-actions@master
17
+ with:
18
+ # NOTE: You must specify a Personal Access Token (PAT) with repo access here. While you can use the default GITHUB_TOKEN, actions taken with it will not trigger other actions, so if you have a CI workflow, commits created by this action will not trigger it.
19
+ token: ${{ secrets.PAT_PASSWORD }}
20
+ # See `Options` section below for more info on these options
21
+ install-command: npm install
22
+ /fixlint.fix-command: npm run fix
@@ -13,7 +13,7 @@ jobs:
13
13
  - name: Set up Node.js
14
14
  uses: actions/setup-node@master
15
15
  with:
16
- node-version: 14.0.0
16
+ node-version: 18.0.0
17
17
  - id: publish
18
18
  uses: JS-DevTools/npm-publish@v1
19
19
  with:
package/HISTORY.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.1.9
2
+ * [Add methods, fix .equals (#46)](https://github.com/PrismarineJS/node-vec3/commit/c6b94c4289cfba5fc460bed99d112cec85fe1cf3) (thanks @szdytom)
3
+ * [Add command gh workflow allowing to use release command in comments (#45)](https://github.com/PrismarineJS/node-vec3/commit/8675f8ecf6065278c0d1f889a585a5febf446cc0) (thanks @rom1504)
4
+ * [Update to node 18.0.0 (#44)](https://github.com/PrismarineJS/node-vec3/commit/358445025ff7d558c8f3fddec2d5786c8c468db5) (thanks @rom1504)
5
+ * [New publish workflow (#38)](https://github.com/PrismarineJS/node-vec3/commit/ed6ba10a9b3d163f5c1ee8cb1b78108296b98477) (thanks @KTibow)
6
+
1
7
  ## 0.1.8
2
8
 
3
9
  * fix some typescript stuff
package/README.md CHANGED
@@ -29,55 +29,61 @@ More available functions are listed below in Test Coverage.
29
29
  ## Test Coverage
30
30
 
31
31
  ```
32
- v()
33
- no args
34
- x, y, z
35
- array
36
- object
37
- string coords
38
- deserialize
39
- invalid deserialize
32
+ v()
33
+ no args
34
+ x, y, z
35
+ array
36
+ object
37
+ string coords
38
+ deserialize
39
+ invalid deserialize
40
40
 
41
41
  vec3
42
- rounded
43
- round
44
- floored
45
- floor
46
- offset
47
- translate
48
- plus
49
- minus
50
- scaled
51
- abs
52
- distanceTo
53
- equals
54
- toString
55
- clone
56
- add
57
- subtract
58
- multiply
59
- divide
60
- set
61
- modulus
62
- volume
63
- min
64
- max
65
- update
66
- norm
67
- dot
68
- cross
69
- unit
70
- normalize
71
- scale
72
- xyDistanceTo
73
- xzDistanceTo
74
- yzDistanceTo
75
- innerProduct
76
- manhattanDistanceTo
77
- toArray
78
-
79
-
80
- 39 passing
42
+ isZero
43
+ at
44
+ xz
45
+ xy
46
+ yz
47
+ xzy
48
+ rounded
49
+ round
50
+ floored
51
+ floor
52
+ offset
53
+ translate
54
+ plus
55
+ minus
56
+ scaled
57
+ abs
58
+ distanceTo
59
+ distanceSquared
60
+ equals
61
+ toString
62
+ clone
63
+ add
64
+ subtract
65
+ multiply
66
+ divide
67
+ set
68
+ modulus
69
+ volume
70
+ min
71
+ max
72
+ update
73
+ norm
74
+ dot
75
+ cross
76
+ unit
77
+ normalize
78
+ ✔ scale
79
+ ✔ xyDistanceTo
80
+ xzDistanceTo
81
+ ✔ yzDistanceTo
82
+ ✔ innerProduct
83
+ ✔ manhattanDistanceTo
84
+ ✔ toArray
85
+
86
+ 50 passing (14ms)
81
87
  ```
82
88
 
83
89
  More functions welcome in the form of pull requests.
package/index.d.ts CHANGED
@@ -5,8 +5,39 @@ export class Vec3 {
5
5
  y: number;
6
6
  z: number;
7
7
 
8
+ /**
9
+ * Returns true when it is a zero vector.
10
+ */
11
+ isZero(): boolean;
12
+
13
+ /**
14
+ * Access component by index
15
+ */
16
+ at(id: number): number;
17
+
18
+ /**
19
+ * Returns an array component x, z
20
+ */
21
+ xz(): [number, number];
22
+
23
+ /**
24
+ * Returns an array component x, y
25
+ */
26
+ xy(): [number, number];
27
+
28
+ /**
29
+ * Returns an array component y, z
30
+ */
31
+ yz(): [number, number];
32
+
33
+ /**
34
+ * Returns a vector with swapped y and z
35
+ */
36
+ xzy(): Vec3;
37
+
8
38
  /**
9
39
  * Set own values to given x y z
40
+ * If some components is given null, then those components won't change
10
41
  */
11
42
  set(x: number, y: number, z: number): this;
12
43
 
@@ -106,9 +137,10 @@ export class Vec3 {
106
137
  distanceSquared(other: Vec3): number;
107
138
 
108
139
  /**
109
- * Returns true when all values match with the values off the other vector
140
+ * Check whether two vectors are equal
141
+ * Returns true if each components have at most `error` difference
110
142
  */
111
- equals(other: Vec3): boolean;
143
+ equals(other: Vec3, error?: number): boolean;
112
144
 
113
145
  /**
114
146
  * Converts own values to a string representation in the format `(x, y, z)`
package/index.js CHANGED
@@ -7,6 +7,30 @@ class Vec3 {
7
7
  this.z = z
8
8
  }
9
9
 
10
+ isZero () {
11
+ return this.x === 0 && this.y === 0 && this.z === 0
12
+ }
13
+
14
+ at (id) {
15
+ return this.toArray()[id]
16
+ }
17
+
18
+ xz () {
19
+ return [this.x, this.z]
20
+ }
21
+
22
+ xy () {
23
+ return [this.x, this.y]
24
+ }
25
+
26
+ yz () {
27
+ return [this.y, this.z]
28
+ }
29
+
30
+ xzy () {
31
+ return new Vec3(this.x, this.z, this.y)
32
+ }
33
+
10
34
  set (x, y, z) {
11
35
  this.x = x
12
36
  this.y = y
@@ -123,8 +147,10 @@ class Vec3 {
123
147
  return dx * dx + dy * dy + dz * dz
124
148
  }
125
149
 
126
- equals (other) {
127
- return this.x === other.x && this.y === other.y && this.z === other.z
150
+ equals (other, error = 0) {
151
+ return Math.abs(this.x - other.x) <= error &&
152
+ Math.abs(this.y - other.y) <= error &&
153
+ Math.abs(this.z - other.z) <= error
128
154
  }
129
155
 
130
156
  toString () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vec3",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "3d vector math with good unit tests",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -17,6 +17,12 @@ expectType<number>(vec.x);
17
17
  expectType<number>(vec.y);
18
18
  expectType<number>(vec.z);
19
19
 
20
+ expectType<boolean>(vec.isZero());
21
+ expectType<number>(vec.at(1));
22
+ expectType<[number, number]>(vec.xz());
23
+ expectType<[number, number]>(vec.xy());
24
+ expectType<[number, number]>(vec.yz());
25
+ expectType<Vec3>(vec.xzy());
20
26
  expectType<Vec3>(vec.set(4, 5, 6));
21
27
  expectType<Vec3>(vec.update(vec));
22
28
  expectType<Vec3>(vec.floored());
package/test/test.js CHANGED
@@ -52,6 +52,43 @@ describe('v()', function () {
52
52
  })
53
53
  })
54
54
  describe('vec3', function () {
55
+ it('isZero', function () {
56
+ const v1 = new Vec3(0, 1, 2)
57
+ const v2 = new Vec3(0, 0, 0)
58
+ assert.ok(!v1.isZero())
59
+ assert.ok(v2.isZero())
60
+ })
61
+ it('at', function () {
62
+ const v1 = new Vec3(0, 1, 2)
63
+ assert.strictEqual(v1.at(0), 0)
64
+ assert.strictEqual(v1.at(1), 1)
65
+ assert.strictEqual(v1.at(2), 2)
66
+ })
67
+ it('xz', function () {
68
+ const v1 = new Vec3(0, 1, 2)
69
+ const a = v1.xz()
70
+ assert.strictEqual(a[0], 0)
71
+ assert.strictEqual(a[1], 2)
72
+ })
73
+ it('xy', function () {
74
+ const v1 = new Vec3(0, 1, 2)
75
+ const a = v1.xy()
76
+ assert.strictEqual(a[0], 0)
77
+ assert.strictEqual(a[1], 1)
78
+ })
79
+ it('yz', function () {
80
+ const v1 = new Vec3(0, 1, 2)
81
+ const a = v1.yz()
82
+ assert.strictEqual(a[0], 1)
83
+ assert.strictEqual(a[1], 2)
84
+ })
85
+ it('xzy', function () {
86
+ const v1 = new Vec3(0, 1, 2)
87
+ const v2 = v1.xzy()
88
+ assert.strictEqual(v2.x, 0)
89
+ assert.strictEqual(v2.y, 2)
90
+ assert.strictEqual(v2.z, 1)
91
+ })
55
92
  it('rounded', function () {
56
93
  const v1 = new Vec3(1.1, -1.5, 1.9)
57
94
  const v2 = v1.rounded()
@@ -168,6 +205,10 @@ describe('vec3', function () {
168
205
  const v2 = v1.scaled(0.23424)
169
206
  const v3 = v1.scaled(0.23424)
170
207
  assert.ok(v2.equals(v3))
208
+ const v4 = new Vec3(0.1, 0, 0)
209
+ const v5 = new Vec3(0.2, 0, 0)
210
+ const v6 = new Vec3(0.3, 0, 0)
211
+ assert.ok(v4.plus(v5).equals(v6, Number.EPSILON))
171
212
  })
172
213
  it('toString', function () {
173
214
  const v1 = new Vec3(1, -1, 3.14)