< Summary

Information
Class: Gravitas.Colliders.ExactMassPoint3D
Assembly: Gravitas
File(s): /home/runner/work/Gravitas/Gravitas/src/Gravitas/Colliders/MassProperties/ExactMassPoint3D.cs
Line coverage
100%
Covered lines: 27
Uncovered lines: 0
Coverable lines: 27
Total lines: 106
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
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%
FromPoint(...)100%11100%
CreateScaledLocalComposition(...)100%22100%
TryGetPoint(...)100%11100%
TryGetWeightedAverage(...)100%11100%
TryAddParallelAxisTensor(...)100%11100%

File(s)

/home/runner/work/Gravitas/Gravitas/src/Gravitas/Colliders/MassProperties/ExactMassPoint3D.cs

#LineLine coverage
 1//=======================================================================
 2// ExactMassPoint3D.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
 10using FixedMathSharp;
 11
 12namespace Gravitas.Colliders;
 13
 14/// <summary>
 15/// Represents a 3D mass-property point that may lie outside the scalar
 16/// coordinate domain while remaining available to aggregate operations.
 17/// </summary>
 18internal readonly struct ExactMassPoint3D
 19{
 20    internal readonly Signed320 XNumerator;
 21    internal readonly Signed320 YNumerator;
 22    internal readonly Signed320 ZNumerator;
 23
 24    internal ExactMassPoint3D(
 25        Signed320 xNumerator,
 26        Signed320 yNumerator,
 27        Signed320 zNumerator)
 28    {
 6753029        XNumerator = xNumerator;
 6753030        YNumerator = yNumerator;
 6753031        ZNumerator = zNumerator;
 6753032    }
 33
 34    /// <summary>Creates a mass point from a representable vector.</summary>
 35    internal static ExactMassPoint3D FromPoint(Vector3d point) =>
 66736        ExactMassProperties.CreatePoint(point);
 37
 38    /// <summary>
 39    /// Creates the scale-invariant quaternion composition
 40    /// <c>outerPoint * outerScale + innerOffset * innerScale +
 41    /// innerRotation * innerDisplacement</c>.
 42    /// </summary>
 43    /// <remarks>
 44    /// The quaternion rotation uses the same rational basis as full-domain
 45    /// geometry and retains 64 fractional guard bits for later aggregation.
 46    /// </remarks>
 47    /// <exception cref="ArgumentException">
 48    /// <paramref name="innerRotation"/> is not normalized.
 49    /// </exception>
 50    internal static ExactMassPoint3D CreateScaledLocalComposition(
 51        Vector3d outerPoint,
 52        Vector3d outerScale,
 53        Vector3d innerOffset,
 54        Vector3d innerScale,
 55        Vector3d innerDisplacement,
 56        FixedQuaternion innerRotation)
 57    {
 6686458        if (!innerRotation.IsNormalized())
 59        {
 160            throw new ArgumentException(
 161                "The mass-point rotation must be normalized.",
 162                nameof(innerRotation));
 63        }
 64
 6686365        return ExactMassProperties.CreatePoint(
 6686366            outerPoint,
 6686367            outerScale,
 6686368            innerOffset,
 6686369            innerScale,
 6686370            innerDisplacement,
 6686371            innerRotation);
 72    }
 73
 74    /// <summary>Attempts to materialize this point as a Q32.32 vector.</summary>
 75    internal bool TryGetPoint(out Vector3d point) =>
 5585576        ExactMassProperties.TryGetPoint(this, out point);
 77
 78    /// <summary>
 79    /// Attempts to obtain the exact positive-weight average of semantic mass
 80    /// points with one final conversion per component.
 81    /// </summary>
 82    internal static bool TryGetWeightedAverage(
 83        ReadOnlySpan<ExactMassPoint3D> points,
 84        ReadOnlySpan<ExactMassWeight> weights,
 85        out Vector3d average) =>
 67186        ExactMassProperties.TryGetWeightedAverage(
 67187            points,
 67188            weights,
 67189            out average);
 90
 91    /// <summary>
 92    /// Attempts to add this point's parallel-axis contribution to a tensor
 93    /// about <paramref name="referencePoint"/>.
 94    /// </summary>
 95    internal bool TryAddParallelAxisTensor(
 96        Fixed3x3 centerTensor,
 97        Fixed64 mass,
 98        Vector3d referencePoint,
 99        out Fixed3x3 tensor) =>
 10383100        ExactMassProperties.TryAddParallelAxisTensor(
 10383101            this,
 10383102            centerTensor,
 10383103            mass,
 10383104            referencePoint,
 10383105            out tensor);
 106}