< Summary

Information
Class: FixedMathSharp.Geometry.ConePrismBoundaryContacts
Assembly: FixedMathSharp
File(s): /home/runner/work/FixedMathSharp/FixedMathSharp/src/FixedMathSharp/Geometry/Wide/Convex/ConePrismBoundaryContacts.cs
Line coverage
100%
Covered lines: 37
Uncovered lines: 0
Coverable lines: 37
Total lines: 84
Line coverage: 100%
Branch coverage
100%
Covered branches: 22
Total branches: 22
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
TryGetContact(...)100%1414100%
Borrow()100%11100%
Visit(...)100%88100%

File(s)

/home/runner/work/FixedMathSharp/FixedMathSharp/src/FixedMathSharp/Geometry/Wide/Convex/ConePrismBoundaryContacts.cs

#LineLine coverage
 1//=======================================================================
 2// ConePrismBoundaryContacts.cs
 3//=======================================================================
 4// MIT License, Copyright (c) 2024-present David Oravsky (mrdav30)
 5// See LICENSE file in the project root for full license information.
 6//=======================================================================
 7
 8using System;
 9
 10namespace FixedMathSharp.Geometry;
 11
 12/// <summary>Streams existing exact cone events on one retained native boundary line.</summary>
 13internal sealed class ConePrismBoundaryContacts
 14{
 15    private readonly ConePlaneRayEventVisitor _visit;
 1116    private ulong[] _values = Array.Empty<ulong>();
 1117    private readonly int[] _signs = new int[ConePlaneRaySelection.SignCount];
 18    private bool _hasValue;
 19    private ConePlaneRayFrame _frame;
 20    private ConePlaneRayEventSource _source;
 21    private ConePlaneRayEvent _event;
 22
 3323    internal ConePrismBoundaryContacts() { _visit = Visit; }
 24
 25    // Side lines are horizontal or have a singleton tangent parameter.
 26    // A cap line identifies its original footprint edge explicitly.
 27    internal bool TryGetContact(in CurvedPrismContactGeometry geometry, int face,
 28        in RationalSegmentInterval clip, Fixed64 lower, Fixed64 upper,
 29        Vector3d center, FixedQuaternion rotation, Vector3d prismOrigin,
 30        out FixedContactAnchors contact, int boundaryEdge = -1, scoped CurvedPrismContactValue native = default,
 31        PrismCurvedBoundaryContactVisitor? visitor = null, int ordinal = 0)
 32    {
 2233        contact = default; _hasValue = false;
 1134        CurvedPrismContact.GetFacePlane(geometry, face, out WideDirection3d normal, out _, out _);
 35        System.Diagnostics.Debug.Assert(!normal.IsZero);
 1136        Span<Signed576> direction = stackalloc Signed576[3] { normal.X, normal.Y, normal.Z };
 2237        WideArithmetic.ReduceCommonScale(direction); normal = new(direction[0], direction[1], direction[2]);
 1538        if (face < 0) lower = upper = face == -1 ? -geometry.PrismHalfThickness : geometry.PrismHalfThickness;
 1139        CurvedPrismContact.GetNativeBoundarySegment(geometry, face >= 0 ? face : boundaryEdge, clip, lower, upper,
 1140            out WideAxis3 a, out WideAxis3 b, out Signed320 coordinateD, out var retained);
 1141        var frame = new ConePlaneRayFrame(geometry.HeightValue, geometry.RadiusValue, coordinateD, normal, WideDirection
 1142        a = new(a.X, WideArithmetic.SubtractSigned320(frame.Finite.ShapeFrame.Cap, a.Y), a.Z);
 1143        b = new(b.X, WideArithmetic.SubtractSigned320(frame.Finite.ShapeFrame.Cap, b.Y), b.Z);
 44        // Same exact original segment/clip owns construction and admission.
 45        // Its complete domain is already on the admitted native surface;
 46        // a plane cohort or second prism-halfplane inventory adds no points.
 1147        ConePlaneRayEvents.VisitNativeSegment(frame, a, b, retained, _visit);
 1248        if (!_hasValue) return false;
 2049        var maximum = Borrow(); var physicalFrame = _frame.WithConePose(center, rotation);
 1050        if (!maximum.TryGetRoundedMaximumDepth(out Fixed64 depth)
 1251            || !ConePlaneRayPointMaterialization.TryGetPointInFrame(physicalFrame, maximum.Point, maximum.Root, prismOri
 52        // An admitted finite exit has |X|,|Z|<=R and |Y|<=H/2 in this
 53        // centered local chart, so nearest rounding cannot exceed Fixed64.
 854        bool exitRepresented = ConePlaneRayPointMaterialization.TryGetExitConeLocalPoint(physicalFrame, maximum.Point, m
 855            ContactQuadratic.At(maximum.Values, maximum.Signs, 0, _frame.FieldWords),
 856            ContactQuadratic.At(maximum.Values, maximum.Signs, 1, _frame.FieldWords), 1, out Vector3d exitPoint);
 57        System.Diagnostics.Debug.Assert(exitRepresented);
 858        contact = new(new FixedPointAnchor(center, rotation, exitPoint), new FixedPointAnchor(prismOrigin, FixedQuaterni
 859            normal.Transform(geometry.WorldBasis).GetNormal(false), depth, false);
 1260        if (visitor != null) visitor(ordinal, contact, native.CompareRootRatio(geometry,
 461            ContactQuadratic.At(maximum.Values, maximum.Signs, 0, _frame.FieldWords),
 462            ContactQuadratic.At(maximum.Values, maximum.Signs, 1, _frame.FieldWords), maximum.Root,
 463            _frame.NormalSquared, WideArithmetic.AddSigned320(_frame.Finite.ShapeFrame.CoordinateDenominator, _frame.Fin
 864        return true;
 65    }
 66
 67    private ConePlaneRaySelection Borrow()
 68    {
 1069        var result = new ConePlaneRaySelection(_values, _signs, _frame.FieldWords, _frame.RootWords);
 2070        result.Restore(_frame, _source, _event); return result;
 71    }
 72
 73    private void Visit(in ConePlaneRayEventSource source, in ConePlaneRayFrame frame, ConePlaneRayEvent descriptor,
 74        scoped ConePlaneRayPoint point, scoped ReadOnlySpan<ulong> root,
 75        scoped in ConePlaneRaySelection positive, scoped in ConePlaneRaySelection negative)
 76    {
 3377        if (!positive.HasValue) return;
 3578        if (_values.Length < frame.SelectionStorageWords) Array.Resize(ref _values, frame.SelectionStorageWords);
 2579        var maximum = new ConePlaneRaySelection(_values, _signs, frame.FieldWords, frame.RootWords);
 4080        if (_hasValue) maximum.Restore(_frame, _source, _event);
 3581        if (!maximum.KeepEvaluated(positive, frame)) return;
 6082        _hasValue = true; _frame = frame; _source = maximum.MaximumSource; _event = maximum.MaximumEvent;
 1583    }
 84}