@immugio/three-math-extensions 0.0.6 → 0.0.7

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/esm/Point2.js CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export {};
package/esm/Point3.js CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export {};
package/esm/Vec2.js CHANGED
@@ -1,19 +1,25 @@
1
- import { Vector2 } from "three";
2
- import { Vec3 } from "./Vec3";
3
- export class Vec2 extends Vector2 {
4
- static fromPoint(point) {
5
- return new Vec2(point.x, point.y);
6
- }
7
- roundIfCloseToInteger(max = 0.000000000001) {
8
- if (Math.abs(this.x - Math.round(this.x)) < max) {
9
- this.x = Math.round(this.x);
10
- }
11
- if (Math.abs(this.y - Math.round(this.y)) < max) {
12
- this.y = Math.round(this.y);
13
- }
14
- return this;
15
- }
16
- in3DSpace(z = 0) {
17
- return new Vec3(this.x, z, this.y);
18
- }
19
- }
1
+ import { Vector2 } from "three";
2
+ import { Vec3 } from "./Vec3";
3
+ export class Vec2 extends Vector2 {
4
+ static fromPoint(point) {
5
+ return new Vec2(point.x, point.y);
6
+ }
7
+ roundIfCloseToInteger(max = 0.000000000001) {
8
+ if (Math.abs(this.x - Math.round(this.x)) < max) {
9
+ this.x = Math.round(this.x);
10
+ }
11
+ if (Math.abs(this.y - Math.round(this.y)) < max) {
12
+ this.y = Math.round(this.y);
13
+ }
14
+ return this;
15
+ }
16
+ in3DSpace(z = 0) {
17
+ return new Vec3(this.x, z, this.y);
18
+ }
19
+ isNear(v, maxDistance = undefined) {
20
+ if (!maxDistance) {
21
+ return this.equals(v);
22
+ }
23
+ return this.distanceTo(v) <= maxDistance;
24
+ }
25
+ }
package/esm/Vec3.js CHANGED
@@ -1,53 +1,59 @@
1
- import { Vector3 } from "three";
2
- import { Vec2 } from "./Vec2";
3
- export class Vec3 extends Vector3 {
4
- #target;
5
- static fromPoint(point) {
6
- return new Vec3(point.x, point.y, point.z);
7
- }
8
- moveTowards(target, amount) {
9
- if (this.#target === undefined) {
10
- this.#target = new Vector3();
11
- }
12
- this.#target.copy(target);
13
- this.add(this.#target.sub(this).normalize().multiplyScalar(amount));
14
- return this;
15
- }
16
- centerTowards(target) {
17
- if (this.#target === undefined) {
18
- this.#target = new Vector3();
19
- }
20
- return this.moveTowards(target, this.distanceTo(target) / 2);
21
- }
22
- addY(y) {
23
- this.y += y;
24
- return this;
25
- }
26
- addX(x) {
27
- this.x += x;
28
- return this;
29
- }
30
- scale(p) {
31
- this.x *= p.x;
32
- this.y *= p.y;
33
- this.z *= p.z;
34
- return this;
35
- }
36
- closest(...points) {
37
- const withDistances = points.map(p => ({ point: p, distance: this.distanceTo(p) }));
38
- const closest = withDistances.reduce((a, b) => a.distance < b.distance ? a : b);
39
- return Vec3.fromPoint(closest.point);
40
- }
41
- toPointWithFlippedYZ() {
42
- return new Vec3(this.x, this.z, this.y);
43
- }
44
- onPlan() {
45
- return new Vec2(this.x, this.z);
46
- }
47
- horizontalDistanceTo(point) {
48
- return new Vector3(this.x, 0, this.z).distanceTo(new Vector3(point.x, 0, point.z));
49
- }
50
- clone() {
51
- return super.clone();
52
- }
53
- }
1
+ import { Vector3 } from "three";
2
+ import { Vec2 } from "./Vec2";
3
+ export class Vec3 extends Vector3 {
4
+ #target;
5
+ static fromPoint(point) {
6
+ return new Vec3(point.x, point.y, point.z);
7
+ }
8
+ moveTowards(target, amount) {
9
+ if (this.#target === undefined) {
10
+ this.#target = new Vector3();
11
+ }
12
+ this.#target.copy(target);
13
+ this.add(this.#target.sub(this).normalize().multiplyScalar(amount));
14
+ return this;
15
+ }
16
+ centerTowards(target) {
17
+ if (this.#target === undefined) {
18
+ this.#target = new Vector3();
19
+ }
20
+ return this.moveTowards(target, this.distanceTo(target) / 2);
21
+ }
22
+ addY(y) {
23
+ this.y += y;
24
+ return this;
25
+ }
26
+ addX(x) {
27
+ this.x += x;
28
+ return this;
29
+ }
30
+ scale(p) {
31
+ this.x *= p.x;
32
+ this.y *= p.y;
33
+ this.z *= p.z;
34
+ return this;
35
+ }
36
+ closest(...points) {
37
+ const withDistances = points.map(p => ({ point: p, distance: this.distanceTo(p) }));
38
+ const closest = withDistances.reduce((a, b) => a.distance < b.distance ? a : b);
39
+ return Vec3.fromPoint(closest.point);
40
+ }
41
+ toPointWithFlippedYZ() {
42
+ return new Vec3(this.x, this.z, this.y);
43
+ }
44
+ onPlan() {
45
+ return new Vec2(this.x, this.z);
46
+ }
47
+ horizontalDistanceTo(point) {
48
+ return new Vector3(this.x, 0, this.z).distanceTo(new Vector3(point.x, 0, point.z));
49
+ }
50
+ isNear(v, maxDistance = undefined) {
51
+ if (maxDistance === undefined) {
52
+ return this.equals(v);
53
+ }
54
+ return this.distanceTo(v) <= maxDistance;
55
+ }
56
+ clone() {
57
+ return super.clone();
58
+ }
59
+ }
package/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { Vec2 } from "./Vec2";
2
- export { Vec3 } from "./Vec3";
3
- export { Line2D } from "./Line2D";
4
- export { Line3D } from "./Line3D";
1
+ export { Vec2 } from "./Vec2";
2
+ export { Vec3 } from "./Vec3";
3
+ export { Line2D } from "./Line2D";
4
+ export { Line3D } from "./Line3D";
package/package.json CHANGED
@@ -1,52 +1,52 @@
1
- {
2
- "name": "@immugio/three-math-extensions",
3
- "version": "0.0.6",
4
- "description": "Set of utilities for 2d and 3d line math built on top of three.js",
5
- "author": "Jan Mikeska <janmikeska@gmail.com>",
6
- "license": "ISC",
7
- "keywords": [
8
- "threejs",
9
- "three",
10
- "math"
11
- ],
12
- "bugs": {
13
- "url": "https://github.com/Immugio/three-math-extensions/issues"
14
- },
15
- "homepage": "https://github.com/Immugio/three-math-extensions#readme",
16
- "sideEffects": false,
17
- "source": "src/index.ts",
18
- "main": "cjs/index.js",
19
- "module": "esm/index.js",
20
- "types": "types/index.d.ts",
21
- "auto-changelog": {
22
- "commitLimit": false,
23
- "template": "keepachangelog"
24
- },
25
- "scripts": {
26
- "test": "npx jest",
27
- "build:esm": "tsc",
28
- "build:cjs": "tsc -p tsconfig-cjs.json",
29
- "clean": "rimraf types cjs esm",
30
- "build": "npm run clean && npm run build:esm && npm run build:cjs",
31
- "preversion": "npm run clean && npm run build && npm run test",
32
- "version": "auto-changelog -p && git add CHANGELOG.md",
33
- "postversion": "git push && git push --tags"
34
- },
35
- "devDependencies": {
36
- "@types/jest": "^29.2.1",
37
- "@types/offscreencanvas": "2019.7.0",
38
- "@types/three": "0.130.1",
39
- "auto-changelog": "^2.4.0",
40
- "jest": "^29.2.2",
41
- "rimraf": "^3.0.2",
42
- "ts-jest": "^29.0.0",
43
- "typescript": "4.7.4"
44
- },
45
- "peerDependencies": {
46
- "three": "^0.130.1"
47
- },
48
- "repository": {
49
- "type": "git",
50
- "url": "git+https://github.com/Immugio/three-math-extensions.git"
51
- }
52
- }
1
+ {
2
+ "name": "@immugio/three-math-extensions",
3
+ "version": "0.0.7",
4
+ "description": "Set of utilities for 2d and 3d line math built on top of three.js",
5
+ "author": "Jan Mikeska <janmikeska@gmail.com>",
6
+ "license": "ISC",
7
+ "keywords": [
8
+ "threejs",
9
+ "three",
10
+ "math"
11
+ ],
12
+ "bugs": {
13
+ "url": "https://github.com/Immugio/three-math-extensions/issues"
14
+ },
15
+ "homepage": "https://github.com/Immugio/three-math-extensions#readme",
16
+ "sideEffects": false,
17
+ "source": "src/index.ts",
18
+ "main": "cjs/index.js",
19
+ "module": "esm/index.js",
20
+ "types": "types/index.d.ts",
21
+ "auto-changelog": {
22
+ "commitLimit": false,
23
+ "template": "keepachangelog"
24
+ },
25
+ "scripts": {
26
+ "test": "npx jest",
27
+ "build:esm": "tsc",
28
+ "build:cjs": "tsc -p tsconfig-cjs.json",
29
+ "clean": "rimraf types cjs esm",
30
+ "build": "npm run clean && npm run build:esm && npm run build:cjs",
31
+ "preversion": "npm run clean && npm run build && npm run test",
32
+ "version": "auto-changelog -p && git add CHANGELOG.md",
33
+ "postversion": "git push && git push --tags"
34
+ },
35
+ "devDependencies": {
36
+ "@types/jest": "^29.2.1",
37
+ "@types/offscreencanvas": "2019.7.0",
38
+ "@types/three": "0.130.1",
39
+ "auto-changelog": "^2.4.0",
40
+ "jest": "^29.2.2",
41
+ "rimraf": "^3.0.2",
42
+ "ts-jest": "^29.0.0",
43
+ "typescript": "4.7.4"
44
+ },
45
+ "peerDependencies": {
46
+ "three": "^0.130.1"
47
+ },
48
+ "repository": {
49
+ "type": "git",
50
+ "url": "git+https://github.com/Immugio/three-math-extensions.git"
51
+ }
52
+ }