< Summary

Information
Class: Gravitas.CollisionHandling.MeshPlaneSampleReduction
Assembly: Gravitas
File(s): /home/runner/work/Gravitas/Gravitas/src/Gravitas/CollisionHandling/Detection/3D/Mesh/MeshPlaneSampleReduction.cs
Line coverage
100%
Covered lines: 33
Uncovered lines: 0
Coverable lines: 33
Total lines: 69
Line coverage: 100%
Branch coverage
100%
Covered branches: 32
Total branches: 32
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ChooseNext(...)100%1616100%
ChooseNext(...)100%1616100%

File(s)

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

#LineLine coverage
 1//=======================================================================
 2// MeshPlaneSampleReduction.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;
 12
 13namespace Gravitas.CollisionHandling;
 14
 15
 16
 17/// <summary>Ranks finite plane samples after their exact maximum has seeded the pool.</summary>
 18internal static class MeshPlaneSampleReduction
 19{
 20    internal static int ChooseNext<T>(ReadOnlySpan<T> pool, ReadOnlySpan<int> chosen,
 21        in WideDirection3d normal, IComparer<T> pointComparer) where T : struct, IPlaneContactSample
 22    {
 23        const int words = 32;
 1035624        Span<ulong> values = stackalloc ulong[8 * words]; Span<int> signs = stackalloc int[8];
 517825        var bestN = ContactQuadratic.At(values, signs, 0, words);
 517826        var bestD = ContactQuadratic.At(values, signs, 1, words);
 517827        var n = ContactQuadratic.At(values, signs, 2, words);
 517828        var d = ContactQuadratic.At(values, signs, 3, words);
 517829        int best = -1;
 4109630        for (int candidate = 1; candidate < pool.Length; candidate++)
 31        {
 1537032            if (chosen.IndexOf(candidate) >= 0) continue;
 1131533            Vector3d p = pool[candidate].Point;
 1131534            d.Set(Signed576.ExtendValue(Signed320.ExtendValue(Signed192.One)));
 1718735            if (chosen.Length == 1) WidePlaneMetrics.GetSpanSquared(normal, pool[chosen[0]].Point, p, n);
 910536            else if (chosen.Length == 2) WidePlaneMetrics.GetAreaSquared(normal, pool[chosen[0]].Point, pool[chosen[1]].
 178137            else WidePlaneMetrics.GetTriangleDistanceSquared(normal, p, pool[chosen[0]].Point,
 178138                pool[chosen[1]].Point, pool[chosen[2]].Point, n, d);
 1131539            int comparison = best < 0 ? 1 : ContactQuadratic.CompareRatios(n, d, ReadOnlySpan<ulong>.Empty,
 1131540                bestN, bestD, ReadOnlySpan<ulong>.Empty);
 1131541            if (comparison > 0 || comparison == 0 && pointComparer.Compare(pool[candidate], pool[best]) < 0)
 1901142            { best = candidate; n.CopyTo(bestN); d.CopyTo(bestD); }
 43        }
 517844        return best;
 45    }
 46
 47    internal static int ChooseNext<T>(ReadOnlySpan<T> pool, ReadOnlySpan<int> chosen,
 48        WidePlaneMetrics metrics, IComparer<T> pointComparer) where T : struct, IPlaneContactSample
 49    {
 5814450        int best = -1;
 11628851        Signed832 bestN = default, bestD = default;
 54112652        for (int candidate = 1; candidate < pool.Length; candidate++)
 53        {
 21241954            if (chosen.IndexOf(candidate) >= 0) continue;
 16062755            Vector3d p = pool[candidate].Point;
 16062756            Signed832 n, d = Signed832.ExtendValue(Signed192.Signed(1));
 23566857            if (chosen.Length == 1) n = metrics.GetSpanSquared(pool[chosen[0]].Point, p);
 13727558            else if (chosen.Length == 2) n = metrics.GetAreaSquared(pool[chosen[0]].Point, pool[chosen[1]].Point, p);
 3389759            else metrics.GetTriangleDistanceSquared(p, pool[chosen[0]].Point,
 3389760                pool[chosen[1]].Point, pool[chosen[2]].Point, out n, out d);
 16062761            int comparison = best < 0 ? 1 : WidePlaneMetrics.CompareRatios(n, d, bestN, bestD);
 62            // Rounded metrics rank coverage only. Equal metrics retain the
 63            // owner's exact point/provenance order before any solver reduction.
 16062764            if (comparison > 0 || comparison == 0 && pointComparer.Compare(pool[candidate], pool[best]) < 0)
 25176065            { best = candidate; bestN = n; bestD = d; }
 66        }
 5814467        return best;
 68    }
 69}