@immugio/three-math-extensions 0.2.21 → 0.2.22

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/CHANGELOG.md CHANGED
@@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
9
9
 
10
- ## [0.2.21](https://github.com/Immugio/three-math-extensions/compare/16.15.10...0.2.21)
10
+ ## [0.2.22](https://github.com/Immugio/three-math-extensions/compare/16.15.10...0.2.22)
11
11
 
12
12
  ### Commits
13
13
 
@@ -16,9 +16,12 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
16
16
  - Add eslint [`98e4912`](https://github.com/Immugio/three-math-extensions/commit/98e4912d637b42ba80e2f3267638b43296113019)
17
17
  - Update jest packages [`af23b4f`](https://github.com/Immugio/three-math-extensions/commit/af23b4f08154bba3407f05b773865215e7e1cba8)
18
18
  - Add Rectangle, update Polygon [`58ee875`](https://github.com/Immugio/three-math-extensions/commit/58ee87539af8f9ade186e5250cba9e01926da514)
19
+ - Documentation update [`905d178`](https://github.com/Immugio/three-math-extensions/commit/905d1787ed7ffffa370b77454222ee04e76f35b5)
20
+ - Documentation update [`70a5f24`](https://github.com/Immugio/three-math-extensions/commit/70a5f243f8af83da3ad5d30e223788cbd877b5f0)
19
21
  - Add isPointInPolygon [`a59eb4b`](https://github.com/Immugio/three-math-extensions/commit/a59eb4be026f17a3106070ae626a0588cd4f4411)
20
22
  - Packages update [`c2ef857`](https://github.com/Immugio/three-math-extensions/commit/c2ef857c01792e64c1558424fdd2f401f72720d0)
21
23
  - Improve Line2D.closestPointToPoint, add Vec2.signedAngle [`151f214`](https://github.com/Immugio/three-math-extensions/commit/151f21462e0358057ad8e9d75d5782563a1061f6)
24
+ - Add Line2D.containsPoint, Line2D.covers, Improve Line2D.equals, Line2D.overlaps, add unit tests [`7b6daf7`](https://github.com/Immugio/three-math-extensions/commit/7b6daf7028303313b6937c16514838604d89515d)
22
25
  - Improve documentation [`d0fcb51`](https://github.com/Immugio/three-math-extensions/commit/d0fcb5132f127b4382ac5f7291575a061b8ec121)
23
26
  - Add isContinuousClosedShape, add Line2D.groupConnectedLines [`4ef8c2f`](https://github.com/Immugio/three-math-extensions/commit/4ef8c2fe83fdc71dd87fee4cbc478ddf0a086442)
24
27
  - Vec3, Line3D - update documentation [`67d9c32`](https://github.com/Immugio/three-math-extensions/commit/67d9c328e08cc0a5599932d2f0529e97f31c9213)
@@ -53,7 +56,13 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
53
56
  - Documentation update [`d5c7a07`](https://github.com/Immugio/three-math-extensions/commit/d5c7a0765f6097f5d3a3be01967d4059f19682fb)
54
57
  - Excluded files from build [`ec70614`](https://github.com/Immugio/three-math-extensions/commit/ec70614bc7df7a98f854c7a6693365118e04faf7)
55
58
 
56
- ## [16.15.10](https://github.com/Immugio/three-math-extensions/compare/0.2.20...16.15.10) - 2023-01-02
59
+ ## [16.15.10](https://github.com/Immugio/three-math-extensions/compare/0.2.21...16.15.10) - 2023-01-02
60
+
61
+ ## [0.2.21](https://github.com/Immugio/three-math-extensions/compare/0.2.20...0.2.21) - 2024-04-03
62
+
63
+ ### Commits
64
+
65
+ - Three dependency update [`7cf5cf3`](https://github.com/Immugio/three-math-extensions/commit/7cf5cf3ece28c408b544d5dcc8626a9fe005b9a5)
57
66
 
58
67
  ## [0.2.20](https://github.com/Immugio/three-math-extensions/compare/0.2.19...0.2.20) - 2024-04-03
59
68
 
package/README.md CHANGED
@@ -6,4 +6,186 @@
6
6
 
7
7
  # @immugio/three-math-extensions
8
8
 
9
- ## [Documentation](docs/modules.md)
9
+ ## Table of contents
10
+
11
+ ### Classes
12
+
13
+ - [BoundingBox](docs/classes/BoundingBox.md)
14
+ - [Line2D](docs/classes/Line2D.md)
15
+ - [Line3D](docs/classes/Line3D.md)
16
+ - [Polygon](docs/classes/Polygon.md)
17
+ - [Rectangle](docs/classes/Rectangle.md)
18
+ - [Size2](docs/classes/Size2.md)
19
+ - [Vec2](docs/classes/Vec2.md)
20
+ - [Vec3](docs/classes/Vec3.md)
21
+
22
+ ### Interfaces
23
+
24
+ - [Point2](docs/interfaces/Point2.md)
25
+ - [Point3](docs/interfaces/Point3.md)
26
+
27
+ ### Variables
28
+
29
+ - [HalfPI](docs/modules.md#halfpi)
30
+ - [TwoPI](docs/modules.md#twopi)
31
+ - [directions](docs/modules.md#directions)
32
+ - [directions2d](docs/modules.md#directions2d)
33
+
34
+ ### Functions
35
+
36
+ - [isContinuousClosedShape](docs/modules.md#iscontinuousclosedshape)
37
+ - [isPointInPolygon](docs/modules.md#ispointinpolygon)
38
+ - [normalizeAngleDegrees](docs/modules.md#normalizeangledegrees)
39
+ - [normalizeAngleRadians](docs/modules.md#normalizeangleradians)
40
+
41
+ ## Variables
42
+
43
+ ### HalfPI
44
+
45
+ • `Const` **HalfPI**: `number`
46
+
47
+ #### Defined in
48
+
49
+ [src/MathConstants.ts:2](https://github.com/Immugio/three-math-extensions/blob/7b6daf7/src/MathConstants.ts#L2)
50
+
51
+ ___
52
+
53
+ ### TwoPI
54
+
55
+ • `Const` **TwoPI**: `number`
56
+
57
+ #### Defined in
58
+
59
+ [src/MathConstants.ts:1](https://github.com/Immugio/three-math-extensions/blob/7b6daf7/src/MathConstants.ts#L1)
60
+
61
+ ___
62
+
63
+ ### directions
64
+
65
+ • `Const` **directions**: `Object`
66
+
67
+ #### Type declaration
68
+
69
+ | Name | Type |
70
+ | :------ | :------ |
71
+ | `Down` | [`Vec3`](docs/classes/Vec3.md) |
72
+ | `East` | [`Vec3`](docs/classes/Vec3.md) |
73
+ | `North` | [`Vec3`](docs/classes/Vec3.md) |
74
+ | `South` | [`Vec3`](docs/classes/Vec3.md) |
75
+ | `Up` | [`Vec3`](docs/classes/Vec3.md) |
76
+ | `West` | [`Vec3`](docs/classes/Vec3.md) |
77
+
78
+ #### Defined in
79
+
80
+ [src/directions.ts:3](https://github.com/Immugio/three-math-extensions/blob/7b6daf7/src/directions.ts#L3)
81
+
82
+ ___
83
+
84
+ ### directions2d
85
+
86
+ • `Const` **directions2d**: `Object`
87
+
88
+ #### Type declaration
89
+
90
+ | Name | Type |
91
+ | :------ | :------ |
92
+ | `Down` | [`Vec2`](docs/classes/Vec2.md) |
93
+ | `Left` | [`Vec2`](docs/classes/Vec2.md) |
94
+ | `Right` | [`Vec2`](docs/classes/Vec2.md) |
95
+ | `Up` | [`Vec2`](docs/classes/Vec2.md) |
96
+
97
+ #### Defined in
98
+
99
+ [src/directions2d.ts:3](https://github.com/Immugio/three-math-extensions/blob/7b6daf7/src/directions2d.ts#L3)
100
+
101
+ ## Functions
102
+
103
+ ### isContinuousClosedShape
104
+
105
+ ▸ **isContinuousClosedShape**\<`T`\>(`lines`, `tolerance?`): `boolean`
106
+
107
+ #### Type parameters
108
+
109
+ | Name | Type |
110
+ | :------ | :------ |
111
+ | `T` | extends [`Line3D`](docs/classes/Line3D.md) \| [`Line2D`](docs/classes/Line2D.md) |
112
+
113
+ #### Parameters
114
+
115
+ | Name | Type | Default value |
116
+ | :------ | :------ | :------ |
117
+ | `lines` | `T`[] | `undefined` |
118
+ | `tolerance` | `number` | `0` |
119
+
120
+ #### Returns
121
+
122
+ `boolean`
123
+
124
+ #### Defined in
125
+
126
+ [src/isContinuousClosedShape.ts:4](https://github.com/Immugio/three-math-extensions/blob/7b6daf7/src/isContinuousClosedShape.ts#L4)
127
+
128
+ ___
129
+
130
+ ### isPointInPolygon
131
+
132
+ ▸ **isPointInPolygon**(`p`, `point`): `boolean`
133
+
134
+ #### Parameters
135
+
136
+ | Name | Type |
137
+ | :------ | :------ |
138
+ | `p` | [`Point2`](docs/interfaces/Point2.md)[] |
139
+ | `point` | [`Point2`](docs/interfaces/Point2.md) |
140
+
141
+ #### Returns
142
+
143
+ `boolean`
144
+
145
+ #### Defined in
146
+
147
+ [src/isPointInPolygon.ts:3](https://github.com/Immugio/three-math-extensions/blob/7b6daf7/src/isPointInPolygon.ts#L3)
148
+
149
+ ___
150
+
151
+ ### normalizeAngleDegrees
152
+
153
+ ▸ **normalizeAngleDegrees**(`angle`): `number`
154
+
155
+ Normalizes an angle in degrees to the range [0, 360].
156
+
157
+ #### Parameters
158
+
159
+ | Name | Type | Description |
160
+ | :------ | :------ | :------ |
161
+ | `angle` | `number` | in degrees |
162
+
163
+ #### Returns
164
+
165
+ `number`
166
+
167
+ #### Defined in
168
+
169
+ [src/normalizeAngleDegrees.ts:5](https://github.com/Immugio/three-math-extensions/blob/7b6daf7/src/normalizeAngleDegrees.ts#L5)
170
+
171
+ ___
172
+
173
+ ### normalizeAngleRadians
174
+
175
+ ▸ **normalizeAngleRadians**(`angle`): `number`
176
+
177
+ Normalize an angle in radians to the range of 0 to 2π.
178
+
179
+ #### Parameters
180
+
181
+ | Name | Type | Description |
182
+ | :------ | :------ | :------ |
183
+ | `angle` | `number` | in radians |
184
+
185
+ #### Returns
186
+
187
+ `number`
188
+
189
+ #### Defined in
190
+
191
+ [src/normalizeAngleRadians.ts:7](https://github.com/Immugio/three-math-extensions/blob/7b6daf7/src/normalizeAngleRadians.ts#L7)
package/cjs/Line2D.js CHANGED
@@ -13,6 +13,7 @@ class Line2D {
13
13
  start;
14
14
  end;
15
15
  index;
16
+ #target = new Vec2_1.Vec2();
16
17
  constructor(start, end, index = 0) {
17
18
  this.start = start;
18
19
  this.end = end;
@@ -141,6 +142,24 @@ class Line2D {
141
142
  get endpoints() {
142
143
  return [this.start, this.end];
143
144
  }
145
+ /**
146
+ * Check that this line segment contains provided point.
147
+ * @param p
148
+ * @param tolerance
149
+ */
150
+ containsPoint(p, tolerance = 0) {
151
+ const closestPointToPoint = this.closestPointToPoint(p, true, this.#target);
152
+ return closestPointToPoint.distanceTo(p) <= tolerance;
153
+ }
154
+ /**
155
+ * Distance from this line to the provided point.
156
+ * @param param
157
+ * @param clampToLine
158
+ */
159
+ distanceToPoint(p, clampToLine = true) {
160
+ const closestPointToPoint = this.closestPointToPoint(p, clampToLine, this.#target);
161
+ return closestPointToPoint.distanceTo(p);
162
+ }
144
163
  /**
145
164
  * Returns the direction of this line.
146
165
  */
@@ -248,14 +267,32 @@ class Line2D {
248
267
  /**
249
268
  * Returns true if there is any overlap between this line and the @other line section.
250
269
  */
251
- overlaps(other) {
252
- if (!this.isCollinearWithTouchOrOverlap(other)) {
253
- return false;
254
- }
255
- if (this.start.equals(other.start) && this.end.equals(other.end)) {
270
+ overlaps(other, distanceTolerance = 0, parallelTolerance = 0) {
271
+ // Special case
272
+ if (this.equals(other, distanceTolerance)) {
256
273
  return true;
257
274
  }
258
- return !this.start.equals(other.end) && !this.end.equals(other.start);
275
+ // Always have to be parallel
276
+ if (this.isParallelTo(other, parallelTolerance)) {
277
+ // To pass as overlapping, at least one point has to be within the other line, but they mush not be equal - "touching" is not considered overlapping
278
+ const otherStartEqualsToAnyOfThisPoint = other.start.distanceTo(this.start) <= distanceTolerance || other.start.distanceTo(this.end) <= distanceTolerance;
279
+ if (this.containsPoint(other.start, distanceTolerance) && !otherStartEqualsToAnyOfThisPoint) {
280
+ return true;
281
+ }
282
+ const otherEndEqualsToAnyOfThisPoint = other.end.distanceTo(this.start) <= distanceTolerance || other.end.distanceTo(this.end) <= distanceTolerance;
283
+ if (this.containsPoint(other.end, distanceTolerance) && !otherEndEqualsToAnyOfThisPoint) {
284
+ return true;
285
+ }
286
+ const thisStartEqualsToAnyOfOtherPoint = this.start.distanceTo(other.start) <= distanceTolerance || this.start.distanceTo(other.end) <= distanceTolerance;
287
+ if (other.containsPoint(this.start, distanceTolerance) && !thisStartEqualsToAnyOfOtherPoint) {
288
+ return true;
289
+ }
290
+ const thisEndEqualsToAnyOfOtherPoint = this.end.distanceTo(other.start) <= distanceTolerance || this.end.distanceTo(other.end) <= distanceTolerance;
291
+ if (other.containsPoint(this.end, distanceTolerance) && !thisEndEqualsToAnyOfOtherPoint) {
292
+ return true;
293
+ }
294
+ }
295
+ return false;
259
296
  }
260
297
  /**
261
298
  * Logical AND of this and the other line section.
@@ -327,6 +364,17 @@ class Line2D {
327
364
  }
328
365
  return result;
329
366
  }
367
+ /**
368
+ * Checks if the current line covers another line.
369
+ * A line is considered to cover another line if they are parallel and both the start and end points of the other line are contained within the current line.
370
+ * Both distance and angle tolerance can be provided.
371
+ */
372
+ covers(other, tolerance = 0, parallelTolerance = 0) {
373
+ if (!this.isParallelTo(other, parallelTolerance)) {
374
+ return false;
375
+ }
376
+ return this.containsPoint(other.start, tolerance) && this.containsPoint(other.end, tolerance);
377
+ }
330
378
  /**
331
379
  * Returns a new line that is the projection of this line onto @other. Uses `closestPointToPoint` to find the projection.
332
380
  * @param other
@@ -643,8 +691,11 @@ class Line2D {
643
691
  in3DSpace(y = 0) {
644
692
  return new Line3D_1.Line3D(this.start.in3DSpace(y), this.end.in3DSpace(y));
645
693
  }
646
- equals(other) {
647
- return !!other && this.start.equals(other.start) && this.end.equals(other.end);
694
+ equals(other, tolerance = 0) {
695
+ if (!tolerance) {
696
+ return !!other && this.start.equals(other.start) && this.end.equals(other.end);
697
+ }
698
+ return !!other && this.start.distanceTo(other.start) <= tolerance && this.end.distanceTo(other.end) <= tolerance;
648
699
  }
649
700
  /**
650
701
  * Deep clone of this line
package/cjs/Line3D.js CHANGED
@@ -253,7 +253,7 @@ class Line3D extends three_1.Line3 {
253
253
  return closestPointToPoint.distanceTo(p) <= tolerance;
254
254
  }
255
255
  /**
256
- * Distance from this line to provided point.
256
+ * Distance from this line to the provided point.
257
257
  * @param p
258
258
  * @param clampToLine
259
259
  */
@@ -1,4 +1,4 @@
1
- [@immugio/three-math-extensions](../README.md) / [Exports](../modules.md) / BoundingBox
1
+ [@immugio/three-math-extensions](../../README.md) / [Exports](../modules.md) / BoundingBox
2
2
 
3
3
  # Class: BoundingBox
4
4
 
@@ -27,7 +27,7 @@
27
27
 
28
28
  ### constructor
29
29
 
30
- • **new BoundingBox**(`minX`, `maxX`, `minY`, `maxY`)
30
+ • **new BoundingBox**(`minX`, `maxX`, `minY`, `maxY`): [`BoundingBox`](BoundingBox.md)
31
31
 
32
32
  #### Parameters
33
33
 
@@ -38,9 +38,13 @@
38
38
  | `minY` | `number` |
39
39
  | `maxY` | `number` |
40
40
 
41
+ #### Returns
42
+
43
+ [`BoundingBox`](BoundingBox.md)
44
+
41
45
  #### Defined in
42
46
 
43
- [src/BoundingBox.ts:4](https://github.com/Immugio/three-math-extensions/blob/66cba15/src/BoundingBox.ts#L4)
47
+ [src/BoundingBox.ts:4](https://github.com/Immugio/three-math-extensions/blob/905d178/src/BoundingBox.ts#L4)
44
48
 
45
49
  ## Properties
46
50
 
@@ -50,7 +54,7 @@
50
54
 
51
55
  #### Defined in
52
56
 
53
- [src/BoundingBox.ts:4](https://github.com/Immugio/three-math-extensions/blob/66cba15/src/BoundingBox.ts#L4)
57
+ [src/BoundingBox.ts:4](https://github.com/Immugio/three-math-extensions/blob/905d178/src/BoundingBox.ts#L4)
54
58
 
55
59
  ___
56
60
 
@@ -60,7 +64,7 @@ ___
60
64
 
61
65
  #### Defined in
62
66
 
63
- [src/BoundingBox.ts:4](https://github.com/Immugio/three-math-extensions/blob/66cba15/src/BoundingBox.ts#L4)
67
+ [src/BoundingBox.ts:4](https://github.com/Immugio/three-math-extensions/blob/905d178/src/BoundingBox.ts#L4)
64
68
 
65
69
  ___
66
70
 
@@ -70,7 +74,7 @@ ___
70
74
 
71
75
  #### Defined in
72
76
 
73
- [src/BoundingBox.ts:4](https://github.com/Immugio/three-math-extensions/blob/66cba15/src/BoundingBox.ts#L4)
77
+ [src/BoundingBox.ts:4](https://github.com/Immugio/three-math-extensions/blob/905d178/src/BoundingBox.ts#L4)
74
78
 
75
79
  ___
76
80
 
@@ -80,7 +84,7 @@ ___
80
84
 
81
85
  #### Defined in
82
86
 
83
- [src/BoundingBox.ts:4](https://github.com/Immugio/three-math-extensions/blob/66cba15/src/BoundingBox.ts#L4)
87
+ [src/BoundingBox.ts:4](https://github.com/Immugio/three-math-extensions/blob/905d178/src/BoundingBox.ts#L4)
84
88
 
85
89
  ## Accessors
86
90
 
@@ -94,7 +98,7 @@ ___
94
98
 
95
99
  #### Defined in
96
100
 
97
- [src/BoundingBox.ts:11](https://github.com/Immugio/three-math-extensions/blob/66cba15/src/BoundingBox.ts#L11)
101
+ [src/BoundingBox.ts:11](https://github.com/Immugio/three-math-extensions/blob/905d178/src/BoundingBox.ts#L11)
98
102
 
99
103
  ## Methods
100
104
 
@@ -114,4 +118,4 @@ ___
114
118
 
115
119
  #### Defined in
116
120
 
117
- [src/BoundingBox.ts:7](https://github.com/Immugio/three-math-extensions/blob/66cba15/src/BoundingBox.ts#L7)
121
+ [src/BoundingBox.ts:7](https://github.com/Immugio/three-math-extensions/blob/905d178/src/BoundingBox.ts#L7)