@thi.ng/geom-tessellate 2.1.131 → 3.0.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 +47 -1
- package/README.md +162 -8
- package/api.d.ts +81 -0
- package/api.js +0 -0
- package/earcut-complex.d.ts +74 -0
- package/earcut-complex.js +415 -0
- package/earcut.d.ts +2 -7
- package/earcut.js +28 -26
- package/edge-split.d.ts +8 -1
- package/edge-split.js +11 -23
- package/index.d.ts +5 -0
- package/index.js +5 -0
- package/inset.d.ts +2 -2
- package/inset.js +11 -19
- package/package.json +33 -14
- package/quad-fan.d.ts +1 -1
- package/quad-fan.js +13 -17
- package/rim-tris.d.ts +1 -1
- package/rim-tris.js +21 -26
- package/tessellate.d.ts +7 -4
- package/tessellate.js +24 -17
- package/tessellation.d.ts +26 -0
- package/tessellation.js +59 -0
- package/tri-fan-boundary.d.ts +3 -0
- package/tri-fan-boundary.js +11 -0
- package/tri-fan-split.d.ts +9 -0
- package/tri-fan-split.js +26 -0
- package/tri-fan.d.ts +1 -1
- package/tri-fan.js +7 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2024-
|
|
3
|
+
- **Last updated**: 2024-06-21T19:34:38Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -9,6 +9,52 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
# [3.0.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/geom-tessellate@3.0.0) (2024-06-21)
|
|
13
|
+
|
|
14
|
+
#### 🛑 Breaking changes
|
|
15
|
+
|
|
16
|
+
- update/rewrite tessellate() & all tessellator impls ([97f1f66](https://github.com/thi-ng/umbrella/commit/97f1f66))
|
|
17
|
+
- BREAKING CHANGE: update tessellate() & all tessellator implementations
|
|
18
|
+
- `Tessellator`s now collect/append results to a `Tessellation` object, consisting of
|
|
19
|
+
a single point array and an array of face vertex IDs
|
|
20
|
+
- add `tessellatedPoints()` and `indexedPoints()` to produce face/point arrays from a result `Tessellation`
|
|
21
|
+
- remove again `edgeSplitWithThreshold()` & `triFanSplitWithThreshold()`,
|
|
22
|
+
to be replaced with a more general alternative approach
|
|
23
|
+
- migrate types from [@thi.ng/geom-api](https://github.com/thi-ng/umbrella/tree/main/packages/geom-api) ([72cff99](https://github.com/thi-ng/umbrella/commit/72cff99))
|
|
24
|
+
- BREAKING CHANGE: migrate/internalize types from [@thi.ng/geom-api](https://github.com/thi-ng/umbrella/tree/main/packages/geom-api)
|
|
25
|
+
- add/migrate Tessellator, Tessellation
|
|
26
|
+
- update imports
|
|
27
|
+
- update deps
|
|
28
|
+
- add/update tessellation types & handling ([c0fb454](https://github.com/thi-ng/umbrella/commit/c0fb454))
|
|
29
|
+
- BREAKING CHANGE: add `ITessellation` interface & impls, update tessellators & `tessellate()`
|
|
30
|
+
- rename/expand `Tessellation` => `ITessellation`
|
|
31
|
+
- add `BasicTessellation` class
|
|
32
|
+
- add `MeshTessellation` class
|
|
33
|
+
- update `Tessellator` signature/return type, now returning list of new faces only
|
|
34
|
+
- update all existing tessellators
|
|
35
|
+
- add `tessellateWith()`
|
|
36
|
+
- rename `tessellateQueue()` => `tessellateFaces()`
|
|
37
|
+
- update `tessellate()`, now only syntax sugar for `tessellateWith()`
|
|
38
|
+
- update `Tessellator` signature ([c2ec98b](https://github.com/thi-ng/umbrella/commit/c2ec98b))
|
|
39
|
+
- BREAKING CHANGE: update `Tessellator` signature, add array arg for collecting tessellated faces
|
|
40
|
+
- update `tessellateFaces()` to avoid concatenating
|
|
41
|
+
- update all tessellators
|
|
42
|
+
|
|
43
|
+
#### 🚀 Features
|
|
44
|
+
|
|
45
|
+
- add edgeSplitWithThreshold() tessellator ([91480c7](https://github.com/thi-ng/umbrella/commit/91480c7))
|
|
46
|
+
- add docstrings
|
|
47
|
+
- add triFanSplit/triFanSplitWithThreshold() tessellators ([417123c](https://github.com/thi-ng/umbrella/commit/417123c))
|
|
48
|
+
- add doc strings
|
|
49
|
+
- initial integration of earCutComplex ([307cb3d](https://github.com/thi-ng/umbrella/commit/307cb3d))
|
|
50
|
+
- add triFanBoundary() tessellator ([a8fc397](https://github.com/thi-ng/umbrella/commit/a8fc397))
|
|
51
|
+
|
|
52
|
+
#### ♻️ Refactoring
|
|
53
|
+
|
|
54
|
+
- update/simplify earCutComplex() internals, add docs ([0b479eb](https://github.com/thi-ng/umbrella/commit/0b479eb))
|
|
55
|
+
- enforce uniform naming convention of internal functions ([56992b2](https://github.com/thi-ng/umbrella/commit/56992b2))
|
|
56
|
+
- minor updates earCutComplex() ([a2d5ec4](https://github.com/thi-ng/umbrella/commit/a2d5ec4))
|
|
57
|
+
|
|
12
58
|
### [2.1.87](https://github.com/thi-ng/umbrella/tree/@thi.ng/geom-tessellate@2.1.87) (2023-11-09)
|
|
13
59
|
|
|
14
60
|
#### ♻️ Refactoring
|
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
[](https://mastodon.thi.ng/@toxi)
|
|
8
8
|
|
|
9
9
|
> [!NOTE]
|
|
10
|
-
> This is one of
|
|
10
|
+
> This is one of 193 standalone projects, maintained as part
|
|
11
11
|
> of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
|
|
12
12
|
> and anti-framework.
|
|
13
13
|
>
|
|
@@ -15,11 +15,22 @@
|
|
|
15
15
|
> GitHub](https://github.com/sponsors/postspectacular). Thank you! ❤️
|
|
16
16
|
|
|
17
17
|
- [About](#about)
|
|
18
|
+
- [Tessellators](#tessellators)
|
|
19
|
+
- [Ear cut](#ear-cut)
|
|
20
|
+
- [Edge split](#edge-split)
|
|
21
|
+
- [Inset](#inset)
|
|
22
|
+
- [Quad fan](#quad-fan)
|
|
23
|
+
- [Rim triangles](#rim-triangles)
|
|
24
|
+
- [Tri fan (with boundary point)](#tri-fan-with-boundary-point)
|
|
25
|
+
- [Tri fan (with centroid)](#tri-fan-with-centroid)
|
|
26
|
+
- [Tri fan (with edge splitting)](#tri-fan-with-edge-splitting)
|
|
27
|
+
- [The `ITessellation` interface & implementation](#the-itessellation-interface--implementation)
|
|
18
28
|
- [Status](#status)
|
|
19
29
|
- [Installation](#installation)
|
|
20
30
|
- [Dependencies](#dependencies)
|
|
21
31
|
- [Usage examples](#usage-examples)
|
|
22
32
|
- [API](#api)
|
|
33
|
+
- [Basic usage](#basic-usage)
|
|
23
34
|
- [Authors](#authors)
|
|
24
35
|
- [License](#license)
|
|
25
36
|
|
|
@@ -27,16 +38,88 @@
|
|
|
27
38
|
|
|
28
39
|
2D/3D convex polygon tessellators. This is a support package for [@thi.ng/geom](https://github.com/thi-ng/umbrella/tree/develop/packages/geom).
|
|
29
40
|
|
|
30
|
-
|
|
41
|
+
### Tessellators
|
|
42
|
+
|
|
43
|
+
The following tessellator algorithms are provided, but the package is designed
|
|
44
|
+
to be fully extensible. See code examples further below.
|
|
45
|
+
|
|
46
|
+
The following diagrams each show the effect of a single tessellator applied to a
|
|
47
|
+
triangle, square, hexagon and octagon.
|
|
48
|
+
|
|
49
|
+
#### Ear cut
|
|
50
|
+
|
|
51
|
+

|
|
52
|
+
|
|
53
|
+
- [earCut](https://github.com/thi-ng/umbrella/tree/develop/packages/geom-tessellate/src/earcut.ts)
|
|
54
|
+
|
|
55
|
+
##### Complex polygons
|
|
56
|
+
|
|
57
|
+
- [earCutComplex](https://github.com/thi-ng/umbrella/tree/develop/packages/geom-tessellate/src/earcut-complex.ts)
|
|
58
|
+
|
|
59
|
+
Higher order tessellator for concave polygons and/or polygons with holes...
|
|
60
|
+
|
|
61
|
+
TODO add comments, credits & example
|
|
62
|
+
|
|
63
|
+
#### Edge split
|
|
64
|
+
|
|
65
|
+

|
|
66
|
+
|
|
31
67
|
- [edgeSplit](https://github.com/thi-ng/umbrella/tree/develop/packages/geom-tessellate/src/edge-split.ts)
|
|
68
|
+
|
|
69
|
+
#### Inset
|
|
70
|
+
|
|
71
|
+

|
|
72
|
+
|
|
32
73
|
- [inset](https://github.com/thi-ng/umbrella/tree/develop/packages/geom-tessellate/src/inset.ts)
|
|
74
|
+
|
|
75
|
+
Higher order tessellator with configurable inset distance (normalized) toward
|
|
76
|
+
centroid and option to keep center polygon (empty by default).
|
|
77
|
+
|
|
78
|
+
#### Quad fan
|
|
79
|
+
|
|
80
|
+

|
|
81
|
+
|
|
33
82
|
- [quadFan](https://github.com/thi-ng/umbrella/tree/develop/packages/geom-tessellate/src/quad-fan.ts)
|
|
83
|
+
|
|
84
|
+
#### Rim triangles
|
|
85
|
+
|
|
86
|
+

|
|
87
|
+
|
|
34
88
|
- [rimTris](https://github.com/thi-ng/umbrella/tree/develop/packages/geom-tessellate/src/rim-tris.ts)
|
|
89
|
+
|
|
90
|
+
#### Tri fan (with boundary point)
|
|
91
|
+
|
|
92
|
+

|
|
93
|
+
|
|
94
|
+
- [triFanBoundary](https://github.com/thi-ng/umbrella/tree/develop/packages/geom-tessellate/src/tri-fan-boundary.ts)
|
|
95
|
+
|
|
96
|
+
#### Tri fan (with centroid)
|
|
97
|
+
|
|
98
|
+

|
|
99
|
+
|
|
35
100
|
- [triFan](https://github.com/thi-ng/umbrella/tree/develop/packages/geom-tessellate/src/tri-fan.ts)
|
|
36
101
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
102
|
+
#### Tri fan (with edge splitting)
|
|
103
|
+
|
|
104
|
+

|
|
105
|
+
|
|
106
|
+
- [triFanSplit](https://github.com/thi-ng/umbrella/tree/develop/packages/geom-tessellate/src/tri-fan-split.ts)
|
|
107
|
+
|
|
108
|
+
### The `ITessellation` interface & implementation
|
|
109
|
+
|
|
110
|
+
The tessellators provided all operate in conjunction with a
|
|
111
|
+
[`ITessellation`](https://docs.thi.ng/umbrella/geom-tessellate/interfaces/ITessellation.html)
|
|
112
|
+
implementation which is used to collect (or index) points/vertices and generated
|
|
113
|
+
faces (not necessarily triangles).
|
|
114
|
+
|
|
115
|
+
Currently, there're two implementations available:
|
|
116
|
+
|
|
117
|
+
- [`BasicTessellation`](https://docs.thi.ng/umbrella/geom-tessellate/classes/BasicTessellation.html)
|
|
118
|
+
is used as the default and merely collects points & faces into arrays
|
|
119
|
+
- [`MeshTessellation`](https://docs.thi.ng/umbrella/geom-tessellate/classes/MeshTessellation.html)
|
|
120
|
+
uses a kD-tree to deduplicate/weld and re-use points (with configurable
|
|
121
|
+
tolerance) and is recommended for use cases when the result tessellation
|
|
122
|
+
should be converted or used for graph-like analysis or other post-processing.
|
|
40
123
|
|
|
41
124
|
## Status
|
|
42
125
|
|
|
@@ -70,14 +153,17 @@ For Node.js REPL:
|
|
|
70
153
|
const gt = await import("@thi.ng/geom-tessellate");
|
|
71
154
|
```
|
|
72
155
|
|
|
73
|
-
Package sizes (brotli'd, pre-treeshake): ESM:
|
|
156
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 3.32 KB
|
|
74
157
|
|
|
75
158
|
## Dependencies
|
|
76
159
|
|
|
160
|
+
- [@thi.ng/api](https://github.com/thi-ng/umbrella/tree/develop/packages/api)
|
|
77
161
|
- [@thi.ng/checks](https://github.com/thi-ng/umbrella/tree/develop/packages/checks)
|
|
78
|
-
- [@thi.ng/geom-
|
|
162
|
+
- [@thi.ng/geom-accel](https://github.com/thi-ng/umbrella/tree/develop/packages/geom-accel)
|
|
79
163
|
- [@thi.ng/geom-isec](https://github.com/thi-ng/umbrella/tree/develop/packages/geom-isec)
|
|
80
164
|
- [@thi.ng/geom-poly-utils](https://github.com/thi-ng/umbrella/tree/develop/packages/geom-poly-utils)
|
|
165
|
+
- [@thi.ng/math](https://github.com/thi-ng/umbrella/tree/develop/packages/math)
|
|
166
|
+
- [@thi.ng/morton](https://github.com/thi-ng/umbrella/tree/develop/packages/morton)
|
|
81
167
|
- [@thi.ng/transducers](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers)
|
|
82
168
|
- [@thi.ng/vectors](https://github.com/thi-ng/umbrella/tree/develop/packages/vectors)
|
|
83
169
|
|
|
@@ -89,6 +175,7 @@ directory are using this package:
|
|
|
89
175
|
|
|
90
176
|
| Screenshot | Description | Live demo | Source |
|
|
91
177
|
|:----------------------------------------------------------------------------------------------------------------------|:-------------------------------------------------------------------------------|:-----------------------------------------------------|:----------------------------------------------------------------------------------|
|
|
178
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/geom-hexgrid.png" width="240"/> | Hex grid generation & tessellations | [Demo](https://demo.thi.ng/umbrella/geom-hexgrid/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/geom-hexgrid) |
|
|
92
179
|
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/geom/tessel.png" width="240"/> | Animated, recursive polygon tessellations | [Demo](https://demo.thi.ng/umbrella/geom-tessel/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/geom-tessel) |
|
|
93
180
|
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/pointfree-geom.jpg" width="240"/> | Live coding playground for 2D geometry generation using @thi.ng/pointfree-lang | [Demo](https://demo.thi.ng/umbrella/pointfree-geom/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/pointfree-geom) |
|
|
94
181
|
|
|
@@ -96,7 +183,74 @@ directory are using this package:
|
|
|
96
183
|
|
|
97
184
|
[Generated API docs](https://docs.thi.ng/umbrella/geom-tessellate/)
|
|
98
185
|
|
|
99
|
-
|
|
186
|
+
**This is a low(er)-level support package for [thi.ng/geom](https://thi.ng/geom)
|
|
187
|
+
and most users are encouraged to use the polymorphic [`tessellate()`
|
|
188
|
+
function](https://docs.thi.ng/umbrella/geom/functions/tessellate.html)
|
|
189
|
+
provided by that package.**
|
|
190
|
+
|
|
191
|
+
In addition to the actual tessellator algorithms described above, this package
|
|
192
|
+
also provides its own set of `tessellate()` functions to simplify
|
|
193
|
+
recursive/iterative application of multiple tessellation passes:
|
|
194
|
+
|
|
195
|
+
- [`tessellate()`](https://docs.thi.ng/umbrella/geom-tessellate/functions/tessellate.html)
|
|
196
|
+
- [`tessellateWith()`](https://docs.thi.ng/umbrella/geom-tessellate/functions/tessellateWith.html)
|
|
197
|
+
- [`tessellateFaces()`](https://docs.thi.ng/umbrella/geom-tessellate/functions/tessellateFaces.html)
|
|
198
|
+
|
|
199
|
+
### Basic usage
|
|
200
|
+
|
|
201
|
+
```ts tangle:export/readme.ts
|
|
202
|
+
import * as gt from "@thi.ng/geom-tessellate";
|
|
203
|
+
|
|
204
|
+
// points of a square polygon
|
|
205
|
+
const points = [[0,0], [100,0], [100,100], [0, 100]];
|
|
206
|
+
|
|
207
|
+
// tessellate square into a triangle fan
|
|
208
|
+
console.log(gt.tessellate(points, gt.triFan));
|
|
209
|
+
// BasicTessellation {
|
|
210
|
+
// points: [[ 0, 0 ], [ 100, 0 ], [ 100, 100 ], [ 0, 100 ], [ 50, 50 ]],
|
|
211
|
+
// faces: [[ 4, 0, 1 ], [ 4, 1, 2 ], [ 4, 2, 3 ], [ 4, 3, 0 ]],
|
|
212
|
+
// ...
|
|
213
|
+
// }
|
|
214
|
+
|
|
215
|
+
// tessellate square first into a triangle fan, then each triangle into a quad fan
|
|
216
|
+
console.log(gt.tessellate(points, [gt.triFan, gt.quadFan]));
|
|
217
|
+
// BasicTessellation {
|
|
218
|
+
// points: [
|
|
219
|
+
// [ 0, 0 ], [ 100, 0 ], [ 100, 100 ], [ 0, 100 ],
|
|
220
|
+
// [ 50, 50 ], [ 50, 16.666 ], [ 75, 25 ], [ 25, 25 ],
|
|
221
|
+
// [ 50, 0 ], [ 83.333, 50 ], [ 75, 75 ], [ 75, 25 ],
|
|
222
|
+
// [ 100, 50 ], [ 50, 83.333 ], [ 25, 75 ], [ 75, 75 ],
|
|
223
|
+
// [ 50, 100 ], [ 16.666, 50 ], [ 25, 25 ], [ 25, 75 ], [ 0, 50 ]
|
|
224
|
+
// ],
|
|
225
|
+
// faces: [
|
|
226
|
+
// [ 5, 6, 4, 7 ], [ 5, 7, 0, 8 ], [ 5, 8, 1, 6 ], [ 9, 10, 4, 11 ],
|
|
227
|
+
// [ 9, 11, 1, 12 ], [ 9, 12, 2, 10 ], [ 13, 14, 4, 15 ], [ 13, 15, 2, 16 ],
|
|
228
|
+
// [ 13, 16, 3, 14 ], [ 17, 18, 4, 19 ], [ 17, 19, 3, 20 ], [ 17, 20, 0, 18 ]
|
|
229
|
+
// ],
|
|
230
|
+
// ...
|
|
231
|
+
// }
|
|
232
|
+
|
|
233
|
+
// apply quadfan twice and use a custom tessellation instance
|
|
234
|
+
// (here to dedupe generated edge midpoints)
|
|
235
|
+
console.log(gt.tessellateWith(new gt.MeshTessellation(2), points, gt.quadFan, 2));
|
|
236
|
+
// MeshTessellation {
|
|
237
|
+
// points: [
|
|
238
|
+
// [ 0, 0 ], [ 100, 0 ], [ 100, 100 ], [ 0, 100 ],
|
|
239
|
+
// [ 50, 50 ], [ 0, 50 ], [ 50, 0 ], [ 100, 50 ],
|
|
240
|
+
// [ 50, 100 ], [ 25, 25 ], [ 50, 25 ], [ 25, 50 ],
|
|
241
|
+
// [ 0, 25 ], [ 25, 0 ], [ 75, 25 ], [ 75, 50 ],
|
|
242
|
+
// [ 75, 0 ], [ 100, 25 ], [ 75, 75 ], [ 50, 75 ],
|
|
243
|
+
// [ 100, 75 ], [ 75, 100 ], [ 25, 75 ], [25, 100], [ 0, 75 ]
|
|
244
|
+
// ],
|
|
245
|
+
// faces: [
|
|
246
|
+
// [ 9, 10, 4, 11 ], [ 9, 11, 5, 12 ], [ 9, 12, 0, 13 ], [ 9, 13, 6, 10 ],
|
|
247
|
+
// [ 14, 15, 4, 10 ], [ 14, 10, 6, 16 ], [ 14, 16, 1, 17 ], [ 14, 17, 7, 15 ],
|
|
248
|
+
// [ 18, 19, 4, 15 ], [ 18, 15, 7, 20 ], [ 18, 20, 2, 21 ], [ 18, 21, 8, 19 ],
|
|
249
|
+
// [ 22, 11, 4, 19 ], [ 22, 19, 8, 23 ], [ 22, 23, 3, 24 ], [ 22, 24, 5, 11 ]
|
|
250
|
+
// ],
|
|
251
|
+
// ...
|
|
252
|
+
// }
|
|
253
|
+
```
|
|
100
254
|
|
|
101
255
|
## Authors
|
|
102
256
|
|
package/api.d.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { IEmpty } from "@thi.ng/api";
|
|
2
|
+
import type { ReadonlyVec } from "@thi.ng/vectors";
|
|
3
|
+
/**
|
|
4
|
+
* Tessellation algorithm implementation. Takes a {@link ITessellation}, an
|
|
5
|
+
* array of `faces` and an array of point/vertex IDs of the face/polygon to
|
|
6
|
+
* tessellate. Any new points created by the impl are to be added to the `tess`
|
|
7
|
+
* via {@link ITessellation.addPoint}. Any generated faces are to be appended to
|
|
8
|
+
* the given `faces` array (which also must be returned).
|
|
9
|
+
*
|
|
10
|
+
* @param tess
|
|
11
|
+
* @param faces
|
|
12
|
+
* @param face
|
|
13
|
+
*/
|
|
14
|
+
export type Tessellator = (tess: ITessellation, faces: number[][], face: number[]) => number[][];
|
|
15
|
+
export interface ITessellation extends IEmpty<ITessellation> {
|
|
16
|
+
/**
|
|
17
|
+
* Points referenced by {@link ITessellation.faces}.
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
* If a {@link Tessellator} is creating new points as part of its
|
|
21
|
+
* processing, these are appended to this array (but **not directly!**).
|
|
22
|
+
* Tessellators MUST use {@link ITessellation.addPoint} or
|
|
23
|
+
* {@link ITessellation.addPoints}).
|
|
24
|
+
*/
|
|
25
|
+
points: ReadonlyVec[];
|
|
26
|
+
/**
|
|
27
|
+
* Array of tessellated faces, each itself an array point IDs/indices,
|
|
28
|
+
* referencing {@link ITessellation.points}.
|
|
29
|
+
*/
|
|
30
|
+
faces: number[][];
|
|
31
|
+
/**
|
|
32
|
+
* Adds given point to tessellation and returns its ID/index.
|
|
33
|
+
*
|
|
34
|
+
* @remarks
|
|
35
|
+
* It's implementation specific if the point will actually be added or if a
|
|
36
|
+
* matching pre-existing point ID will be reused (e.g. see
|
|
37
|
+
* {@link MeshTessellation}).
|
|
38
|
+
*
|
|
39
|
+
* @param point
|
|
40
|
+
*/
|
|
41
|
+
addPoint(point: ReadonlyVec): number;
|
|
42
|
+
/**
|
|
43
|
+
* Batch version of {@link ITessellation.addPoint}, returning an array of
|
|
44
|
+
* point IDs.
|
|
45
|
+
*
|
|
46
|
+
* @param points
|
|
47
|
+
*/
|
|
48
|
+
addPoints(points: ReadonlyVec[]): number[];
|
|
49
|
+
/**
|
|
50
|
+
* Add given faces to {@link ITessellation.faces}.
|
|
51
|
+
*
|
|
52
|
+
* @remarks
|
|
53
|
+
* Note: Because {@link Tessellator}s might be applied recursively, they
|
|
54
|
+
* **do not** directly add faces to a given {@link ITessellation}, but onl
|
|
55
|
+
* return generated faces as separate array. Currently, this function is
|
|
56
|
+
* only called by {@link tessellateFaces} (and implicitly by
|
|
57
|
+
* {@link tessellate}, {@link tessellateWith}).
|
|
58
|
+
*
|
|
59
|
+
* @param faces
|
|
60
|
+
*/
|
|
61
|
+
addFaces(faces: number[][]): this;
|
|
62
|
+
/**
|
|
63
|
+
* Takes an array of point IDs and returns their actual points.
|
|
64
|
+
*
|
|
65
|
+
* @remarks
|
|
66
|
+
* No bounds checking performed. IDs are assumed to be valid.
|
|
67
|
+
*
|
|
68
|
+
* @param indices
|
|
69
|
+
*/
|
|
70
|
+
pointsForIDs(indices: number[]): ReadonlyVec[];
|
|
71
|
+
/**
|
|
72
|
+
* Similar to {@link ITessellation.pointsForIDs}, but takes an array of
|
|
73
|
+
* faces (by default all current faces in the tessellation) and returns an
|
|
74
|
+
* array of faces where wach face is an array of points (rather than point
|
|
75
|
+
* IDs).
|
|
76
|
+
*
|
|
77
|
+
* @param faces
|
|
78
|
+
*/
|
|
79
|
+
pointsForFaces(faces?: number[][]): ReadonlyVec[][];
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=api.d.ts.map
|
package/api.js
ADDED
|
File without changes
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { ReadonlyVec } from "@thi.ng/vectors";
|
|
2
|
+
import type { Tessellator } from "./api.js";
|
|
3
|
+
/**
|
|
4
|
+
* Higher-order tessellator, implementing an ear slicing triangulation
|
|
5
|
+
* algorithm, optionally optimized by Morton/Z-curve hashing/sorting and able to
|
|
6
|
+
* handle complex polygons with holes, twists, degeneracies and
|
|
7
|
+
* self-intersections.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* This is an adapted version of https://github.com/mapbox/earcut with the
|
|
11
|
+
* following changes to the original implementation:
|
|
12
|
+
*
|
|
13
|
+
* - Input points given as array of points (not flattened, only 2D supported)
|
|
14
|
+
* - Appends results to given tessellation instance as per contract of all
|
|
15
|
+
* tessellators in this package
|
|
16
|
+
* - Configurable Z-curve hashing threshold (default: 80)
|
|
17
|
+
* - If Z-curve hashing is used, points are pre-scaled once internally for
|
|
18
|
+
* various simplifications and to avoid passing extraneous args around
|
|
19
|
+
* - Use unsigned 16 bits (per coord) hashing (instead of 15 bits)
|
|
20
|
+
* - Re-use existing thi.ng/umbrella fns for some processing steps
|
|
21
|
+
* - Add small tolerance for colinear check
|
|
22
|
+
* - Rename `Node` => `Vertex`
|
|
23
|
+
* - Minor other refactoring (use of destructuring, add types, renames etc.)
|
|
24
|
+
*
|
|
25
|
+
* Original implementation Copyright (c) 2016, Mapbox, ISC License. Original
|
|
26
|
+
* author: Volodymyr Agafonkin
|
|
27
|
+
*
|
|
28
|
+
* References:
|
|
29
|
+
*
|
|
30
|
+
* - https://www.cosy.sbg.ac.at/~held/projects/triang/triang.html
|
|
31
|
+
* - https://www.geometrictools.com/Documentation/TriangulationByEarClipping.pdf
|
|
32
|
+
* - https://docs.thi.ng/umbrella/morton/
|
|
33
|
+
*
|
|
34
|
+
* @param holeIDs
|
|
35
|
+
* @param hashThreshold
|
|
36
|
+
*/
|
|
37
|
+
export declare const earCutComplex: (holeIDs?: number[], hashThreshold?: number) => Tessellator;
|
|
38
|
+
/**
|
|
39
|
+
* Takes an array of `boundary` points and another array of `holes` containing
|
|
40
|
+
* point arrays of individual holes. Concatenates all points (both boundary &
|
|
41
|
+
* holes) and returns a tuple of `[points, holeIDs]`, suitable for
|
|
42
|
+
* {@link earCutComplex}.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts tangle:../export/earcut-complex.ts
|
|
46
|
+
* import {
|
|
47
|
+
* earCutComplex, earCutComplexPrepare, tessellate
|
|
48
|
+
* } from "@thi.ng/geom-tessellate";
|
|
49
|
+
*
|
|
50
|
+
* const boundary = [[0,0], [100,0], [100,100], [0,100]];
|
|
51
|
+
* const hole = [[20,20],[50,80],[80,20]];
|
|
52
|
+
*
|
|
53
|
+
* const [points, holeIDs] = earCutComplexPrepare(boundary, [hole]);
|
|
54
|
+
*
|
|
55
|
+
* const tess = tessellate(points, earCutComplex(holeIDs));
|
|
56
|
+
*
|
|
57
|
+
* console.log(tess);
|
|
58
|
+
* // {
|
|
59
|
+
* // points: [
|
|
60
|
+
* // [ 0, 0 ], [ 100, 0 ], [ 100, 100 ], [ 0, 100 ],
|
|
61
|
+
* // [ 20, 20 ], [ 50, 80 ], [ 80, 20 ]
|
|
62
|
+
* // ],
|
|
63
|
+
* // indices: [
|
|
64
|
+
* // [ 0, 4, 5 ], [ 6, 4, 0 ], [ 3, 0, 5 ], [ 6, 0, 1 ],
|
|
65
|
+
* // [ 2, 3, 5 ], [ 5, 6, 1 ], [ 1, 2, 5 ]
|
|
66
|
+
* // ],
|
|
67
|
+
* // }
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @param boundary
|
|
71
|
+
* @param holes
|
|
72
|
+
*/
|
|
73
|
+
export declare const earCutComplexPrepare: (boundary: ReadonlyVec[], holes: ReadonlyVec[][]) => [ReadonlyVec[], number[]];
|
|
74
|
+
//# sourceMappingURL=earcut-complex.d.ts.map
|