< 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: 28
Uncovered lines: 0
Coverable lines: 28
Total lines: 82
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%
CalculateInertiaTensor(...)100%11100%
TryCreate(...)100%22100%

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 FixedMathSharp;
 9using FixedMathSharp.Geometry;
 10using System;
 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    {
 42725        Area = area;
 42726        CenterOfMass = centerOfMass;
 42727        InertiaReferencePoint = inertiaReferencePoint;
 42728        UnitMassInertiaTensor = unitMassInertiaTensor;
 42729    }
 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    {
 12246        Fixed3x3 referenceTensor = UnitMassInertiaTensor * mass;
 12247        Fixed3x3 centerTensor = InertiaTensorMath.SubtractParallelAxisTensor(
 12248            referenceTensor,
 12249            mass,
 12250            InertiaReferencePoint - CenterOfMass);
 12251        return InertiaTensorMath.AddParallelAxisTensor(
 12252            centerTensor,
 12253            mass,
 12254            localReferencePoint - CenterOfMass);
 55    }
 56
 57    internal static bool TryCreate(
 58        ReadOnlySpan<Vector3d> localVertices,
 59        ReadOnlySpan<int> triangles,
 60        Fixed64 totalArea,
 61        out ExactMassWeight totalWeight,
 62        out MeshSurfaceMassProperties properties)
 63    {
 45364        properties = default;
 45365        if (!TriangleShellMassProperties.TryCreateUniformShell(
 45366                localVertices,
 45367                triangles,
 45368                out totalWeight,
 45369                out Vector3d centerOfMass,
 45370                out Fixed3x3 unitCenterTensor))
 71        {
 2672            return false;
 73        }
 74
 42775        properties = new MeshSurfaceMassProperties(
 42776            totalArea,
 42777            centerOfMass,
 42778            centerOfMass,
 42779            unitCenterTensor);
 42780        return true;
 81    }
 82}