< Summary

Class:GDX.RigidbodyExtensions
Assembly:GDX
File(s):./Packages/com.dotbunny.gdx/GDX/RigidbodyExtensions.cs
Covered lines:0
Uncovered lines:4
Coverable lines:4
Total lines:39
Line coverage:0% (0 of 4)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:1
Method coverage:0% (0 of 1)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
MomentOfInertia(...)0%6200%

File(s)

./Packages/com.dotbunny.gdx/GDX/RigidbodyExtensions.cs

#LineLine coverage
 1// Copyright (c) 2020-2024 dotBunny Inc.
 2// dotBunny licenses this file to you under the BSL-1.0 license.
 3// See the LICENSE file in the project root for more information.
 4
 5using UnityEngine;
 6
 7#if !UNITY_DOTSRUNTIME
 8namespace GDX
 9{
 10    /// <summary>
 11    ///     <see cref="UnityEngine.Rigidbody" /> Based Extension Methods
 12    /// </summary>
 13    /// <exception cref="UnsupportedRuntimeException">Not supported on DOTS Runtime.</exception>
 14    [VisualScriptingCompatible(2)]
 15    public static class RigidbodyExtensions
 16    {
 17        /// <summary>
 18        ///     Get a <see cref="Rigidbody" />'s moment of inertia for a <paramref name="targetAxis" />.
 19        /// </summary>
 20        /// <remarks>
 21        ///     Provided <paramref name="targetAxis" /> must not be <see cref="Vector3.zero" />.
 22        /// </remarks>
 23        /// <param name="targetRigidbody">The <see cref="Rigidbody" /> to evaluate.</param>
 24        /// <param name="targetAxis">The axis use to calculate the moment of inertia.</param>
 25        /// <returns>The moment of inertia for the <paramref name="targetAxis" />.</returns>
 26        public static float MomentOfInertia(this Rigidbody targetRigidbody, Vector3 targetAxis)
 027        {
 28            // Normalize axis
 029            targetAxis = targetAxis.normalized;
 30
 031            return targetAxis.sqrMagnitude == 0f
 32                ? float.NaN
 33                : Vector3.Scale(
 34                    Quaternion.Inverse(targetRigidbody.transform.rotation * targetRigidbody.inertiaTensorRotation) *
 35                    targetAxis, targetRigidbody.inertiaTensor).magnitude;
 036        }
 37    }
 38}
 39#endif // !UNITY_DOTSRUNTIME