Skip to content

Commit f94e526

Browse files
committed
docs: update manual
1 parent 32dc1b6 commit f94e526

File tree

3 files changed

+68
-26
lines changed

3 files changed

+68
-26
lines changed

Documentation~/manual/advanced/dynamic-triangulation.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ This feature is especially useful in scenarios like path-finding in RTS games, w
99

1010
## DynamicInsertPoint
1111

12-
The [DynamicInsertPoint][dynamic-insert-point] method allows you to insert a point into a specified triangle using barycentric coordinates. This method only supports point insertion within the original triangulation domain and cannot be used to insert points outside the existing mesh.
12+
The [`DynamicInsertPoint`][dynamic-insert-point] method allows you to insert a point into a specified triangle using barycentric coordinates. This method only supports point insertion within the original triangulation domain and cannot be used to insert points outside the existing mesh.
1313

1414
Inserting a point at specific `T2 p` coordinates can be computationally expensive since it requires locating the triangle that contains the point `p`.
1515
This package does not include acceleration structures, as it assumes the user will implement this based on their specific requirements.
1616
It is recommended to use structures such as bounding volume hierarchies, 2D trees, grids, or buckets for efficient point lookup (`p` $\to \triangle$).
1717
The most suitable acceleration structure may vary depending on the use case.
1818

19-
The [DynamicInsertPoint][dynamic-insert-point] method accepts the following parameters (in addition to `output` and `allocator`):
19+
The [`DynamicInsertPoint`][dynamic-insert-point] method accepts the following parameters (in addition to `output` and `allocator`):
2020

2121
- `tId` the index of the triangle where the point should be inserted.
2222
- `bar` the barycentric coordinates of the point inside triangle `tId`.
@@ -75,11 +75,11 @@ t.DynamicInsertPoint(output, tId: 42, bar: 1f / 3, allocator: Allocator.Persiste
7575
7676
## DynamicSplitHalfedge
7777
78-
The [DynamicSplitHalfedge][dynamic-split-halfedge] method allows you to split specified halfedge by inserting a point at a position determined by linear interpolation.
78+
The [`DynamicSplitHalfedge`][dynamic-split-halfedge] method allows you to split specified halfedge by inserting a point at a position determined by linear interpolation.
7979
The position is interpolated between the start and end points of the halfedge in the triangulation using $\alpha$ as the interpolation parameter.
8080
This method preserves the "constrained" state of the halfedge, meaning that if the specified halfedge is constrained, the two resulting sub-segments will also be marked as constrained.
8181
82-
The [DynamicSplitHalfedge][dynamic-split-halfedge] method accepts the following parameters (in addition to `output` and `allocator`):
82+
The [`DynamicSplitHalfedge`][dynamic-split-halfedge] method accepts the following parameters (in addition to `output` and `allocator`):
8383
8484
- `he` the index of the halfedge to split.
8585
- `alpha` the interpolation parameter for positioning the new point between the start and end points of the halfedge, where $p = (1 - \alpha) \, \text{start} + \alpha \, \text{end}$.
@@ -121,10 +121,10 @@ for(int i = 0; i < 32; i++)
121121
122122
## DynamicRemoveBulkPoint
123123

124-
The [DynamicRemoveBulkPoint][dynamic-remove-point] method allows you to remove bulk points, i.e. points which are not boundary ones, and re-triangulates the affected region to maintain a valid triangulation.
124+
The [`DynamicRemoveBulkPoint`][dynamic-remove-point] method allows you to remove bulk points, i.e. points which are not boundary ones, and re-triangulates the affected region to maintain a valid triangulation.
125125
In addition to `output` and `allocator`, the method requires the index of the point to be removed, specified as `pId`.
126126

127-
Below is an example demonstrating how to use the [DynamicRemoveBulkPoint][dynamic-remove-point] API:
127+
Below is an example demonstrating how to use the [`DynamicRemoveBulkPoint`][dynamic-remove-point] API:
128128

129129
```csharp
130130
using var inputPositions = new NativeArray<double2>(..., Allocator.Persistent);

Documentation~/manual/advanced/unsafe-triangulator.md

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Below, you can find extensions (with descriptions and examples) that can be used
8383

8484
### Triangulate
8585

86-
The extension [`Triangulate(input, output, args, allocator)`][triangulate] is the simplest option to use. The action of this extension essentially produces the same result as the [`Run`][run] method for the managed [`Triangulator`][triangulator]. It can be useful when triangulation is done with [`Allocator.Temp`][allocator-temp] in a single job or to combine this with different extensions.
86+
The extension [`Triangulate`][triangulate] is the simplest option to use. The action of this extension essentially produces the same result as the [`Run`][run] method for the managed [`Triangulator`][triangulator]. It can be useful when triangulation is done with [`Allocator.Temp`][allocator-temp] in a single job or to combine this with different extensions.
8787

8888
```csharp
8989
using var positions = new NativeArray<float2>(..., Allocator.Persistent);
@@ -100,7 +100,7 @@ new UnsafeTriangulator<float2>().Triangulate(
100100

101101
### ConstrainEdge
102102

103-
The [`ConstrainEdge(output, pi, pj, args, allocator, ignoreForPlantingSeeds)`][constrain-edge] extension allows for constraining the edge `(pi, pj)`.
103+
The [`ConstrainEdge`][constrain-edge] extension allows for constraining the edge `(pi, pj)`.
104104
This is especially useful during dynamic triangulation when the user wants to insert a path dynamically and constrain the edges.
105105
This method is restricted to **bulk** mesh, meaning the edge to be constrained must not intersect any holes.
106106
The optional parameter `ignoreForPlantingSeeds` is used to ignore the halfedges corresponding to `(pi, pj)` during the seed planting step.
@@ -130,16 +130,14 @@ var output = new NativeOutputData<double2>
130130
IgnoredHalfedgesForPlantingSeeds = ignoredHalfedgesForPlantingSeeds,
131131
};
132132

133-
var args = Args.Default();
134-
135133
var t = new UnsafeTriangulator<double2>();
136-
t.Triangulate(input, output, args, Allocator.Persistent);
137-
t.ConstrainEdge(output, pi: 0, pj: 1, args, allocator: Allocator.Persistent, ignoreForPlantingSeeds: true);
134+
t.Triangulate(input, output, args: Args.Default(), Allocator.Persistent);
135+
t.ConstrainEdge(output, pi: 0, pj: 1, allocator: Allocator.Persistent, ignoreForPlantingSeeds: true);
138136
```
139137

140138
### PlantHoleSeeds
141139

142-
The extension [`PlantHoleSeeds(input, output, args, allocator)`][plant-seeds] is particularly useful when the user requires mesh data *without* removed triangles and additional mesh copy *with* removed triangles. In this case, the triangulation is performed once, which is generally a more expensive operation. Below is an example usage with the `autoHolesAndBoundary` option selected:
140+
The extension [`PlantHoleSeeds`][plant-seeds] is particularly useful when the user requires mesh data *without* removed triangles and additional mesh copy *with* removed triangles. In this case, the triangulation is performed once, which is generally a more expensive operation. Below is an example usage with the `autoHolesAndBoundary` option selected:
143141

144142
```csharp
145143
var input = new NativeInputData<double2>
@@ -156,18 +154,39 @@ var output = new NativeOutputData<double2>
156154
Halfedges = halfedges,
157155
ConstrainedHalfedges = constrainedHalfedges,
158156
};
159-
var args = Args.Default();
160157
var t = new UnsafeTriangulator<double2>();
161-
t.Triangulate(input, output, args), Allocator.Persistent);
162-
t.PlantHoleSeeds(input, output, args.With(autoHolesAndBoundary: true), Allocator.Persistent);
158+
t.Triangulate(input, output, args.Default(), Allocator.Persistent);
159+
t.PlantHoleSeeds(output, Allocator.Persistent, autoHolesAndBoundary: true);
163160
```
164161

165-
> [!NOTE]
162+
> [!NOTE]
166163
> Depending on the options, some of the buffers may not be required for [`PlantHoleSeeds`][plant-seeds]. For example, when the user provides `HoleSeeds` in [`NativeInputData<T2>`][n-output-data], `Positions` in [`NativeOutputData<T2>`][n-output-data] must be provided. However, in other cases, it may not be required.
167164
165+
The extension provides also an option to generate a `mapping` from the initial triangles (`t1`) to the triangles after planting seeds (`t2`).
166+
The condition `t1[3*i + k] == t2[mapping[3*i + k]]` (for $k\in\{0, 1, 2\}$) should hold for triangles that still exist in `t2`.
167+
If `mapping[i] == -1`, then the corresponding triangle `i` no longer exists in `t2`.
168+
See example below:
169+
170+
```csharp
171+
var t = new UnsafeTriangulator<double2>();
172+
173+
using var triangles1 = new NativeList<int>(Allocator.Persistent);
174+
t.Triangulate(input, output: new(){ Triangles = triangles1, ... }, args.Default(), Allocator.Persistent);
175+
176+
using var mapping = new NativeList<int>(Allocator.Persistent);
177+
using var triangles2 = new NativeList<int>(Allocator.Persistent);
178+
triangles2.CopyFrom(triangles1);
179+
t.PlantHoleSeeds(new(){ Triangles = triangles2, ... }, Allocator.Persistent, mapping: mapping);
180+
181+
// The result:
182+
// - `triangles1`: the initial triangles buffer before planting seeds.
183+
// - `triangles2`: the triangles after planting seeds.
184+
// - `mapping`: `triangles1` → `triangles2`.
185+
```
186+
168187
### RefineMesh
169188

170-
The extension [`RefineMesh(output, allocator, areaThreshold?, angleThreshold?, concentricShells?, constrainBoundary?)`][refine-mesh] can be used to refine any triangulation mesh, even an already refined one. Please note that both the managed [`TriangulationSettings`][m-settings] and native [`Args`][n-args] provide refinement parameter setups only for [`float`][float] precision. This extension allows you to provide these parameters with the selected precision type `T` in generics. These parameters have the following default values (in the given precision type `T`, if this extension is available for `T`):
189+
The extension [`RefineMesh`][refine-mesh] can be used to refine any triangulation mesh, even an already refined one. Please note that both the managed [`TriangulationSettings`][m-settings] and native [`Args`][n-args] provide refinement parameter setups only for [`float`][float] precision. This extension allows you to provide these parameters with the selected precision type `T` in generics. These parameters have the following default values (in the given precision type `T`, if this extension is available for `T`):
171190

172191
- `areaThreshold = 1`;
173192
- `angleThreshold = math.radians(5)`

Documentation~/manual/utilities.md

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,31 @@ uid: utilities-md
66

77
The package also provides several utilities related to triangulations.
88
These utilities can be found in the [Utilities] and [Extensions] classes.
9+
Most of the utilities are *Burst-compatible* and are implemented using spans, so they can be used with any collection type.
10+
11+
## BoundingBox
12+
13+
The method [`BoundingBox`][bounding-box] returns *axis-aligned bounding box* for provided collection of points.
14+
It supports all position types (`float2`/`int2`/`double2`/`fp2`), see example below:
15+
16+
```csharp
17+
var positions = new float2[]{ ... };
18+
var (min, max) = Utilities.BoundingBox(positions);
19+
```
20+
21+
## CenterOfMass
22+
23+
The method [`CenterOfMass`][center-of-mass] returns *center of mass* (COM) for provided collection of points, assuming equal weights for all positions.
24+
It supports all position types (`float2`/`int2`/`double2`/`fp2`), see example below:
25+
26+
```csharp
27+
var positions = new float2[]{ ... };
28+
var com = Utilities.CenterOfMass(positions);
29+
```
930

1031
## GenerateHalfedges
1132

12-
The method [GenerateHalfedges(Span&lt;int&gt; halfedges, ReadOnlySpan&lt;int&gt; triangles, Allocator allocator)][generate-halfedges] can be used to generate halfedges based on the given triangles. The provided `allocator` is used for temporary data allocation.
33+
The method [`GenerateHalfedges`][generate-halfedges] can be used to generate halfedges based on the given triangles. The provided `allocator` is used for temporary data allocation.
1334
This function is especially useful when you have mesh data but need to use halfedges, for example, when iterating through the mesh.
1435
Learn more about halfedges [here](advanced/output-halfedges.md).
1536

@@ -25,7 +46,7 @@ Utilities.GenerateHalfedges(halfdeges, triangles, Allocator.Persistent);
2546

2647
## GeneratePointTriangleCount
2748

28-
The method [GeneratePointTriangleCount][generate-point-triangle-count] populates the `pointTriangleCount` buffer with the number of triangles each vertex index is part of, based on the provided triangles index buffer.
49+
The method [`GeneratePointTriangleCount`][generate-point-triangle-count] populates the `pointTriangleCount` buffer with the number of triangles each vertex index is part of, based on the provided triangles index buffer.
2950
The provided `pointTriangleCount` buffer for counting triangles must be large enough to accommodate the highest index in `triangles`.
3051
An example usage is shown below:
3152

@@ -36,7 +57,7 @@ Utilities.GeneratePointTriangleCount(pointTriangleCount, triangles);
3657

3758
## GenerateTriangleColors
3859

39-
The method [GenerateTriangleColors][generate-triangle-colors] can be used to generate triangle colors using the provided halfedges.
60+
The method [`GenerateTriangleColors`][generate-triangle-colors] can be used to generate triangle colors using the provided halfedges.
4061
Triangles that share a common edge are assigned the same color index.
4162
The resulting colors contains values in the range $[0, \,\mathtt{colorsCount})$.
4263
Below is an illustration of an example coloring result, where colors represent actual visual colors rather than ids.
@@ -57,7 +78,7 @@ Utilities.GenerateTriangleColors(colors, halfedges, out var colorsCount, Allocat
5778

5879
## InsertSubMesh
5980

60-
The [InsertSubMesh][insert-submesh] utility can be used to combine meshes by inserting a sub-mesh into the *main* mesh.
81+
The [`InsertSubMesh`][insert-submesh] utility can be used to combine meshes by inserting a sub-mesh into the *main* mesh.
6182
In such cases, triangle indices must be adjusted accordingly, and this method handles that for you.
6283

6384
Example usage:
@@ -77,7 +98,7 @@ Utilities.InsertSubMesh(positions, triangles, subpositions, subtriangles);
7798

7899
## NextHalfedge
79100

80-
The [NextHalfedge(int he)][next-halfedge] method is a simple yet powerful utility.
101+
The [`NextHalfedge`][next-halfedge] method is a simple yet powerful utility.
81102
As its name suggests, it returns the index of the next halfedge.
82103
This is particularly useful when iterating through a triangular mesh.
83104
Learn more about halfedges [here](advanced/output-halfedges.md).
@@ -105,7 +126,7 @@ for (int he = 0; he < halfedges.Length; he++)
105126
## Retriangulate
106127

107128
This package provides a utility for [Mesh](xref:UnityEngine.Mesh) retriangulation.
108-
To retriangulate a mesh, use [Retriangulate] extension method.
129+
To retriangulate a mesh, use [`Retriangulate`][retriangulate] extension method.
109130
This method supports non-uniform meshes, including those with *windmill*-like connections between triangles (e.g., the red and blue triangles in the figure in [GenerateTriangleColors](#generatetrianglecolors)).
110131
See the example below:
111132

@@ -123,7 +144,7 @@ mesh.Retriangulate(
123144
```
124145

125146
> [!NOTE]
126-
> Refer to the [Retriangulate] API documentation for additional settings.
147+
> Refer to the [`Retriangulate`][retriangulate] API documentation for additional settings.
127148
128149
For more advanced use cases, [`Utilities.RetriangulateMeshJob`][retrianglate-mesh-job] provides greater customization.
129150
This job can be executed on the main thread, scheduled within the Job System, or run inside another job.
@@ -147,10 +168,12 @@ dependencies.Complete();
147168

148169
[Utilities]: xref:andywiecko.BurstTriangulator.Utilities
149170
[Extensions]: xref:andywiecko.BurstTriangulator.Extensions
171+
[bounding-box]: xref:andywiecko.BurstTriangulator.Utilities.BoundingBox*
172+
[center-of-mass]: xref:andywiecko.BurstTriangulator.Utilities.CenterOfMass*
150173
[generate-halfedges]: xref:andywiecko.BurstTriangulator.Utilities.GenerateHalfedges*
151174
[generate-point-triangle-count]: xref:andywiecko.BurstTriangulator.Utilities.GeneratePointTriangleCount*
152175
[generate-triangle-colors]: xref:andywiecko.BurstTriangulator.Utilities.GenerateTriangleColors*
153176
[insert-submesh]: xref:andywiecko.BurstTriangulator.Utilities.InsertSubMesh*
154177
[next-halfedge]: xref:andywiecko.BurstTriangulator.Utilities.NextHalfedge*
155-
[Retriangulate]: xref:andywiecko.BurstTriangulator.Extensions.Retriangulate*
178+
[retriangulate]: xref:andywiecko.BurstTriangulator.Extensions.Retriangulate*
156179
[retrianglate-mesh-job]: xref:andywiecko.BurstTriangulator.Utilities.RetriangulateMeshJob

0 commit comments

Comments
 (0)