@immugio/three-math-extensions 0.1.0 → 0.2.0
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 +17 -2
- package/cjs/BoundingBox.js +23 -0
- package/cjs/Polygon.js +38 -4
- package/cjs/Rectangle.js +77 -0
- package/cjs/Vec3.js +1 -1
- package/cjs/index.js +9 -1
- package/docs/classes/BoundingBox.md +117 -0
- package/docs/classes/Line2D.md +49 -49
- package/docs/classes/Line3D.md +59 -31
- package/docs/classes/Polygon.md +235 -0
- package/docs/classes/Rectangle.md +287 -0
- package/docs/classes/Size2.md +51 -0
- package/docs/classes/Vec2.md +5 -5
- package/docs/classes/Vec3.md +12 -12
- package/docs/modules.md +4 -0
- package/esm/BoundingBox.js +19 -0
- package/esm/Polygon.js +38 -4
- package/esm/Rectangle.js +73 -0
- package/esm/Vec3.js +1 -1
- package/esm/index.js +4 -0
- package/package.json +2 -2
- package/src/BoundingBox.ts +14 -0
- package/src/Polygon.ts +55 -11
- package/src/Rectangle.ts +93 -0
- package/src/Vec3.ts +1 -1
- package/src/index.ts +5 -1
- package/types/BoundingBox.d.ts +10 -0
- package/types/Polygon.d.ts +7 -8
- package/types/Rectangle.d.ts +25 -0
- package/types/Vec3.d.ts +1 -1
- package/types/index.d.ts +4 -0
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
[@immugio/three-math-extensions](../README.md) / [Exports](../modules.md) / Rectangle
|
|
2
|
+
|
|
3
|
+
# Class: Rectangle
|
|
4
|
+
|
|
5
|
+
## Table of contents
|
|
6
|
+
|
|
7
|
+
### Constructors
|
|
8
|
+
|
|
9
|
+
- [constructor](Rectangle.md#constructor)
|
|
10
|
+
|
|
11
|
+
### Properties
|
|
12
|
+
|
|
13
|
+
- [bottomY](Rectangle.md#bottomy)
|
|
14
|
+
- [leftX](Rectangle.md#leftx)
|
|
15
|
+
- [rightX](Rectangle.md#rightx)
|
|
16
|
+
- [topY](Rectangle.md#topy)
|
|
17
|
+
|
|
18
|
+
### Accessors
|
|
19
|
+
|
|
20
|
+
- [center](Rectangle.md#center)
|
|
21
|
+
- [hasSize](Rectangle.md#hassize)
|
|
22
|
+
- [offset](Rectangle.md#offset)
|
|
23
|
+
- [size](Rectangle.md#size)
|
|
24
|
+
|
|
25
|
+
### Methods
|
|
26
|
+
|
|
27
|
+
- [centerOnOrigin](Rectangle.md#centeronorigin)
|
|
28
|
+
- [clone](Rectangle.md#clone)
|
|
29
|
+
- [equals](Rectangle.md#equals)
|
|
30
|
+
- [flipVertical](Rectangle.md#flipvertical)
|
|
31
|
+
- [overlaps](Rectangle.md#overlaps)
|
|
32
|
+
- [toPoints](Rectangle.md#topoints)
|
|
33
|
+
- [toPolygon](Rectangle.md#topolygon)
|
|
34
|
+
- [translate](Rectangle.md#translate)
|
|
35
|
+
|
|
36
|
+
## Constructors
|
|
37
|
+
|
|
38
|
+
### constructor
|
|
39
|
+
|
|
40
|
+
• **new Rectangle**(`leftX`, `rightX`, `topY`, `bottomY`)
|
|
41
|
+
|
|
42
|
+
#### Parameters
|
|
43
|
+
|
|
44
|
+
| Name | Type |
|
|
45
|
+
| :------ | :------ |
|
|
46
|
+
| `leftX` | `number` |
|
|
47
|
+
| `rightX` | `number` |
|
|
48
|
+
| `topY` | `number` |
|
|
49
|
+
| `bottomY` | `number` |
|
|
50
|
+
|
|
51
|
+
#### Defined in
|
|
52
|
+
|
|
53
|
+
[src/Rectangle.ts:7](https://github.com/Immugio/three-math-extensions/blob/c004965/src/Rectangle.ts#L7)
|
|
54
|
+
|
|
55
|
+
## Properties
|
|
56
|
+
|
|
57
|
+
### bottomY
|
|
58
|
+
|
|
59
|
+
• **bottomY**: `number`
|
|
60
|
+
|
|
61
|
+
#### Defined in
|
|
62
|
+
|
|
63
|
+
[src/Rectangle.ts:7](https://github.com/Immugio/three-math-extensions/blob/c004965/src/Rectangle.ts#L7)
|
|
64
|
+
|
|
65
|
+
___
|
|
66
|
+
|
|
67
|
+
### leftX
|
|
68
|
+
|
|
69
|
+
• **leftX**: `number`
|
|
70
|
+
|
|
71
|
+
#### Defined in
|
|
72
|
+
|
|
73
|
+
[src/Rectangle.ts:7](https://github.com/Immugio/three-math-extensions/blob/c004965/src/Rectangle.ts#L7)
|
|
74
|
+
|
|
75
|
+
___
|
|
76
|
+
|
|
77
|
+
### rightX
|
|
78
|
+
|
|
79
|
+
• **rightX**: `number`
|
|
80
|
+
|
|
81
|
+
#### Defined in
|
|
82
|
+
|
|
83
|
+
[src/Rectangle.ts:7](https://github.com/Immugio/three-math-extensions/blob/c004965/src/Rectangle.ts#L7)
|
|
84
|
+
|
|
85
|
+
___
|
|
86
|
+
|
|
87
|
+
### topY
|
|
88
|
+
|
|
89
|
+
• **topY**: `number`
|
|
90
|
+
|
|
91
|
+
#### Defined in
|
|
92
|
+
|
|
93
|
+
[src/Rectangle.ts:7](https://github.com/Immugio/three-math-extensions/blob/c004965/src/Rectangle.ts#L7)
|
|
94
|
+
|
|
95
|
+
## Accessors
|
|
96
|
+
|
|
97
|
+
### center
|
|
98
|
+
|
|
99
|
+
• `get` **center**(): [`Vec2`](Vec2.md)
|
|
100
|
+
|
|
101
|
+
#### Returns
|
|
102
|
+
|
|
103
|
+
[`Vec2`](Vec2.md)
|
|
104
|
+
|
|
105
|
+
#### Defined in
|
|
106
|
+
|
|
107
|
+
[src/Rectangle.ts:20](https://github.com/Immugio/three-math-extensions/blob/c004965/src/Rectangle.ts#L20)
|
|
108
|
+
|
|
109
|
+
___
|
|
110
|
+
|
|
111
|
+
### hasSize
|
|
112
|
+
|
|
113
|
+
• `get` **hasSize**(): `boolean`
|
|
114
|
+
|
|
115
|
+
#### Returns
|
|
116
|
+
|
|
117
|
+
`boolean`
|
|
118
|
+
|
|
119
|
+
#### Defined in
|
|
120
|
+
|
|
121
|
+
[src/Rectangle.ts:41](https://github.com/Immugio/three-math-extensions/blob/c004965/src/Rectangle.ts#L41)
|
|
122
|
+
|
|
123
|
+
___
|
|
124
|
+
|
|
125
|
+
### offset
|
|
126
|
+
|
|
127
|
+
• `get` **offset**(): [`Vec2`](Vec2.md)
|
|
128
|
+
|
|
129
|
+
#### Returns
|
|
130
|
+
|
|
131
|
+
[`Vec2`](Vec2.md)
|
|
132
|
+
|
|
133
|
+
#### Defined in
|
|
134
|
+
|
|
135
|
+
[src/Rectangle.ts:27](https://github.com/Immugio/three-math-extensions/blob/c004965/src/Rectangle.ts#L27)
|
|
136
|
+
|
|
137
|
+
___
|
|
138
|
+
|
|
139
|
+
### size
|
|
140
|
+
|
|
141
|
+
• `get` **size**(): [`Vec2`](Vec2.md)
|
|
142
|
+
|
|
143
|
+
#### Returns
|
|
144
|
+
|
|
145
|
+
[`Vec2`](Vec2.md)
|
|
146
|
+
|
|
147
|
+
#### Defined in
|
|
148
|
+
|
|
149
|
+
[src/Rectangle.ts:13](https://github.com/Immugio/three-math-extensions/blob/c004965/src/Rectangle.ts#L13)
|
|
150
|
+
|
|
151
|
+
## Methods
|
|
152
|
+
|
|
153
|
+
### centerOnOrigin
|
|
154
|
+
|
|
155
|
+
▸ **centerOnOrigin**(): [`Rectangle`](Rectangle.md)
|
|
156
|
+
|
|
157
|
+
#### Returns
|
|
158
|
+
|
|
159
|
+
[`Rectangle`](Rectangle.md)
|
|
160
|
+
|
|
161
|
+
#### Defined in
|
|
162
|
+
|
|
163
|
+
[src/Rectangle.ts:54](https://github.com/Immugio/three-math-extensions/blob/c004965/src/Rectangle.ts#L54)
|
|
164
|
+
|
|
165
|
+
___
|
|
166
|
+
|
|
167
|
+
### clone
|
|
168
|
+
|
|
169
|
+
▸ **clone**(): [`Rectangle`](Rectangle.md)
|
|
170
|
+
|
|
171
|
+
#### Returns
|
|
172
|
+
|
|
173
|
+
[`Rectangle`](Rectangle.md)
|
|
174
|
+
|
|
175
|
+
#### Defined in
|
|
176
|
+
|
|
177
|
+
[src/Rectangle.ts:9](https://github.com/Immugio/three-math-extensions/blob/c004965/src/Rectangle.ts#L9)
|
|
178
|
+
|
|
179
|
+
___
|
|
180
|
+
|
|
181
|
+
### equals
|
|
182
|
+
|
|
183
|
+
▸ **equals**(`other`): `boolean`
|
|
184
|
+
|
|
185
|
+
#### Parameters
|
|
186
|
+
|
|
187
|
+
| Name | Type |
|
|
188
|
+
| :------ | :------ |
|
|
189
|
+
| `other` | [`Rectangle`](Rectangle.md) |
|
|
190
|
+
|
|
191
|
+
#### Returns
|
|
192
|
+
|
|
193
|
+
`boolean`
|
|
194
|
+
|
|
195
|
+
#### Defined in
|
|
196
|
+
|
|
197
|
+
[src/Rectangle.ts:90](https://github.com/Immugio/three-math-extensions/blob/c004965/src/Rectangle.ts#L90)
|
|
198
|
+
|
|
199
|
+
___
|
|
200
|
+
|
|
201
|
+
### flipVertical
|
|
202
|
+
|
|
203
|
+
▸ **flipVertical**(`xCenter`): [`Rectangle`](Rectangle.md)
|
|
204
|
+
|
|
205
|
+
#### Parameters
|
|
206
|
+
|
|
207
|
+
| Name | Type |
|
|
208
|
+
| :------ | :------ |
|
|
209
|
+
| `xCenter` | `number` |
|
|
210
|
+
|
|
211
|
+
#### Returns
|
|
212
|
+
|
|
213
|
+
[`Rectangle`](Rectangle.md)
|
|
214
|
+
|
|
215
|
+
#### Defined in
|
|
216
|
+
|
|
217
|
+
[src/Rectangle.ts:80](https://github.com/Immugio/three-math-extensions/blob/c004965/src/Rectangle.ts#L80)
|
|
218
|
+
|
|
219
|
+
___
|
|
220
|
+
|
|
221
|
+
### overlaps
|
|
222
|
+
|
|
223
|
+
▸ **overlaps**(`other`): `boolean`
|
|
224
|
+
|
|
225
|
+
#### Parameters
|
|
226
|
+
|
|
227
|
+
| Name | Type |
|
|
228
|
+
| :------ | :------ |
|
|
229
|
+
| `other` | [`Rectangle`](Rectangle.md) |
|
|
230
|
+
|
|
231
|
+
#### Returns
|
|
232
|
+
|
|
233
|
+
`boolean`
|
|
234
|
+
|
|
235
|
+
#### Defined in
|
|
236
|
+
|
|
237
|
+
[src/Rectangle.ts:34](https://github.com/Immugio/three-math-extensions/blob/c004965/src/Rectangle.ts#L34)
|
|
238
|
+
|
|
239
|
+
___
|
|
240
|
+
|
|
241
|
+
### toPoints
|
|
242
|
+
|
|
243
|
+
▸ **toPoints**(): [`Vec2`](Vec2.md)[]
|
|
244
|
+
|
|
245
|
+
The polygon is always constructed as "clockwise", assuming X axis to the right and Y axis down.
|
|
246
|
+
|
|
247
|
+
#### Returns
|
|
248
|
+
|
|
249
|
+
[`Vec2`](Vec2.md)[]
|
|
250
|
+
|
|
251
|
+
#### Defined in
|
|
252
|
+
|
|
253
|
+
[src/Rectangle.ts:71](https://github.com/Immugio/three-math-extensions/blob/c004965/src/Rectangle.ts#L71)
|
|
254
|
+
|
|
255
|
+
___
|
|
256
|
+
|
|
257
|
+
### toPolygon
|
|
258
|
+
|
|
259
|
+
▸ **toPolygon**(): [`Polygon`](Polygon.md)
|
|
260
|
+
|
|
261
|
+
#### Returns
|
|
262
|
+
|
|
263
|
+
[`Polygon`](Polygon.md)
|
|
264
|
+
|
|
265
|
+
#### Defined in
|
|
266
|
+
|
|
267
|
+
[src/Rectangle.ts:64](https://github.com/Immugio/three-math-extensions/blob/c004965/src/Rectangle.ts#L64)
|
|
268
|
+
|
|
269
|
+
___
|
|
270
|
+
|
|
271
|
+
### translate
|
|
272
|
+
|
|
273
|
+
▸ **translate**(`diff`): [`Rectangle`](Rectangle.md)
|
|
274
|
+
|
|
275
|
+
#### Parameters
|
|
276
|
+
|
|
277
|
+
| Name | Type |
|
|
278
|
+
| :------ | :------ |
|
|
279
|
+
| `diff` | `Point2` |
|
|
280
|
+
|
|
281
|
+
#### Returns
|
|
282
|
+
|
|
283
|
+
[`Rectangle`](Rectangle.md)
|
|
284
|
+
|
|
285
|
+
#### Defined in
|
|
286
|
+
|
|
287
|
+
[src/Rectangle.ts:45](https://github.com/Immugio/three-math-extensions/blob/c004965/src/Rectangle.ts#L45)
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
[@immugio/three-math-extensions](../README.md) / [Exports](../modules.md) / Size2
|
|
2
|
+
|
|
3
|
+
# Class: Size2
|
|
4
|
+
|
|
5
|
+
## Table of contents
|
|
6
|
+
|
|
7
|
+
### Constructors
|
|
8
|
+
|
|
9
|
+
- [constructor](Size2.md#constructor)
|
|
10
|
+
|
|
11
|
+
### Properties
|
|
12
|
+
|
|
13
|
+
- [height](Size2.md#height)
|
|
14
|
+
- [width](Size2.md#width)
|
|
15
|
+
|
|
16
|
+
## Constructors
|
|
17
|
+
|
|
18
|
+
### constructor
|
|
19
|
+
|
|
20
|
+
• **new Size2**(`width`, `height`)
|
|
21
|
+
|
|
22
|
+
#### Parameters
|
|
23
|
+
|
|
24
|
+
| Name | Type |
|
|
25
|
+
| :------ | :------ |
|
|
26
|
+
| `width` | `number` |
|
|
27
|
+
| `height` | `number` |
|
|
28
|
+
|
|
29
|
+
#### Defined in
|
|
30
|
+
|
|
31
|
+
[src/Size2.ts:2](https://github.com/Immugio/three-math-extensions/blob/c004965/src/Size2.ts#L2)
|
|
32
|
+
|
|
33
|
+
## Properties
|
|
34
|
+
|
|
35
|
+
### height
|
|
36
|
+
|
|
37
|
+
• **height**: `number`
|
|
38
|
+
|
|
39
|
+
#### Defined in
|
|
40
|
+
|
|
41
|
+
[src/Size2.ts:2](https://github.com/Immugio/three-math-extensions/blob/c004965/src/Size2.ts#L2)
|
|
42
|
+
|
|
43
|
+
___
|
|
44
|
+
|
|
45
|
+
### width
|
|
46
|
+
|
|
47
|
+
• **width**: `number`
|
|
48
|
+
|
|
49
|
+
#### Defined in
|
|
50
|
+
|
|
51
|
+
[src/Size2.ts:2](https://github.com/Immugio/three-math-extensions/blob/c004965/src/Size2.ts#L2)
|
package/docs/classes/Vec2.md
CHANGED
|
@@ -67,7 +67,7 @@ A new Vec3 instance.
|
|
|
67
67
|
|
|
68
68
|
#### Defined in
|
|
69
69
|
|
|
70
|
-
[src/Vec2.ts:51](https://github.com/Immugio/three-math-extensions/blob/
|
|
70
|
+
[src/Vec2.ts:51](https://github.com/Immugio/three-math-extensions/blob/c004965/src/Vec2.ts#L51)
|
|
71
71
|
|
|
72
72
|
___
|
|
73
73
|
|
|
@@ -91,7 +91,7 @@ maxDistance is the maximum distance between the two vectors within which they ar
|
|
|
91
91
|
|
|
92
92
|
#### Defined in
|
|
93
93
|
|
|
94
|
-
[src/Vec2.ts:59](https://github.com/Immugio/three-math-extensions/blob/
|
|
94
|
+
[src/Vec2.ts:59](https://github.com/Immugio/three-math-extensions/blob/c004965/src/Vec2.ts#L59)
|
|
95
95
|
|
|
96
96
|
___
|
|
97
97
|
|
|
@@ -116,7 +116,7 @@ This Vec2 instance.
|
|
|
116
116
|
|
|
117
117
|
#### Defined in
|
|
118
118
|
|
|
119
|
-
[src/Vec2.ts:25](https://github.com/Immugio/three-math-extensions/blob/
|
|
119
|
+
[src/Vec2.ts:25](https://github.com/Immugio/three-math-extensions/blob/c004965/src/Vec2.ts#L25)
|
|
120
120
|
|
|
121
121
|
___
|
|
122
122
|
|
|
@@ -140,7 +140,7 @@ This Vec2 instance.
|
|
|
140
140
|
|
|
141
141
|
#### Defined in
|
|
142
142
|
|
|
143
|
-
[src/Vec2.ts:36](https://github.com/Immugio/three-math-extensions/blob/
|
|
143
|
+
[src/Vec2.ts:36](https://github.com/Immugio/three-math-extensions/blob/c004965/src/Vec2.ts#L36)
|
|
144
144
|
|
|
145
145
|
___
|
|
146
146
|
|
|
@@ -164,4 +164,4 @@ A new Vec2 instance.
|
|
|
164
164
|
|
|
165
165
|
#### Defined in
|
|
166
166
|
|
|
167
|
-
[src/Vec2.ts:15](https://github.com/Immugio/three-math-extensions/blob/
|
|
167
|
+
[src/Vec2.ts:15](https://github.com/Immugio/three-math-extensions/blob/c004965/src/Vec2.ts#L15)
|
package/docs/classes/Vec3.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# Class: Vec3
|
|
4
4
|
|
|
5
|
-
Vec3 represents a
|
|
5
|
+
Vec3 represents a 3D vector. It extends `Vector3` from the `threejs` library.
|
|
6
6
|
|
|
7
7
|
## Hierarchy
|
|
8
8
|
|
|
@@ -72,7 +72,7 @@ Adds x amount to this Vec3 instance and return this
|
|
|
72
72
|
|
|
73
73
|
#### Defined in
|
|
74
74
|
|
|
75
|
-
[src/Vec3.ts:65](https://github.com/Immugio/three-math-extensions/blob/
|
|
75
|
+
[src/Vec3.ts:65](https://github.com/Immugio/three-math-extensions/blob/c004965/src/Vec3.ts#L65)
|
|
76
76
|
|
|
77
77
|
___
|
|
78
78
|
|
|
@@ -94,7 +94,7 @@ Adds y amount to this Vec3 instance and return this
|
|
|
94
94
|
|
|
95
95
|
#### Defined in
|
|
96
96
|
|
|
97
|
-
[src/Vec3.ts:56](https://github.com/Immugio/three-math-extensions/blob/
|
|
97
|
+
[src/Vec3.ts:56](https://github.com/Immugio/three-math-extensions/blob/c004965/src/Vec3.ts#L56)
|
|
98
98
|
|
|
99
99
|
___
|
|
100
100
|
|
|
@@ -112,7 +112,7 @@ Vector3.clone
|
|
|
112
112
|
|
|
113
113
|
#### Defined in
|
|
114
114
|
|
|
115
|
-
[src/Vec3.ts:114](https://github.com/Immugio/three-math-extensions/blob/
|
|
115
|
+
[src/Vec3.ts:114](https://github.com/Immugio/three-math-extensions/blob/c004965/src/Vec3.ts#L114)
|
|
116
116
|
|
|
117
117
|
___
|
|
118
118
|
|
|
@@ -134,7 +134,7 @@ Returns a clone of the point closest to this from the given points.
|
|
|
134
134
|
|
|
135
135
|
#### Defined in
|
|
136
136
|
|
|
137
|
-
[src/Vec3.ts:74](https://github.com/Immugio/three-math-extensions/blob/
|
|
137
|
+
[src/Vec3.ts:74](https://github.com/Immugio/three-math-extensions/blob/c004965/src/Vec3.ts#L74)
|
|
138
138
|
|
|
139
139
|
___
|
|
140
140
|
|
|
@@ -156,7 +156,7 @@ Get distance to another vector while ignoring the y-axis.
|
|
|
156
156
|
|
|
157
157
|
#### Defined in
|
|
158
158
|
|
|
159
|
-
[src/Vec3.ts:98](https://github.com/Immugio/three-math-extensions/blob/
|
|
159
|
+
[src/Vec3.ts:98](https://github.com/Immugio/three-math-extensions/blob/c004965/src/Vec3.ts#L98)
|
|
160
160
|
|
|
161
161
|
___
|
|
162
162
|
|
|
@@ -180,7 +180,7 @@ maxDistance is the maximum distance between the two vectors within which they ar
|
|
|
180
180
|
|
|
181
181
|
#### Defined in
|
|
182
182
|
|
|
183
|
-
[src/Vec3.ts:106](https://github.com/Immugio/three-math-extensions/blob/
|
|
183
|
+
[src/Vec3.ts:106](https://github.com/Immugio/three-math-extensions/blob/c004965/src/Vec3.ts#L106)
|
|
184
184
|
|
|
185
185
|
___
|
|
186
186
|
|
|
@@ -204,7 +204,7 @@ This Vec3 instance.
|
|
|
204
204
|
|
|
205
205
|
#### Defined in
|
|
206
206
|
|
|
207
|
-
[src/Vec3.ts:43](https://github.com/Immugio/three-math-extensions/blob/
|
|
207
|
+
[src/Vec3.ts:43](https://github.com/Immugio/three-math-extensions/blob/c004965/src/Vec3.ts#L43)
|
|
208
208
|
|
|
209
209
|
___
|
|
210
210
|
|
|
@@ -229,7 +229,7 @@ This Vec3 instance.
|
|
|
229
229
|
|
|
230
230
|
#### Defined in
|
|
231
231
|
|
|
232
|
-
[src/Vec3.ts:27](https://github.com/Immugio/three-math-extensions/blob/
|
|
232
|
+
[src/Vec3.ts:27](https://github.com/Immugio/three-math-extensions/blob/c004965/src/Vec3.ts#L27)
|
|
233
233
|
|
|
234
234
|
___
|
|
235
235
|
|
|
@@ -245,7 +245,7 @@ Projects this Vec3 instance onto 2d plan. Vec3.z becomes Vec2.y and Vec3.y is ig
|
|
|
245
245
|
|
|
246
246
|
#### Defined in
|
|
247
247
|
|
|
248
|
-
[src/Vec3.ts:90](https://github.com/Immugio/three-math-extensions/blob/
|
|
248
|
+
[src/Vec3.ts:90](https://github.com/Immugio/three-math-extensions/blob/c004965/src/Vec3.ts#L90)
|
|
249
249
|
|
|
250
250
|
___
|
|
251
251
|
|
|
@@ -261,7 +261,7 @@ Returns a clone of this Vec3 instance with y and z swapped.
|
|
|
261
261
|
|
|
262
262
|
#### Defined in
|
|
263
263
|
|
|
264
|
-
[src/Vec3.ts:83](https://github.com/Immugio/three-math-extensions/blob/
|
|
264
|
+
[src/Vec3.ts:83](https://github.com/Immugio/three-math-extensions/blob/c004965/src/Vec3.ts#L83)
|
|
265
265
|
|
|
266
266
|
___
|
|
267
267
|
|
|
@@ -285,4 +285,4 @@ A new Vec3 instance.
|
|
|
285
285
|
|
|
286
286
|
#### Defined in
|
|
287
287
|
|
|
288
|
-
[src/Vec3.ts:17](https://github.com/Immugio/three-math-extensions/blob/
|
|
288
|
+
[src/Vec3.ts:17](https://github.com/Immugio/three-math-extensions/blob/c004965/src/Vec3.ts#L17)
|
package/docs/modules.md
CHANGED
|
@@ -6,7 +6,11 @@
|
|
|
6
6
|
|
|
7
7
|
### Classes
|
|
8
8
|
|
|
9
|
+
- [BoundingBox](classes/BoundingBox.md)
|
|
9
10
|
- [Line2D](classes/Line2D.md)
|
|
10
11
|
- [Line3D](classes/Line3D.md)
|
|
12
|
+
- [Polygon](classes/Polygon.md)
|
|
13
|
+
- [Rectangle](classes/Rectangle.md)
|
|
14
|
+
- [Size2](classes/Size2.md)
|
|
11
15
|
- [Vec2](classes/Vec2.md)
|
|
12
16
|
- [Vec3](classes/Vec3.md)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Vec2 } from "./Vec2";
|
|
2
|
+
export class BoundingBox {
|
|
3
|
+
minX;
|
|
4
|
+
maxX;
|
|
5
|
+
minY;
|
|
6
|
+
maxY;
|
|
7
|
+
constructor(minX, maxX, minY, maxY) {
|
|
8
|
+
this.minX = minX;
|
|
9
|
+
this.maxX = maxX;
|
|
10
|
+
this.minY = minY;
|
|
11
|
+
this.maxY = maxY;
|
|
12
|
+
}
|
|
13
|
+
equals(other) {
|
|
14
|
+
return this.minX === other.minX && this.maxX === other.maxX && this.minY === other.minY && this.maxY === other.maxY;
|
|
15
|
+
}
|
|
16
|
+
get size() {
|
|
17
|
+
return new Vec2(this.maxX - this.minX, this.maxY - this.minY);
|
|
18
|
+
}
|
|
19
|
+
}
|
package/esm/Polygon.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Vec2 } from "./Vec2";
|
|
2
|
-
import {
|
|
2
|
+
import { Rectangle } from "./Rectangle";
|
|
3
|
+
import { BoundingBox } from "./BoundingBox";
|
|
3
4
|
export class Polygon {
|
|
4
5
|
contour;
|
|
5
6
|
holes;
|
|
@@ -12,7 +13,7 @@ export class Polygon {
|
|
|
12
13
|
}
|
|
13
14
|
get size() {
|
|
14
15
|
const { minX, maxX, minY, maxY } = this.boundingBox();
|
|
15
|
-
return new
|
|
16
|
+
return new Vec2(maxX - minX, maxY - minY);
|
|
16
17
|
}
|
|
17
18
|
centerOnOrigin() {
|
|
18
19
|
const center = this.center();
|
|
@@ -36,7 +37,7 @@ export class Polygon {
|
|
|
36
37
|
}
|
|
37
38
|
ensureLastPoint() {
|
|
38
39
|
function ensure(points) {
|
|
39
|
-
if (points[0].
|
|
40
|
+
if (!points[0].equals(points.at(-1))) {
|
|
40
41
|
points.push(points[0].clone());
|
|
41
42
|
}
|
|
42
43
|
}
|
|
@@ -58,7 +59,7 @@ export class Polygon {
|
|
|
58
59
|
if (maxY < p.y)
|
|
59
60
|
maxY = p.y;
|
|
60
61
|
}
|
|
61
|
-
return
|
|
62
|
+
return new BoundingBox(minX, maxX, minY, maxY);
|
|
62
63
|
}
|
|
63
64
|
toBoundingPolygon() {
|
|
64
65
|
const bounding = this.boundingBox();
|
|
@@ -81,4 +82,37 @@ export class Polygon {
|
|
|
81
82
|
point.x = point.x < centerX ? centerX + xDistanceToCenter : centerX - xDistanceToCenter;
|
|
82
83
|
}
|
|
83
84
|
}
|
|
85
|
+
toRectangle() {
|
|
86
|
+
const bounding = this.boundingBox();
|
|
87
|
+
return new Rectangle(bounding.minX, bounding.maxX, bounding.minY, bounding.maxY);
|
|
88
|
+
}
|
|
89
|
+
clone() {
|
|
90
|
+
return new Polygon(this.contour.map(p => p.clone()), this.holes?.map(h => h.map(p => p.clone())));
|
|
91
|
+
}
|
|
92
|
+
equals(other) {
|
|
93
|
+
if (this.contour.length !== other.contour.length) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
for (let i = 0; i < this.contour.length; i++) {
|
|
97
|
+
if (!this.contour[i].equals(other.contour[i])) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (this.holes?.length !== other.holes?.length) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
for (let i = 0; i < this.holes?.length; i++) {
|
|
105
|
+
const hole = this.holes[i];
|
|
106
|
+
const otherHole = other.holes[i];
|
|
107
|
+
if (hole.length !== otherHole.length) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
for (let j = 0; j < hole.length; j++) {
|
|
111
|
+
if (!hole[j].equals(otherHole[j])) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
84
118
|
}
|
package/esm/Rectangle.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Polygon } from "./Polygon";
|
|
2
|
+
import { Vec2 } from "./Vec2";
|
|
3
|
+
export class Rectangle {
|
|
4
|
+
leftX;
|
|
5
|
+
rightX;
|
|
6
|
+
topY;
|
|
7
|
+
bottomY;
|
|
8
|
+
constructor(leftX, rightX, topY, bottomY) {
|
|
9
|
+
this.leftX = leftX;
|
|
10
|
+
this.rightX = rightX;
|
|
11
|
+
this.topY = topY;
|
|
12
|
+
this.bottomY = bottomY;
|
|
13
|
+
}
|
|
14
|
+
clone() {
|
|
15
|
+
return new Rectangle(this.leftX, this.rightX, this.topY, this.bottomY);
|
|
16
|
+
}
|
|
17
|
+
get size() {
|
|
18
|
+
return new Vec2(this.rightX - this.leftX, this.topY - this.bottomY);
|
|
19
|
+
}
|
|
20
|
+
get center() {
|
|
21
|
+
return new Vec2((this.leftX + this.rightX) / 2, (this.topY + this.bottomY) / 2);
|
|
22
|
+
}
|
|
23
|
+
get offset() {
|
|
24
|
+
return new Vec2((this.leftX + this.rightX) / -2, (this.topY + this.bottomY) / -2);
|
|
25
|
+
}
|
|
26
|
+
overlaps(other) {
|
|
27
|
+
// Proof is by contradiction. Any one of four conditions guarantees that NO OVERLAP CAN EXIST.
|
|
28
|
+
const result = this.bottomY >= other.topY || this.topY <= other.bottomY || this.rightX <= other.leftX || this.leftX >= other.rightX;
|
|
29
|
+
return !result;
|
|
30
|
+
}
|
|
31
|
+
get hasSize() {
|
|
32
|
+
return this.rightX - this.leftX > 1 && this.topY - this.bottomY > 1;
|
|
33
|
+
}
|
|
34
|
+
translate(diff) {
|
|
35
|
+
this.leftX += diff.x;
|
|
36
|
+
this.rightX += diff.x;
|
|
37
|
+
this.topY += diff.y;
|
|
38
|
+
this.bottomY += diff.y;
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
centerOnOrigin() {
|
|
42
|
+
const center = this.center;
|
|
43
|
+
this.leftX -= center.x;
|
|
44
|
+
this.rightX -= center.x;
|
|
45
|
+
this.topY -= center.y;
|
|
46
|
+
this.bottomY -= center.y;
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
toPolygon() {
|
|
50
|
+
return new Polygon(this.toPoints());
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The polygon is always constructed as "clockwise", assuming X axis to the right and Y axis down.
|
|
54
|
+
*/
|
|
55
|
+
toPoints() {
|
|
56
|
+
return [
|
|
57
|
+
new Vec2(this.leftX, Math.min(this.topY, this.bottomY)),
|
|
58
|
+
new Vec2(this.rightX, Math.min(this.topY, this.bottomY)),
|
|
59
|
+
new Vec2(this.rightX, Math.max(this.topY, this.bottomY)),
|
|
60
|
+
new Vec2(this.leftX, Math.max(this.topY, this.bottomY)),
|
|
61
|
+
];
|
|
62
|
+
}
|
|
63
|
+
flipVertical(xCenter) {
|
|
64
|
+
const left = xCenter - (this.rightX - xCenter);
|
|
65
|
+
const right = xCenter - (this.leftX - xCenter);
|
|
66
|
+
this.leftX = left;
|
|
67
|
+
this.rightX = right;
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
equals(other) {
|
|
71
|
+
return !!other && this.leftX === other.leftX && this.rightX === other.rightX && this.topY === other.topY && this.bottomY === other.bottomY;
|
|
72
|
+
}
|
|
73
|
+
}
|
package/esm/Vec3.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Vector3 } from "three";
|
|
2
2
|
import { Vec2 } from "./Vec2";
|
|
3
3
|
/**
|
|
4
|
-
* Vec3 represents a
|
|
4
|
+
* Vec3 represents a 3D vector. It extends `Vector3` from the `threejs` library.
|
|
5
5
|
*/
|
|
6
6
|
export class Vec3 extends Vector3 {
|
|
7
7
|
#target;
|
package/esm/index.js
CHANGED
|
@@ -2,3 +2,7 @@ export { Vec2 } from "./Vec2";
|
|
|
2
2
|
export { Vec3 } from "./Vec3";
|
|
3
3
|
export { Line2D } from "./Line2D";
|
|
4
4
|
export { Line3D } from "./Line3D";
|
|
5
|
+
export { Size2 } from "./Size2";
|
|
6
|
+
export { Polygon } from "./Polygon";
|
|
7
|
+
export { BoundingBox } from "./BoundingBox";
|
|
8
|
+
export { Rectangle } from "./Rectangle";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@immugio/three-math-extensions",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Set of utilities for 2d and 3d line math built on top of three.js",
|
|
5
5
|
"author": "Jan Mikeska <janmikeska@gmail.com>",
|
|
6
6
|
"license": "ISC",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"ts-jest": "^29.0.0",
|
|
43
43
|
"typedoc": "^0.23.23",
|
|
44
44
|
"typedoc-plugin-markdown": "^3.14.0",
|
|
45
|
-
"typescript": "4.
|
|
45
|
+
"typescript": "4.9.5"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"three": ">=0.130.1"
|