< Summary

Information
Class: FixedMathSharp.Geometry.ConePlaneRayFrame
Assembly: FixedMathSharp
File(s): /home/runner/work/FixedMathSharp/FixedMathSharp/src/FixedMathSharp/Geometry/Wide/FiniteAxis/ConePlaneRayFrame.cs
Line coverage
100%
Covered lines: 118
Uncovered lines: 0
Coverable lines: 118
Total lines: 216
Line coverage: 100%
Branch coverage
100%
Covered branches: 60
Total branches: 60
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_SourceFrame()100%11100%
get_UsesWideBanks()100%22100%
get_FieldWords()100%22100%
get_RootWords()100%22100%
get_CircleWords()100%22100%
get_PointStorageWords()100%11100%
get_SelectionStorageWords()100%11100%
get_AdmissionWords()100%22100%
get_VerificationWords()100%22100%
WithWideParameters()100%22100%
WithConePose(...)100%11100%
.ctor(...)100%11100%
.ctor(...)100%11100%
.ctor(...)100%11100%
.ctor(...)100%1616100%
.ctor(...)100%1414100%
get_AuthoredNormal()100%11100%
GetWorldNormal(...)100%22100%
Transform(...)100%11100%
ContainsPoint(...)100%22100%
IntersectsSegment(...)100%44100%
IsCoplanar(...)100%11100%
GetTriangleEdgeWall(...)100%66100%
GetEdgeLine(...)100%22100%
DotWall(...)100%11100%

File(s)

/home/runner/work/FixedMathSharp/FixedMathSharp/src/FixedMathSharp/Geometry/Wide/FiniteAxis/ConePlaneRayFrame.cs

#LineLine coverage
 1//=======================================================================
 2// ConePlaneRayFrame.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>One canonical authored plane and exact cone frame shared by its finite sections.</summary>
 13internal readonly struct ConePlaneRayFrame
 14{
 15    internal readonly Vector3d ConeCenter;
 16    internal readonly FixedQuaternion ConeRotation;
 17    internal readonly Fixed64 Height, Radius;
 18    internal readonly ConeFiniteSectionFrame Finite;
 19    internal readonly WideDirection3d Normal;
 20    internal readonly Signed832 PlaneConstant, NormalSquared;
 21    private readonly WideAxis3 authoredNormal;
 22    private readonly bool _wideParameters;
 4323    internal ScaledRigidFrame3d SourceFrame => Finite.ShapeFrame.SourceFrame;
 122236524    internal bool UsesWideBanks => Finite.ShapeFrame.HasExactScale || _wideParameters;
 30924725    internal int FieldWords => UsesWideBanks ? 192 : ConePlaneRaySelection.FieldWords;
 17487826    internal int RootWords => UsesWideBanks ? 120 : ConePlaneRaySelection.RootWords;
 72419227    internal int CircleWords => UsesWideBanks ? 60 : 20;
 2691728    internal int PointStorageWords => 8 * FieldWords;
 15129    internal int SelectionStorageWords => 12 * FieldWords + RootWords;
 1112630    internal int AdmissionWords => UsesWideBanks ? 432 : 144;
 290431    internal int VerificationWords => UsesWideBanks ? 528 : 176;
 632    internal ConePlaneRayFrame WithWideParameters() => UsesWideBanks ? this : new ConePlaneRayFrame(this);
 33
 34    // Numeric native charts are already cone-local. Materialization supplies
 35    // their actual physical pose without retransforming or replaying an event.
 1036    internal ConePlaneRayFrame WithConePose(Vector3d center, FixedQuaternion rotation) => new(this, center, rotation);
 37    private ConePlaneRayFrame(in ConePlaneRayFrame source, Vector3d center, FixedQuaternion rotation)
 4038    { this = source; ConeCenter = center; ConeRotation = rotation; }
 39
 40    private ConePlaneRayFrame(in ConePlaneRayFrame source)
 41    {
 542        this = source;
 543        _wideParameters = true;
 544    }
 45
 46    /// <summary>Shares an exact primitive-local native plane without a rounded source transform.</summary>
 47    internal ConePlaneRayFrame(Fixed64 height, Fixed64 radius, Signed320 coordinateDenominator,
 48        in WideDirection3d centeredNormal, Signed832 doubledCenteredConstant)
 49    {
 1250        this = default;
 3651        ConeRotation = FixedQuaternion.Identity; Height = height; Radius = radius;
 1252        Finite = new ConeFiniteSectionFrame(height, radius, coordinateDenominator);
 1253        Normal = new(centeredNormal.X, WideArithmetic.Negate(centeredNormal.Y), centeredNormal.Z);
 1254        PlaneConstant = WideArithmetic.SubtractSigned832(doubledCenteredConstant,
 1255            WideArithmetic.MultiplySigned576ToSigned832(centeredNormal.Y, Finite.ShapeFrame.Cap));
 1256        NormalSquared = Normal.SquaredLength;
 1257        authoredNormal = new(Signed320.NarrowValue(centeredNormal.X), Signed320.NarrowValue(centeredNormal.Y), Signed320
 1258    }
 59
 60    internal ConePlaneRayFrame(FixedTriangle planeTriangle, Vector3d origin, FixedQuaternion rotation,
 61        Vector3d coneCenter, FixedQuaternion coneRotation, Fixed64 height, Fixed64 radius)
 62    {
 72363        _wideParameters = false;
 289264        ConeCenter = coneCenter; ConeRotation = coneRotation; Height = height; Radius = radius;
 72365        Finite = new ConeFiniteSectionFrame(origin, rotation, coneCenter, coneRotation, height, radius);
 72166        planeTriangle.GetExactNormal(out Signed192 nx, out Signed192 ny, out Signed192 nz, out _);
 72167        Span<Signed320> primitive = stackalloc Signed320[3]
 72168        {
 72169            Signed320.ExtendValue(nx), Signed320.ExtendValue(ny), Signed320.ExtendValue(nz)
 72170        };
 72171        if (!nx.IsZero || !ny.IsZero || !nz.IsZero)
 71472            WideArithmetic.ReduceCommonScale(primitive);
 72173        int orientation = primitive[0].Sign != 0 ? primitive[0].Sign
 72174            : primitive[1].Sign != 0 ? primitive[1].Sign : primitive[2].Sign;
 72175        if (orientation < 0)
 148076            for (int axis = 0; axis < 3; axis++)
 55577                primitive[axis] = WideArithmetic.Negate(primitive[axis]);
 72178        authoredNormal = new WideAxis3(primitive[0], primitive[1], primitive[2]);
 72179        WideAxis3 localNormal = WideRigidProjection.TransformLocalAxis(Finite.ShapeFrame.Basis,
 72180            Signed192.NarrowProven(primitive[0]), Signed192.NarrowProven(primitive[1]), Signed192.NarrowProven(primitive
 81        // Reflect the centered +Y coordinates into the apex-to-base +Y
 82        // cone frame. This is an exact coordinate convention, not rounding.
 216383        primitive[0] = localNormal.X; primitive[1] = WideArithmetic.Negate(localNormal.Y); primitive[2] = localNormal.Z;
 84        // A positive common scale carries no plane or ray geometry. Remove
 85        // the quaternion basis denominator here so it does not multiply every
 86        // critical-event coefficient, while preserving the authored orientation.
 143587        if (!localNormal.IsZero) WideArithmetic.ReduceCommonScale(primitive);
 72188        Normal = new WideDirection3d(new WideAxis3(primitive[0], primitive[1], primitive[2]));
 72189        PlaneConstant = WideDirection3d.Dot(Normal, Transform(planeTriangle.A));
 72190        NormalSquared = Normal.SquaredLength;
 72191    }
 92
 93    internal ConePlaneRayFrame(FixedTriangle planeTriangle, in ScaledRigidFrame3d sourceFrame,
 94        Vector3d coneCenter, FixedQuaternion coneRotation, Fixed64 height, Fixed64 radius)
 95    {
 3396        if (sourceFrame.IsRigid)
 97        {
 1298            this = new ConePlaneRayFrame(planeTriangle, sourceFrame.RigidOrigin, sourceFrame.Rotation,
 1299                coneCenter, coneRotation, height, radius);
 12100            return;
 101        }
 84102        ConeCenter = coneCenter; ConeRotation = coneRotation; Height = height; Radius = radius;
 21103        _wideParameters = false;
 21104        Finite = new ConeFiniteSectionFrame(sourceFrame, coneCenter, coneRotation, height, radius);
 21105        WideDirection3d edge = WideDirection3d.GetLocalEdge(sourceFrame, planeTriangle.A, planeTriangle.B);
 21106        WideDirection3d side = WideDirection3d.GetLocalEdge(sourceFrame, planeTriangle.A, planeTriangle.C);
 21107        WideDirection3d cross = WideDirection3d.Cross(edge, side);
 21108        Span<Signed320> primitive = stackalloc Signed320[3]
 21109        {
 21110            Signed320.NarrowValue(cross.X), Signed320.NarrowValue(cross.Y), Signed320.NarrowValue(cross.Z)
 21111        };
 41112        if (!cross.IsZero) WideArithmetic.ReduceCommonScale(primitive);
 21113        int orientation = primitive[0].Sign != 0 ? primitive[0].Sign
 21114            : primitive[1].Sign != 0 ? primitive[1].Sign : primitive[2].Sign;
 21115        if (orientation < 0)
 198116            for (int axis = 0; axis < 3; axis++) primitive[axis] = WideArithmetic.Negate(primitive[axis]);
 21117        authoredNormal = new WideAxis3(primitive[0], primitive[1], primitive[2]);
 21118        WideDirection3d local = new WideDirection3d(authoredNormal).Transform(Finite.ShapeFrame.Basis);
 21119        Span<Signed576> localComponents = stackalloc Signed576[3]
 21120        { local.X, WideArithmetic.SubtractSigned576(default, local.Y), local.Z };
 41121        if (!local.IsZero) WideArithmetic.ReduceCommonScale(localComponents);
 21122        Normal = new WideDirection3d(localComponents[0], localComponents[1], localComponents[2]);
 123        // Scaled edges <110 bits give an authored normal <221; a relative
 124        // rigid basis adds <130. Plane and norm² stay below 660/705 bits.
 21125        PlaneConstant = WideDirection3d.Dot(Normal, Transform(planeTriangle.A));
 21126        NormalSquared = Normal.SquaredLength;
 21127    }
 128
 129    /// <summary>Gets the exact canonical covector in the original authored frame, before normal rounding.</summary>
 2130    internal WideAxis3 AuthoredNormal => authoredNormal;
 131
 132    /// <summary>Materializes the canonical plane normal in its original authored rigid frame.</summary>
 133    /// <remarks>The rotation is the same validated authored rotation used to construct this frame.</remarks>
 134    internal Vector3d GetWorldNormal(FixedQuaternion authoredRotation)
 135    {
 10136        if (Finite.ShapeFrame.HasExactScale)
 5137            return new WideDirection3d(authoredNormal).Transform(SourceFrame.GeometryBasis).GetNormal(false);
 138        // Primitive authored normal components are <130 bits and a normalized
 139        // quaternion's exact basis numerators are <65 bits. The three-term
 140        // transform stays <197 bits, within Signed320, without rounding a
 141        // local normal first or losing its canonical leading-component sign.
 5142        WideAxis3 normal = WideRigidProjection.TransformLocalAxis(new WideRationalBasis3d(authoredRotation),
 5143            Signed192.NarrowProven(authoredNormal.X), Signed192.NarrowProven(authoredNormal.Y),
 5144            Signed192.NarrowProven(authoredNormal.Z));
 5145        return WideNormalization.GetNormalized(normal.X, normal.Y, normal.Z);
 146    }
 147
 49501148    internal WideAxis3 Transform(Vector3d point) => Finite.Transform(point);
 149
 150    internal bool ContainsPoint(Vector3d point)
 151    {
 4152        WideAxis3 p = Finite.Transform(point);
 4153        return IsCoplanar(p) && Finite.ContainsTransformedPoint(p);
 154    }
 155
 156    internal bool IntersectsSegment(FixedSegment segment)
 157    {
 248158        WideAxis3 start = Finite.Transform(segment.Start), end = Finite.Transform(segment.End);
 124159        return IsCoplanar(start) && IsCoplanar(end) && Finite.IntersectsTransformedSegment(start, end);
 160    }
 161
 162    internal bool IsCoplanar(WideAxis3 point) =>
 261163        WideArithmetic.SubtractSigned832(WideDirection3d.Dot(Normal, point), PlaneConstant).IsZero;
 164
 165    internal void GetTriangleEdgeWall(FixedTriangle triangle, int edgeIndex,
 166        out Signed576 x, out Signed576 y, out Signed576 z, out Signed832 offset)
 167    {
 12032168        FixedSegment edge = triangle.GetEdge(edgeIndex);
 12032169        GetEdgeLine(edge, out x, out y, out z, out offset);
 12032170        WideAxis3 opposite = Transform(edgeIndex == 0 ? triangle.C : edgeIndex == 1 ? triangle.A : triangle.B);
 12032171        if (WideArithmetic.SubtractSigned832(DotWall(x, y, z, opposite), offset).Sign < 0)
 172        {
 846173            x = WideArithmetic.SubtractSigned576(default, x);
 846174            y = WideArithmetic.SubtractSigned576(default, y);
 846175            z = WideArithmetic.SubtractSigned576(default, z);
 846176            offset = WideArithmetic.SubtractSigned832(default, offset);
 177        }
 12032178    }
 179
 180    // The sign of an exact line equation is immaterial for its roots. Segment
 181    // sources therefore need no invented opposite vertex or enclosing triangle.
 182    internal void GetEdgeLine(FixedSegment edge,
 183        out Signed576 x, out Signed576 y, out Signed576 z, out Signed832 offset)
 184    {
 21646185        if (Finite.ShapeFrame.HasExactScale)
 186        {
 21187            WideDirection3d direction = WideDirection3d.GetLocalEdge(SourceFrame, edge.Start, edge.End);
 21188            WideDirection3d scaledWall = WideDirection3d.Cross(new WideDirection3d(authoredNormal), direction)
 21189                .Transform(Finite.ShapeFrame.Basis);
 63190            x = scaledWall.X; y = WideArithmetic.SubtractSigned576(default, scaledWall.Y); z = scaledWall.Z;
 21191            offset = DotWall(x, y, z, Transform(edge.Start));
 21192            return;
 193        }
 21625194        WideAxis3 delta = new(
 21625195            Signed320.ExtendValue(WideArithmetic.SubtractSigned192(Signed192.Raw(edge.End.X), Signed192.Raw(edge.Start.X
 21625196            Signed320.ExtendValue(WideArithmetic.SubtractSigned192(Signed192.Raw(edge.End.Y), Signed192.Raw(edge.Start.Y
 21625197            Signed320.ExtendValue(WideArithmetic.SubtractSigned192(Signed192.Raw(edge.End.Z), Signed192.Raw(edge.Start.Z
 198        // Form the wall in the authored frame first: primitive normal <130,
 199        // edge <65, wall <196, exact relative basis <130. A direct cross of
 200        // the transformed normal and transformed edge would need >320 bits.
 21625201        WideAxis3 wall = WideAxis3.Cross(authoredNormal, delta);
 21625202        WideRigidProjection.TransformLocalAxis(Finite.ShapeFrame.Basis, wall, out x, out y, out z);
 21625203        y = WideArithmetic.SubtractSigned576(default, y);
 21625204        offset = DotWall(x, y, z, Transform(edge.Start));
 21625205    }
 206
 207    private static Signed832 DotWall(Signed576 x, Signed576 y, Signed576 z, WideAxis3 point)
 208    {
 209        // Each transformed authored wall component <326 and point <198;
 210        // three signed products need <526 bits, safely inside Signed576.
 33678211        return WideArithmetic.AddSigned832(
 33678212            WideArithmetic.AddSigned832(WideArithmetic.MultiplySigned576ToSigned832(x, point.X),
 33678213                WideArithmetic.MultiplySigned576ToSigned832(y, point.Y)),
 33678214            WideArithmetic.MultiplySigned576ToSigned832(z, point.Z));
 215    }
 216}

Methods/Properties

get_SourceFrame()
get_UsesWideBanks()
get_FieldWords()
get_RootWords()
get_CircleWords()
get_PointStorageWords()
get_SelectionStorageWords()
get_AdmissionWords()
get_VerificationWords()
WithWideParameters()
WithConePose(FixedMathSharp.Vector3d,FixedMathSharp.FixedQuaternion)
.ctor(FixedMathSharp.Geometry.ConePlaneRayFrame&,FixedMathSharp.Vector3d,FixedMathSharp.FixedQuaternion)
.ctor(FixedMathSharp.Geometry.ConePlaneRayFrame&)
.ctor(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Signed320,FixedMathSharp.Geometry.WideDirection3d&,FixedMathSharp.Signed832)
.ctor(FixedMathSharp.Geometry.FixedTriangle,FixedMathSharp.Vector3d,FixedMathSharp.FixedQuaternion,FixedMathSharp.Vector3d,FixedMathSharp.FixedQuaternion,FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
.ctor(FixedMathSharp.Geometry.FixedTriangle,FixedMathSharp.Geometry.ScaledRigidFrame3d&,FixedMathSharp.Vector3d,FixedMathSharp.FixedQuaternion,FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
get_AuthoredNormal()
GetWorldNormal(FixedMathSharp.FixedQuaternion)
Transform(FixedMathSharp.Vector3d)
ContainsPoint(FixedMathSharp.Vector3d)
IntersectsSegment(FixedMathSharp.Geometry.FixedSegment)
IsCoplanar(FixedMathSharp.Geometry.WideAxis3)
GetTriangleEdgeWall(FixedMathSharp.Geometry.FixedTriangle,System.Int32,FixedMathSharp.Signed576&,FixedMathSharp.Signed576&,FixedMathSharp.Signed576&,FixedMathSharp.Signed832&)
GetEdgeLine(FixedMathSharp.Geometry.FixedSegment,FixedMathSharp.Signed576&,FixedMathSharp.Signed576&,FixedMathSharp.Signed576&,FixedMathSharp.Signed832&)
DotWall(FixedMathSharp.Signed576,FixedMathSharp.Signed576,FixedMathSharp.Signed576,FixedMathSharp.Geometry.WideAxis3)