| | | 1 | | //======================================================================= |
| | | 2 | | // MeshSurfaceConnectivity.cs |
| | | 3 | | //======================================================================= |
| | | 4 | | // MIT License, Copyright (c) 2026-present David Oravsky (mrdav30) |
| | | 5 | | // See LICENSE file in the project root for full license information. |
| | | 6 | | //======================================================================= |
| | | 7 | | |
| | | 8 | | using System; |
| | | 9 | | using System.Collections.Generic; |
| | | 10 | | using FixedMathSharp; |
| | | 11 | | using FixedMathSharp.Geometry; |
| | | 12 | | using Gravitas.Colliders; |
| | | 13 | | using SwiftCollections; |
| | | 14 | | |
| | | 15 | | namespace Gravitas.CollisionHandling; |
| | | 16 | | |
| | | 17 | | /// <summary>Retains exact admitted connectivity for one prepared mesh surface.</summary> |
| | | 18 | | internal sealed class MeshSurfaceConnectivity |
| | | 19 | | { |
| | 21572 | 20 | | private readonly SwiftDictionary<int, int> _nodeByTriangle = new(); |
| | 21572 | 21 | | private readonly SwiftList<int> _triangles = new(); |
| | 21572 | 22 | | private readonly SwiftList<int> _parents = new(); |
| | 21572 | 23 | | private readonly SwiftList<int> _regionByRoot = new(); |
| | 21572 | 24 | | private readonly SwiftList<int> _roots = new(); |
| | 21572 | 25 | | private readonly SwiftHashSet<int> _visitedVertices = new(); |
| | | 26 | | private readonly IComparer<int> _regionComparer; |
| | 21572 | 27 | | private ulong[] _minimumValues = Array.Empty<ulong>(); |
| | 21572 | 28 | | private int[] _minimumSigns = Array.Empty<int>(); |
| | 21572 | 29 | | private bool[] _hasMinimum = Array.Empty<bool>(); |
| | 21572 | 30 | | private int[] _boundaryRanks = Array.Empty<int>(); |
| | | 31 | | private bool _ordersSupport; |
| | | 32 | | |
| | 137600 | 33 | | internal int RegionCount => _roots.Count; |
| | | 34 | | |
| | 111462 | 35 | | internal ReadOnlySpan<int> TriangleIndices => _triangles.AsReadOnlySpan(); |
| | | 36 | | |
| | | 37 | | internal bool IsCompleteSingleRegion(PhysicsMesh mesh) |
| | | 38 | | { |
| | 5770 | 39 | | if (RegionCount != 1) return false; |
| | | 40 | | // Prepared connected owners record every shared-edge neighbor. A |
| | | 41 | | // nonempty admitted subset closed under them contains the whole owner. |
| | 24837 | 42 | | foreach (int triangle in TriangleIndices) |
| | 40267 | 43 | | foreach (int neighbor in mesh.GetCoplanarTriangleNeighbors(triangle)) |
| | 18750 | 44 | | if (GetRegionOrdinal(neighbor) != 0) return false; |
| | 489 | 45 | | return true; |
| | | 46 | | } |
| | | 47 | | |
| | 43144 | 48 | | internal MeshSurfaceConnectivity() => _regionComparer = Comparer<int>.Create(CompareRegions); |
| | | 49 | | |
| | | 50 | | internal void Build(PhysicsMesh mesh, int surfaceTriangle, Vector3d coneCenter, |
| | | 51 | | FixedQuaternion coneRotation, Fixed64 height, Fixed64 radius, ReadOnlySpan<int> admittedTriangles) |
| | | 52 | | { |
| | 518 | 53 | | mesh.GetGeometryTriangleVertices(surfaceTriangle, out Vector3d a, out Vector3d b, out Vector3d c); |
| | 518 | 54 | | var frame = new ConePlaneRayFrame(new FixedTriangle(a, b, c), mesh.GeometryFrame, |
| | 518 | 55 | | coneCenter, coneRotation, height, radius); |
| | 518 | 56 | | Build(mesh, surfaceTriangle, frame, admittedTriangles); |
| | 518 | 57 | | } |
| | | 58 | | |
| | | 59 | | internal void BuildCapsule(PhysicsMesh mesh, int surfaceTriangle, Vector3d capsuleCenter, |
| | | 60 | | FixedQuaternion capsuleRotation, Fixed64 coreLength, Fixed64 radius, ReadOnlySpan<int> admittedTriangles) |
| | | 61 | | { |
| | 161 | 62 | | var frame = new CapsuleFiniteSectionFrame(mesh.GeometryFrame, capsuleCenter, capsuleRotation, coreLength, radius |
| | 161 | 63 | | Build(mesh, surfaceTriangle, new CapsuleSection(frame), admittedTriangles); |
| | 161 | 64 | | } |
| | | 65 | | |
| | | 66 | | internal void BuildCapsule(PhysicsMesh mesh, int surfaceTriangle, in CapsuleFiniteSectionFrame frame, |
| | 26059 | 67 | | ReadOnlySpan<int> admittedTriangles) => Build(mesh, surfaceTriangle, new CapsuleSection(frame), admittedTriangle |
| | | 68 | | |
| | | 69 | | internal void BuildSlab(PhysicsMesh mesh, int surfaceTriangle, in FiniteSlabSectionFrame frame, |
| | | 70 | | LSCollider2D? embedded, ReadOnlySpan<int> admittedTriangles) => |
| | 2492 | 71 | | Build(mesh, surfaceTriangle, new SlabSection(frame, embedded), admittedTriangles); |
| | | 72 | | |
| | | 73 | | internal void BuildSlab(PhysicsMesh mesh, int surfaceTriangle, in FiniteSlabSectionFrame frame, |
| | | 74 | | ReadOnlyMemory<Vector2d> offsets, ReadOnlySpan<int> admittedTriangles) => |
| | 18977 | 75 | | Build(mesh, surfaceTriangle, new SlabSection(frame, null, offsets), admittedTriangles); |
| | | 76 | | |
| | | 77 | | internal void Build(PhysicsMesh mesh, int surfaceTriangle, in ConePlaneRayFrame frame, ReadOnlySpan<int> admittedTri |
| | 12410 | 78 | | Build(mesh, surfaceTriangle, new ConeSection(frame), admittedTriangles); |
| | | 79 | | |
| | | 80 | | /// <remarks> |
| | | 81 | | /// The input contains every exactly admitted triangle, without duplicates. |
| | | 82 | | /// Only the seed's prepared surface owner is consumed. Preparation alone |
| | | 83 | | /// never establishes connectivity: every join needs finite shape admission. |
| | | 84 | | /// </remarks> |
| | | 85 | | private void Build<TSection>(PhysicsMesh mesh, int surfaceTriangle, in TSection section, ReadOnlySpan<int> admittedT |
| | | 86 | | where TSection : struct, ISection |
| | | 87 | | { |
| | 60099 | 88 | | BuildGraph(mesh, surfaceTriangle, section, admittedTriangles); |
| | 60099 | 89 | | _ordersSupport = false; |
| | 60099 | 90 | | OrderRegions(mesh, surfaceTriangle, section); |
| | 60099 | 91 | | } |
| | | 92 | | |
| | | 93 | | private void BuildGraph<TSection>(PhysicsMesh mesh, int surfaceTriangle, in TSection section, ReadOnlySpan<int> admi |
| | | 94 | | where TSection : struct, IAdmission |
| | | 95 | | { |
| | 180501 | 96 | | _nodeByTriangle.Clear(); _triangles.FastClear(); _parents.FastClear(); |
| | 120334 | 97 | | _regionByRoot.FastClear(); _roots.FastClear(); |
| | 60167 | 98 | | _visitedVertices.Clear(); |
| | 65766 | 99 | | if (admittedTriangles.IsEmpty) return; |
| | 54568 | 100 | | int owner = mesh.GetManifoldSurfaceOwner(surfaceTriangle); |
| | 54568 | 101 | | _nodeByTriangle.EnsureCapacity(admittedTriangles.Length); |
| | 54568 | 102 | | _triangles.EnsureCapacity(admittedTriangles.Length); |
| | 54568 | 103 | | _parents.EnsureCapacity(admittedTriangles.Length); |
| | 54568 | 104 | | _regionByRoot.EnsureCapacity(admittedTriangles.Length); |
| | 54568 | 105 | | _roots.EnsureCapacity(admittedTriangles.Length); |
| | 54568 | 106 | | _visitedVertices.EnsureCapacity(admittedTriangles.Length * 3); |
| | 281482 | 107 | | foreach (int triangle in admittedTriangles) |
| | | 108 | | { |
| | 86173 | 109 | | if (mesh.GetManifoldSurfaceOwner(triangle) != owner) continue; |
| | 86167 | 110 | | int node = _triangles.Count; |
| | 172334 | 111 | | _nodeByTriangle.Add(triangle, node); _triangles.Add(triangle); |
| | 172334 | 112 | | _parents.Add(node); _regionByRoot.Add(-1); |
| | | 113 | | } |
| | 54570 | 114 | | if (_triangles.Count == 0) return; |
| | 54566 | 115 | | JoinAdmittedFeatures(mesh, section); |
| | 281466 | 116 | | for (int node = 0; node < _triangles.Count; node++) |
| | | 117 | | { |
| | 86167 | 118 | | int root = Find(node); |
| | 86167 | 119 | | if (_regionByRoot[root] < 0) |
| | | 120 | | { |
| | 55945 | 121 | | _regionByRoot[root] = _roots.Count; |
| | 55945 | 122 | | _roots.Add(root); |
| | | 123 | | } |
| | | 124 | | } |
| | 54566 | 125 | | } |
| | | 126 | | |
| | | 127 | | private void OrderRegions<TSection>(PhysicsMesh mesh, int surfaceTriangle, in TSection section) |
| | | 128 | | where TSection : struct, ISection |
| | | 129 | | { |
| | | 130 | | // If a connected section misses the true domain boundary it is the |
| | | 131 | | // whole convex shape section, hence the only region. Otherwise exact |
| | | 132 | | // minima on exposed segments order regions independently of authored |
| | | 133 | | // diagonals, discovery order and collinear perimeter subdivision. |
| | 60099 | 134 | | if (_roots.Count > 1) |
| | | 135 | | { |
| | | 136 | | // One region always has ordinal zero. Its exact boundary extrema |
| | | 137 | | // cannot affect ordering, so neither retain nor evaluate them. |
| | 466 | 138 | | if (_minimumValues.Length < _roots.Count * FiniteSectionPoint.StorageWords) |
| | | 139 | | { |
| | 61 | 140 | | Array.Resize(ref _minimumValues, _roots.Count * FiniteSectionPoint.StorageWords); |
| | 61 | 141 | | Array.Resize(ref _minimumSigns, _roots.Count * FiniteSectionPoint.SignCount); |
| | 61 | 142 | | Array.Resize(ref _hasMinimum, _roots.Count); |
| | | 143 | | } |
| | 466 | 144 | | Array.Clear(_hasMinimum, 0, _roots.Count); |
| | 466 | 145 | | FindBoundaryMinima(mesh, surfaceTriangle, section); |
| | | 146 | | #if DEBUG |
| | | 147 | | for (int region = 0; region < _roots.Count; region++) |
| | | 148 | | System.Diagnostics.Debug.Assert(_hasMinimum[region]); |
| | | 149 | | #endif |
| | 466 | 150 | | _roots.SortInPlace(_regionComparer); |
| | | 151 | | } |
| | 231892 | 152 | | for (int region = 0; region < _roots.Count; region++) |
| | 55847 | 153 | | _regionByRoot[_roots[region]] = region; |
| | 60099 | 154 | | } |
| | | 155 | | |
| | | 156 | | internal void BuildSlabSupport(PhysicsMesh mesh, int surfaceTriangle, MeshSlabFaceRegions faces, |
| | | 157 | | LSCollider2D? embedded, ReadOnlySpan<int> admittedTriangles) => |
| | 55 | 158 | | BuildSupport(mesh, surfaceTriangle, new SlabSupport(faces, embedded), admittedTriangles); |
| | | 159 | | |
| | | 160 | | internal void BuildHullSupport(PhysicsMesh mesh, int surfaceTriangle, MeshHullSurfaceContacts faces, |
| | | 161 | | ReadOnlySpan<int> admittedTriangles) => |
| | 13 | 162 | | BuildSupport(mesh, surfaceTriangle, new HullSupport(faces), admittedTriangles); |
| | | 163 | | |
| | | 164 | | private void BuildSupport<TSupport>(PhysicsMesh mesh, int surfaceTriangle, in TSupport support, |
| | | 165 | | ReadOnlySpan<int> admittedTriangles) where TSupport : struct, ISupport |
| | | 166 | | { |
| | 68 | 167 | | BuildGraph(mesh, surfaceTriangle, support, admittedTriangles); |
| | 68 | 168 | | _ordersSupport = true; |
| | 68 | 169 | | if (_roots.Count > 1) |
| | | 170 | | { |
| | 58 | 171 | | if (_boundaryRanks.Length < _parents.Count) Array.Resize(ref _boundaryRanks, _parents.Count); |
| | 30 | 172 | | Array.Fill(_boundaryRanks, int.MaxValue, 0, _parents.Count); |
| | 30 | 173 | | ReadOnlySpan<int> edges = mesh.GetCanonicalSurfaceBoundaryVertexPairs(surfaceTriangle); |
| | 30 | 174 | | int owner = mesh.GetManifoldSurfaceOwner(surfaceTriangle); |
| | 540 | 175 | | for (int edge = 0; edge < edges.Length; edge += 2) |
| | | 176 | | { |
| | 240 | 177 | | int region = support.FindEdgeRegion(mesh, owner, edges[edge], edges[edge + 1], this); |
| | 356 | 178 | | if (region >= 0) _boundaryRanks[_roots[region]] = Math.Min(_boundaryRanks[_roots[region]], edge / 2); |
| | | 179 | | } |
| | | 180 | | // A convex support footprint meets a straight boundary span in one |
| | | 181 | | // interval: distinct connected regions have distinct boundary ranks. |
| | | 182 | | #if DEBUG |
| | | 183 | | foreach (int root in _roots.AsReadOnlySpan()) System.Diagnostics.Debug.Assert(_boundaryRanks[root] != int.Ma |
| | | 184 | | #endif |
| | 30 | 185 | | _roots.SortInPlace(_regionComparer); |
| | | 186 | | } |
| | 430 | 187 | | for (int region = 0; region < _roots.Count; region++) _regionByRoot[_roots[region]] = region; |
| | 68 | 188 | | } |
| | | 189 | | |
| | 142084 | 190 | | internal int GetRegionOrdinal(int triangleIndex) => _nodeByTriangle.TryGetValue(triangleIndex, out int node) |
| | 142084 | 191 | | ? _regionByRoot[Find(node)] : -1; |
| | | 192 | | |
| | | 193 | | private void JoinAdmittedFeatures<TSection>(PhysicsMesh mesh, in TSection section) where TSection : struct, IAdmissi |
| | | 194 | | { |
| | 54566 | 195 | | int components = _triangles.Count; |
| | 99137 | 196 | | if (components == 1) return; |
| | | 197 | | // Exact admitted joins are transitive. Once every node is connected, |
| | | 198 | | // further feature tests cannot change the single region or its ordinal. |
| | 9995 | 199 | | ReadOnlySpan<Vector3d> vertices = mesh.GeometryVertices; |
| | 41900 | 200 | | for (int node = 0; node < _triangles.Count; node++) |
| | | 201 | | { |
| | 20454 | 202 | | int triangle = _triangles[node]; |
| | 20454 | 203 | | ReadOnlySpan<int> welded = mesh.GetWeldedTriangleVertexIndices(triangle); |
| | 104488 | 204 | | foreach (int neighbor in mesh.GetCoplanarTriangleNeighbors(triangle)) |
| | | 205 | | { |
| | 36002 | 206 | | if (!_nodeByTriangle.TryGetValue(neighbor, out int other) || other <= node) continue; |
| | 25298 | 207 | | ReadOnlySpan<int> adjacent = mesh.GetWeldedTriangleVertexIndices(neighbor); |
| | 50596 | 208 | | int first = -1, second = -1; |
| | 202384 | 209 | | foreach (int vertex in welded) |
| | 75894 | 210 | | if (adjacent.IndexOf(vertex) >= 0) |
| | | 211 | | { |
| | 75894 | 212 | | if (first < 0) first = vertex; |
| | 25298 | 213 | | else second = vertex; |
| | | 214 | | } |
| | | 215 | | System.Diagnostics.Debug.Assert(first >= 0 && second >= 0); |
| | 25298 | 216 | | if (section.IntersectsSegment(new FixedSegment(vertices[first], vertices[second])) |
| | 33722 | 217 | | && Union(node, other) && --components == 1) return; |
| | | 218 | | } |
| | 93143 | 219 | | foreach (int vertex in welded) |
| | | 220 | | { |
| | | 221 | | // Each welded star is traversed once, even when an admitted |
| | | 222 | | // center belongs to every face of a large planar fan. |
| | 35079 | 223 | | if (!_visitedVertices.Add(vertex) || !section.ContainsPoint(vertices[vertex])) continue; |
| | 41649 | 224 | | foreach (int incident in mesh.GetWeldedVertexTriangleIndices(vertex)) |
| | 16330 | 225 | | if (_nodeByTriangle.TryGetValue(incident, out int other) |
| | 17405 | 226 | | && Union(node, other) && --components == 1) return; |
| | | 227 | | } |
| | | 228 | | } |
| | 496 | 229 | | } |
| | | 230 | | |
| | | 231 | | private void FindBoundaryMinima<TSection>(PhysicsMesh mesh, int surfaceTriangle, in TSection section) where TSection |
| | | 232 | | { |
| | 466 | 233 | | Span<ulong> values = stackalloc ulong[FiniteSectionPoint.StorageWords]; |
| | 466 | 234 | | Span<int> signs = stackalloc int[FiniteSectionPoint.SignCount]; |
| | 466 | 235 | | var point = new FiniteSectionPoint(values, signs); |
| | 466 | 236 | | ReadOnlySpan<int> pairs = mesh.GetManifoldSurfaceBoundaryVertexPairs(surfaceTriangle); |
| | 466 | 237 | | ReadOnlySpan<Vector3d> vertices = mesh.GeometryVertices; |
| | | 238 | | // Multiple regions require a certified patch with a true perimeter. |
| | | 239 | | // A declined owner contains only its single convex triangle section. |
| | | 240 | | System.Diagnostics.Debug.Assert(!pairs.IsEmpty); |
| | 32042 | 241 | | for (int edge = 0; edge < pairs.Length; edge += 2) KeepBoundaryPoint(mesh, pairs[edge], pairs[edge + 1], section |
| | 466 | 242 | | } |
| | | 243 | | |
| | | 244 | | private void KeepBoundaryPoint<TSection>(PhysicsMesh mesh, int first, int second, in TSection section, |
| | | 245 | | FiniteSectionPoint point, ReadOnlySpan<Vector3d> vertices) where TSection : struct, ISection |
| | | 246 | | { |
| | 15771 | 247 | | if (!section.TryGetFirstSegmentPoint(new FixedSegment(vertices[first], vertices[second]), point)) return; |
| | 24621 | 248 | | foreach (int triangle in mesh.GetWeldedVertexTriangleIndices(first)) |
| | | 249 | | { |
| | 9826 | 250 | | if (!_nodeByTriangle.TryGetValue(triangle, out int node) |
| | 9826 | 251 | | || mesh.GetWeldedTriangleVertexIndices(triangle).IndexOf(second) < 0) continue; |
| | 4969 | 252 | | int region = _regionByRoot[Find(node)]; |
| | 4969 | 253 | | FiniteSectionPoint minimum = Minimum(region); |
| | 4969 | 254 | | if (!_hasMinimum[region] || FiniteSectionPoint.CompareLexicographic(point, minimum) < 0) |
| | | 255 | | { |
| | 3798 | 256 | | point.CopyTo(minimum); _hasMinimum[region] = true; |
| | | 257 | | } |
| | 1899 | 258 | | break; // A trusted exposed edge has one owner on this surface. |
| | | 259 | | } |
| | 3070 | 260 | | } |
| | | 261 | | |
| | 2118 | 262 | | private int CompareRegions(int first, int second) => _ordersSupport ? _boundaryRanks[first].CompareTo(_boundaryRanks |
| | 2118 | 263 | | : FiniteSectionPoint.CompareLexicographic(Minimum(_regionByRoot[first]), Minimum(_regionByRoot[second])); |
| | | 264 | | |
| | 9145 | 265 | | private FiniteSectionPoint Minimum(int region) => new(_minimumValues.AsSpan(region * FiniteSectionPoint.StorageWords |
| | 9145 | 266 | | _minimumSigns.AsSpan(region * FiniteSectionPoint.SignCount, FiniteSectionPoint.SignCount)); |
| | | 267 | | |
| | | 268 | | private int Find(int node) |
| | | 269 | | { |
| | 310006 | 270 | | int root = node; |
| | 507918 | 271 | | while (_parents[root] != root) root = _parents[root]; |
| | 408962 | 272 | | while (_parents[node] != node) |
| | | 273 | | { |
| | 296868 | 274 | | int next = _parents[node]; _parents[node] = root; node = next; |
| | | 275 | | } |
| | 310006 | 276 | | return root; |
| | | 277 | | } |
| | | 278 | | |
| | | 279 | | private bool Union(int first, int second) |
| | | 280 | | { |
| | 82358 | 281 | | first = Find(first); second = Find(second); |
| | 52136 | 282 | | if (first == second) return false; |
| | 30222 | 283 | | _parents[Math.Max(first, second)] = Math.Min(first, second); |
| | 30222 | 284 | | return true; |
| | | 285 | | } |
| | | 286 | | |
| | | 287 | | // Constrained value-type calls share the graph without delegates, boxing, |
| | | 288 | | // or storing both shape frames in every operation. |
| | | 289 | | private interface IAdmission |
| | | 290 | | { |
| | | 291 | | bool ContainsPoint(Vector3d point); |
| | | 292 | | bool IntersectsSegment(FixedSegment segment); |
| | | 293 | | } |
| | | 294 | | |
| | | 295 | | private interface ISection : IAdmission |
| | | 296 | | { |
| | | 297 | | bool TryGetFirstSegmentPoint(FixedSegment segment, FiniteSectionPoint point); |
| | | 298 | | } |
| | | 299 | | |
| | | 300 | | private interface ISupport : IAdmission |
| | | 301 | | { |
| | | 302 | | int FindEdgeRegion(PhysicsMesh mesh, int owner, int first, int second, MeshSurfaceConnectivity connectivity); |
| | | 303 | | } |
| | | 304 | | |
| | | 305 | | private readonly struct HullSupport : ISupport |
| | | 306 | | { |
| | | 307 | | private readonly MeshHullSurfaceContacts faces; |
| | 13 | 308 | | internal HullSupport(MeshHullSurfaceContacts faces) => this.faces = faces; |
| | 64 | 309 | | public bool ContainsPoint(Vector3d point) => IntersectsSegment(new FixedSegment(point, point)); |
| | 89 | 310 | | public bool IntersectsSegment(FixedSegment segment) => faces.IntersectsSupport(segment); |
| | | 311 | | public int FindEdgeRegion(PhysicsMesh mesh, int owner, int first, int second, MeshSurfaceConnectivity connectivi |
| | 48 | 312 | | MeshSurfaceBoundaryTopology.FindSupportEdgeRegion(mesh, owner, first, second, connectivity, faces); |
| | | 313 | | } |
| | | 314 | | |
| | | 315 | | private readonly struct SlabSupport : ISupport |
| | | 316 | | { |
| | | 317 | | private readonly MeshSlabFaceRegions faces; |
| | | 318 | | private readonly LSCollider2D? embedded; |
| | | 319 | | internal SlabSupport(MeshSlabFaceRegions faces, LSCollider2D? embedded) |
| | 165 | 320 | | { this.faces = faces; this.embedded = embedded; } |
| | 201 | 321 | | public bool ContainsPoint(Vector3d point) => IntersectsSegment(new FixedSegment(point, point)); |
| | | 322 | | public bool IntersectsSegment(FixedSegment segment) |
| | | 323 | | { |
| | 261 | 324 | | Span<Vector2d> box = stackalloc Vector2d[4]; |
| | 261 | 325 | | return faces.IntersectsSupport(segment, faces.PrismOffsets.IsEmpty |
| | 261 | 326 | | ? CollisionDetectionMixed.GetConvexPrismOffsets(embedded, box) : faces.PrismOffsets.Span); |
| | | 327 | | } |
| | | 328 | | public int FindEdgeRegion(PhysicsMesh mesh, int owner, int first, int second, MeshSurfaceConnectivity connectivi |
| | 192 | 329 | | MeshSurfaceBoundaryTopology.FindSupportEdgeRegion(mesh, owner, first, second, connectivity, faces, embedded) |
| | | 330 | | } |
| | | 331 | | |
| | | 332 | | private readonly struct ConeSection : ISection |
| | | 333 | | { |
| | | 334 | | private readonly ConePlaneRayFrame frame; |
| | 12410 | 335 | | internal ConeSection(ConePlaneRayFrame frame) => this.frame = frame; |
| | 11144 | 336 | | public bool ContainsPoint(Vector3d point) => frame.ContainsPoint(point); |
| | 12023 | 337 | | public bool IntersectsSegment(FixedSegment segment) => frame.IntersectsSegment(segment); |
| | | 338 | | public bool TryGetFirstSegmentPoint(FixedSegment segment, FiniteSectionPoint point) => |
| | 558 | 339 | | FiniteSectionPoint.TryGetFirstSegmentPoint(segment, frame.Finite, point); |
| | | 340 | | } |
| | | 341 | | |
| | | 342 | | private readonly struct CapsuleSection : ISection |
| | | 343 | | { |
| | | 344 | | private readonly CapsuleFiniteSectionFrame frame; |
| | 26220 | 345 | | internal CapsuleSection(CapsuleFiniteSectionFrame frame) => this.frame = frame; |
| | 10784 | 346 | | public bool ContainsPoint(Vector3d point) => frame.ContainsPoint(point); |
| | 10287 | 347 | | public bool IntersectsSegment(FixedSegment segment) => frame.IntersectsSegment(segment); |
| | | 348 | | public bool TryGetFirstSegmentPoint(FixedSegment segment, FiniteSectionPoint point) => |
| | 9188 | 349 | | FiniteSectionPoint.TryGetFirstSegmentPoint(segment, frame, point); |
| | | 350 | | } |
| | | 351 | | |
| | | 352 | | private readonly struct SlabSection : ISection |
| | | 353 | | { |
| | | 354 | | private readonly FiniteSlabSectionFrame frame; |
| | | 355 | | private readonly LSCollider2D? embedded; |
| | | 356 | | private readonly ReadOnlyMemory<Vector2d> offsets; |
| | | 357 | | internal SlabSection(in FiniteSlabSectionFrame frame, LSCollider2D? embedded, ReadOnlyMemory<Vector2d> offsets = |
| | 85876 | 358 | | { this.frame = frame; this.embedded = embedded; this.offsets = offsets; } |
| | | 359 | | public bool ContainsPoint(Vector3d point) |
| | | 360 | | { |
| | 1860 | 361 | | Span<Vector2d> box = stackalloc Vector2d[4]; |
| | 1860 | 362 | | return frame.ContainsPoint(point, offsets.IsEmpty ? CollisionDetectionMixed.GetConvexPrismOffsets(embedded, |
| | | 363 | | } |
| | | 364 | | public bool IntersectsSegment(FixedSegment segment) |
| | | 365 | | { |
| | 2903 | 366 | | Span<Vector2d> box = stackalloc Vector2d[4]; |
| | 2903 | 367 | | return frame.IntersectsSegment(segment, offsets.IsEmpty ? CollisionDetectionMixed.GetConvexPrismOffsets(embe |
| | | 368 | | } |
| | | 369 | | public bool TryGetFirstSegmentPoint(FixedSegment segment, FiniteSectionPoint point) |
| | | 370 | | { |
| | 624 | 371 | | Span<Vector2d> box = stackalloc Vector2d[4]; |
| | 624 | 372 | | return FiniteSectionPoint.TryGetFirstSegmentPoint(segment, frame, |
| | 624 | 373 | | offsets.IsEmpty ? CollisionDetectionMixed.GetConvexPrismOffsets(embedded, box) : offsets.Span, point); |
| | | 374 | | } |
| | | 375 | | } |
| | | 376 | | } |