@immugio/three-math-extensions 0.0.4 → 0.0.5
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/Line2D.js +540 -0
- package/esm/Line3D.js +388 -0
- package/esm/Point2.js +1 -0
- package/esm/Point3.js +1 -0
- package/esm/Vec2.js +19 -0
- package/esm/Vec3.js +53 -0
- package/esm/index.js +4 -0
- package/package.json +1 -1
- package/types/Line2D.d.ts +215 -0
- package/types/Line3D.d.ts +151 -0
- package/types/Point2.d.ts +4 -0
- package/types/Point3.d.ts +5 -0
- package/types/Vec2.d.ts +8 -0
- package/types/Vec3.d.ts +17 -0
- package/types/index.d.ts +4 -0
- package/.github/workflows/build.yml +0 -28
- package/.github/workflows/publish.yml +0 -51
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { Line3, Vector3 } from "three";
|
|
2
|
+
import { Vec3 } from "./Vec3";
|
|
3
|
+
import { Point3 } from "./Point3";
|
|
4
|
+
import { Line2D } from "./Line2D";
|
|
5
|
+
export declare class Line3D extends Line3 {
|
|
6
|
+
#private;
|
|
7
|
+
start: Vec3;
|
|
8
|
+
end: Vec3;
|
|
9
|
+
constructor(start: Vec3, end: Vec3);
|
|
10
|
+
static fromPoints(start: Point3, end: Point3): Line3D;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a polygon formed by an array of lines from points provided.
|
|
13
|
+
* The polygon will only be closed if either
|
|
14
|
+
* 1) the first and last points are the same or 2) `forceClosedPolygon` is true.
|
|
15
|
+
*/
|
|
16
|
+
static fromPolygon(polygon: Point3[], forceClosedPolygon?: boolean): Line3D[];
|
|
17
|
+
/**
|
|
18
|
+
* Returns lines that are the result of clipping this line by the @other line.
|
|
19
|
+
* Clips must be parallel to this line.
|
|
20
|
+
* Clones the line, does not modify this.
|
|
21
|
+
* @param other
|
|
22
|
+
* @param parallelTolerance
|
|
23
|
+
*/
|
|
24
|
+
clipLine(other: Line3D, parallelTolerance?: number): Line3D[];
|
|
25
|
+
/**
|
|
26
|
+
* Returns lines that are the result of clipping this line by the @clips.
|
|
27
|
+
* Clips must be parallel to this line.
|
|
28
|
+
* Clones the line, does not modify this.
|
|
29
|
+
* @param clips
|
|
30
|
+
* @param distanceTolerance
|
|
31
|
+
* @param parallelTolerance
|
|
32
|
+
*/
|
|
33
|
+
clipLines(clips: Line3D[], distanceTolerance?: number, parallelTolerance?: number): Line3D[];
|
|
34
|
+
/**
|
|
35
|
+
* Joins a copy of this line with the @other line.
|
|
36
|
+
* Other must be parallel to this line.
|
|
37
|
+
* Returns null if there is no overlap
|
|
38
|
+
* Clones the line, does not modify this.
|
|
39
|
+
* @param other
|
|
40
|
+
* @param distanceTolerance
|
|
41
|
+
* @param parallelTolerance
|
|
42
|
+
*/
|
|
43
|
+
joinLine(other: Line3D, distanceTolerance?: number, parallelTolerance?: number): Line3D;
|
|
44
|
+
/**
|
|
45
|
+
* Joins provided lines into several joined lines.
|
|
46
|
+
* Lines must be parallel for joining.
|
|
47
|
+
* @param lines
|
|
48
|
+
* @param distanceTolerance
|
|
49
|
+
* @param parallelTolerance
|
|
50
|
+
*/
|
|
51
|
+
static joinLines(lines: Line3D[], distanceTolerance?: number, parallelTolerance?: number): Line3D[];
|
|
52
|
+
/**
|
|
53
|
+
* Returns true if this line section completely overlaps the @other line section.
|
|
54
|
+
* @param other
|
|
55
|
+
* @param tolerance
|
|
56
|
+
*/
|
|
57
|
+
covers(other: Line3D, tolerance?: number): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Returns true if there is any overlap between this line and the @other line section.
|
|
60
|
+
* @param other
|
|
61
|
+
* @param distanceTolerance
|
|
62
|
+
* @param parallelTolerance
|
|
63
|
+
*/
|
|
64
|
+
overlaps(other: Line3D, distanceTolerance?: number, parallelTolerance?: number): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Returns this line's length.
|
|
67
|
+
*/
|
|
68
|
+
get length(): number;
|
|
69
|
+
/**
|
|
70
|
+
* Set the length of this line. Center and direction remain unchanged.
|
|
71
|
+
* @param length
|
|
72
|
+
*/
|
|
73
|
+
setLength(length: number): this;
|
|
74
|
+
/**
|
|
75
|
+
* Returns the direction of this line.
|
|
76
|
+
*/
|
|
77
|
+
get direction(): Vec3;
|
|
78
|
+
/**
|
|
79
|
+
* Returns the center of this line
|
|
80
|
+
*/
|
|
81
|
+
get center(): Vec3;
|
|
82
|
+
/**
|
|
83
|
+
* Set the center of the line to the provided point. Length and direction remain unchanged.
|
|
84
|
+
* @param value
|
|
85
|
+
*/
|
|
86
|
+
setCenter(value: Vector3): this;
|
|
87
|
+
/** Returns the start and end points of the line as an array. */
|
|
88
|
+
get endpoints(): Vec3[];
|
|
89
|
+
/**
|
|
90
|
+
* Check that this line section contains provided point.
|
|
91
|
+
* @param p
|
|
92
|
+
* @param tolerance
|
|
93
|
+
*/
|
|
94
|
+
containsPoint(p: Vector3, tolerance?: number): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Distance from this line to provided point.
|
|
97
|
+
* @param p
|
|
98
|
+
* @param clampToLine
|
|
99
|
+
*/
|
|
100
|
+
distanceToPoint(p: Vector3, clampToLine?: boolean): number;
|
|
101
|
+
/**
|
|
102
|
+
* Returns a copy of @other line, the direction of @other is reversed if needed.
|
|
103
|
+
* Returns null if lines are not parallel.
|
|
104
|
+
* @param other
|
|
105
|
+
* @param tolerance
|
|
106
|
+
*/
|
|
107
|
+
getParallelLineInTheSameDirection(other: Line3D, tolerance?: number): Line3D;
|
|
108
|
+
/**
|
|
109
|
+
* Check if @other is parallel to this line.
|
|
110
|
+
* @param other
|
|
111
|
+
* @param tolerance
|
|
112
|
+
*/
|
|
113
|
+
isParallelTo(other: Line3D, tolerance?: number): boolean;
|
|
114
|
+
resize(amount: number): this;
|
|
115
|
+
moveStartPoint(amount: number): Line3D;
|
|
116
|
+
moveEndPoint(amount: number): Line3D;
|
|
117
|
+
/**
|
|
118
|
+
* Returns a new line that is the projection of this line onto @other. Uses `closestPointToPoint` to find the projection.
|
|
119
|
+
* @param other
|
|
120
|
+
* @param clampToLine
|
|
121
|
+
*/
|
|
122
|
+
projectOn(other: Line3D, clampToLine: boolean): Line3D;
|
|
123
|
+
/**
|
|
124
|
+
* Divides the Line3D into a number of segments of the given length.
|
|
125
|
+
* @param maxSegmentLength number
|
|
126
|
+
*/
|
|
127
|
+
chunk(maxSegmentLength: number): Line3D[];
|
|
128
|
+
/**
|
|
129
|
+
* Note that this works well for moving the endpoints as it's currently used
|
|
130
|
+
* If it were to be made public, it would need to handle the situation where the point to move is in the center of the line which would require a different approach
|
|
131
|
+
*/
|
|
132
|
+
private movePointOnThisLine;
|
|
133
|
+
/**
|
|
134
|
+
* Move this line by the given vector.
|
|
135
|
+
* @param p
|
|
136
|
+
*/
|
|
137
|
+
translate(p: Vector3): this;
|
|
138
|
+
/**
|
|
139
|
+
* Project the line to 2D space, Y value is dropped
|
|
140
|
+
*/
|
|
141
|
+
onPlan(): Line2D;
|
|
142
|
+
/**
|
|
143
|
+
* Equals with tolerance
|
|
144
|
+
*/
|
|
145
|
+
equals(other: Line3D, tolerance?: number): boolean;
|
|
146
|
+
/**
|
|
147
|
+
* Deep clone of this line
|
|
148
|
+
*/
|
|
149
|
+
clone(): this;
|
|
150
|
+
toString(): string;
|
|
151
|
+
}
|
package/types/Vec2.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Vector2 } from "three";
|
|
2
|
+
import { Vec3 } from "./Vec3";
|
|
3
|
+
import { Point2 } from "./Point2";
|
|
4
|
+
export declare class Vec2 extends Vector2 {
|
|
5
|
+
static fromPoint(point: Point2): Vec2;
|
|
6
|
+
roundIfCloseToInteger(max?: number): this;
|
|
7
|
+
in3DSpace(z?: number): Vec3;
|
|
8
|
+
}
|
package/types/Vec3.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Vector3 } from "three";
|
|
2
|
+
import { Vec2 } from "./Vec2";
|
|
3
|
+
import { Point3 } from "./Point3";
|
|
4
|
+
export declare class Vec3 extends Vector3 {
|
|
5
|
+
#private;
|
|
6
|
+
static fromPoint(point: Point3): Vec3;
|
|
7
|
+
moveTowards(target: Vector3, amount: number): Vec3;
|
|
8
|
+
centerTowards(target: Vector3): Vec3;
|
|
9
|
+
addY(y: number): Vec3;
|
|
10
|
+
addX(x: number): Vec3;
|
|
11
|
+
scale(p: Vector3): Vec3;
|
|
12
|
+
closest(...points: Vector3[]): Vec3;
|
|
13
|
+
toPointWithFlippedYZ(): Vec3;
|
|
14
|
+
onPlan(): Vec2;
|
|
15
|
+
horizontalDistanceTo(point: Vector3): number;
|
|
16
|
+
clone(): this;
|
|
17
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
name: Build
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches: [ master ]
|
|
6
|
-
pull_request:
|
|
7
|
-
branches: [ master ]
|
|
8
|
-
|
|
9
|
-
jobs:
|
|
10
|
-
build:
|
|
11
|
-
|
|
12
|
-
runs-on: ubuntu-latest
|
|
13
|
-
|
|
14
|
-
strategy:
|
|
15
|
-
matrix:
|
|
16
|
-
node-version: [16.x]
|
|
17
|
-
|
|
18
|
-
steps:
|
|
19
|
-
- uses: actions/checkout@v3
|
|
20
|
-
|
|
21
|
-
- name: Use Node.js ${{ matrix.node-version }}
|
|
22
|
-
uses: actions/setup-node@v3
|
|
23
|
-
|
|
24
|
-
with:
|
|
25
|
-
node-version: ${{ matrix.node-version }}
|
|
26
|
-
- run: npm ci
|
|
27
|
-
- run: npm run build --if-present
|
|
28
|
-
- run: npm test
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
name: Publish to NPM
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
tags:
|
|
6
|
-
- '[0-9]+.[0-9]+.[0-9]+'
|
|
7
|
-
jobs:
|
|
8
|
-
build:
|
|
9
|
-
runs-on: ubuntu-latest
|
|
10
|
-
|
|
11
|
-
strategy:
|
|
12
|
-
matrix:
|
|
13
|
-
node-version: [16.x]
|
|
14
|
-
|
|
15
|
-
steps:
|
|
16
|
-
- uses: actions/checkout@v2
|
|
17
|
-
- name: Use Node.js ${{ matrix.node-version }}
|
|
18
|
-
uses: actions/setup-node@v1
|
|
19
|
-
with:
|
|
20
|
-
node-version: ${{ matrix.node-version }}
|
|
21
|
-
- uses: actions/cache@v2
|
|
22
|
-
with:
|
|
23
|
-
path: node_modules
|
|
24
|
-
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
|
25
|
-
restore-keys: |
|
|
26
|
-
${{ runner.os }}-node-
|
|
27
|
-
|
|
28
|
-
- name: Install Dependencies
|
|
29
|
-
run: npm install
|
|
30
|
-
|
|
31
|
-
- name: Building
|
|
32
|
-
run: npm run build
|
|
33
|
-
|
|
34
|
-
- name: Publish to NPM
|
|
35
|
-
run: |
|
|
36
|
-
npm config set //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN
|
|
37
|
-
npm publish
|
|
38
|
-
env:
|
|
39
|
-
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
|
|
40
|
-
- name: Package lib
|
|
41
|
-
run: npm pack
|
|
42
|
-
|
|
43
|
-
- name: Release
|
|
44
|
-
uses: docker://antonyurchenko/git-release:v3
|
|
45
|
-
env:
|
|
46
|
-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
47
|
-
ALLOW_EMPTY_CHANGELOG: "false"
|
|
48
|
-
ALLOW_TAG_PREFIX: "true"
|
|
49
|
-
with:
|
|
50
|
-
args: |
|
|
51
|
-
three-math-extensions-*.tgz
|