< Summary

Information
Class: Gravitas.Queries.SweptSphereQueryWorker
Assembly: Gravitas
File(s): /home/runner/work/Gravitas/Gravitas/src/Gravitas/Queries/3D/Sweeps/SweptSphereQueryWorker.cs
Line coverage
100%
Covered lines: 343
Uncovered lines: 0
Coverable lines: 343
Total lines: 608
Line coverage: 100%
Branch coverage
100%
Covered branches: 112
Total branches: 112
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
.ctor()100%11100%
Prepare(...)100%44100%
TrySweep(...)100%2222100%
TrySweepSphere(...)100%11100%
TrySweepSphere(...)100%22100%
TrySweepCapsule(...)100%22100%
TrySweepCylinder(...)100%11100%
TrySweepCone(...)100%11100%
TrySweepSupportMapped(...)100%44100%
TrySweepCuboid(...)100%22100%
TrySweepMeshForContinuousCollision(...)100%11100%
TrySweepMesh(...)100%11100%
TrySweepMesh(...)100%5454100%
TrySweepCompound(...)100%22100%
TrySweepTriangle(...)100%22100%
TrySweepTriangleFace(...)100%1212100%
TrySweepTriangleEdge(...)100%22100%
BuildFiniteAxisSweepHit(...)100%11100%
TryKeepEarlierSweep(...)100%44100%
CreateSweepBounds(...)100%11100%

File(s)

/home/runner/work/Gravitas/Gravitas/src/Gravitas/Queries/3D/Sweeps/SweptSphereQueryWorker.cs

#LineLine coverage
 1//=======================================================================
 2// SweptSphereQueryWorker.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.Queries;
 17
 18/// <summary>
 19/// Performs deterministic swept-sphere checks for one prepared segment.
 20/// </summary>
 21public sealed class SweptSphereQueryWorker
 22{
 123    private static readonly Fixed64 BoundsTolerance = Fixed64.FromFraction(1, 4096);
 24
 1864325    private readonly SwiftList<int> _meshTriangleBuffer = new();
 1864326    private readonly ConvexSweepQueryWorker _finiteAxisConvexSweep = new();
 27
 28    private Vector3d _start;
 29    private Vector3d _end;
 30    private Vector3d _sweptBoundsMin;
 31    private Vector3d _sweptBoundsMax;
 32    private Fixed64 _length;
 33    private Fixed64 _radius;
 34    private int _sweepDepth;
 35
 36    internal int LastMeshTriangleCandidateCount { get; private set; }
 37
 38    /// <summary>
 39    /// Prepares this worker for a swept sphere from <paramref name="start"/> to <paramref name="end"/>.
 40    /// </summary>
 41    public void Prepare(Vector3d start, Vector3d end, Fixed64 radius)
 42    {
 2204843        _start = start;
 2204844        _end = end;
 2204845        _radius = radius;
 46
 2204847        if (!Vector3d.TrySubtract(end, start, out Vector3d segment)
 2204848            || !Vector3d.TryGetMagnitude(segment, out _length))
 49        {
 250            _length = Fixed64.Zero;
 251            return;
 52        }
 53
 2204654        SweepBoundsUtility.CreateSweptSphereBounds(
 2204655            start,
 2204656            end,
 2204657            radius,
 2204658            BoundsTolerance,
 2204659            out _sweptBoundsMin,
 2204660            out _sweptBoundsMax);
 2204661        _finiteAxisConvexSweep.PrepareSphereSource(
 2204662            start,
 2204663            radius,
 2204664            segment);
 2204665    }
 66
 67    /// <summary>
 68    /// Checks a collider against the prepared swept sphere.
 69    /// </summary>
 70    public bool TrySweep(
 71        LSCollider collider,
 72        out Vector3d sphereCenterAtImpact,
 73        out Fixed64 impactDistance)
 74    {
 2090275        if (_sweepDepth == 0)
 1960776            LastMeshTriangleCandidateCount = 0;
 77
 2090278        _sweepDepth++;
 2090279        sphereCenterAtImpact = Vector3d.Zero;
 2090280        impactDistance = Fixed64.Zero;
 81
 82        try
 83        {
 2090284            if (_length <= Fixed64.Epsilon
 2090285                || !SweepBoundsUtility.OverlapsInclusive(_sweptBoundsMin, _sweptBoundsMax, collider.BoundsMin, collider.
 86            {
 606787                return false;
 88            }
 89
 1483590            bool found = collider switch
 1483591            {
 847592                LSSphereCollider sphere => TrySweepSphere(sphere.Center, sphere.ScaledRadius, _radius, out sphereCenterA
 4193                LSCapsuleCollider capsule => TrySweepCapsule(capsule, out sphereCenterAtImpact, out impactDistance),
 116994                LSCuboidCollider cuboid => TrySweepCuboid(cuboid, out sphereCenterAtImpact, out impactDistance),
 70295                LSCylinderCollider cylinder => TrySweepCylinder(cylinder, out sphereCenterAtImpact, out impactDistance),
 68796                LSConeCollider cone => TrySweepCone(cone, out sphereCenterAtImpact, out impactDistance),
 252697                LSMeshCollider mesh => TrySweepMesh(mesh, out sphereCenterAtImpact, out impactDistance),
 123098                LSCompoundCollider compound => TrySweepCompound(compound, out sphereCenterAtImpact, out impactDistance),
 599                _ => false
 14835100            };
 101
 14835102            if (!found)
 103            {
 766104                sphereCenterAtImpact = Vector3d.Zero;
 766105                impactDistance = Fixed64.Zero;
 106            }
 107
 14835108            return found;
 109        }
 110        finally
 111        {
 20902112            _sweepDepth--;
 20902113        }
 20902114    }
 115
 116    private bool TrySweepSphere(
 117        Vector3d center,
 118        Fixed64 radius,
 119        Fixed64 radiusExpansion,
 120        out Vector3d sphereCenterAtImpact,
 121        out Fixed64 impactDistance) =>
 8475122        TrySweepSphere(
 8475123            _start,
 8475124            _end,
 8475125            _length,
 8475126            center,
 8475127            radius,
 8475128            radiusExpansion,
 8475129            out sphereCenterAtImpact,
 8475130            out impactDistance);
 131
 132    private static bool TrySweepSphere(
 133        Vector3d start,
 134        Vector3d end,
 135        Fixed64 length,
 136        Vector3d center,
 137        Fixed64 radius,
 138        Fixed64 radiusExpansion,
 139        out Vector3d sphereCenterAtImpact,
 140        out Fixed64 impactDistance)
 141    {
 15039142        sphereCenterAtImpact = Vector3d.Zero;
 15039143        impactDistance = Fixed64.Zero;
 144
 15039145        var query = new FixedSegment(start, end);
 15039146        if (!query.TryGetSphereIntersectionDistanceInterval(
 15039147                new FixedBoundSphere(center, radius),
 15039148                radiusExpansion,
 15039149                length,
 15039150                out Fixed64 distance,
 15039151                out _,
 15039152                out _,
 15039153                out _))
 7060154            return false;
 155
 7979156        impactDistance = distance;
 7979157        sphereCenterAtImpact = query.GetPointAtDistance(distance, length);
 7979158        return true;
 159    }
 160
 161    private bool TrySweepCapsule(
 162        LSCapsuleCollider capsule,
 163        out Vector3d sphereCenterAtImpact,
 164        out Fixed64 impactDistance)
 165    {
 41166        sphereCenterAtImpact = Vector3d.Zero;
 41167        impactDistance = Fixed64.Zero;
 168
 41169        var query = new FixedSegment(_start, _end);
 41170        if (!query.TryGetCapsuleIntersectionDistanceInterval(
 41171                capsule.Center,
 41172                capsule.Rotation,
 41173                capsule.AxisLength,
 41174                capsule.ScaledRadius,
 41175                _radius,
 41176                _length,
 41177                out Fixed64 entry,
 41178                out _,
 41179                out _,
 41180                out _))
 181        {
 2182            return false;
 183        }
 184
 39185        BuildFiniteAxisSweepHit(entry, out sphereCenterAtImpact, out impactDistance);
 39186        return true;
 187    }
 188
 189    private bool TrySweepCylinder(
 190        LSCylinderCollider cylinder,
 191        out Vector3d sphereCenterAtImpact,
 192        out Fixed64 impactDistance) =>
 702193        TrySweepSupportMapped(
 702194            cylinder,
 702195            out sphereCenterAtImpact,
 702196            out impactDistance);
 197
 198    private bool TrySweepCone(
 199        LSConeCollider cone,
 200        out Vector3d sphereCenterAtImpact,
 201        out Fixed64 impactDistance) =>
 687202        TrySweepSupportMapped(
 687203            cone,
 687204            out sphereCenterAtImpact,
 687205            out impactDistance);
 206
 207    private bool TrySweepSupportMapped(
 208        LSCollider target,
 209        out Vector3d sphereCenterAtImpact,
 210        out Fixed64 impactDistance)
 211    {
 1389212        sphereCenterAtImpact = Vector3d.Zero;
 1389213        impactDistance = Fixed64.Zero;
 1389214        bool found = _finiteAxisConvexSweep.TrySweepPreparedSource(
 1389215                target,
 1389216                out Physics3DHit hit);
 1389217        LastMeshTriangleCandidateCount += _finiteAxisConvexSweep.LastMeshTriangleCandidateCount;
 1389218        if (!found)
 219        {
 12220            return false;
 221        }
 222
 1377223        Fixed64 distance = _length - hit.Distance <= BoundsTolerance
 1377224            ? _length
 1377225            : hit.Distance;
 1377226        BuildFiniteAxisSweepHit(
 1377227            distance,
 1377228            out sphereCenterAtImpact,
 1377229            out impactDistance);
 1377230        return true;
 231    }
 232
 233    private bool TrySweepCuboid(
 234        LSCuboidCollider cuboid,
 235        out Vector3d sphereCenterAtImpact,
 236        out Fixed64 impactDistance)
 237    {
 1169238        sphereCenterAtImpact = Vector3d.Zero;
 1169239        impactDistance = Fixed64.Zero;
 240
 1169241        var query = new FixedSegment(_start, _end);
 1169242        if (!query.TryGetSweptSphereOrientedBoxIntersectionDistance(
 1169243                cuboid.OrientedBox,
 1169244                _radius,
 1169245                _length,
 1169246                out Fixed64 entry))
 247        {
 20248            return false;
 249        }
 250
 1149251        BuildFiniteAxisSweepHit(entry, out sphereCenterAtImpact, out impactDistance);
 1149252        return true;
 253    }
 254
 255    internal bool TrySweepMeshForContinuousCollision(LSMeshCollider mesh,
 256        ContinuousSurfaceTriangleAdmission admit, out Physics3DHit hit)
 257    {
 342258        LastMeshTriangleCandidateCount = 0;
 342259        return TrySweepMesh(mesh, out _, out _, out hit, admit);
 260    }
 261
 262    private bool TrySweepMesh(
 263        LSMeshCollider mesh,
 264        out Vector3d sphereCenterAtImpact,
 2526265        out Fixed64 impactDistance) => TrySweepMesh(mesh, out sphereCenterAtImpact, out impactDistance, out _, null);
 266
 267    private bool TrySweepMesh(LSMeshCollider mesh, out Vector3d sphereCenterAtImpact, out Fixed64 impactDistance,
 268        out Physics3DHit admittedHit, ContinuousSurfaceTriangleAdmission? admit)
 269    {
 2868270        admittedHit = default;
 2868271        sphereCenterAtImpact = Vector3d.Zero;
 2868272        impactDistance = Fixed64.MaxValue;
 273
 2868274        CreateSweepBounds(_start, _end, _radius, out Vector3d min, out Vector3d max);
 2868275        mesh.GetTrianglesInBounds(new FixedBoundVolume(min, max), _meshTriangleBuffer);
 2868276        LastMeshTriangleCandidateCount += _meshTriangleBuffer.Count;
 277
 2868278        var startAnchor = new FixedPointAnchor(
 2868279            _start,
 2868280            FixedQuaternion.Identity,
 2868281            Vector3d.Zero);
 2868282        var endAnchor = new FixedPointAnchor(
 2868283            _end,
 2868284            FixedQuaternion.Identity,
 2868285            Vector3d.Zero);
 2868286        bool rigid = mesh.Mesh.GeometryFrame.IsRigid;
 2868287        Vector3d chartOrigin = rigid ? mesh.Mesh.GeometryFrame.RigidOrigin : mesh.Mesh.Origin;
 2868288        FixedQuaternion chartRotation = rigid ? mesh.Mesh.GeometryFrame.Rotation : FixedQuaternion.Identity;
 2868289        if (!startAnchor.TryGetLocalPointIn(
 2868290                chartOrigin,
 2868291                chartRotation,
 2868292                out Vector3d localStart)
 2868293            || !endAnchor.TryGetLocalPointIn(
 2868294                chartOrigin,
 2868295                chartRotation,
 2868296                out Vector3d localEnd))
 297        {
 2298            return false;
 299        }
 300
 2866301        ReadOnlySpan<int> corners = default;
 2866302        if (admit == null && _meshTriangleBuffer.Count > 2
 2866303            && _meshTriangleBuffer.Count == mesh.Mesh.TriangleCount && mesh.Mesh.HasSingleConvexCoplanarPatch)
 304        {
 69305            CreateSweepBounds(_start, _start, _radius, out Vector3d initialMin, out Vector3d initialMax);
 69306            if (!SweepBoundsUtility.OverlapsInclusive(initialMin, initialMax, mesh.Bounds.Min, mesh.Bounds.Max))
 60307                corners = mesh.Mesh.GetConvexCoplanarPatchCornerVertexIndices(0);
 308        }
 309
 2866310        bool found = false;
 2866311        int triangleCount = corners.IsEmpty ? _meshTriangleBuffer.Count : corners.Length - 2;
 17340312        for (int i = 0; i < triangleCount; i++)
 313        {
 5804314            int triangleIndex = corners.IsEmpty ? _meshTriangleBuffer[i] : -1;
 315            Vector3d first, second, third, normal;
 5804316            if (corners.IsEmpty)
 317            {
 5684318                mesh.Mesh.GetGeometryTriangleVertices(triangleIndex, out first, out second, out third);
 5684319                normal = mesh.Mesh.GetScaledLocalFaceNormal(triangleIndex);
 320            }
 321            else
 322            {
 323                // The certified corner fan covers the same finite surface; CCD keeps authored identities.
 120324                var vertices = mesh.Mesh.GeometryVertices;
 120325                first = vertices[corners[0]];
 120326                second = vertices[corners[i + 1]];
 120327                third = vertices[corners[i + 2]];
 120328                normal = mesh.Mesh.GetScaledLocalFaceNormal(0);
 329            }
 330            bool triangleFound;
 331            Fixed64 triangleDistance;
 5804332            if (!rigid)
 333            {
 304334                var authoredTriangle = new FixedTriangle(first, second, third);
 335                // Retain the analytic finite roots whenever the physical
 336                // triangle is exactly representable in this translated chart.
 337                // A failed exact division must never round its input geometry.
 304338                if (!mesh.Mesh.GeometryFrame.GetPoint(first).TryGetExactLocalPointIn(chartOrigin, chartRotation, out fir
 304339                    || !mesh.Mesh.GeometryFrame.GetPoint(second).TryGetExactLocalPointIn(chartOrigin, chartRotation, out
 304340                    || !mesh.Mesh.GeometryFrame.GetPoint(third).TryGetExactLocalPointIn(chartOrigin, chartRotation, out 
 341                {
 63342                    triangleFound = WideTriangleRelations.TryGetSweptSphereDistance(authoredTriangle,
 63343                        mesh.Mesh.GeometryFrame, new FixedSegment(_start, _end), _length, _radius,
 63344                        out triangleDistance);
 63345                    goto SelectTriangle;
 346                }
 241347                normal = WideTriangleRelations.GetScaledTriangleLocalNormal(authoredTriangle, mesh.Mesh.GeometryFrame)
 241348                    .Transform(mesh.Mesh.GeometryFrame.GeometryBasis).GetNormal(false);
 349            }
 5741350            triangleFound = TrySweepTriangle(
 5741351                    first,
 5741352                    second,
 5741353                    third,
 5741354                    normal,
 5741355                    localStart,
 5741356                    localEnd,
 5741357                    exactFaceProjection: !corners.IsEmpty,
 5741358                    out _, out triangleDistance);
 359        SelectTriangle:
 5804360            if (!triangleFound || triangleDistance >= impactDistance) continue;
 2835361            Physics3DHit candidate = default;
 2835362            if (admit != null)
 363            {
 365364                Vector3d center = new FixedSegment(_start, _end).GetPointAtDistance(triangleDistance, _length);
 365365                mesh.Mesh.GetGeometryTriangleVertices(triangleIndex, out var a, out var b, out var c);
 366                // A finite closest point stays in the admitted small physical
 367                // mesh envelope. Its bounds center supplies a nearby chart even
 368                // at clipped scalar faces; the authored origin may be far away.
 365369                bool represented = WideTriangleRelations.TryGetClosestPointAnchor(new(a, b, c), mesh.Mesh.GeometryFrame,
 365370                    center, mesh.Bounds.Center, out FixedPointAnchor anchor);
 371                System.Diagnostics.Debug.Assert(represented);
 365372                RationalPoint3d point = RationalPoint3d.FromAnchor(anchor);
 365373                WideDirection3d axis = WideTriangleRelations.GetScaledPointDifference(RationalPoint3d.FromScalarPoint(ce
 365374                    point, WideArithmetic.TruncateSigned320By64(point.Denominator));
 365375                RationalPoint3d centerPoint = RationalPoint3d.FromScalarPoint(center);
 365376                if (axis.IsZero || WideTriangleRelations.ContainsProjection(new(a, b, c), mesh.Mesh.GeometryFrame, cente
 377                {
 378                    // A face projection has its exact plane normal even when
 379                    // rounding the final point moves it onto an authored seam.
 314380                    axis = WideTriangleRelations.GetScaledTriangleLocalNormal(new(a, b, c), mesh.Mesh.GeometryFrame)
 314381                        .Transform(mesh.Mesh.GeometryFrame.GeometryBasis);
 314382                    var sweep = new WideAxis3(Signed320.ExtendValue(WideArithmetic.Difference(_end.X, _start.X)),
 314383                        Signed320.ExtendValue(WideArithmetic.Difference(_end.Y, _start.Y)),
 314384                        Signed320.ExtendValue(WideArithmetic.Difference(_end.Z, _start.Z)));
 314385                    int side = WideDirection3d.Dot(axis, WideTriangleRelations.GetScaledPointDifference(centerPoint,
 314386                        mesh.Mesh.GeometryFrame.GetPoint(a), mesh.Mesh.GeometryFrame.RotationDenominator)).Sign;
 317387                    if (side < 0 || side == 0 && WideDirection3d.Dot(axis, sweep).Sign > 0) axis = -axis;
 388                }
 365389                candidate = new(mesh, new ContactAnchor(anchor), axis.GetNormal(false), triangleDistance, (_end - _start
 365390                if (!admit(triangleIndex, ref candidate, axis)) continue;
 391            }
 2637392            found = true;
 2637393            impactDistance = triangleDistance;
 2637394            admittedHit = candidate;
 395        }
 396
 2866397        if (found)
 398        {
 2588399            sphereCenterAtImpact = new FixedSegment(
 2588400                _start,
 2588401                _end).GetPointAtDistance(
 2588402                    impactDistance,
 2588403                    _length);
 404        }
 2866405        return found;
 406    }
 407
 408    private bool TrySweepCompound(
 409        LSCompoundCollider compound,
 410        out Vector3d sphereCenterAtImpact,
 411        out Fixed64 impactDistance)
 412    {
 1230413        sphereCenterAtImpact = Vector3d.Zero;
 1230414        impactDistance = Fixed64.MaxValue;
 415
 1230416        bool found = false;
 5050417        for (int i = 0; i < compound.PartCount; i++)
 418        {
 1295419            found |= TryKeepEarlierSweep(
 1295420                TrySweep(compound.GetPartCollider(i), out Vector3d partHit, out Fixed64 partDistance),
 1295421                partHit,
 1295422                partDistance,
 1295423                ref sphereCenterAtImpact,
 1295424                ref impactDistance);
 425        }
 426
 1230427        return found;
 428    }
 429
 430    private bool TrySweepTriangle(
 431        Vector3d first,
 432        Vector3d second,
 433        Vector3d third,
 434        Vector3d normal,
 435        Vector3d start,
 436        Vector3d end,
 437        bool exactFaceProjection,
 438        out Vector3d sphereCenterAtImpact,
 439        out Fixed64 impactDistance)
 440    {
 5741441        sphereCenterAtImpact = Vector3d.Zero;
 5741442        impactDistance = Fixed64.MaxValue;
 443
 5741444        var triangle = new FixedTriangle(first, second, third);
 5741445        Vector3d closestAtStart = triangle.ClosestPoint(start);
 5741446        if (Vector3d.DistanceSquared(start, closestAtStart) <= _radius * _radius)
 447        {
 3553448            sphereCenterAtImpact = start;
 3553449            impactDistance = Fixed64.Zero;
 3553450            return true;
 451        }
 452
 2188453        bool found = false;
 2188454        found |= TryKeepEarlierSweep(
 2188455            TrySweepTriangleFace(triangle, normal, _radius, start, end, exactFaceProjection, out Vector3d frontHit, out 
 2188456            frontHit,
 2188457            frontDistance,
 2188458            ref sphereCenterAtImpact,
 2188459            ref impactDistance);
 2188460        found |= TryKeepEarlierSweep(
 2188461            TrySweepTriangleFace(triangle, normal, -_radius, start, end, exactFaceProjection, out Vector3d backHit, out 
 2188462            backHit,
 2188463            backDistance,
 2188464            ref sphereCenterAtImpact,
 2188465            ref impactDistance);
 2188466        found |= TryKeepEarlierSweep(
 2188467            TrySweepTriangleEdge(first, second, start, end, out Vector3d firstEdgeHit, out Fixed64 firstEdgeDistance),
 2188468            firstEdgeHit,
 2188469            firstEdgeDistance,
 2188470            ref sphereCenterAtImpact,
 2188471            ref impactDistance);
 2188472        found |= TryKeepEarlierSweep(
 2188473            TrySweepTriangleEdge(second, third, start, end, out Vector3d secondEdgeHit, out Fixed64 secondEdgeDistance),
 2188474            secondEdgeHit,
 2188475            secondEdgeDistance,
 2188476            ref sphereCenterAtImpact,
 2188477            ref impactDistance);
 2188478        found |= TryKeepEarlierSweep(
 2188479            TrySweepTriangleEdge(third, first, start, end, out Vector3d thirdEdgeHit, out Fixed64 thirdEdgeDistance),
 2188480            thirdEdgeHit,
 2188481            thirdEdgeDistance,
 2188482            ref sphereCenterAtImpact,
 2188483            ref impactDistance);
 2188484        found |= TryKeepEarlierSweep(
 2188485            TrySweepSphere(start, end, _length, first, Fixed64.Zero, _radius, out Vector3d firstVertexHit, out Fixed64 f
 2188486            firstVertexHit,
 2188487            firstVertexDistance,
 2188488            ref sphereCenterAtImpact,
 2188489            ref impactDistance);
 2188490        found |= TryKeepEarlierSweep(
 2188491            TrySweepSphere(start, end, _length, second, Fixed64.Zero, _radius, out Vector3d secondVertexHit, out Fixed64
 2188492            secondVertexHit,
 2188493            secondVertexDistance,
 2188494            ref sphereCenterAtImpact,
 2188495            ref impactDistance);
 2188496        found |= TryKeepEarlierSweep(
 2188497            TrySweepSphere(start, end, _length, third, Fixed64.Zero, _radius, out Vector3d thirdVertexHit, out Fixed64 t
 2188498            thirdVertexHit,
 2188499            thirdVertexDistance,
 2188500            ref sphereCenterAtImpact,
 2188501            ref impactDistance);
 502
 2188503        return found;
 504    }
 505
 506    private bool TrySweepTriangleFace(
 507        FixedTriangle triangle,
 508        Vector3d normal,
 509        Fixed64 signedRadius,
 510        Vector3d start,
 511        Vector3d end,
 512        bool exactFaceProjection,
 513        out Vector3d sphereCenterAtImpact,
 514        out Fixed64 impactDistance)
 515    {
 4376516        sphereCenterAtImpact = Vector3d.Zero;
 4376517        impactDistance = Fixed64.Zero;
 518
 4376519        Fixed64 denominator = Vector3d.Dot(end - start, normal);
 4376520        if (denominator == Fixed64.Zero)
 1006521            return false;
 522
 3370523        Fixed64 signedStartDistance = Vector3d.Dot(start - triangle.A, normal);
 524        // Keep plane entry and the final center on the same authored chord;
 525        // a rounded unit direction can move a grazing trajectory across a face.
 3370526        if (!Fixed64.TryMultiplyDivide(signedRadius - signedStartDistance, _length,
 3370527                denominator, out Fixed64 distance)
 3370528            || distance < Fixed64.Zero || distance > _length)
 1864529            return false;
 530
 1506531        Vector3d center = new FixedSegment(start, end).GetPointAtDistance(distance, _length);
 1506532        Vector3d pointOnPlane = center - normal * signedRadius;
 533        // Retriangulation must retain admitted micro faces; authored fallback keeps its original predicate.
 1506534        bool contains = exactFaceProjection
 1506535            ? WideTriangleRelations.ContainsProjection(triangle, Vector3d.Zero, FixedQuaternion.Identity,
 1506536                new FixedPointAnchor(pointOnPlane, FixedQuaternion.Identity, Vector3d.Zero))
 1506537            : triangle.ContainsProjection(pointOnPlane);
 1506538        if (!contains)
 361539            return false;
 540
 1145541        sphereCenterAtImpact = center;
 1145542        impactDistance = distance;
 1145543        return true;
 544    }
 545
 546    private bool TrySweepTriangleEdge(
 547        Vector3d edgeStart,
 548        Vector3d edgeEnd,
 549        Vector3d start,
 550        Vector3d end,
 551        out Vector3d sphereCenterAtImpact,
 552        out Fixed64 impactDistance)
 553    {
 6564554        sphereCenterAtImpact = Vector3d.Zero;
 6564555        impactDistance = Fixed64.MaxValue;
 556
 6564557        var query = new FixedSegment(start, end);
 6564558        var edgeAxis = new FixedSegment(edgeStart, edgeEnd);
 6564559        if (!query.TryGetFiniteCylinderIntersectionDistanceInterval(
 6564560                edgeAxis,
 6564561                Fixed64.Zero,
 6564562                _radius,
 6564563                _length,
 6564564                out Fixed64 entry,
 6564565                out _,
 6564566                out _,
 6564567                out _))
 568        {
 5701569            return false;
 570        }
 571
 863572        impactDistance = entry;
 863573        sphereCenterAtImpact = query.GetPointAtDistance(entry, _length);
 863574        return true;
 575    }
 576
 577    private void BuildFiniteAxisSweepHit(
 578        Fixed64 distance,
 579        out Vector3d sphereCenterAtImpact,
 580        out Fixed64 impactDistance)
 581    {
 2565582        impactDistance = distance;
 2565583        sphereCenterAtImpact = new FixedSegment(_start, _end)
 2565584            .GetPointAtDistance(distance, _length);
 2565585    }
 586
 587    private static bool TryKeepEarlierSweep(
 588        bool candidateFound,
 589        Vector3d candidateCenter,
 590        Fixed64 candidateDistance,
 591        ref Vector3d sphereCenterAtImpact,
 592        ref Fixed64 impactDistance)
 593    {
 18799594        if (!candidateFound || candidateDistance >= impactDistance)
 16210595            return false;
 596
 2589597        sphereCenterAtImpact = candidateCenter;
 2589598        impactDistance = candidateDistance;
 2589599        return true;
 600    }
 601
 602    private static void CreateSweepBounds(Vector3d start, Vector3d end, Fixed64 radius, out Vector3d min, out Vector3d m
 603    {
 2937604        Vector3d radiusExtents = Vector3d.One * radius;
 2937605        min = Vector3d.Min(start, end) - radiusExtents;
 2937606        max = Vector3d.Max(start, end) + radiusExtents;
 2937607    }
 608}

Methods/Properties

.cctor()
.ctor()
Prepare(FixedMathSharp.Vector3d,FixedMathSharp.Vector3d,FixedMathSharp.Fixed64)
TrySweep(Gravitas.Colliders.LSCollider,FixedMathSharp.Vector3d&,FixedMathSharp.Fixed64&)
TrySweepSphere(FixedMathSharp.Vector3d,FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Vector3d&,FixedMathSharp.Fixed64&)
TrySweepSphere(FixedMathSharp.Vector3d,FixedMathSharp.Vector3d,FixedMathSharp.Fixed64,FixedMathSharp.Vector3d,FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Vector3d&,FixedMathSharp.Fixed64&)
TrySweepCapsule(Gravitas.Colliders.LSCapsuleCollider,FixedMathSharp.Vector3d&,FixedMathSharp.Fixed64&)
TrySweepCylinder(Gravitas.Colliders.LSCylinderCollider,FixedMathSharp.Vector3d&,FixedMathSharp.Fixed64&)
TrySweepCone(Gravitas.Colliders.LSConeCollider,FixedMathSharp.Vector3d&,FixedMathSharp.Fixed64&)
TrySweepSupportMapped(Gravitas.Colliders.LSCollider,FixedMathSharp.Vector3d&,FixedMathSharp.Fixed64&)
TrySweepCuboid(Gravitas.Colliders.LSCuboidCollider,FixedMathSharp.Vector3d&,FixedMathSharp.Fixed64&)
TrySweepMeshForContinuousCollision(Gravitas.Colliders.LSMeshCollider,Gravitas.Queries.ContinuousSurfaceTriangleAdmission,Gravitas.Queries.Physics3DHit&)
TrySweepMesh(Gravitas.Colliders.LSMeshCollider,FixedMathSharp.Vector3d&,FixedMathSharp.Fixed64&)
TrySweepMesh(Gravitas.Colliders.LSMeshCollider,FixedMathSharp.Vector3d&,FixedMathSharp.Fixed64&,Gravitas.Queries.Physics3DHit&,Gravitas.Queries.ContinuousSurfaceTriangleAdmission)
TrySweepCompound(Gravitas.Colliders.LSCompoundCollider,FixedMathSharp.Vector3d&,FixedMathSharp.Fixed64&)
TrySweepTriangle(FixedMathSharp.Vector3d,FixedMathSharp.Vector3d,FixedMathSharp.Vector3d,FixedMathSharp.Vector3d,FixedMathSharp.Vector3d,FixedMathSharp.Vector3d,System.Boolean,FixedMathSharp.Vector3d&,FixedMathSharp.Fixed64&)
TrySweepTriangleFace(FixedMathSharp.Geometry.FixedTriangle,FixedMathSharp.Vector3d,FixedMathSharp.Fixed64,FixedMathSharp.Vector3d,FixedMathSharp.Vector3d,System.Boolean,FixedMathSharp.Vector3d&,FixedMathSharp.Fixed64&)
TrySweepTriangleEdge(FixedMathSharp.Vector3d,FixedMathSharp.Vector3d,FixedMathSharp.Vector3d,FixedMathSharp.Vector3d,FixedMathSharp.Vector3d&,FixedMathSharp.Fixed64&)
BuildFiniteAxisSweepHit(FixedMathSharp.Fixed64,FixedMathSharp.Vector3d&,FixedMathSharp.Fixed64&)
TryKeepEarlierSweep(System.Boolean,FixedMathSharp.Vector3d,FixedMathSharp.Fixed64,FixedMathSharp.Vector3d&,FixedMathSharp.Fixed64&)
CreateSweepBounds(FixedMathSharp.Vector3d,FixedMathSharp.Vector3d,FixedMathSharp.Fixed64,FixedMathSharp.Vector3d&,FixedMathSharp.Vector3d&)