| | | 1 | | //======================================================================= |
| | | 2 | | // VoxelContactManifold.cs |
| | | 3 | | //======================================================================= |
| | | 4 | | // MIT License, Copyright (c) 2024-present David Oravsky (mrdav30) |
| | | 5 | | // See LICENSE file in the project root for full license information. |
| | | 6 | | //======================================================================= |
| | | 7 | | |
| | | 8 | | using FixedMathSharp; |
| | | 9 | | using GridForge.Spatial; |
| | | 10 | | |
| | | 11 | | namespace GridForge.Grids.Topology; |
| | | 12 | | |
| | | 13 | | |
| | | 14 | | |
| | | 15 | | |
| | | 16 | | |
| | | 17 | | /// <summary> |
| | | 18 | | /// Describes exact point, edge, face, or volume contact between two cell prisms. |
| | | 19 | | /// </summary> |
| | | 20 | | public readonly struct VoxelContactManifold |
| | | 21 | | { |
| | | 22 | | /// <summary>The source cell identity.</summary> |
| | | 23 | | public WorldVoxelIndex Source { get; } |
| | | 24 | | |
| | | 25 | | /// <summary>The target cell identity.</summary> |
| | | 26 | | public WorldVoxelIndex Target { get; } |
| | | 27 | | |
| | | 28 | | /// <summary>The target-center displacement from the source center.</summary> |
| | | 29 | | public Vector3d SourceToTarget { get; } |
| | | 30 | | |
| | | 31 | | /// <summary>The exact contact classification.</summary> |
| | | 32 | | public VoxelContactKind Kind { get; } |
| | | 33 | | |
| | | 34 | | /// <summary>The face orientation when <see cref="Kind"/> is <see cref="VoxelContactKind.Face"/>.</summary> |
| | | 35 | | public VoxelContactFaceKind FaceKind { get; } |
| | | 36 | | |
| | | 37 | | /// <summary>The lower bound of the shared vertical interval or horizontal face plane.</summary> |
| | | 38 | | public Fixed64 VerticalMin { get; } |
| | | 39 | | |
| | | 40 | | /// <summary>The upper bound of the shared vertical interval or horizontal face plane.</summary> |
| | | 41 | | public Fixed64 VerticalMax { get; } |
| | | 42 | | |
| | | 43 | | /// <summary>The first endpoint of a vertical face's exact XZ contact segment.</summary> |
| | | 44 | | public Vector2d HorizontalSegmentStart { get; } |
| | | 45 | | |
| | | 46 | | /// <summary>The second endpoint of a vertical face's exact XZ contact segment.</summary> |
| | | 47 | | public Vector2d HorizontalSegmentEnd { get; } |
| | | 48 | | |
| | | 49 | | /// <summary>The exact overlap polygon for a horizontal face or volume overlap.</summary> |
| | | 50 | | public GridConvexPolygon2d HorizontalPolygon { get; } |
| | | 51 | | |
| | | 52 | | /// <summary>The face area, or horizontal overlap area for a volume overlap.</summary> |
| | | 53 | | public Fixed64 CheckedArea { get; } |
| | | 54 | | |
| | | 55 | | /// <summary>Whether <see cref="CheckedArea"/> is representable without saturation.</summary> |
| | | 56 | | public bool IsAreaRepresentable { get; } |
| | | 57 | | |
| | | 58 | | /// <summary>Whether this manifold can be considered as an automatic portal before agent clearance checks.</summary> |
| | | 59 | | public bool IsPositiveAreaFace => |
| | 2468 | 60 | | Kind == VoxelContactKind.Face |
| | 2468 | 61 | | && IsAreaRepresentable |
| | 2468 | 62 | | && CheckedArea > Fixed64.Zero; |
| | | 63 | | |
| | | 64 | | /// <summary>The exact width of a vertical face contact segment.</summary> |
| | 6 | 65 | | public Fixed64 VerticalFaceWidth => FaceKind == VoxelContactFaceKind.Vertical |
| | 6 | 66 | | ? Vector2d.Distance(HorizontalSegmentStart, HorizontalSegmentEnd) |
| | 6 | 67 | | : Fixed64.Zero; |
| | | 68 | | |
| | | 69 | | /// <summary>The exact height of a vertical face contact interval.</summary> |
| | 6 | 70 | | public Fixed64 VerticalFaceHeight => FaceKind == VoxelContactFaceKind.Vertical |
| | 6 | 71 | | ? VerticalMax - VerticalMin |
| | 6 | 72 | | : Fixed64.Zero; |
| | | 73 | | |
| | | 74 | | internal VoxelContactManifold( |
| | | 75 | | WorldVoxelIndex source, |
| | | 76 | | WorldVoxelIndex target, |
| | | 77 | | Vector3d sourceToTarget, |
| | | 78 | | VoxelContactKind kind, |
| | | 79 | | VoxelContactFaceKind faceKind, |
| | | 80 | | Fixed64 verticalMin, |
| | | 81 | | Fixed64 verticalMax, |
| | | 82 | | Vector2d horizontalSegmentStart, |
| | | 83 | | Vector2d horizontalSegmentEnd, |
| | | 84 | | GridConvexPolygon2d horizontalPolygon, |
| | | 85 | | Fixed64 checkedArea, |
| | | 86 | | bool isAreaRepresentable) |
| | | 87 | | { |
| | 2662 | 88 | | Source = source; |
| | 2662 | 89 | | Target = target; |
| | 2662 | 90 | | SourceToTarget = sourceToTarget; |
| | 2662 | 91 | | Kind = kind; |
| | 2662 | 92 | | FaceKind = faceKind; |
| | 2662 | 93 | | VerticalMin = verticalMin; |
| | 2662 | 94 | | VerticalMax = verticalMax; |
| | 2662 | 95 | | HorizontalSegmentStart = horizontalSegmentStart; |
| | 2662 | 96 | | HorizontalSegmentEnd = horizontalSegmentEnd; |
| | 2662 | 97 | | HorizontalPolygon = horizontalPolygon; |
| | 2662 | 98 | | CheckedArea = checkedArea; |
| | 2662 | 99 | | IsAreaRepresentable = isAreaRepresentable; |
| | 2662 | 100 | | } |
| | | 101 | | } |