< Summary

Information
Class: Gravitas.Colliders.MeshSurfaceMassProperties
Assembly: Gravitas
File(s): /home/runner/work/Gravitas/Gravitas/src/Gravitas/Colliders/Mesh/MeshSurfaceMassProperties.cs
Line coverage
100%
Covered lines: 26
Uncovered lines: 0
Coverable lines: 26
Total lines: 85
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
CalculateInertiaTensor(...)100%11100%
Create(...)100%11100%

File(s)

/home/runner/work/Gravitas/Gravitas/src/Gravitas/Colliders/Mesh/MeshSurfaceMassProperties.cs

#LineLine coverage
 1//=======================================================================
 2// MeshSurfaceMassProperties.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;
 10using FixedMathSharp.Geometry;
 11
 12namespace Gravitas.Colliders;
 13
 14/// <summary>
 15/// Stores deterministic uniform thin-shell mass properties for scaled mesh triangles.
 16/// </summary>
 17public readonly struct MeshSurfaceMassProperties
 18{
 19    internal MeshSurfaceMassProperties(
 20        Fixed64 area,
 21        Vector3d centerOfMass,
 22        Vector3d inertiaReferencePoint,
 23        Fixed3x3 unitMassInertiaTensor)
 24    {
 444025        Area = area;
 444026        CenterOfMass = centerOfMass;
 444027        InertiaReferencePoint = inertiaReferencePoint;
 444028        UnitMassInertiaTensor = unitMassInertiaTensor;
 444029    }
 30
 31    /// <summary>Gets the scaled triangle surface area represented by this shell.</summary>
 32    public Fixed64 Area { get; }
 33
 34    /// <summary>Gets the shell center of mass in scaled mesh-local coordinates.</summary>
 35    public Vector3d CenterOfMass { get; }
 36
 37    /// <summary>Gets the scaled mesh-local point about which the cached unit tensor is expressed.</summary>
 38    public Vector3d InertiaReferencePoint { get; }
 39
 40    /// <summary>Gets the unit-mass thin-shell inertia tensor about <see cref="InertiaReferencePoint"/>.</summary>
 41    public Fixed3x3 UnitMassInertiaTensor { get; }
 42
 43    /// <summary>Calculates shell inertia for the supplied mass about a scaled mesh-local reference point.</summary>
 44    public Fixed3x3 CalculateInertiaTensor(Fixed64 mass, Vector3d localReferencePoint)
 45    {
 146        Fixed3x3 referenceTensor = UnitMassInertiaTensor * mass;
 147        Fixed3x3 centerTensor = InertiaTensorMath.SubtractParallelAxisTensor(
 148            referenceTensor,
 149            mass,
 150            InertiaReferencePoint - CenterOfMass);
 151        return InertiaTensorMath.AddParallelAxisTensor(
 152            centerTensor,
 153            mass,
 154            localReferencePoint - CenterOfMass);
 55    }
 56
 57    internal static MeshSurfaceMassProperties Create(
 58        ReadOnlySpan<Vector3d> localVertices,
 59        ReadOnlySpan<int> triangles,
 60        Fixed64 totalArea,
 61        out ExactMassWeight totalWeight,
 62        out MeshMassIntegrals integrals,
 63        in ScaledRigidFrame3d sourceFrame = default,
 64        bool exactScale = false)
 65    {
 66        // The caller has admitted every vertex within MaximumGeometryReach and
 67        // every triangle above the degeneracy threshold. Positive shell weights
 68        // bound the exact centroid by the hull; centered second moments, including
 69        // scalar centroid rounding, stay well inside Fixed64 at the supported reach.
 444070        bool valid = TriangleShellMassProperties.TryCreateUniformShell(
 444071            localVertices,
 444072            triangles,
 444073            out totalWeight,
 444074            out Vector3d centerOfMass,
 444075            out Fixed3x3 unitCenterTensor,
 444076            out integrals, sourceFrame, exactScale);
 77        System.Diagnostics.Debug.Assert(valid);
 78
 444079        return new MeshSurfaceMassProperties(
 444080            totalArea,
 444081            centerOfMass,
 444082            centerOfMass,
 444083            unitCenterTensor);
 84    }
 85}