< Summary

Information
Class: FixedMathSharp.Geometry.NativePrismYawFrame3d
Assembly: FixedMathSharp
File(s): /home/runner/work/FixedMathSharp/FixedMathSharp/src/FixedMathSharp/Geometry/Wide/Common/NativePrismYawFrame3d.cs
Line coverage
100%
Covered lines: 38
Uncovered lines: 0
Coverable lines: 38
Total lines: 87
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
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%
get_RotationDenominator()100%11100%
get_Denominator()100%11100%
GetPoint(...)100%11100%
GetEdgeDirection(...)100%11100%
GetFaceNormal(...)100%11100%
GetInwardAxis(...)100%11100%
TryGetTriangleHalfPlanes(...)100%44100%

File(s)

/home/runner/work/FixedMathSharp/FixedMathSharp/src/FixedMathSharp/Geometry/Wide/Common/NativePrismYawFrame3d.cs

#LineLine coverage
 1//=======================================================================
 2// NativePrismYawFrame3d.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
 13
 14/// <summary>Preserves the scalar Sin/Cos prism chart without asserting a rigid inverse.</summary>
 15internal readonly struct NativePrismYawFrame3d : IForwardHullFrame3d
 16{
 117    private static readonly Signed192 Unit = Signed192.Raw(Fixed64.One);
 118    private static readonly Signed320 CoordinateDenominator = new(0UL, 0UL, 0UL, 1UL, 0UL);
 19    private readonly RationalPoint3d _origin;
 20    private readonly WideConvex2dRelations.RotationFrame2d _yaw;
 21
 22    internal NativePrismYawFrame3d(Vector3d origin, Fixed64 yaw)
 23    {
 8424        _origin = RationalPoint3d.FromScalarPoint(origin);
 8425        _yaw = new(yaw);
 8426    }
 27
 1070628    public Signed192 RotationDenominator => Signed192.Signed(1);
 4369829    public Signed320 Denominator => CoordinateDenominator;
 30
 31    public RationalPoint3d GetPoint(Vector3d point)
 32    {
 4364333        WideConvex2dRelations.GetRotatedOffset(_yaw, new(point.X, point.Z), out Signed192 x, out Signed192 z);
 4364334        RationalPoint3d scalar = RationalPoint3d.FromScalarPoint(point);
 35        // Native products have one Q denominator; lift them into the existing
 36        // Q² point domain before adding the absolute origin (under 129 bits).
 4364337        return new(
 4364338            WideArithmetic.AddSigned320(_origin.X, WideArithmetic.MultiplySigned192(x, Unit)),
 4364339            WideArithmetic.AddSigned320(_origin.Y, scalar.Y),
 4364340            WideArithmetic.AddSigned320(_origin.Z, WideArithmetic.MultiplySigned192(z, Unit)), Denominator);
 41    }
 42
 43    public WideDirection3d GetEdgeDirection(Vector3d first, Vector3d second)
 44    {
 1103145        WideConvex2dRelations.GetRotatedOffset(_yaw, new(first.X, first.Z), out Signed192 ax, out Signed192 az);
 1103146        WideConvex2dRelations.GetRotatedOffset(_yaw, new(second.X, second.Z), out Signed192 bx, out Signed192 bz);
 1103147        Signed192 y = WideArithmetic.SubtractSigned192(Signed192.Raw(second.Y), Signed192.Raw(first.Y));
 1103148        return new(Signed576.ExtendValue(WideArithmetic.SubtractSigned192(bx, ax)),
 1103149            WideArithmetic.MultiplySigned320(Signed320.ExtendValue(y), Unit),
 1103150            Signed576.ExtendValue(WideArithmetic.SubtractSigned192(bz, az)));
 51    }
 52
 53    public WideDirection3d GetFaceNormal(in FixedTriangle triangle)
 54    {
 263955        triangle.GetExactNormal(out Signed192 x, out Signed192 y, out Signed192 z, out _);
 263956        Signed320 nx = WideArithmetic.SubtractSigned320(WideArithmetic.MultiplySigned192(x, _yaw.Cosine),
 263957            WideArithmetic.MultiplySigned192(z, _yaw.Sine));
 263958        Signed320 nz = WideArithmetic.AddSigned320(WideArithmetic.MultiplySigned192(x, _yaw.Sine),
 263959            WideArithmetic.MultiplySigned192(z, _yaw.Cosine));
 263960        Signed320 radialMetric = WideArithmetic.AddSigned320(WideArithmetic.MultiplySigned192(_yaw.Cosine, _yaw.Cosine),
 263961            WideArithmetic.MultiplySigned192(_yaw.Sine, _yaw.Sine));
 62        // Cofactors preserve the actual nonunit scalar matrix: c²+s² need
 63        // not equal Q². Raw face normals need <131 bits, so outputs need <197.
 263964        return new(WideArithmetic.MultiplySigned320(nx, Unit),
 263965            WideArithmetic.MultiplySigned320(radialMetric, y), WideArithmetic.MultiplySigned320(nz, Unit));
 66    }
 67
 68    public WideDirection3d GetInwardAxis(in FixedTriangle triangle, Vector3d first, Vector3d second) =>
 669        WideDirection3d.Cross(GetFaceNormal(triangle), GetEdgeDirection(first, second));
 70
 71    public bool TryGetTriangleHalfPlanes(in FixedTriangle triangle, in RationalPoint3d point, Span<Signed832> values)
 72    {
 179973        WideDirection3d normal = GetFaceNormal(triangle);
 180374        if (normal.IsZero) return false;
 179575        Span<Vector3d> vertices = stackalloc Vector3d[3] { triangle.A, triangle.B, triangle.C };
 1436076        for (int edge = 0; edge < 3; edge++)
 77        {
 1077078            Vector3d first = vertices[edge], second = vertices[(edge + 1) % 3];
 538579            WideDirection3d inward = WideDirection3d.Cross(normal, GetEdgeDirection(first, second));
 538580            WideDirection3d delta = WideTriangleRelations.GetScaledPointDifference(point, GetPoint(first), RotationDenom
 81            // Native inward axes need <295 bits; even affine point differences
 82            // keep the complete dot below the existing 832-bit half-plane bank.
 538583            values[edge] = WideDirection3d.Dot(inward, delta);
 84        }
 179585        return true;
 86    }
 87}