< Summary

Information
Class: Gravitas.Colliders.CompoundInertiaTensor
Assembly: Gravitas
File(s): /home/runner/work/Gravitas/Gravitas/src/Gravitas/Colliders/MassProperties/CompoundInertiaTensor.cs
Line coverage
100%
Covered lines: 22
Uncovered lines: 0
Coverable lines: 22
Total lines: 54
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Materialize(...)100%22100%
TryMoment(...)100%11100%
MaterializeSaturated(...)100%11100%
SaturatedMoment(...)100%44100%

File(s)

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

#LineLine coverage
 1//=======================================================================
 2// CompoundInertiaTensor.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 FixedMathSharp;
 10
 11namespace Gravitas.Colliders;
 12
 13/// <summary>Stores an aggregate's unmaterialized weighted tensor about its requested reference.</summary>
 14// Full-domain shape weights fit 256 bits and semantic displacements fit 162.
 15// Squared shifts, factor sixty and an int-bounded part sum stay below 650 bits;
 16// applying full-domain mass fits 704. Intrinsic/rotation terms fit 576 bits.
 17internal struct CompoundInertiaTensor
 18{
 19    internal Signed704 Xx, Yy, Zz, Xy, Xz, Yz;
 20
 21    internal Fixed3x3 Materialize(Fixed64 mass, ExactMassWeight weight)
 22    {
 242723        Signed576 denominator = WideArithmetic.MultiplySigned320(
 242724            CompoundInertiaMath3D.ScaleWeight(weight), CompoundInertiaMath3D.Q192);
 242725        bool representable = TryMoment(Xx, mass, denominator, out Fixed64 xx)
 242726            & TryMoment(Yy, mass, denominator, out Fixed64 yy)
 242727            & TryMoment(Zz, mass, denominator, out Fixed64 zz)
 242728            & TryMoment(Xy, mass, denominator, out Fixed64 xy)
 242729            & TryMoment(Xz, mass, denominator, out Fixed64 xz)
 242730            & TryMoment(Yz, mass, denominator, out Fixed64 yz);
 242731        if (!representable)
 232            throw new InvalidOperationException("The compound collider's inertia tensor is outside the Fixed64 scalar do
 242533        return new Fixed3x3(xx, xy, xz, xy, yy, yz, xz, yz, zz);
 34    }
 35
 36    private static bool TryMoment(Signed704 geometry, Fixed64 mass, Signed576 denominator, out Fixed64 moment) =>
 1485037        Fixed64.TryGetSignedRawRatio(
 1485038            WideArithmetic.MultiplySigned704ToSigned832(geometry, Signed192.Raw(mass)),
 1485039            Signed832.ExtendValue(denominator), numeratorLeftShift: 0, out moment);
 40
 41    internal Fixed3x3 MaterializeSaturated(Fixed64 mass, ExactMassWeight weight)
 42    {
 4843        Signed576 denominator = WideArithmetic.MultiplySigned320(
 4844            CompoundInertiaMath3D.ScaleWeight(weight), CompoundInertiaMath3D.Q192);
 9645        Fixed64 xx = SaturatedMoment(Xx, mass, denominator), yy = SaturatedMoment(Yy, mass, denominator);
 9646        Fixed64 zz = SaturatedMoment(Zz, mass, denominator), xy = SaturatedMoment(Xy, mass, denominator);
 9647        Fixed64 xz = SaturatedMoment(Xz, mass, denominator), yz = SaturatedMoment(Yz, mass, denominator);
 4848        return new Fixed3x3(xx, xy, xz, xy, yy, yz, xz, yz, zz);
 49    }
 50
 51    private static Fixed64 SaturatedMoment(Signed704 geometry, Fixed64 mass, Signed576 denominator) =>
 28852        TryMoment(geometry, mass, denominator, out Fixed64 moment) ? moment
 28853            : (geometry.Sign < 0) != (mass < Fixed64.Zero) ? Fixed64.MinValue : Fixed64.MaxValue;
 54}