< Summary

Information
Class: Gravitas.Colliders.ExactMassWeight
Assembly: Gravitas
File(s): /home/runner/work/Gravitas/Gravitas/src/Gravitas/Colliders/MassProperties/ExactMassWeight.cs
Line coverage
100%
Covered lines: 20
Uncovered lines: 0
Coverable lines: 20
Total lines: 104
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%
get_Zero()100%11100%
get_One()100%11100%
get_IsZero()100%11100%
FromMeasure(...)100%11100%
FromProduct(...)100%11100%
FromProduct(...)100%11100%
FromProduct(...)100%11100%
Add(...)100%22100%
TryAdd(...)100%11100%
TryGetMeasure(...)100%11100%
TryGetProportionalShare(...)100%11100%

File(s)

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

#LineLine coverage
 1//=======================================================================
 2// ExactMassWeight.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 nonnegative relative mass-property measure without narrowing
 16/// products or aggregate sums to <see cref="Fixed64"/>.
 17/// </summary>
 18internal readonly struct ExactMassWeight
 19{
 20    internal readonly Signed320 Numerator;
 21
 22    internal ExactMassWeight(Signed320 numerator)
 23    {
 17910624        Numerator = numerator;
 17910625    }
 26
 27    /// <summary>Gets the zero relative weight.</summary>
 139228    internal static ExactMassWeight Zero => default;
 29
 30    /// <summary>Gets a unit relative weight.</summary>
 31    internal static ExactMassWeight One =>
 4632        ExactMassProperties.CreateWeight(Fixed64.One);
 33
 34    /// <summary>Gets whether this weight is exactly zero.</summary>
 393635    internal bool IsZero => Numerator.IsZero;
 36
 37    /// <summary>Creates a weight from one nonnegative measure.</summary>
 38    internal static ExactMassWeight FromMeasure(Fixed64 measure) =>
 2939        ExactMassProperties.CreateWeight(measure);
 40
 41    /// <summary>Creates a weight from an exact product of nonnegative factors.</summary>
 42    internal static ExactMassWeight FromProduct(
 43        Fixed64 first,
 44        Fixed64 second) =>
 145        ExactMassProperties.CreateWeight(first, second);
 46
 47    /// <summary>Creates a weight from an exact product of nonnegative factors.</summary>
 48    internal static ExactMassWeight FromProduct(
 49        Fixed64 first,
 50        Fixed64 second,
 51        Fixed64 third) =>
 480152        ExactMassProperties.CreateWeight(first, second, third);
 53
 54    /// <summary>Creates a weight from an exact product of nonnegative factors.</summary>
 55    internal static ExactMassWeight FromProduct(
 56        Fixed64 first,
 57        Fixed64 second,
 58        Fixed64 third,
 59        Fixed64 fourth) =>
 255960        ExactMassProperties.CreateWeight(first, second, third, fourth);
 61
 62    /// <summary>Adds another nonnegative weight without scalar narrowing.</summary>
 63    /// <exception cref="OverflowException">
 64    /// The exact aggregate exceeds the semantic weight domain.
 65    /// </exception>
 66    internal ExactMassWeight Add(ExactMassWeight other)
 67    {
 352368        if (!TryAdd(other, out ExactMassWeight result))
 69        {
 170            throw new OverflowException(
 171                "The aggregate mass-property weight is outside the semantic weight domain.");
 72        }
 73
 352274        return result;
 75    }
 76
 77    /// <summary>
 78    /// Attempts to add another nonnegative weight without scalar narrowing.
 79    /// </summary>
 80    internal bool TryAdd(
 81        ExactMassWeight other,
 82        out ExactMassWeight result) =>
 371483        ExactMassProperties.TryAdd(this, other, out result);
 84
 85    /// <summary>
 86    /// Attempts to materialize the represented measure as <see cref="Fixed64"/>.
 87    /// </summary>
 88    internal bool TryGetMeasure(out Fixed64 measure) =>
 3289        ExactMassProperties.TryGetMeasure(this, out measure);
 90
 91    /// <summary>
 92    /// Attempts to distribute <paramref name="total"/> by this weight's exact
 93    /// share of <paramref name="totalWeight"/>.
 94    /// </summary>
 95    internal bool TryGetProportionalShare(
 96        Fixed64 total,
 97        ExactMassWeight totalWeight,
 98        out Fixed64 share) =>
 199599        ExactMassProperties.TryGetProportionalShare(
 1995100            this,
 1995101            total,
 1995102            totalWeight,
 1995103            out share);
 104}