@immugio/three-math-extensions 0.0.11 → 0.0.13

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,30 +1,58 @@
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
- moveTowards(target, amount) {
8
- const move = target.clone().sub(this).normalize().multiplyScalar(amount);
9
- this.add(move);
10
- return this;
11
- }
12
- roundIfCloseToInteger(max = 0.000000000001) {
13
- if (Math.abs(this.x - Math.round(this.x)) < max) {
14
- this.x = Math.round(this.x);
15
- }
16
- if (Math.abs(this.y - Math.round(this.y)) < max) {
17
- this.y = Math.round(this.y);
18
- }
19
- return this;
20
- }
21
- in3DSpace(z = 0) {
22
- return new Vec3(this.x, z, this.y);
23
- }
24
- isNear(v, maxDistance = undefined) {
25
- if (!maxDistance) {
26
- return this.equals(v);
27
- }
28
- return this.distanceTo(v) <= maxDistance;
29
- }
30
- }
1
+ import { Vector2 } from "three";
2
+ import { Vec3 } from "./Vec3";
3
+ /**
4
+ * Vec2 represents a 2D vector. It extends `Vector2` from the `three` library.
5
+ */
6
+ export class Vec2 extends Vector2 {
7
+ /**
8
+ * Creates a new Vec2 instance from an {x, y} object.
9
+ * @param point - The {x, y} instance.
10
+ * @returns A new Vec2 instance.
11
+ */
12
+ static fromPoint(point) {
13
+ return new Vec2(point.x, point.y);
14
+ }
15
+ /**
16
+ * Moves this Vec2 instance towards the target Vec2 by the given amount.
17
+ * @param target - The target Vec2.
18
+ * @param amount - The distance to move.
19
+ * @returns This Vec2 instance.
20
+ */
21
+ moveTowards(target, amount) {
22
+ const move = target.clone().sub(this).normalize().multiplyScalar(amount);
23
+ this.add(move);
24
+ return this;
25
+ }
26
+ /**
27
+ * Rounds the x and y values of this Vec2 instance if they are close to an integer value.
28
+ * @param max - The maximum difference between the value and the nearest integer.
29
+ * @returns This Vec2 instance.
30
+ */
31
+ roundIfCloseToInteger(max = 0.000000000001) {
32
+ if (Math.abs(this.x - Math.round(this.x)) < max) {
33
+ this.x = Math.round(this.x);
34
+ }
35
+ if (Math.abs(this.y - Math.round(this.y)) < max) {
36
+ this.y = Math.round(this.y);
37
+ }
38
+ return this;
39
+ }
40
+ /**
41
+ * Projects this Vec2 instance to a Vec3 instance in 3D space.
42
+ * @param z - The z value of the new Vec3 instance.
43
+ * @returns A new Vec3 instance.
44
+ */
45
+ in3DSpace(z = 0) {
46
+ return new Vec3(this.x, z, this.y);
47
+ }
48
+ /**
49
+ * Determines if this Vec2 instance is near the target Vec2.
50
+ * maxDistance is the maximum distance between the two vectors within which they are considered `near`.
51
+ */
52
+ isNear(v, maxDistance = undefined) {
53
+ if (!maxDistance) {
54
+ return this.equals(v);
55
+ }
56
+ return this.distanceTo(v) <= maxDistance;
57
+ }
58
+ }
package/esm/Vec3.js CHANGED
@@ -1,59 +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
- 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
- }
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.11",
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.13",
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
+ }