< Summary

Line coverage
100%
Covered lines: 324
Uncovered lines: 0
Coverable lines: 324
Total lines: 583
Line coverage: 100%
Branch coverage
100%
Covered branches: 348
Total branches: 348
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

/home/runner/work/Gravitas/Gravitas/src/Gravitas/Core/3D/StaticSurfaces/StaticSurface.ContinuousCollision.cs

#LineLine coverage
 1//=======================================================================
 2// StaticSurface.ContinuousCollision.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 Gravitas.CollisionHandling;
 13using SwiftCollections;
 14using SwiftCollections.Query;
 15
 16namespace Gravitas;
 17
 18/// <content>Admits CCD witness normals against the existing exact incident surface sectors.</content>
 19public sealed partial class StaticSurface
 20{
 49321    private readonly MeshSurfaceBoundaryFan _continuousFan = new();
 49322    private readonly SwiftList<MeshSurfaceBoundaryDomain> _continuousBoundaries = new();
 49323    private readonly SwiftList<LSMeshCollider> _continuousMixedMembers = new();
 24    private ContactManifold? _continuousMixedFiltered;
 4325    internal int ContinuousOrder => ((IPhysicsColliderRegistryItem)_members[0]).ReplayOrder;
 26
 27    internal bool IntersectsMixedContinuous(LSCollider2D mover, Fixed64 padding = default,
 28        ReadOnlySpan<(LSMeshCollider Supplier, int Owner)> resolved = default)
 29    {
 71230        if (!GatherMixedContinuous(mover, padding)) return true;
 238031        foreach (var surface in _surfaces.AsReadOnlySpan())
 32        {
 66733            LSMeshCollider member = surface.Collider;
 66734            int owner = member.Mesh.GetManifoldSurfaceOwner(surface.Triangle);
 66735            bool handled = IsHandledContinuousFamily(member, owner, resolved);
 66736            if (padding > Fixed64.Zero && ContinuousCollisionBounds.AreSeparated(member, mover, padding)) continue;
 66737            if (CollisionDetectionMixed.IntersectsForContinuousCollision(member, mover, padding, owner,
 103738                handled ? SlabFaces : null)) return true;
 39        }
 33840        return false;
 41    }
 42
 43    internal void AppendMixedContinuousContacts(LSCollider2D mover, ContactManifold destination,
 44        ReadOnlySpan<(LSMeshCollider Supplier, int Owner)> resolved = default)
 45    {
 2646        GatherMixedContinuous(mover, Fixed64.Zero);
 2647        _continuousMixedMembers.Clear();
 48        try
 49        {
 50            // Native emission gathers projected suppliers again. Snapshot only
 51            // the local carrier candidates before those existing owners run.
 2652            LSMeshCollider? previous = null;
 14453            foreach (var surface in _surfaces.AsReadOnlySpan())
 4654                if (surface.Collider != previous)
 9055                { previous = surface.Collider; _continuousMixedMembers.Add(previous); }
 14256            foreach (LSMeshCollider member in _continuousMixedMembers.AsReadOnlySpan())
 57            {
 4558                ContactManifold target = resolved.IsEmpty ? destination : (_continuousMixedFiltered ??= new());
 6059                if (!resolved.IsEmpty) target.BeginUpdate(_context.FrameCount);
 4560                CollisionDetectionMixed.AppendManifold(member, mover, target, 0, 0, surfaceResponse: true);
 4561                if (resolved.IsEmpty) continue;
 6062                for (int index = 0; index < target.GroupCount; index++)
 63                {
 1564                    ref ContactGroup group = ref target.GetGroup(index);
 1565                    if (SlabFaces.TryGetContinuousFamily(group.Key, out LSMeshCollider supplier, out int owner)
 1566                        && IsHandledContinuousFamily(supplier, owner, resolved)) continue;
 5667                    for (int point = 0; point < group.Count; point++) destination.AddContact(group.Key, group[point]);
 68                }
 69            }
 2670        }
 7871        finally { _continuousMixedMembers.Clear(); _continuousMixedFiltered?.Reset(); }
 2672    }
 73
 74    internal void CaptureMixedContinuousFamilies(ContactManifold manifold, in ContactResponseSnapshot impact,
 75        LSCollider2D mover, SwiftList<(LSMeshCollider Supplier, int Owner)> destination)
 76    {
 10577        destination.Clear();
 42878        for (int index = 0; index < manifold.GroupCount; index++)
 79        {
 10980            ref ContactGroup group = ref manifold.GetGroup(index);
 10981            if (!SlabFaces.TryGetContinuousFamily(group.Key, out LSMeshCollider supplier, out int owner)) continue;
 21482            for (int point = 0; point < group.Count; point++)
 10683                if (MixedContact.IsClosingContact(group[point], impact.CenterA, impact.LinearA, impact.AngularA,
 10684                    impact.CenterB, impact.LinearB, impact.AngularB, impact.PlanarAngularB, mover))
 20885                { destination.Add((supplier, owner)); break; }
 86        }
 10587    }
 88
 89    private bool IsHandledContinuousFamily(LSMeshCollider member, int owner,
 90        ReadOnlySpan<(LSMeshCollider Supplier, int Owner)> resolved)
 91    {
 70592        if (!_facesCurrent || !_mixedSlab) return false;
 184293        foreach (var family in resolved)
 41294            if (family.Supplier.StaticSurface == this
 71295                && SlabFaces.IsSameContinuousFamily(member, owner, family.Supplier, family.Owner)) return true;
 35996        return false;
 97    }
 98
 99    private bool GatherMixedContinuous(LSCollider2D mover, Fixed64 padding)
 100    {
 736101        FixedBoundBox box = mover.MixedBounds3D;
 736102        if (padding > Fixed64.Zero)
 103        {
 234104            Vector3d expansion = Vector3d.One * padding;
 234105            if (!Vector3d.TrySubtract(box.Min, expansion, out Vector3d minimum)
 236106                || !Vector3d.TryAdd(box.Max, expansion, out Vector3d maximum)) return false;
 232107            box = FixedBoundBox.FromMinMax(minimum, maximum);
 108        }
 734109        Gather(null, mover, new FixedBoundVolume(box.Min, box.Max));
 734110        return true;
 111    }
 112
 113    internal bool AdmitContinuousWitness(LSCollider? mover, LSCollider2D? embedded, Vector3d center,
 114        LSMeshCollider target, int triangle, in ContactAnchor witness,
 115        WideDirection3d? exactOutward = null, Fixed64? circleSlabHalfThickness = null)
 116    {
 117        System.Diagnostics.Debug.Assert(triangle >= 0);
 39118        Fixed64 reach = mover != null ? mover.CanonicalCenteredProxyRadius * Fixed64.Two
 39119            : embedded!.CanonicalCenteredProxyRadius * Fixed64.Two + embedded.MixedHalfThickness;
 39120        FixedBoundBox box = FixedBoundBox.FromCenterAndScopeClippedToDomain(center, Vector3d.One * reach);
 39121        Gather(mover, embedded, new(box.Min, box.Max));
 39122        _continuousBoundaries.FastClear();
 220123        foreach (var surface in _surfaces.AsReadOnlySpan())
 71124            _continuousBoundaries.Add(_boundaries[(surface.Collider.Mesh,
 71125                surface.Collider.Mesh.GetManifoldSurfaceOwner(surface.Triangle))]);
 167126        foreach (var boundary in _continuousBoundaries.AsReadOnlySpan())
 127        {
 63128            if (_meshes[boundary.SourceMember] != target.Mesh
 63129                || boundary.SourceSurface != target.Mesh.GetManifoldSurfaceOwner(triangle)) continue;
 130            // Only exact original-boundary incidence can remove a conservative
 131            // cast. Unknown/interior witnesses keep their geometric result.
 37132            if (_continuousFan.BuildAtAnchor(_meshes, boundary.SourceMember, triangle,
 37133                    witness.GeometryPoint, _continuousBoundaries.AsReadOnlySpan()))
 134            {
 37135                RationalPoint3d point = RationalPoint3d.FromAnchor(witness.GeometryPoint);
 37136                if (circleSlabHalfThickness.HasValue)
 137                {
 138                    // A finite circle/slab has a vertical core. Its side ray
 139                    // is horizontal while the witness is inside that core;
 140                    // cap/rim provenance stays conservative here.
 4141                    RationalPoint3d lower = RationalPoint3d.FromAnchor(new FixedPointAnchor(center,
 4142                        FixedQuaternion.Identity, new Vector3d(Fixed64.Zero, -circleSlabHalfThickness.Value, Fixed64.Zer
 4143                    RationalPoint3d upper = RationalPoint3d.FromAnchor(new FixedPointAnchor(center,
 4144                        FixedQuaternion.Identity, new Vector3d(Fixed64.Zero, circleSlabHalfThickness.Value, Fixed64.Zero
 4145                    exactOutward = null;
 4146                    if (RationalPoint3d.CompareProjection(point, lower, Vector3d.Up) >= 0
 4147                        && RationalPoint3d.CompareProjection(point, upper, Vector3d.Up) <= 0)
 148                    {
 2149                        WideDirection3d radial = WideTriangleRelations.GetScaledPointDifference(RationalPoint3d.FromScal
 2150                            point, WideArithmetic.TruncateSigned320By64(point.Denominator));
 2151                        exactOutward = new WideDirection3d(radial.X, default, radial.Z);
 152                    }
 153                }
 154                // A rounded normal without its producer's axis cannot certify
 155                // exclusion. Rounded witnesses must also retain the original
 156                // finite triangle's supporting-point contract.
 37157                return !exactOutward.HasValue || exactOutward.Value.IsZero
 37158                    || !MeshSurfaceBoundaryFan.SupportsTriangle(target.Mesh, triangle,
 37159                        point, exactOutward.Value)
 37160                    || _continuousFan.Supports(exactOutward.Value);
 161            }
 162        }
 2163        return true;
 164    }
 165}

/home/runner/work/Gravitas/Gravitas/src/Gravitas/Core/3D/StaticSurfaces/StaticSurface.cs

#LineLine coverage
 1//=======================================================================
 2// StaticSurface.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 Gravitas.CollisionHandling;
 13using SwiftCollections;
 14using SwiftCollections.Query;
 15
 16namespace Gravitas;
 17
 18/// <summary>Declares continuity between registered static meshes using triangle-surface collision in one context.</summ
 19/// <remarks>
 20/// Exact shared boundary spans participate in one physical surface while members
 21/// retain their collider identities, materials, queries and overlap events.
 22/// Members require <see cref="MeshColliderMode.Concave"/>; their geometry may be
 23/// convex or closed, but a closed shell is not treated as a filled convex volume.
 24/// Create declarations through <see cref="GravitasPhysicsService.CreateStaticSurface"/>.
 25/// Context reset or disposal ends the declaration's lifetime.
 26/// </remarks>
 27/// <content>Owns declared member lifetime and cached finite response families.</content>
 28public sealed partial class StaticSurface : IDisposable, Chronicler.IRecordable
 29{
 30    private readonly GravitasWorldContext _context;
 49331    private LSMeshCollider[] _members = Array.Empty<LSMeshCollider>();
 49332    private PhysicsMesh[] _meshes = Array.Empty<PhysicsMesh>();
 49333    private FixedBoundBox[] _memberBounds = Array.Empty<FixedBoundBox>();
 49334    private readonly SwiftHashSet<int> _changedSuppliers = new();
 49335    private readonly SwiftHashSet<PhysicsMesh> _dirtyMeshes = new();
 49336    private readonly SwiftDictionary<(PhysicsMesh, int), MeshSurfaceBoundaryDomain> _boundaries = new();
 98637    private readonly SwiftList<int> _candidates = new(), _triangles = new();
 49338    private readonly SwiftList<(LSMeshCollider Collider, int Triangle)> _surfaces = new();
 49339    private readonly SwiftHashSet<(PhysicsMesh, int)> _owners = new();
 49340    private readonly SwiftList<(PhysicsMesh, int)> _cachedOwners = new();
 41    private Vector3d _center;
 42    private FixedQuaternion _rotation;
 43    private Fixed64 _coreLength, _radius;
 44    private enum ContactFamily { Rounded, Cone, Slab, Hull }
 45    private ContactFamily _cachedFamily;
 46    private bool _facesCurrent;
 47    private Vector2d _halfFootprint;
 48    private MeshSlabFaceRegions? _slabFaces;
 49    private MeshHullSurfaceContacts? _hullContacts;
 50    private PhysicsMesh? _movingMesh;
 51    private uint _movingVersion;
 52    private bool _dirty, _disposed;
 49353    internal readonly MeshCapsuleFaceRegions Faces = new();
 49354    internal readonly MeshConeFaceRegions ConeFaces = new();
 1886255    internal MeshSlabFaceRegions SlabFaces => _slabFaces ??= new();
 1061856    internal MeshHullSurfaceContacts HullContacts => _hullContacts ??= new();
 412657    internal int ReplayMembership => _members.Length == 0 ? 0 : _members[0].ReplayOrdinal + 1;
 58
 49359    internal StaticSurface(GravitasWorldContext context, ReadOnlySpan<LSMeshCollider> members)
 60    {
 49361        _context = context;
 49362        ReplaceMembers(members);
 49063    }
 64
 65    /// <summary>Atomically replaces the registered members of this declaration.</summary>
 66    /// <param name="members">Distinct active meshes in <see cref="MeshColliderMode.Concave"/> with bodyless or explicit
 67    /// <remarks>
 68    /// Call between complete fixed steps. Rejection preserves the previous membership.
 69    /// Membership permits exact joining; disconnected pieces retain their boundaries.
 70    /// Deactivated members must be explicitly added again after reinitialization.
 71    /// </remarks>
 72    /// <exception cref="ArgumentException">A member is ineligible or belongs to another declaration.</exception>
 73    /// <exception cref="ObjectDisposedException">This declaration or its context has ended.</exception>
 74    /// <exception cref="InvalidOperationException">A fixed step is in progress.</exception>
 75    public void ReplaceMembers(ReadOnlySpan<LSMeshCollider> members)
 76    {
 56577        _context.ThrowIfDisposed();
 56478        _context.ThrowIfFixedStepMutationNotAllowed();
 56579        if (_disposed) throw new ObjectDisposedException(nameof(StaticSurface));
 56180        var next = members.ToArray();
 56181        var meshes = new PhysicsMesh[next.Length];
 56182        var unique = new SwiftHashSet<LSMeshCollider>();
 336283        for (int index = 0; index < next.Length; index++)
 84        {
 113585            LSMeshCollider member = next[index];
 86            // Registry identity verifies context and rejects stale or recycled IDs.
 113587            if (member == null || !unique.Add(member)
 113588                || !_context.Physics.TryGetColliderById(member.Id, out var registered) || registered != member
 113589                || !member.IsStatic || !member.IsActive || member.IsDeactivationInProgress
 113590                || member.Mode != MeshColliderMode.Concave
 113591                || member.StaticSurface != null && member.StaticSurface != this)
 1592                throw new ArgumentException("Members must be distinct registered static concave meshes in this context."
 93        }
 54694        bool unchanged = next.Length == _members.Length;
 141995        foreach (LSMeshCollider member in _members) unchanged &= unique.Contains(member);
 59096        if (unchanged) return;
 97        // Logical live registration order survives recycled registry-slot layouts.
 50298        Array.Sort(next, static (first, second) => ((IPhysicsColliderRegistryItem)first).ReplayOrder
 50299            .CompareTo(((IPhysicsColliderRegistryItem)second).ReplayOrder));
 4118100        for (int index = 0; index < next.Length; index++) meshes[index] = next[index].Mesh;
 101        // Prepare before publishing associations so failed admission leaves the old declaration usable.
 502102        var prepared = PrepareBoundaries(meshes);
 502103        var bounds = new FixedBoundBox[next.Length];
 4118104        for (int index = 0; index < next.Length; index++) bounds[index] = next[index].Bounds;
 502105        LSMeshCollider[] previousMembers = _members;
 1076106        foreach (LSMeshCollider previous in previousMembers)
 60107            if (!unique.Contains(previous)) Invalidate(changed: previous);
 1112108        foreach (LSMeshCollider previous in previousMembers) previous.StaticSurface = null;
 1506109        _members = next; _meshes = meshes; _memberBounds = bounds;
 502110        _dirtyMeshes.Clear();
 4518111        _continuousBoundaries.Clear(); Faces.ReleaseJoined(); ConeFaces.ReleaseJoined(); _slabFaces?.ReleaseJoined(); _h
 502112        _boundaries.Clear();
 4226113        foreach (var entry in prepared) _boundaries.Add(entry.Key, entry.Value);
 4118114        foreach (LSMeshCollider member in _members) member.StaticSurface = this;
 3080115        foreach (LSMeshCollider member in _members)
 2064116            if (Array.IndexOf(previousMembers, member) < 0) Invalidate(changed: member);
 502117        _dirty = false;
 502118    }
 119
 120    private static SwiftDictionary<(PhysicsMesh, int), MeshSurfaceBoundaryDomain> PrepareBoundaries(PhysicsMesh[] meshes
 121    {
 502122        var result = new SwiftDictionary<(PhysicsMesh, int), MeshSurfaceBoundaryDomain>();
 3080123        for (int member = 0; member < meshes.Length; member++)
 124        {
 1038125            PhysicsMesh mesh = meshes[member];
 8542126            for (int triangle = 0; triangle < mesh.TriangleCount; triangle++)
 127            {
 3233128                int owner = mesh.GetManifoldSurfaceOwner(triangle);
 3233129                if (result.ContainsKey((mesh, owner))) continue;
 1074130                var domain = new MeshSurfaceBoundaryDomain();
 1074131                domain.Build(meshes, member, triangle);
 1074132                result.Add((mesh, owner), domain);
 133            }
 134        }
 502135        return result;
 136    }
 137
 138    internal void Invalidate(bool geometryChanged = false, LSMeshCollider? changed = null, bool includeNeighbors = true)
 139    {
 1579140        _dirty |= geometryChanged;
 1579141        _facesCurrent = false;
 1579142        _mixedSlab = false;
 1579143        _changedSuppliers.Clear();
 3158144        FixedBoundBox before = default, after = default;
 1579145        if (changed != null)
 146        {
 1089147            int index = Array.IndexOf(_members, changed);
 2178148            before = _memberBounds[index]; after = changed.Bounds;
 1089149            _memberBounds[index] = after;
 150        }
 11326151        for (int index = 0; index < _members.Length; index++)
 4084152            if (changed == null || _members[index] == changed || includeNeighbors
 4084153                && (_memberBounds[index].Intersects(before) || _memberBounds[index].Intersects(after)))
 154            {
 3197155                _changedSuppliers.Add(_members[index].Id + 1);
 3197156                _members[index].MarkContactDependencyChanged(notifySurface: false);
 3228157                if (geometryChanged) _dirtyMeshes.Add(_meshes[index]);
 158            }
 159        // Borrowed rows can live on a carrier without an overlap pair for the
 160        // edited supplier. Scan existing references only when a member changes.
 11326161        foreach (LSMeshCollider member in _members)
 4084162            _context.Physics.ClearWarmStartCachesForCollider(member, _changedSuppliers);
 1579163        _context.MixedCollisions.InvalidateSurfaceContacts(this, null, _changedSuppliers);
 1579164        _changedSuppliers.Clear();
 1579165    }
 166
 167    internal void Remove(LSMeshCollider member)
 168    {
 11169        int index = Array.IndexOf(_members, member);
 12170        if (index < 0) return;
 10171        Invalidate(geometryChanged: true, changed: member);
 10172        member.StaticSurface = null;
 100173        _continuousBoundaries.Clear(); Faces.ReleaseJoined(); ConeFaces.ReleaseJoined(); _slabFaces?.ReleaseJoined(); _h
 10174        Array.Copy(_members, index + 1, _members, index, _members.Length - index - 1);
 10175        Array.Copy(_memberBounds, index + 1, _memberBounds, index, _memberBounds.Length - index - 1);
 10176        Array.Resize(ref _members, _members.Length - 1);
 10177        Array.Resize(ref _memberBounds, _members.Length);
 10178        _meshes = new PhysicsMesh[_members.Length];
 47179        for (int i = 0; i < _members.Length; i++) _meshes[i] = _members[i].Mesh;
 10180        _dirtyMeshes.Clear();
 47181        foreach (PhysicsMesh mesh in _meshes) _dirtyMeshes.Add(mesh);
 10182    }
 183
 49205184    internal int Gather(LSCollider mover, FixedBoundVolume bounds) => Gather(mover, null, bounds);
 185
 186    private int Gather(LSCollider? mover, LSCollider2D? embedded, FixedBoundVolume bounds)
 187    {
 52669188        if (_dirty)
 189        {
 54190            for (int member = 0; member < _meshes.Length; member++)
 191            {
 17192                PhysicsMesh mesh = _meshes[member];
 17193                if (!_dirtyMeshes.Contains(mesh)) continue;
 84194                for (int triangle = 0; triangle < mesh.TriangleCount; triangle++)
 195                {
 28196                    int owner = mesh.GetManifoldSurfaceOwner(triangle);
 28197                    if (owner != triangle) continue;
 14198                    if (!_boundaries.TryGetValue((mesh, owner), out MeshSurfaceBoundaryDomain domain))
 7199                        _boundaries.Add((mesh, owner), domain = new());
 14200                    domain.Build(_meshes, member, triangle);
 201                }
 202            }
 10203            _dirtyMeshes.Clear();
 10204            _dirty = false;
 205        }
 105338206        _surfaces.Clear(); _owners.Clear();
 52669207        LSCollider? participant = mover?.CompoundOwner ?? mover;
 52669208        LSCollider2D? planar = embedded?.CompoundOwner ?? embedded;
 209        // Reuse the committed index; Y rejection keeps its planar candidates conservative in 3D.
 52669210        _context.Collisions.QueryPlanarColliderCandidates(new(bounds.Min.X, bounds.Min.Z, bounds.Max.X, bounds.Max.Z), _
 377952211        foreach (int id in _candidates.AsReadOnlySpan())
 212        {
 136307213            _context.Physics.TryGetColliderById(id, out var candidate);
 136307214            if (candidate is not LSMeshCollider mesh
 136307215                || mesh.StaticSurface != this || mesh.IsTrigger
 136307216                || (participant != null ? !_context.Physics.RequireCollisionPair(mesh, participant)
 136307217                    : !_context.MixedCollisions.RequireCollisionPair(mesh, planar!))
 136307218                || mesh.BoundsMax.Y < bounds.Min.Y || mesh.BoundsMin.Y > bounds.Max.Y) continue;
 86638219            mesh.GetTrianglesInBounds(bounds, _triangles);
 599440220            foreach (int triangle in _triangles.AsReadOnlySpan())
 299772221                if (_owners.Add((mesh.Mesh, mesh.Mesh.GetManifoldSurfaceOwner(triangle)))) _surfaces.Add((mesh, triangle
 222        }
 52669223        return _surfaces.Count;
 224    }
 225
 226    internal int GatherProjectedSupport(LSCollider mover)
 227    {
 228        // A support projected onto an intersecting plane is within sqrt(2) R
 229        // of the shape center. 2 R conservatively includes its finite supplier,
 230        // even when that piece has no initial overlap or broad-phase pair.
 13065231        Fixed64 reach = mover.CanonicalCenteredProxyRadius * Fixed64.Two;
 13065232        FixedBoundBox bounds = FixedBoundBox.FromCenterAndScopeClippedToDomain(mover.Center, Vector3d.One * reach);
 13065233        return Gather(mover, new(bounds.Min, bounds.Max));
 234    }
 235
 236    internal void BuildHull(LSMeshCollider mover)
 237    {
 5955238        bool reuse = _facesCurrent && _cachedFamily == ContactFamily.Hull && _movingMesh == mover.Mesh
 5955239            && _movingVersion == mover.RuntimeShapeVersion && _center == mover.Center && _rotation == mover.Rotation
 5955240            && _cachedOwners.Count == _owners.Count;
 44334241        foreach (var owner in _cachedOwners.AsReadOnlySpan()) reuse &= _owners.Contains(owner);
 7247242        if (reuse) return;
 9326243        _facesCurrent = false; _cachedFamily = ContactFamily.Hull;
 4663244        HullContacts.Build(_surfaces.AsReadOnlySpan(), mover, _meshes, _boundaries);
 4663245        _cachedOwners.Clear();
 26270246        foreach (var surface in _surfaces.AsReadOnlySpan())
 8472247            _cachedOwners.Add((surface.Collider.Mesh, surface.Collider.Mesh.GetManifoldSurfaceOwner(surface.Triangle)));
 9326248        _movingMesh = mover.Mesh; _movingVersion = mover.RuntimeShapeVersion;
 13989249        _center = mover.Center; _rotation = mover.Rotation; _facesCurrent = true;
 4663250    }
 251
 252    internal void BuildRounded(Vector3d center, FixedQuaternion rotation, Fixed64 coreLength, Fixed64 radius)
 253    {
 254        // Gather rechecks live eligibility. Reuse requires the complete owner set, not a hash of it.
 13192255        bool reuse = _facesCurrent && _cachedFamily == ContactFamily.Rounded && _center == center && _rotation == rotati
 13192256            && _radius == radius && _cachedOwners.Count == _owners.Count;
 106601257        foreach (var owner in _cachedOwners.AsReadOnlySpan()) reuse &= _owners.Contains(owner);
 20205258        if (reuse) return;
 12358259        _facesCurrent = false; _cachedFamily = ContactFamily.Rounded;
 6179260        Faces.BuildJoined(_surfaces.AsReadOnlySpan(), center, rotation, coreLength, radius, _meshes, _boundaries);
 6179261        _cachedOwners.Clear();
 37416262        foreach (var surface in _surfaces.AsReadOnlySpan())
 12529263            _cachedOwners.Add((surface.Collider.Mesh, surface.Collider.Mesh.GetManifoldSurfaceOwner(surface.Triangle)));
 24716264        _center = center; _rotation = rotation; _coreLength = coreLength; _radius = radius;
 6179265        _facesCurrent = true;
 6179266    }
 267
 268    internal void BuildCone(LSConeCollider cone)
 269    {
 6381270        bool reuse = _facesCurrent && _cachedFamily == ContactFamily.Cone && _center == cone.Center && _rotation == cone
 6381271            && _coreLength == cone.Height && _radius == cone.ScaledRadius && _cachedOwners.Count == _owners.Count;
 51501272        foreach (var owner in _cachedOwners.AsReadOnlySpan()) reuse &= _owners.Contains(owner);
 9722273        if (reuse) return;
 6080274        _facesCurrent = false; _cachedFamily = ContactFamily.Cone;
 3040275        ConeFaces.BuildJoined(_surfaces.AsReadOnlySpan(), cone, _meshes, _boundaries);
 3040276        _cachedOwners.Clear();
 18410277        foreach (var surface in _surfaces.AsReadOnlySpan())
 6165278            _cachedOwners.Add((surface.Collider.Mesh, surface.Collider.Mesh.GetManifoldSurfaceOwner(surface.Triangle)));
 12160279        _center = cone.Center; _rotation = cone.Rotation; _coreLength = cone.Height; _radius = cone.ScaledRadius;
 3040280        _facesCurrent = true;
 3040281    }
 282
 283    internal void BuildSlab(LSCollider mover, Fixed64 radius, Fixed64 halfThickness, Vector2d halfFootprint)
 284    {
 7110285        bool reuse = _facesCurrent && _cachedFamily == ContactFamily.Slab && !_mixedSlab && _center == mover.Center && _
 7110286            && _coreLength == halfThickness && _radius == radius && _halfFootprint == halfFootprint && _cachedOwners.Cou
 53685287        foreach (var owner in _cachedOwners.AsReadOnlySpan()) reuse &= _owners.Contains(owner);
 8703288        if (reuse) return;
 11034289        _facesCurrent = false; _cachedFamily = ContactFamily.Slab;
 5517290        _mixedSlab = false;
 5517291        SlabFaces.BuildJoined(_surfaces.AsReadOnlySpan(), mover, radius, halfThickness, halfFootprint, _meshes, _boundar
 5517292        _cachedOwners.Clear();
 31370293        foreach (var surface in _surfaces.AsReadOnlySpan())
 10168294            _cachedOwners.Add((surface.Collider.Mesh, surface.Collider.Mesh.GetManifoldSurfaceOwner(surface.Triangle)));
 27585295        _center = mover.Center; _rotation = mover.Rotation; _coreLength = halfThickness; _radius = radius; _halfFootprin
 5517296        _facesCurrent = true;
 5517297    }
 298
 299    /// <summary>Ends this declaration and restores independent member response.</summary>
 300    /// <remarks>Call between complete fixed steps. Members remain registered. Repeated disposal is harmless.</remarks>
 301    /// <exception cref="InvalidOperationException">A fixed step is in progress.</exception>
 302    public void Dispose()
 303    {
 636304        if (_disposed) return;
 484305        _context.ThrowIfFixedStepMutationNotAllowed();
 483306        Release();
 483307        _context.Physics.RemoveStaticSurface(this);
 483308    }
 309
 310    internal void Release()
 311    {
 490312        Invalidate();
 3956313        foreach (LSMeshCollider member in _members) member.StaticSurface = null;
 980314        _members = Array.Empty<LSMeshCollider>(); _meshes = Array.Empty<PhysicsMesh>();
 980315        _memberBounds = Array.Empty<FixedBoundBox>(); _dirtyMeshes.Clear();
 1960316        _boundaries.Clear(); _surfaces.Clear(); _cachedOwners.Clear(); _owners.Clear();
 3430317        _continuousBoundaries.Clear(); Faces.ReleaseJoined(); ConeFaces.ReleaseJoined(); _slabFaces?.ReleaseJoined(); _h
 490318    }
 319}

/home/runner/work/Gravitas/Gravitas/src/Gravitas/Core/3D/StaticSurfaces/StaticSurface.Mixed.cs

#LineLine coverage
 1//=======================================================================
 2// StaticSurface.Mixed.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 Gravitas.CollisionHandling;
 13
 14namespace Gravitas;
 15
 16/// <content>Reuses joined finite-slab response for an embedded planar participant.</content>
 17public sealed partial class StaticSurface
 18{
 19    private bool _mixedSlab;
 20    private Fixed64 _mixedLength;
 21
 22    internal bool AppendMixed(LSMeshCollider overlap, LSCollider2D mover, ContactManifold destination,
 23        int namespace3D, int namespace2D)
 24    {
 269125        Vector3d center = MixedEmbedded2DGeometry.GetCenter3D(mover);
 269126        Fixed64 reach = mover.CanonicalCenteredProxyRadius * Fixed64.Two + mover.MixedHalfThickness;
 269127        FixedBoundBox box = FixedBoundBox.FromCenterAndScopeClippedToDomain(center, Vector3d.One * reach);
 269128        Gather(null, mover, new(box.Min, box.Max));
 269129        Fixed64 yaw = mover is LSAABBoxCollider2D ? Fixed64.Zero : mover.Rotation;
 269130        FixedQuaternion rotation = FixedQuaternion.FromAxisAngle(Vector3d.Up, -yaw);
 269131        Span<Vector2d> boxOffsets = stackalloc Vector2d[4];
 269132        ReadOnlySpan<Vector2d> offsets = CollisionDetectionMixed.GetConvexPrismOffsets(mover, boxOffsets);
 269133        Fixed64 length = mover is LSCapsuleCollider2D capsule ? capsule.AxisLength : Fixed64.Zero;
 269134        Fixed64 radius = mover is LSCircleCollider2D circle ? circle.ScaledRadius
 269135            : mover is LSCapsuleCollider2D stadium ? stadium.ScaledRadius : Fixed64.Zero;
 269136        bool reuse = _facesCurrent && _cachedFamily == ContactFamily.Slab && _mixedSlab
 269137            && _center == center && _rotation == rotation && _mixedLength == length && _radius == radius
 269138            && _coreLength == mover.MixedHalfThickness && SlabFaces.PrismOffsets.Span.SequenceEqual(offsets)
 269139            && _cachedOwners.Count == _owners.Count;
 1966840        foreach (var owner in _cachedOwners.AsReadOnlySpan()) reuse &= _owners.Contains(owner);
 269141        if (!reuse)
 42        {
 372043            _facesCurrent = false; _cachedFamily = ContactFamily.Slab;
 186044            SlabFaces.BuildJoined(_surfaces.AsReadOnlySpan(), center, rotation, length, radius,
 186045                mover.MixedHalfThickness, offsets,
 186046                new(mover.MixedBounds3D.Min, mover.MixedBounds3D.Max), false, _meshes, _boundaries);
 186047            _cachedOwners.Clear();
 1045448            foreach (var surface in _surfaces.AsReadOnlySpan())
 336749                _cachedOwners.Add((surface.Collider.Mesh, surface.Collider.Mesh.GetManifoldSurfaceOwner(surface.Triangle
 558050            _mixedSlab = true; _mixedLength = length; _radius = radius;
 744051            _center = center; _rotation = rotation; _coreLength = mover.MixedHalfThickness; _facesCurrent = true;
 52        }
 269153        return SlabFaces.AppendJoinedContacts(overlap, mover.Material, _context.CollisionScratch.MeshSlabBoundary,
 269154            destination, mover, namespace3D, namespace2D);
 55    }
 56}

/home/runner/work/Gravitas/Gravitas/src/Gravitas/Core/3D/StaticSurfaces/StaticSurface.Serialization.cs

#LineLine coverage
 1//=======================================================================
 2// StaticSurface.Serialization.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.Globalization;
 10using Chronicler;
 11using Gravitas.Colliders;
 12
 13namespace Gravitas;
 14
 15/// <content>Records declared membership using host-resolved links to existing collider lifetimes.</content>
 16public sealed partial class StaticSurface
 17{
 18    /// <inheritdoc/>
 19    public void RecordData(IChronicler chronicler)
 20    {
 2621        ChronicleGuard.ThrowIfNull(chronicler, nameof(chronicler));
 2522        _context.ThrowIfDisposed();
 2723        if (_disposed) throw new ObjectDisposedException(nameof(StaticSurface));
 2324        bool loading = chronicler.Mode == SerializationMode.Loading;
 3925        if (loading) _context.ThrowIfFixedStepMutationNotAllowed();
 2226        int schema = 1;
 2227        RecordValues.Look(chronicler, ref schema, "SurfaceSchemaVersion", 0);
 2428        if (schema != 1) throw new InvalidOperationException("Unsupported static-surface membership schema.");
 2029        int count = _members.Length;
 2030        RecordValues.Look(chronicler, ref count, "MemberCount", -1);
 2031        if (count < 0 || count > _context.Physics.ColliderCount)
 332            throw new ArgumentOutOfRangeException(nameof(count), "Membership must fit the registered collider graph.");
 1733        LSMeshCollider[] members = loading ? new LSMeshCollider[count] : _members;
 8034        for (int index = 0; index < count; index++)
 35        {
 2536            LSMeshCollider member = members[index];
 2537            RecordLinks.Look(chronicler, ref member, "Member" + index.ToString(CultureInfo.InvariantCulture));
 3838            if (loading) members[index] = member;
 39        }
 40        // Resolve the entire candidate graph before publishing any association.
 2441        if (loading) ReplaceMembers(members);
 1142    }
 43}

Methods/Properties

.ctor(Gravitas.GravitasWorldContext,System.ReadOnlySpan`1<Gravitas.Colliders.LSMeshCollider>)
get_ContinuousOrder()
IntersectsMixedContinuous(Gravitas.Colliders.LSCollider2D,FixedMathSharp.Fixed64,System.ReadOnlySpan`1<System.ValueTuple`2<Gravitas.Colliders.LSMeshCollider,System.Int32>>)
AppendMixedContinuousContacts(Gravitas.Colliders.LSCollider2D,Gravitas.CollisionHandling.ContactManifold,System.ReadOnlySpan`1<System.ValueTuple`2<Gravitas.Colliders.LSMeshCollider,System.Int32>>)
CaptureMixedContinuousFamilies(Gravitas.CollisionHandling.ContactManifold,Gravitas.CollisionHandling.ContactResponseSnapshot&,Gravitas.Colliders.LSCollider2D,SwiftCollections.SwiftList`1<System.ValueTuple`2<Gravitas.Colliders.LSMeshCollider,System.Int32>>)
IsHandledContinuousFamily(Gravitas.Colliders.LSMeshCollider,System.Int32,System.ReadOnlySpan`1<System.ValueTuple`2<Gravitas.Colliders.LSMeshCollider,System.Int32>>)
GatherMixedContinuous(Gravitas.Colliders.LSCollider2D,FixedMathSharp.Fixed64)
AdmitContinuousWitness(Gravitas.Colliders.LSCollider,Gravitas.Colliders.LSCollider2D,FixedMathSharp.Vector3d,Gravitas.Colliders.LSMeshCollider,System.Int32,Gravitas.CollisionHandling.ContactAnchor&,System.Nullable`1<FixedMathSharp.Geometry.WideDirection3d>,System.Nullable`1<FixedMathSharp.Fixed64>)
.ctor(Gravitas.GravitasWorldContext,System.ReadOnlySpan`1<Gravitas.Colliders.LSMeshCollider>)
get_SlabFaces()
get_HullContacts()
get_ReplayMembership()
ReplaceMembers(System.ReadOnlySpan`1<Gravitas.Colliders.LSMeshCollider>)
PrepareBoundaries(Gravitas.Colliders.PhysicsMesh[])
Invalidate(System.Boolean,Gravitas.Colliders.LSMeshCollider,System.Boolean)
Remove(Gravitas.Colliders.LSMeshCollider)
Gather(Gravitas.Colliders.LSCollider,SwiftCollections.Query.FixedBoundVolume)
Gather(Gravitas.Colliders.LSCollider,Gravitas.Colliders.LSCollider2D,SwiftCollections.Query.FixedBoundVolume)
GatherProjectedSupport(Gravitas.Colliders.LSCollider)
BuildHull(Gravitas.Colliders.LSMeshCollider)
BuildRounded(FixedMathSharp.Vector3d,FixedMathSharp.FixedQuaternion,FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
BuildCone(Gravitas.Colliders.LSConeCollider)
BuildSlab(Gravitas.Colliders.LSCollider,FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Vector2d)
Dispose()
Release()
AppendMixed(Gravitas.Colliders.LSMeshCollider,Gravitas.Colliders.LSCollider2D,Gravitas.CollisionHandling.ContactManifold,System.Int32,System.Int32)
RecordData(Chronicler.IChronicler)