Skip to content

Commit

Permalink
docs: status error codes
Browse files Browse the repository at this point in the history
  • Loading branch information
andywiecko committed Sep 18, 2024
1 parent 9864c79 commit 543369b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
39 changes: 25 additions & 14 deletions Documentation~/manual/advanced/input-validation.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
# Input validation

If [`ValidateInput`][validate] is set to true, the provided data will be validated before running the triangulation procedure. Input positions, as well as input constraints, have several restrictions:

- Points count must be greater/equal 3.
- Points positions cannot be duplicated.
- Points cannot contain NaNs or infinities.
- Constraint edges cannot intersect with each other.
- Constraint edges cannot be duplicated or swapped duplicated.
- Zero-length constraint edges are forbidden.
- Constraint edges cannot intersect with points other than the points for which they are defined.
- [`IgnoreConstraintForPlantingSeeds`][ignore-constraint] must have a length equal to half the length of [ConstraintEdges][constraints].
- If [`IgnoreConstraintForPlantingSeeds`][ignore-constraint] is provided, [`ConstraintEdges`][constraints] must also be provided.

If any of these conditions fail, triangulation will not be calculated. You can catch this as an error by using [`Status`][status] (native, can be used in jobs).
If [`ValidateInput`][validate] set to true, the provided [`InputData<T2>`][input-data] and [`TriangulationSettings`][settings] will be validated before executing the triangulation procedure.
The input
[`InputData<T2>.Positions`][positions],
[`InputData<T2>.ConstraintEdges`][constraints],
[`InputData<T2>.HoleSeeds`][holes],
and [`InputData<T2>.IgnoreConstraintForPlantingSeeds`][ignore-constraint] have certain restrictions:

- [Positions][positions] count must be greater or equal 3.
- [Positions][positions] and [HoleSeeds][holes] cannot contain NaNs or infinities.
- [Positions][positions] cannot be duplicated.
- [ConstraintEdges][constraints] should have length multiple of 2.
- [ConstraintEdges][constraints] should have constraints defined in [Positions][positions] range.
- [ConstraintEdges][constraints] cannot be duplicated, swapped duplicated, or create self-loop.
- [ConstraintEdges][constraints] cannot intersect with each other.
- [ConstraintEdges][constraints] cannot be collinear with positions which is not included in the constraint.
- [IgnoreConstraintForPlantingSeeds][ignore-constraint] must have a length equal to half the length of [ConstraintEdges][constraints].

If any of these conditions fail, triangulation will not be calculated. You can catch this as an error by using [`Status`][status-ref] (native reference, can be used in jobs).
For more details about error codes, refer to the [Status][status] API documentation.

```csharp
using var triangulator = new Triangulator(Allocator.Persistent)
Expand All @@ -32,6 +38,11 @@ var status = triangulator.Output.Status.Value;
> Input validation can be expensive. If you are certain of your input, consider disabling this option for additional performance.
[validate]: xref:andywiecko.BurstTriangulator.TriangulationSettings.ValidateInput
[status]: xref:andywiecko.BurstTriangulator.Status
[input-data]: xref:andywiecko.BurstTriangulator.InputData`1
[settings]: xref:andywiecko.BurstTriangulator.TriangulationSettings
[positions]: xref:andywiecko.BurstTriangulator.InputData`1.Positions
[constraints]: xref:andywiecko.BurstTriangulator.InputData`1.ConstraintEdges
[holes]: xref:andywiecko.BurstTriangulator.InputData`1.HoleSeeds
[ignore-constraint]: xref:andywiecko.BurstTriangulator.InputData`1.IgnoreConstraintForPlantingSeeds
[status-ref]: xref:andywiecko.BurstTriangulator.OutputData`1.Status
[status]: xref:andywiecko.BurstTriangulator.Status
9 changes: 7 additions & 2 deletions Documentation~/manual/examples/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var triangles = triangulator.Output.Triangles;
> If you want to call this within a jobs pipeline, schedule a job using [`triangulator.Schedule(dependencies)`][schedule].
> Click [**here**](xref:example-unity-jobs) to learn how to use triangulation within a jobs pipeline.
If triangulation fails for some reason, you can catch the information using [`Status`][status]
If triangulation fails for some reason, you can catch the information using [`Status`][status-ref]

```csharp
status = triangulator.Output.Status.Value;
Expand All @@ -32,6 +32,10 @@ if (status != Status.OK) // ERROR!
}
```

> [!WARNING]
> The [Status][status-ref] can be used to handle various error codes.
> For more information about other enum values, refer to the [API documentation][status].
The result of the triangulation procedure will depend on the selected settings.
There are a few settings for triangulation, which are briefly described in the [API documentation][settings].
Follow the articles in the manual to learn more about settings.
Expand All @@ -43,4 +47,5 @@ In other examples, the following *cool* guitar was used as an input test case:
[settings]: xref:andywiecko.BurstTriangulator.TriangulationSettings
[run]: xref:andywiecko.BurstTriangulator.Triangulator.Run
[schedule]: xref:andywiecko.BurstTriangulator.Triangulator.Schedule(Unity.Jobs.JobHandle)
[status]: xref:andywiecko.BurstTriangulator.OutputData`1.Status
[status-ref]: xref:andywiecko.BurstTriangulator.OutputData`1.Status
[status]: xref:andywiecko.BurstTriangulator.Status

0 comments on commit 543369b

Please sign in to comment.