< Summary

Information
Class: Gravitas.Colliders.ExactMassPoint2D
Assembly: Gravitas
File(s): /home/runner/work/Gravitas/Gravitas/src/Gravitas/Colliders/MassProperties/ExactMassPoint2D.cs
Line coverage
100%
Covered lines: 22
Uncovered lines: 0
Coverable lines: 22
Total lines: 87
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%
FromPoint(...)100%11100%
CreateScaledLocalComposition(...)100%11100%
TryGetPoint(...)100%11100%
TryGetWeightedAverage(...)100%11100%
TryAddParallelAxisMoment(...)100%11100%

File(s)

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

#LineLine coverage
 1//=======================================================================
 2// ExactMassPoint2D.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 2D mass-property point that may lie outside the scalar
 16/// coordinate domain while remaining available to aggregate operations.
 17/// </summary>
 18internal readonly struct ExactMassPoint2D
 19{
 20    internal readonly Signed320 XNumerator;
 21    internal readonly Signed320 YNumerator;
 22
 23    internal ExactMassPoint2D(
 24        Signed320 xNumerator,
 25        Signed320 yNumerator)
 26    {
 4888227        XNumerator = xNumerator;
 4888228        YNumerator = yNumerator;
 4888229    }
 30
 31    /// <summary>Creates a mass point from a representable vector.</summary>
 32    internal static ExactMassPoint2D FromPoint(Vector2d point) =>
 71333        ExactMassProperties.CreatePoint(point);
 34
 35    /// <summary>
 36    /// Creates the exact planar composition
 37    /// <c>outerPoint * outerScale + innerOffset * innerScale +
 38    /// Rotate(innerDisplacement, innerRotation)</c>.
 39    /// </summary>
 40    internal static ExactMassPoint2D CreateScaledLocalComposition(
 41        Vector2d outerPoint,
 42        Vector2d outerScale,
 43        Vector2d innerOffset,
 44        Vector2d innerScale,
 45        Vector2d innerDisplacement,
 46        Fixed64 innerRotation) =>
 4816947        ExactMassProperties.CreatePoint(
 4816948            outerPoint,
 4816949            outerScale,
 4816950            innerOffset,
 4816951            innerScale,
 4816952            innerDisplacement,
 4816953            innerRotation);
 54
 55    /// <summary>Attempts to materialize this point as a Q32.32 vector.</summary>
 56    internal bool TryGetPoint(out Vector2d point) =>
 3000157        ExactMassProperties.TryGetPoint(this, out point);
 58
 59    /// <summary>
 60    /// Attempts to obtain the exact positive-weight average of semantic mass
 61    /// points with one final conversion per component.
 62    /// </summary>
 63    internal static bool TryGetWeightedAverage(
 64        ReadOnlySpan<ExactMassPoint2D> points,
 65        ReadOnlySpan<ExactMassWeight> weights,
 66        out Vector2d average) =>
 71667        ExactMassProperties.TryGetWeightedAverage(
 71668            points,
 71669            weights,
 71670            out average);
 71
 72    /// <summary>
 73    /// Attempts to add this point's parallel-axis contribution to a scalar
 74    /// moment about <paramref name="referencePoint"/>.
 75    /// </summary>
 76    internal bool TryAddParallelAxisMoment(
 77        Fixed64 centerMoment,
 78        Fixed64 mass,
 79        Vector2d referencePoint,
 80        out Fixed64 moment) =>
 1748581        ExactMassProperties.TryAddParallelAxisMoment(
 1748582            this,
 1748583            centerMoment,
 1748584            mass,
 1748585            referencePoint,
 1748586            out moment);
 87}