< Summary

Line coverage
100%
Covered lines: 405
Uncovered lines: 0
Coverable lines: 405
Total lines: 796
Line coverage: 100%
Branch coverage
100%
Covered branches: 262
Total branches: 262
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
File 1: .ctor()100%11100%
File 1: get_SelectionWords()100%11100%
File 1: get_PointWords()100%11100%
File 1: get_SamplingOrigin()100%11100%
File 1: Build(...)100%11100%
File 1: Build(...)100%44100%
File 1: Reserve(...)100%44100%
File 1: GatherEvents(...)100%1414100%
File 1: AdmitEvaluatedPoint(...)100%1616100%
File 1: GetCompleteConvexFan(...)100%88100%
File 1: FindPointRegion(...)100%1212100%
File 1: BorrowWinner(...)100%22100%
File 1: KeepWinner(...)100%22100%
File 1: ReduceRegion(...)100%66100%
File 1: GetNormal(...)100%44100%
File 1: GetOrientation(...)100%11100%
File 1: TryGetSelectedRay(...)100%44100%
File 1: ValidateRegion(...)100%22100%
File 1: .ctor(...)100%11100%
File 1: .ctor(...)100%11100%
File 2: .ctor()100%11100%
File 2: ReleaseJoined()100%11100%
File 2: BuildJoined(...)100%3838100%
File 2: JoinFiniteSpans()100%2222100%
File 2: JoinAtPoint(...)100%88100%
File 2: AdmitJoinedPoint(...)100%2020100%
File 2: KeepJoinedWinner(...)100%1414100%
File 2: GetClip(...)100%22100%
File 2: GetFrame(...)100%22100%
File 2: GetRegionFrame(...)100%11100%
File 2: GetNativeOrientation(...)100%22100%
File 2: CompareJoinedPoints(...)100%11100%
File 2: IsResponseCarrier(...)100%11100%
File 2: GetJoinedSample(...)100%11100%
File 2: GetJoinedBoundary(...)100%66100%
File 2: GetRetainedBoundaryInterval(...)100%11100%
File 2: GetMember(...)100%11100%
File 2: GetBoundaryFrame(...)100%44100%
File 2: GetBoundaryOrientation(...)100%44100%
File 2: IsJoinedSpan(...)100%11100%
File 2: GetJoinedCornerFan(...)100%11100%
File 2: AppendJoinedBoundaries(...)100%88100%
File 3: .ctor()100%11100%
File 3: GetSampleCount(...)100%22100%
File 3: TryGetSample(...)100%66100%
File 3: GetSampleIdentity(...)100%11100%
File 3: ReduceSamples(...)100%1414100%
File 3: KeepSample(...)100%1414100%
File 3: ComparePoints(...)100%88100%
File 3: CheckRay(...)100%66100%
File 3: MaterializeSelected(...)100%22100%
File 3: TryMaterializeSample(...)100%22100%
File 3: .ctor(...)100%11100%
File 3: .ctor(...)100%11100%
File 3: get_Point()100%11100%
File 3: .ctor(...)100%11100%

File(s)

/home/runner/work/Gravitas/Gravitas/src/Gravitas/CollisionHandling/Detection/3D/Mesh/FaceRegions/MeshConeFaceRegions.cs

#LineLine coverage
 1//=======================================================================
 2// MeshConeFaceRegions.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
 8using System;
 9using FixedMathSharp;
 10using FixedMathSharp.Geometry;
 11using Gravitas.Colliders;
 12
 13namespace Gravitas.CollisionHandling;
 14
 15/// <summary>Chooses the smaller exact face-ray maximum independently for each admitted surface component.</summary>
 16/// <content>Exact component orientation and retained triangle grouping.</content>
 17internal sealed partial class MeshConeFaceRegions
 18{
 1074619    private Region[] _regions = Array.Empty<Region>();
 20    private ConePlaneRayFrame _frame;
 21    private Vector3d _worldNormal;
 22    private Vector3d _samplingOrigin;
 1074623    private ulong[] _selectionValues = Array.Empty<ulong>();
 1074624    private int[] _selectionSigns = Array.Empty<int>();
 1074625    private Winner[] _winners = Array.Empty<Winner>();
 2149226    private int _fieldWords = ConePlaneRaySelection.FieldWords, _rootWords = ConePlaneRaySelection.RootWords;
 32027127    private int SelectionWords => 12 * _fieldWords + _rootWords;
 3972928    private int PointWords => 8 * _fieldWords;
 29    private readonly ConePlaneRayEventVisitor _eventVisitor;
 30    private PhysicsMesh? _gatherMesh;
 31    private MeshSurfaceConnectivity? _gatherConnectivity;
 32    private int _gatherSurfaceTriangle;
 33    private bool _gatherUsesConvexFan;
 34    private bool _gatherContainsSection;
 35    private bool _wholeConeSamplingRangeRepresentable;
 36
 1074637    internal MeshConeFaceRegions()
 38    {
 1074639        _eventVisitor = AdmitEvaluatedPoint;
 1074640        _sampleComparer = System.Collections.Generic.Comparer<Sample>.Create(ComparePoints);
 1074641    }
 42
 43    internal int RegionCount { get; private set; }
 44    internal bool HasBoundaryIntersection { get; private set; }
 150645    internal Vector3d SamplingOrigin => _samplingOrigin;
 46
 47    internal void Build(PhysicsMesh mesh, int surfaceTriangle, Vector3d coneCenter,
 48        FixedQuaternion coneRotation, Fixed64 height, Fixed64 radius,
 49        MeshSurfaceConnectivity connectivity, ReadOnlySpan<int> admittedTriangles, Vector3d samplingOrigin = default)
 50    {
 37551        mesh.GetGeometryTriangleVertices(surfaceTriangle, out Vector3d a, out Vector3d b, out Vector3d c);
 37552        var frame = new ConePlaneRayFrame(new FixedTriangle(a, b, c), mesh.GeometryFrame,
 37553            coneCenter, coneRotation, height, radius);
 37554        Build(mesh, surfaceTriangle, frame, connectivity, admittedTriangles, samplingOrigin);
 37555    }
 56
 57    /// <remarks>
 58    /// Connectivity must have been built from this same mesh, surface, cone
 59    /// frame and complete admitted list. Descriptors and grouped indices are
 60    /// valid until the next Build; only the prepared surface owner is consumed.
 61    /// This selects an orientation and its extremal ray, before sample coverage
 62    /// or rigid-body response policy is applied.
 63    /// </remarks>
 64    internal void Build(PhysicsMesh mesh, int surfaceTriangle, in ConePlaneRayFrame frame,
 65        MeshSurfaceConnectivity connectivity, ReadOnlySpan<int> admittedTriangles, Vector3d samplingOrigin = default)
 66    {
 610267        _joined = null;
 610268        _currentMember = _currentSupplier = _currentSpan = -1;
 610269        RegionCount = connectivity.RegionCount;
 610270        HasBoundaryIntersection = false;
 610371        if (RegionCount == 0) return;
 1220272        _fieldWords = frame.FieldWords; _rootWords = frame.RootWords;
 610173        Reserve(RegionCount);
 610174        mesh.GetGeometryTriangleVertices(surfaceTriangle, out Vector3d a, out Vector3d b, out Vector3d c);
 610175        _frame = frame;
 610176        _samplingOrigin = samplingOrigin;
 610177        _wholeConeSamplingRangeRepresentable = ConePlaneRayPointMaterialization.IsRangeRepresentable(_frame, samplingOri
 610178        _worldNormal = _frame.GetWorldNormal(mesh.Rotation);
 610179        var metrics = new WidePlaneMetrics(new FixedTriangle(a, b, c), mesh.GeometryFrame);
 610180        Array.Clear(_winners, 0, 2 * RegionCount);
 610181        _poolEvents.FastClear();
 610182        GatherEvents(mesh, surfaceTriangle, connectivity);
 2445083        for (int region = 0; region < RegionCount; region++)
 84        {
 612485            ReduceRegion(region);
 612486            ReduceSamples(region, metrics);
 87        }
 610188    }
 89
 90    private void Reserve(int count)
 91    {
 914192        if (_regions.Length < count)
 93        {
 30394            int capacity = Math.Max(count, _regions.Length * 2);
 30395            Array.Resize(ref _regions, capacity);
 30396            Array.Resize(ref _sampleCounts, capacity);
 30397            Array.Resize(ref _selectionSigns, 2 * capacity * ConePlaneRaySelection.SignCount);
 30398            Array.Resize(ref _winners, 2 * capacity);
 30399            Array.Resize(ref _samples, capacity * ContactManifold.MaxContactsPerGroup);
 100        }
 9141101        int required = 2 * _regions.Length * SelectionWords;
 9444102        if (_selectionValues.Length < required) Array.Resize(ref _selectionValues, required);
 9141103    }
 104
 105    private void GatherEvents(PhysicsMesh mesh, int surfaceTriangle, MeshSurfaceConnectivity connectivity)
 106    {
 6101107        _gatherSurfaceTriangle = surfaceTriangle;
 6101108        _gatherMesh = mesh;
 6101109        _gatherConnectivity = connectivity;
 110        try
 111        {
 6101112            ReadOnlySpan<int> boundary = mesh.GetCanonicalSurfaceBoundaryVertexPairs(surfaceTriangle);
 6101113            ReadOnlySpan<Vector3d> vertices = mesh.GeometryVertices;
 6101114            int firstIntersectingEdge = 0;
 50217115            for (; firstIntersectingEdge < boundary.Length; firstIntersectingEdge += 2)
 22696116                if (_frame.IntersectsSegment(new FixedSegment(vertices[boundary[firstIntersectingEdge]],
 22696117                    vertices[boundary[firstIntersectingEdge + 1]]))) break;
 6101118            HasBoundaryIntersection = firstIntersectingEdge < boundary.Length;
 119            // The finite cone section is connected and at least one triangle
 120            // is admitted. A complete owner with a disjoint true boundary
 121            // contains that whole section. Neighbor closure also preserves
 122            // callers' deliberately partial admitted domains; hole boundaries
 123            // and closed touch prevent the containment certificate.
 6101124            if (RegionCount == 1 && firstIntersectingEdge == boundary.Length)
 125            {
 5463126                _gatherContainsSection = connectivity.IsCompleteSingleRegion(mesh);
 127                // A complete section needs no fan, and an incomplete owner
 128                // cannot use one. Do not repeat the same closure check.
 5463129                _gatherUsesConvexFan = false;
 130            }
 131            else
 132            {
 638133                _gatherContainsSection = false;
 638134                _gatherUsesConvexFan = !GetCompleteConvexFan(mesh, surfaceTriangle, connectivity).IsEmpty;
 135            }
 136            // Synchronous visitation borrows each exact construction directly,
 137            // avoiding chart reconstruction per descriptor. Only compact pool
 138            // metadata and the two owned winner banks survive the callback.
 6101139            ConePlaneRayEvents.VisitEvents(ConePlaneRayEventSource.Plane, _frame, _eventVisitor);
 17036140            for (int edge = firstIntersectingEdge; edge < boundary.Length; edge += 2)
 141            {
 2417142                var segment = new FixedSegment(vertices[boundary[edge]], vertices[boundary[edge + 1]]);
 2417143                if (edge != firstIntersectingEdge && !_frame.IntersectsSegment(segment)) continue;
 2035144                var source = new ConePlaneRayEventSource(segment);
 2035145                ConePlaneRayEvents.VisitEvents(source, _frame, _eventVisitor);
 146            }
 6101147        }
 148        finally
 149        {
 150            // Context scratch must not retain the last queried mesh, including
 151            // when exact geometry or materialization rejects the operation.
 6101152            _gatherMesh = null;
 6101153            _gatherConnectivity = null;
 6101154            _gatherUsesConvexFan = false;
 6101155            _gatherContainsSection = false;
 6101156        }
 6101157    }
 158
 159    private void AdmitEvaluatedPoint(in ConePlaneRayEventSource source, in ConePlaneRayFrame frame,
 160        ConePlaneRayEvent descriptor, scoped ConePlaneRayPoint point, scoped ReadOnlySpan<ulong> root,
 161        scoped in ConePlaneRaySelection positive, scoped in ConePlaneRaySelection negative)
 162    {
 37307163        PhysicsMesh mesh = _gatherMesh!;
 37307164        ReadOnlySpan<int> corners = _gatherUsesConvexFan
 37307165            ? mesh.GetConvexCoplanarPatchCornerVertexIndices(_gatherSurfaceTriangle) : ReadOnlySpan<int>.Empty;
 37307166        int region = FindPointRegion(mesh, _gatherConnectivity!, corners, point, root);
 39849167        if (region < 0) return;
 34765168        KeepWinner(2 * region, positive);
 34765169        KeepWinner(2 * region + 1, negative);
 34765170        bool pointRepresentable = ConePlaneRayPointMaterialization.TryGetPointInFrame(frame, point, root, _samplingOrigi
 171        // Distinct constructions can certify the same exact point. Merge
 172        // their available directions before duplicate range checks; each
 173        // direction retains its own certificate for final materialization.
 174        // The callback already owns the incoming exact point; reconstruct
 175        // only the retained event when checking coordinate equality.
 228044176        for (int index = 0; index < _poolEvents.Count; index++)
 177        {
 81844178            PoolEvent retained = _poolEvents[index];
 81844179            if (retained.Region != region || retained.MeshPoint != meshPoint || ConePlaneRayEvents.CompareEventAnchors(
 81844180                point, root, retained.Source, retained.Event, frame) != 0) continue;
 2587181            _poolEvents[index] = new PoolEvent(retained.Source, retained.Event, region, meshPoint,
 2587182                retained.Positive.HasValue ? retained.Positive : CheckRay(positive, 1, pointRepresentable),
 2587183                retained.Negative.HasValue ? retained.Negative : CheckRay(negative, -1, pointRepresentable));
 2587184            return;
 185        }
 32178186        _poolEvents.Add(new PoolEvent(source, descriptor, region, meshPoint,
 32178187            CheckRay(positive, 1, pointRepresentable), CheckRay(negative, -1, pointRepresentable)));
 32178188    }
 189
 190    private ReadOnlySpan<int> GetCompleteConvexFan(PhysicsMesh mesh, int surfaceTriangle, MeshSurfaceConnectivity connec
 191    {
 661192        if (RegionCount != 1) return ReadOnlySpan<int>.Empty;
 615193        ReadOnlySpan<int> corners = mesh.GetConvexCoplanarPatchCornerVertexIndices(surfaceTriangle);
 940194        if (corners.IsEmpty || corners.Length - 2 >= connectivity.TriangleIndices.Length) return ReadOnlySpan<int>.Empty
 290195        return connectivity.IsCompleteSingleRegion(mesh) ? corners : ReadOnlySpan<int>.Empty;
 196    }
 197
 198    private int FindPointRegion(PhysicsMesh mesh, MeshSurfaceConnectivity connectivity, ReadOnlySpan<int> corners,
 199        scoped ConePlaneRayPoint point, scoped ReadOnlySpan<ulong> root)
 200    {
 38437201        if (_gatherContainsSection) return 0;
 36177202        if (!corners.IsEmpty)
 203        {
 4896204            ReadOnlySpan<Vector3d> vertices = mesh.GeometryVertices;
 16704205            for (int corner = 1; corner < corners.Length - 1; corner++)
 7200206                if (ConePlaneRayPointExits.ContainsTrianglePoint(new FixedTriangle(vertices[corners[0]],
 10944207                    vertices[corners[corner]], vertices[corners[corner + 1]]), _frame, point, root)) return 0;
 1152208            return -1;
 209        }
 210        // A shared admitted point joins its incident triangles, so its first
 211        // closed-triangle match identifies the unique connectivity component.
 212        // A complete convex owner uses O(T + K*(B-2)) assignment.
 213        // ponytail: O(K*T) for incomplete, nonconvex and multiple-region owners;
 214        // use prepared incidence if measured large patches need it.
 131981215        foreach (int triangle in connectivity.TriangleIndices)
 216        {
 49655217            mesh.GetGeometryTriangleVertices(triangle, out Vector3d a, out Vector3d b, out Vector3d c);
 49655218            if (ConePlaneRayPointExits.ContainsTrianglePoint(new FixedTriangle(a, b, c), _frame, point, root))
 29891219                return connectivity.GetRegionOrdinal(triangle);
 220        }
 1390221        return -1;
 222    }
 223
 224    private ConePlaneRaySelection BorrowWinner(int index)
 225    {
 128256226        var selection = new ConePlaneRaySelection(
 128256227            _selectionValues.AsSpan(index * SelectionWords, SelectionWords),
 128256228            _selectionSigns.AsSpan(index * ConePlaneRaySelection.SignCount, ConePlaneRaySelection.SignCount), _fieldWord
 128256229        Winner winner = _winners[index];
 238124230        if (winner.HasValue) selection.Restore(GetFrame(winner.Member), winner.Source, winner.Event);
 128256231        return selection;
 232    }
 233
 234    private void KeepWinner(int index, scoped in ConePlaneRaySelection candidate)
 235    {
 69530236        var selection = BorrowWinner(index);
 69530237        if (selection.KeepEvaluated(candidate, _frame))
 40885238            _winners[index] = new Winner(selection.MaximumSource, selection.MaximumEvent);
 69530239    }
 240
 241    private void ReduceRegion(int region)
 242    {
 9187243        var positive = BorrowWinner(2 * region);
 9187244        var negative = BorrowWinner(2 * region + 1);
 245        // Each closed component's maximum is intrinsic to its common plane or
 246        // lies on its true boundary; authored internal seams add no extrema.
 247        // Shared normal metric and frame scale cancel in the exact comparison.
 248        System.Diagnostics.Debug.Assert(positive.HasValue && negative.HasValue);
 9187249        int comparison = _joined?.Active == true ? positive.CompareDepth(negative) : ContactQuadratic.CompareRatios(
 9187250            ContactQuadratic.At(positive.Values, positive.Signs, 0, _fieldWords),
 9187251            ContactQuadratic.At(positive.Values, positive.Signs, 1, _fieldWords), positive.Root,
 9187252            ContactQuadratic.At(negative.Values, negative.Signs, 0, _fieldWords),
 9187253            ContactQuadratic.At(negative.Values, negative.Signs, 1, _fieldWords), negative.Root);
 9187254        int orientation = comparison <= 0 ? 1 : -1;
 9187255        _regions[region] = new Region(orientation);
 9187256    }
 257
 258    // The cone witness lies along the exit ray from the mesh. Response moves
 259    // the cone in the opposite direction, including at exact zero-depth touch.
 18402260    internal Vector3d GetNormal(int region) => _joined?.Active == true
 18402261        ? -GetRegionFrame(region).GetWorldNormal(_joined.Members[_joined.NodeMembers[_joined.Roots[region]]].Collider.Me
 18402262        : -_worldNormal * GetOrientation(region);
 263
 19934264    internal int GetOrientation(int region) => _regions[ValidateRegion(region)].Orientation;
 265
 266    internal bool TryGetSelectedRay(int region, out Vector3d meshPoint, out Vector3d conePoint, out Fixed64 depth)
 267    {
 142268        meshPoint = conePoint = default; depth = default;
 73269        if ((uint)region >= (uint)RegionCount) return false;
 69270        if (_sampleCounts[region] > 0)
 271        {
 66272            Sample maximum = _samples[region * ContactManifold.MaxContactsPerGroup];
 198273            meshPoint = maximum.MeshPoint; conePoint = maximum.ConePoint; depth = maximum.Depth;
 66274            return true;
 275        }
 3276        int orientation = _regions[region].Orientation;
 3277        var selected = BorrowWinner(2 * region + (orientation > 0 ? 0 : 1));
 3278        return selected.TryMaterialize(_frame, orientation, _samplingOrigin, out meshPoint, out conePoint, out depth);
 279    }
 280
 281    private int ValidateRegion(int region)
 282    {
 77328283        if ((uint)region >= (uint)RegionCount) throw new ArgumentOutOfRangeException(nameof(region));
 77318284        return region;
 285    }
 286
 287    private readonly struct Region
 288    {
 289        internal readonly int Orientation;
 9187290        internal Region(int orientation) => Orientation = orientation;
 291    }
 292
 293    private readonly struct Winner
 294    {
 295        internal readonly ConePlaneRayEventSource Source;
 296        internal readonly ConePlaneRayEvent Event;
 297        internal readonly bool HasValue;
 298        internal readonly int Member, Supplier;
 299        internal readonly int Span;
 300        internal Winner(ConePlaneRayEventSource source, ConePlaneRayEvent descriptor,
 301            int member = -1, int supplier = -1, int span = -1)
 436282302        { Source = source; Event = descriptor; HasValue = true; Member = member; Supplier = supplier; Span = span; }
 303    }
 304}

/home/runner/work/Gravitas/Gravitas/src/Gravitas/CollisionHandling/Detection/3D/Mesh/FaceRegions/MeshConeFaceRegions.Joined.cs

#LineLine coverage
 1//=======================================================================
 2// MeshConeFaceRegions.Joined.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
 8using System;
 9using FixedMathSharp;
 10using FixedMathSharp.Geometry;
 11using Gravitas.Colliders;
 12using SwiftCollections;
 13using SwiftCollections.Query;
 14using Member = Gravitas.CollisionHandling.Member<FixedMathSharp.Geometry.ConePlaneRayFrame>;
 15
 16namespace Gravitas.CollisionHandling;
 17
 18/// <content>Visits declared native member domains through the existing cone event and sample reducer.</content>
 19internal sealed partial class MeshConeFaceRegions
 20{
 21    private MeshJoinedSurfaceRegions<ConePlaneRayFrame>? _joined;
 1074622    private readonly SwiftHashSet<int> _visitedJoinedRegions = new();
 2149223    private int _currentMember = -1, _currentSupplier = -1, _currentRegion, _otherMember, _currentSpan;
 24    private ConePlaneRayEventVisitor? _joinedVisitor, _joinVisitor;
 25
 300626    internal void ReleaseJoined() { _joined = null; RegionCount = 0; }
 27
 28    internal void BuildJoined(ReadOnlySpan<(LSMeshCollider Collider, int Triangle)> sources,
 29        LSConeCollider cone, ReadOnlySpan<PhysicsMesh> meshes,
 30        SwiftDictionary<(PhysicsMesh, int), MeshSurfaceBoundaryDomain> boundaries)
 31    {
 304032        var state = _joined ??= new();
 304033        state.Prepare(sources, meshes, boundaries);
 304034        state.PrepareResponseComponents();
 35        // Response batching does not certify complete finite cone exits.
 36        // The trusted finite-region union below owns perimeter suppression.
 1841037        foreach (Member member in state.Members.AsReadOnlySpan()[..state.Inputs.Count])
 616538            Array.Clear(member.JoinedSpans, 0, member.Boundary.Spans.Length);
 304039        var bounds = new FixedBoundVolume(cone.BoundsMin, cone.BoundsMax);
 1841040        for (int index = 0; index < state.Inputs.Count; index++)
 41        {
 1233042            Member member = state.Members[index]; PhysicsMesh mesh = member.Collider.Mesh;
 616543            mesh.GetGeometryTriangleVertices(member.Triangle, out Vector3d a, out Vector3d b, out Vector3d c);
 616544            member.Frame = new(new FixedTriangle(a, b, c), mesh.GeometryFrame,
 616545                cone.Center, cone.Rotation, cone.Height, cone.ScaledRadius);
 616546            member.Admitted.FastClear();
 616547            member.Collider.GetTrianglesInBounds(bounds, state.Candidates);
 4124848            foreach (int triangle in state.Candidates.AsReadOnlySpan())
 49            {
 1445950                if (mesh.GetManifoldSurfaceOwner(triangle) != member.Owner) continue;
 1443951                mesh.GetGeometryTriangleVertices(triangle, out a, out b, out c);
 2367652                if (ConePlaneRayEvents.IntersectsTriangle(member.Frame, new FixedTriangle(a, b, c))) member.Admitted.Add
 53            }
 616554            member.Connectivity.Build(mesh, member.Triangle, member.Frame, member.Admitted.AsReadOnlySpan());
 1206155            if (member.Connectivity.RegionCount > 0) state.AddAdmittedMember(index);
 616556            state.AddRegions(index);
 57        }
 304058        bool wide = false;
 1841059        foreach (Member member in state.Members.AsReadOnlySpan()[..state.Inputs.Count])
 60        {
 616561            wide |= member.Frame.UsesWideBanks;
 9275762            foreach (var span in member.Boundary.Spans) wide |= span.Interval.HasWideBounds;
 63        }
 304064        if (wide)
 665            foreach (Member member in state.Members.AsReadOnlySpan()[..state.Inputs.Count])
 266                member.Frame = member.Frame.WithWideParameters();
 608067        _fieldWords = state.Members[0].Frame.FieldWords; _rootWords = state.Members[0].Frame.RootWords;
 304068        JoinFiniteSpans();
 304069        state.CompleteRegions();
 608070        RegionCount = state.Roots.Count; HasBoundaryIntersection = false;
 912071        Reserve(RegionCount); Array.Clear(_winners, 0, 2 * RegionCount); _poolEvents.FastClear();
 304072        _samplingOrigin = cone.Center;
 304073        _joinedVisitor ??= AdmitJoinedPoint;
 1220674        for (int region = 0; region < RegionCount; region++)
 75        {
 612676            _currentRegion = region; _currentMember = state.NodeMembers[state.Roots[region]];
 612677            _frame = GetFrame(_currentMember); _currentSpan = -1;
 306378            _wholeConeSamplingRangeRepresentable = ConePlaneRayPointMaterialization.IsRangeRepresentable(_frame, _sampli
 306379            ConePlaneRayEvents.VisitEvents(ConePlaneRayEventSource.Plane, _frame, _joinedVisitor);
 80        }
 304081        _currentRegion = -1;
 1841082        for (int member = 0; member < state.Inputs.Count; member++)
 83        {
 616584            Member source = state.Members[member];
 616585            if (source.Connectivity.RegionCount == 0) continue;
 1179286            _currentMember = member; _frame = source.Frame;
 589687            ReadOnlySpan<BoundarySpan3D> spans = source.Boundary.Spans;
 6311288            for (int span = 0; span < spans.Length; span++)
 89            {
 2566090                if (source.JoinedSpans[span] || !_frame.IntersectsSegment(new FixedSegment(spans[span].Start, spans[span
 207291                _currentSpan = span;
 207292                var segment = new FixedSegment(spans[span].Start, spans[span].End);
 207293                RationalSegmentInterval clip = source.GetRetainedInterval(ref span);
 207294                ConePlaneRayEvents.VisitEvents(new ConePlaneRayEventSource(segment), _frame, clip, _joinedVisitor);
 95            }
 96        }
 1220697        for (int region = 0; region < RegionCount; region++)
 98        {
 306399            ReduceRegion(region);
 3063100            Member source = state.Members[state.NodeMembers[state.Roots[region]]];
 3063101            source.Collider.Mesh.GetGeometryTriangleVertices(source.Triangle, out Vector3d a, out Vector3d b, out Vector
 3063102            ReduceSamples(region, new WidePlaneMetrics(new FixedTriangle(a, b, c), source.Collider.Mesh.GeometryFrame));
 103        }
 3040104        state.Commit();
 3040105    }
 106
 107    private void JoinFiniteSpans()
 108    {
 6080109        var state = _joined!; _joinVisitor ??= JoinAtPoint;
 18410110        for (int member = 0; member < state.Inputs.Count; member++)
 111        {
 6165112            Member source = state.Members[member];
 113            // Finite face exits require a complete canonical-owner domain.
 114            // A certified span can still suppress its seam and share response,
 115            // but ambiguous owner coverage cannot merge the exit regions.
 6165116            if (!source.BoundaryTrusted) continue;
 6140117            ReadOnlySpan<BoundarySpan3D> spans = source.Boundary.Spans;
 65684118            for (int span = 0; span < spans.Length; span++)
 119            {
 26702120                var edge = spans[span];
 26702121                if (edge.Kind != SpanKind.Joined
 26702122                    || !state.MemberBySurface.TryGetValue((state.Meshes[edge.OtherMember], edge.OtherSurface), out int o
 6220123                Member target = state.Members[other];
 6220124                if (!target.BoundaryTrusted) continue;
 6212125                if (!edge.Interval.IsClipped && source.Connectivity.RegionCount == 1 && target.Connectivity.RegionCount 
 126                {
 4668127                    if (source.Frame.IntersectsSegment(new FixedSegment(edge.Start, edge.End)))
 9328128                    { state.Union(source.Offset, target.Offset); source.JoinedSpans[span] = true; }
 4664129                    continue;
 130                }
 4632131                _currentMember = member; _otherMember = other; _currentSpan = span;
 1544132                ConePlaneRayEvents.VisitEvents(new ConePlaneRayEventSource(new FixedSegment(edge.Start, edge.End)),
 1544133                    source.Frame, edge.Interval, _joinVisitor);
 134            }
 135        }
 3040136    }
 137
 138    private void JoinAtPoint(in ConePlaneRayEventSource source, in ConePlaneRayFrame frame, ConePlaneRayEvent descriptor
 139        scoped ConePlaneRayPoint point, scoped ReadOnlySpan<ulong> root,
 140        scoped in ConePlaneRaySelection positive, scoped in ConePlaneRaySelection negative)
 141    {
 8862142        var state = _joined!; Member first = state.Members[_currentMember], second = state.Members[_otherMember];
 11912143        foreach (int a in first.Connectivity.TriangleIndices)
 144        {
 3002145            first.Collider.Mesh.GetGeometryTriangleVertices(a, out Vector3d aa, out Vector3d ab, out Vector3d ac);
 3002146            if (!ConePlaneRayPointExits.ContainsTrianglePoint(new FixedTriangle(aa, ab, ac), first.Frame, point, root)) 
 12020147            foreach (int b in second.Connectivity.TriangleIndices)
 148            {
 3044149                second.Collider.Mesh.GetGeometryTriangleVertices(b, out Vector3d ba, out Vector3d bb, out Vector3d bc);
 3044150                if (!ConePlaneRayPointExits.ContainsTrianglePoint(new FixedTriangle(ba, bb, bc), second.Frame, point, ro
 2986151                state.Union(first.Offset + first.Connectivity.GetRegionOrdinal(a), second.Offset + second.Connectivity.G
 2986152                first.JoinedSpans[_currentSpan] = true;
 153            }
 154        }
 2954155    }
 156
 157    private void AdmitJoinedPoint(in ConePlaneRayEventSource source, in ConePlaneRayFrame frame, ConePlaneRayEvent descr
 158        scoped ConePlaneRayPoint point, scoped ReadOnlySpan<ulong> root,
 159        scoped in ConePlaneRaySelection positive, scoped in ConePlaneRaySelection negative)
 160    {
 31606161        var state = _joined!; _visitedJoinedRegions.Clear();
 31606162        int first = _currentRegion < 0 ? _currentMember : 0, end = _currentRegion < 0 ? first + 1 : state.Inputs.Count;
 95332163        for (int member = first; member < end; member++)
 164        {
 31863165            Member target = state.Members[member];
 159382166            foreach (int triangle in target.Connectivity.TriangleIndices)
 167            {
 47828168                int region = state.RegionByRoot[state.Find(target.Offset + target.Connectivity.GetRegionOrdinal(triangle
 47828169                if (_currentRegion >= 0 && region != _currentRegion || _visitedJoinedRegions.Contains(region)) continue;
 30699170                target.Collider.Mesh.GetGeometryTriangleVertices(triangle, out Vector3d a, out Vector3d b, out Vector3d 
 30699171                if (!ConePlaneRayPointExits.ContainsTrianglePoint(new FixedTriangle(a, b, c), target.Frame, point, root,
 31324172                _visitedJoinedRegions.Add(region); _currentSupplier = member;
 15662173                int aligned = WideDirection3d.Dot(frame.Normal, GetRegionFrame(region).Normal).Sign;
 15662174                KeepJoinedWinner(2 * region + (aligned > 0 ? 0 : 1), positive);
 15662175                KeepJoinedWinner(2 * region + (aligned > 0 ? 1 : 0), negative);
 15662176                bool represented = ConePlaneRayPointMaterialization.TryGetPointInFrame(frame, point, root, _samplingOrig
 15662177                HasBoundaryIntersection |= source.Scope == ConePlaneRayEventScope.Segment;
 15662178                var sample = new PoolEvent(source, descriptor, region, p, CheckRay(aligned > 0 ? positive : negative, al
 15662179                    CheckRay(aligned > 0 ? negative : positive, -aligned, represented), _currentMember, member);
 180                // Final coverage drops coincident exact points; retaining compact
 181                // descriptors here avoids storing a second bank of wide points.
 15662182                _poolEvents.Add(sample);
 183            }
 184        }
 15803185    }
 186
 187    private void KeepJoinedWinner(int slot, scoped in ConePlaneRaySelection candidate)
 188    {
 31486189        if (!candidate.HasValue) return;
 31162190        var previous = BorrowWinner(slot);
 31162191        if (previous.HasValue)
 192        {
 25036193            int order = candidate.CompareDepth(previous);
 25437194            if (order < 0) return;
 24635195            if (order == 0)
 196            {
 21301197                Winner old = _winners[slot];
 21301198                order = candidate.Point.CompareTo(previous.Point, candidate.Root, previous.Root, _frame, GetFrame(old.Me
 30621199                if (order > 0 || order == 0 && _currentSupplier >= old.Supplier) return;
 200            }
 201        }
 42882202        candidate.Values.CopyTo(previous.Values); candidate.Signs.CopyTo(previous.Signs);
 21441203        _winners[slot] = new(candidate.MaximumSource, candidate.MaximumEvent, _currentMember, _currentSupplier, _current
 21441204    }
 205
 39729206    private RationalSegmentInterval GetClip(int member, int span) => span < 0 ? default : _joined!.Members[member].GetRe
 285231207    private ref readonly ConePlaneRayFrame GetFrame(int member) => ref (member < 0 ? ref _frame : ref _joined!.Members[m
 40676208    private ref readonly ConePlaneRayFrame GetRegionFrame(int region) => ref GetFrame(_joined!.NodeMembers[_joined.Roots
 36496209    private int GetNativeOrientation(int region, int member, int orientation) => member < 0 ? orientation
 36496210        : orientation * WideDirection3d.Dot(GetFrame(member).Normal, GetRegionFrame(region).Normal).Sign;
 211
 212    private int CompareJoinedPoints(Sample first, Sample second)
 213    {
 12420214        Span<ulong> a = stackalloc ulong[PointWords], b = stackalloc ulong[PointWords];
 12420215        Span<int> sa = stackalloc int[ConePlaneRayPoint.SignCount], sb = stackalloc int[ConePlaneRayPoint.SignCount];
 12420216        Span<ulong> ra = stackalloc ulong[_rootWords], rb = stackalloc ulong[_rootWords];
 12420217        var pa = new ConePlaneRayPoint(a, sa, _fieldWords); var pb = new ConePlaneRayPoint(b, sb, _fieldWords);
 6210218        ref readonly ConePlaneRayFrame fa = ref GetFrame(first.Member);
 6210219        ref readonly ConePlaneRayFrame fb = ref GetFrame(second.Member);
 6210220        bool foundA = ConePlaneRayEvents.ReconstructPoint(first.Source, fa, first.Event, GetClip(first.Member, first.Spa
 6210221        bool foundB = ConePlaneRayEvents.ReconstructPoint(second.Source, fb, second.Event, GetClip(second.Member, second
 222        System.Diagnostics.Debug.Assert(foundA && foundB);
 6210223        return pa.CompareTo(pb, ra, rb, fa, fb);
 224    }
 225
 226    internal bool IsResponseCarrier(LSMeshCollider collider, int region) =>
 6418227        _joined!.Members[_joined.GetResponseMember(_joined.NodeMembers[_joined.Roots[region]])].Collider == collider;
 228
 229    internal FixedContactAnchors GetJoinedSample(int region, int index, out LSMeshCollider supplier, out int owner)
 230    {
 12674231        Sample sample = _samples[region * ContactManifold.MaxContactsPerGroup + index];
 12674232        supplier = _joined!.Members[sample.Supplier].Collider;
 12674233        owner = _joined.Members[sample.Supplier].Owner;
 12674234        return new(new FixedPointAnchor(_samplingOrigin, FixedQuaternion.Identity, sample.MeshPoint),
 12674235            new FixedPointAnchor(_samplingOrigin, GetFrame(sample.Member).ConeRotation, sample.ConeLocalPoint), GetNorma
 236    }
 237
 372238    internal MeshSurfaceBoundaryDomain? GetJoinedBoundary(LSMeshCollider collider, int triangle) => _joined?.Active == t
 372239        && GetMember(collider, triangle).BoundaryTrusted ? GetMember(collider, triangle).Boundary : null;
 240    internal RationalSegmentInterval GetRetainedBoundaryInterval(LSMeshCollider collider, int triangle, ref int span) =>
 58241        GetMember(collider, triangle).GetRetainedInterval(ref span);
 486242    private Member GetMember(LSMeshCollider collider, int triangle) => _joined!.Members[
 486243        _joined.MemberBySurface[(collider.Mesh, collider.Mesh.GetManifoldSurfaceOwner(triangle))]];
 372244    internal ConePlaneRayFrame GetBoundaryFrame(LSMeshCollider collider, int triangle) => _joined?.Active == true ? GetM
 245    internal int GetBoundaryOrientation(LSMeshCollider collider, int triangle, int region)
 246    {
 2911247        if (_joined?.Active != true) return GetOrientation(region);
 101248        Member member = GetMember(collider, triangle);
 101249        int joined = _joined.RegionByRoot[_joined.Find(member.Offset + region)];
 101250        return WideDirection3d.Dot(member.Frame.Normal, GetRegionFrame(joined).Normal).Sign * GetOrientation(joined);
 251    }
 174252    internal bool IsJoinedSpan(LSMeshCollider collider, int triangle, int span) => GetMember(collider, triangle).JoinedS
 253    internal ReadOnlySpan<WideAxis3> GetJoinedCornerFan(LSMeshCollider collider, int triangle, int vertex, out bool supp
 35254        _joined!.GetCornerFan(collider, triangle, vertex, out suppress);
 255
 256    internal bool AppendJoinedBoundaries(LSMeshCollider collider, LSConeCollider cone, MeshConeSurfaceBoundary boundary,
 257    {
 6381258        bool overlaps = false;
 38782259        for (int index = 0; index < _joined!.Inputs.Count; index++)
 260        {
 13010261            Member member = _joined.Members[index];
 13010262            if (member.Connectivity.RegionCount == 0) continue;
 12122263            overlaps |= member.Collider == collider;
 12122264            if (_joined.Members[_joined.GetResponseMember(index)].Collider != collider) continue;
 265            // Face samples and their finite perimeter share one solver pass.
 6078266            if (HasBoundaryIntersection) boundary.BuildSurfaceContacts(member.Collider, cone, member.Triangle, member.Co
 267        }
 6381268        return overlaps;
 269    }
 270}

/home/runner/work/Gravitas/Gravitas/src/Gravitas/CollisionHandling/Detection/3D/Mesh/FaceRegions/MeshConeFaceRegions.Samples.cs

#LineLine coverage
 1//=======================================================================
 2// MeshConeFaceRegions.Samples.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
 8using System;
 9using System.Collections.Generic;
 10using FixedMathSharp;
 11using FixedMathSharp.Geometry;
 12using SwiftCollections;
 13
 14namespace Gravitas.CollisionHandling;
 15
 16/// <content>Finite admitted sampling and exact coverage metrics on once-rounded world anchors in one translated frame.<
 17internal sealed partial class MeshConeFaceRegions
 18{
 1074619    private readonly SwiftList<PoolEvent> _poolEvents = new();
 1074620    private readonly SwiftList<Sample> _samplePool = new();
 21    private readonly IComparer<Sample> _sampleComparer;
 1074622    private Sample[] _samples = Array.Empty<Sample>();
 1074623    private int[] _sampleCounts = Array.Empty<int>();
 24
 25    /// <summary>Gets the reduced count, throwing if eligible geometry could not be materialized.</summary>
 26    internal int GetSampleCount(int region)
 27    {
 5738928        int count = _sampleCounts[ValidateRegion(region)];
 5738829        if (count < 0) throw new OverflowException("An admitted face sample is outside the Fixed64 sampling range.");
 5738230        return count;
 31    }
 32
 33    internal bool TryGetSample(int region, int index, out Vector3d meshPoint, out Vector3d conePoint, out Fixed64 depth)
 34    {
 4573035        meshPoint = conePoint = default; depth = default;
 2288036        if ((uint)region >= (uint)RegionCount || index < 0 || index >= _sampleCounts[region]) return false;
 2285037        Sample sample = _samples[region * ContactManifold.MaxContactsPerGroup + index];
 6855038        meshPoint = sample.MeshPoint; conePoint = sample.ConePoint; depth = sample.Depth;
 2285039        return true;
 40    }
 41
 42    internal ulong GetSampleIdentity(int region, int index)
 43    {
 3540444        ChronicleGuard.ThrowIfListIndexInvalid(index, GetSampleCount(region));
 3540445        return _samples[region * ContactManifold.MaxContactsPerGroup + index].Identity;
 46    }
 47
 48    private void ReduceSamples(int region, WidePlaneMetrics metrics)
 49    {
 918750        _samplePool.FastClear();
 918751        _sampleCounts[region] = 0;
 918752        int orientation = _regions[region].Orientation;
 918753        int peakSlot = 2 * region + (orientation > 0 ? 0 : 1);
 918754        Winner winner = _winners[peakSlot];
 2756155        _currentMember = winner.Member; _currentSupplier = winner.Supplier; _currentSpan = winner.Span;
 918756        _frame = GetFrame(winner.Member);
 918757        int nativeOrientation = GetNativeOrientation(region, winner.Member, orientation);
 918758        var selected = BorrowWinner(peakSlot);
 918759        if (!ConePlaneRayPointMaterialization.TryGetPointInFrame(_frame, selected.Point, selected.Root,
 918760            _samplingOrigin, out Vector3d maximumPoint)
 918761            || !TryMaterializeSample(selected, nativeOrientation, maximumPoint, out Sample maximum))
 462        { _sampleCounts[region] = -1; return; }
 63        // Keep the exact regional maximum first. The rest of this finite pool
 64        // uses intrinsic and true-boundary constructions, independent of seams.
 918565        _samplePool.Add(maximum);
 11518166        foreach (PoolEvent descriptor in _poolEvents.AsReadOnlySpan())
 4840667            if (descriptor.Region == region && !KeepSample(descriptor, orientation))
 268            { _sampleCounts[region] = -1; return; }
 69        System.Diagnostics.Debug.Assert(_samplePool.Count > 0);
 918470        int count = Math.Min(ContactManifold.MaxContactsPerGroup, _samplePool.Count);
 918471        int offset = region * ContactManifold.MaxContactsPerGroup;
 918472        _samples[offset] = _samplePool[0];
 1836873        Span<int> chosen = stackalloc int[ContactManifold.MaxContactsPerGroup]; chosen[0] = 0;
 7298674        for (int slot = 1; slot < count; slot++)
 75        {
 2730976            int best = MeshPlaneSampleReduction.ChooseNext(_samplePool.AsReadOnlySpan(), chosen[..slot], metrics, _sampl
 5461877            chosen[slot] = best; _samples[offset + slot] = _samplePool[best];
 78        }
 79        // Greedy coverage needs only the once-rounded mesh anchors. Round
 80        // exits/depths for the selected outputs, after validating every eligible
 81        // candidate's exact exit range. The exact maximum bounds all depths.
 7298682        for (int slot = 1; slot < count; slot++)
 2730983            _samples[offset + slot] = MaterializeSelected(_samples[offset + slot], GetNativeOrientation(region, _samples
 918484        _sampleCounts[region] = count;
 918485    }
 86
 87    private bool KeepSample(PoolEvent source, int orientation)
 88    {
 4782889        Ray ray = orientation > 0 ? source.Positive : source.Negative;
 4827390        if (!ray.HasValue) return true;
 4738491        if (!ray.IsRepresentable) return false;
 4738292        Vector3d p = source.MeshPoint;
 4738293        var sample = new Sample(ray.Source, ray.Event, p, default, default, member: ray.Member, supplier: source.Supplie
 94        // Native cohorts and joined members can share an exact point.
 95        // Deduplicate before coverage, retaining the first canonical supplier.
 21831796        foreach (Sample existing in _samplePool.AsReadOnlySpan()[..(source.Member < 0 ? 1 : _samplePool.Count)])
 7577697            if (existing.MeshPoint == p && ComparePoints(sample, existing) == 0) return true;
 3804998        _samplePool.Add(sample);
 3804999        return true;
 100    }
 101
 102    private int ComparePoints(Sample first, Sample second)
 103    {
 104        // With identity cone rotation, world X is a positive affine image of
 105        // exact cone-frame X. Distinct rounded X values therefore certify its
 106        // order. Equal X or a rotated cone still needs exact reconstruction;
 107        // rounded Y/Z cannot decide before a potentially distinct exact X.
 19932108        if (_frame.ConeRotation == FixedQuaternion.Identity)
 109        {
 18926110            int order = first.MeshPoint.X.CompareTo(second.MeshPoint.X);
 20256111            if (order != 0) return order;
 112        }
 24812113        if (first.Member >= 0 || second.Member >= 0) return CompareJoinedPoints(first, second);
 12392114        return ConePlaneRayEvents.CompareEventAnchors(first.Source, first.Event, second.Source, second.Event,
 12392115            _frame, includeCoincidentProvenance: false);
 116    }
 117
 118    private Ray CheckRay(scoped in ConePlaneRaySelection selection, int orientation, bool pointRepresentable)
 119    {
 97939120        if (!selection.HasValue) return default;
 121        // A positive whole-cone certificate covers every admitted finite exit.
 122        // An inconclusive bound retains the original exact per-ray range test.
 93895123        bool representable = pointRepresentable && (_wholeConeSamplingRangeRepresentable || ConePlaneRayPointMaterializa
 93895124            _frame, selection.Point, selection.Root,
 93895125            ContactQuadratic.At(selection.Values, selection.Signs, 0, _fieldWords),
 93895126            ContactQuadratic.At(selection.Values, selection.Signs, 1, _fieldWords), orientation, _samplingOrigin));
 93895127        return new Ray(selection.MaximumSource, selection.MaximumEvent, representable, _currentMember, _currentSpan);
 128    }
 129
 130    private Sample MaterializeSelected(Sample sample, int orientation)
 131    {
 81927132        _currentMember = sample.Member; _currentSupplier = sample.Supplier; _currentSpan = sample.Span;
 27309133        _frame = GetFrame(sample.Member);
 27309134        Span<ulong> pv = stackalloc ulong[SelectionWords];
 27309135        Span<ulong> nv = stackalloc ulong[SelectionWords];
 27309136        Span<int> ps = stackalloc int[ConePlaneRaySelection.SignCount];
 27309137        Span<int> ns = stackalloc int[ConePlaneRaySelection.SignCount];
 54618138        var positive = new ConePlaneRaySelection(pv, ps, _fieldWords, _rootWords); var negative = new ConePlaneRaySelect
 27309139        Span<ulong> pointValues = stackalloc ulong[PointWords];
 27309140        Span<int> pointSigns = stackalloc int[ConePlaneRayPoint.SignCount];
 27309141        var point = new ConePlaneRayPoint(pointValues, pointSigns, _fieldWords);
 27309142        Span<ulong> root = stackalloc ulong[_rootWords];
 27309143        bool exists = ConePlaneRayEvents.TryEvaluateEvent(sample.Source, _frame, sample.Event, GetClip(sample.Member, sa
 27309144            ref positive, ref negative, requestedOrientation: orientation);
 27309145        ConePlaneRaySelection selected = orientation > 0 ? positive : negative;
 146        System.Diagnostics.Debug.Assert(exists && selected.HasValue);
 27309147        bool represented = TryMaterializeSample(selected, orientation, sample.MeshPoint, out Sample result);
 148        // The source/frame is unchanged and every eligible exit range was
 149        // checked exactly before reduction; replay preserves that certificate.
 150        System.Diagnostics.Debug.Assert(represented);
 27309151        return result;
 152    }
 153
 154    private bool TryMaterializeSample(scoped in ConePlaneRaySelection selection, int orientation,
 155        Vector3d meshPoint, out Sample sample)
 156    {
 36495157        sample = default;
 158        // The chosen regional minimum is at most half the cone's projection
 159        // width. Its enclosing sphere has radius <= max(height,radius), so
 160        // every selected depth fits Fixed64; the shared getter guards defects.
 36495161        Fixed64 depth = selection.GetRoundedMaximumDepth();
 36495162        if (!ConePlaneRayPointMaterialization.TryGetExitPointsInFrame(_frame, selection.Point, selection.Root,
 36495163                ContactQuadratic.At(selection.Values, selection.Signs, 0, _fieldWords),
 36495164                ContactQuadratic.At(selection.Values, selection.Signs, 1, _fieldWords),
 36496165                orientation, _samplingOrigin, out Vector3d exit, out Vector3d coneLocal)) return false;
 36494166        ref readonly ConePlaneRayFrame supplierFrame = ref GetFrame(_currentSupplier);
 36494167        bool meshLocal = ConePlaneRayPointMaterialization.TryGetAuthoredPoint(supplierFrame, selection.Point, selection.
 36494168            _frame, out Vector3d p);
 169        // Round authored identity directly from the exact point. The paired
 170        // exit owner independently rounds its cone-local anchor; neither is
 171        // recovered by inverting the once-rounded common-frame outputs.
 172        System.Diagnostics.Debug.Assert(meshLocal);
 36494173        ulong identity = ContactManifold.CreateContactId(ContactAnchor.FromWorldPoint(p), 0, ContactAnchor.FromWorldPoin
 36494174        sample = new Sample(selection.MaximumSource, selection.MaximumEvent, meshPoint, exit, depth, identity, _currentM
 36494175        return true;
 176    }
 177
 178    // Availability and exact output range are retained separately. Opposite
 179    // direction overflow cannot poison the chosen direction's finite pool.
 180    private readonly struct Ray
 181    {
 182        internal readonly ConePlaneRayEventSource Source;
 183        internal readonly ConePlaneRayEvent Event;
 184        internal readonly bool HasValue, IsRepresentable;
 185        internal readonly int Member;
 186        internal readonly int Span;
 187        internal Ray(ConePlaneRayEventSource source, ConePlaneRayEvent descriptor, bool representable,
 188            int member = -1, int span = -1)
 657265189        { Source = source; Event = descriptor; HasValue = true; IsRepresentable = representable; Member = member; Span =
 190    }
 191
 192    private readonly struct PoolEvent
 193    {
 194        internal readonly ConePlaneRayEventSource Source;
 195        internal readonly ConePlaneRayEvent Event;
 196        internal readonly int Region;
 197        internal readonly Vector3d MeshPoint;
 198        internal readonly Ray Positive, Negative;
 199        internal readonly int Member, Supplier;
 200        internal PoolEvent(ConePlaneRayEventSource source, ConePlaneRayEvent descriptor, int region, Vector3d meshPoint,
 453843201        { Source = source; Event = descriptor; Region = region; MeshPoint = meshPoint; Positive = positive; Negative = n
 202    }
 203
 204    private readonly struct Sample : IPlaneContactSample
 205    {
 241827206        public Vector3d Point => MeshPoint;
 207        internal readonly ConePlaneRayEventSource Source;
 208        internal readonly ConePlaneRayEvent Event;
 209        internal readonly Vector3d MeshPoint, ConePoint, AuthoredPoint, ConeLocalPoint;
 210        internal readonly Fixed64 Depth;
 211        internal readonly ulong Identity;
 212        internal readonly int Member, Supplier;
 213        internal readonly int Span;
 214        internal Sample(ConePlaneRayEventSource source, ConePlaneRayEvent descriptor, Vector3d p, Vector3d q, Fixed64 de
 215            int member = -1, int supplier = -1, int span = -1,
 216            Vector3d authored = default, Vector3d coneLocal = default)
 217        {
 503256218            Source = source; Event = descriptor; MeshPoint = p; ConePoint = q; Depth = depth; Identity = identity;
 419380219            Member = member; Supplier = supplier; Span = span; AuthoredPoint = authored; ConeLocalPoint = coneLocal;
 83876220        }
 221    }
 222}

Methods/Properties

.ctor()
get_SelectionWords()
get_PointWords()
get_SamplingOrigin()
Build(Gravitas.Colliders.PhysicsMesh,System.Int32,FixedMathSharp.Vector3d,FixedMathSharp.FixedQuaternion,FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,Gravitas.CollisionHandling.MeshSurfaceConnectivity,System.ReadOnlySpan`1<System.Int32>,FixedMathSharp.Vector3d)
Build(Gravitas.Colliders.PhysicsMesh,System.Int32,FixedMathSharp.Geometry.ConePlaneRayFrame&,Gravitas.CollisionHandling.MeshSurfaceConnectivity,System.ReadOnlySpan`1<System.Int32>,FixedMathSharp.Vector3d)
Reserve(System.Int32)
GatherEvents(Gravitas.Colliders.PhysicsMesh,System.Int32,Gravitas.CollisionHandling.MeshSurfaceConnectivity)
AdmitEvaluatedPoint(FixedMathSharp.Geometry.ConePlaneRayEventSource&,FixedMathSharp.Geometry.ConePlaneRayFrame&,FixedMathSharp.Geometry.ConePlaneRayEvent,FixedMathSharp.Geometry.ConePlaneRayPoint,System.ReadOnlySpan`1<System.UInt64>,FixedMathSharp.Geometry.ConePlaneRaySelection&,FixedMathSharp.Geometry.ConePlaneRaySelection&)
GetCompleteConvexFan(Gravitas.Colliders.PhysicsMesh,System.Int32,Gravitas.CollisionHandling.MeshSurfaceConnectivity)
FindPointRegion(Gravitas.Colliders.PhysicsMesh,Gravitas.CollisionHandling.MeshSurfaceConnectivity,System.ReadOnlySpan`1<System.Int32>,FixedMathSharp.Geometry.ConePlaneRayPoint,System.ReadOnlySpan`1<System.UInt64>)
BorrowWinner(System.Int32)
KeepWinner(System.Int32,FixedMathSharp.Geometry.ConePlaneRaySelection&)
ReduceRegion(System.Int32)
GetNormal(System.Int32)
GetOrientation(System.Int32)
TryGetSelectedRay(System.Int32,FixedMathSharp.Vector3d&,FixedMathSharp.Vector3d&,FixedMathSharp.Fixed64&)
ValidateRegion(System.Int32)
.ctor(System.Int32)
.ctor(FixedMathSharp.Geometry.ConePlaneRayEventSource,FixedMathSharp.Geometry.ConePlaneRayEvent,System.Int32,System.Int32,System.Int32)
.ctor()
ReleaseJoined()
BuildJoined(System.ReadOnlySpan`1<System.ValueTuple`2<Gravitas.Colliders.LSMeshCollider,System.Int32>>,Gravitas.Colliders.LSConeCollider,System.ReadOnlySpan`1<Gravitas.Colliders.PhysicsMesh>,SwiftCollections.SwiftDictionary`2<System.ValueTuple`2<Gravitas.Colliders.PhysicsMesh,System.Int32>,Gravitas.CollisionHandling.MeshSurfaceBoundaryDomain>)
JoinFiniteSpans()
JoinAtPoint(FixedMathSharp.Geometry.ConePlaneRayEventSource&,FixedMathSharp.Geometry.ConePlaneRayFrame&,FixedMathSharp.Geometry.ConePlaneRayEvent,FixedMathSharp.Geometry.ConePlaneRayPoint,System.ReadOnlySpan`1<System.UInt64>,FixedMathSharp.Geometry.ConePlaneRaySelection&,FixedMathSharp.Geometry.ConePlaneRaySelection&)
AdmitJoinedPoint(FixedMathSharp.Geometry.ConePlaneRayEventSource&,FixedMathSharp.Geometry.ConePlaneRayFrame&,FixedMathSharp.Geometry.ConePlaneRayEvent,FixedMathSharp.Geometry.ConePlaneRayPoint,System.ReadOnlySpan`1<System.UInt64>,FixedMathSharp.Geometry.ConePlaneRaySelection&,FixedMathSharp.Geometry.ConePlaneRaySelection&)
KeepJoinedWinner(System.Int32,FixedMathSharp.Geometry.ConePlaneRaySelection&)
GetClip(System.Int32,System.Int32)
GetFrame(System.Int32)
GetRegionFrame(System.Int32)
GetNativeOrientation(System.Int32,System.Int32,System.Int32)
CompareJoinedPoints(Gravitas.CollisionHandling.MeshConeFaceRegions/Sample,Gravitas.CollisionHandling.MeshConeFaceRegions/Sample)
IsResponseCarrier(Gravitas.Colliders.LSMeshCollider,System.Int32)
GetJoinedSample(System.Int32,System.Int32,Gravitas.Colliders.LSMeshCollider&,System.Int32&)
GetJoinedBoundary(Gravitas.Colliders.LSMeshCollider,System.Int32)
GetRetainedBoundaryInterval(Gravitas.Colliders.LSMeshCollider,System.Int32,System.Int32&)
GetMember(Gravitas.Colliders.LSMeshCollider,System.Int32)
GetBoundaryFrame(Gravitas.Colliders.LSMeshCollider,System.Int32)
GetBoundaryOrientation(Gravitas.Colliders.LSMeshCollider,System.Int32,System.Int32)
IsJoinedSpan(Gravitas.Colliders.LSMeshCollider,System.Int32,System.Int32)
GetJoinedCornerFan(Gravitas.Colliders.LSMeshCollider,System.Int32,System.Int32,System.Boolean&)
AppendJoinedBoundaries(Gravitas.Colliders.LSMeshCollider,Gravitas.Colliders.LSConeCollider,Gravitas.CollisionHandling.MeshConeSurfaceBoundary,Gravitas.CollisionHandling.ContactManifold)
.ctor()
GetSampleCount(System.Int32)
TryGetSample(System.Int32,System.Int32,FixedMathSharp.Vector3d&,FixedMathSharp.Vector3d&,FixedMathSharp.Fixed64&)
GetSampleIdentity(System.Int32,System.Int32)
ReduceSamples(System.Int32,FixedMathSharp.Geometry.WidePlaneMetrics)
KeepSample(Gravitas.CollisionHandling.MeshConeFaceRegions/PoolEvent,System.Int32)
ComparePoints(Gravitas.CollisionHandling.MeshConeFaceRegions/Sample,Gravitas.CollisionHandling.MeshConeFaceRegions/Sample)
CheckRay(FixedMathSharp.Geometry.ConePlaneRaySelection&,System.Int32,System.Boolean)
MaterializeSelected(Gravitas.CollisionHandling.MeshConeFaceRegions/Sample,System.Int32)
TryMaterializeSample(FixedMathSharp.Geometry.ConePlaneRaySelection&,System.Int32,FixedMathSharp.Vector3d,Gravitas.CollisionHandling.MeshConeFaceRegions/Sample&)
.ctor(FixedMathSharp.Geometry.ConePlaneRayEventSource,FixedMathSharp.Geometry.ConePlaneRayEvent,System.Boolean,System.Int32,System.Int32)
.ctor(FixedMathSharp.Geometry.ConePlaneRayEventSource,FixedMathSharp.Geometry.ConePlaneRayEvent,System.Int32,FixedMathSharp.Vector3d,Gravitas.CollisionHandling.MeshConeFaceRegions/Ray,Gravitas.CollisionHandling.MeshConeFaceRegions/Ray,System.Int32,System.Int32)
get_Point()
.ctor(FixedMathSharp.Geometry.ConePlaneRayEventSource,FixedMathSharp.Geometry.ConePlaneRayEvent,FixedMathSharp.Vector3d,FixedMathSharp.Vector3d,FixedMathSharp.Fixed64,System.UInt64,System.Int32,System.Int32,System.Int32,FixedMathSharp.Vector3d,FixedMathSharp.Vector3d)