< Summary

Information
Class: Trailblazer.Pathing.KinematicBodyShape
Assembly: Trailblazer
File(s): /home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Pathing/Query/KinematicBodyShape.cs
Line coverage
100%
Covered lines: 33
Uncovered lines: 0
Coverable lines: 33
Total lines: 96
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
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%
Equals(...)100%44100%
Equals(...)100%22100%
GetHashCode()100%11100%
op_Equality(...)100%11100%
op_Inequality(...)100%11100%
get_IsValid()100%11100%
Validate(...)100%11100%

File(s)

/home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Pathing/Query/KinematicBodyShape.cs

#LineLine coverage
 1//=======================================================================
 2// KinematicBodyShape.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;
 9using FixedMathSharp;
 10using SwiftCollections.Utility;
 11
 12namespace Trailblazer.Pathing;
 13
 14/// <summary>
 15/// Defines the authoritative deterministic body geometry used by navigation and movement.
 16/// </summary>
 17public readonly struct KinematicBodyShape : IEquatable<KinematicBodyShape>
 18{
 19    /// <summary>
 20    /// Gets the non-negative horizontal body radius.
 21    /// </summary>
 22    public Fixed64 Radius { get; }
 23
 24    /// <summary>
 25    /// Gets the positive body height measured upward from the foot position.
 26    /// </summary>
 27    public Fixed64 Height { get; }
 28
 29    /// <summary>
 30    /// Gets the non-negative vertical offset from the host root to its foot position.
 31    /// </summary>
 32    public Fixed64 RootToFootOffsetY { get; }
 33
 34    /// <summary>
 35    /// Creates an immutable body shape.
 36    /// </summary>
 37    /// <exception cref="ArgumentOutOfRangeException">Thrown when a dimension is outside its valid range.</exception>
 38    public KinematicBodyShape(Fixed64 radius, Fixed64 height, Fixed64 rootToFootOffsetY)
 39    {
 159840        SwiftThrowHelper.ThrowIfArgumentOutOfRange(
 159841            radius < Fixed64.Zero,
 159842            actualValue: null,
 159843            nameof(radius),
 159844            "Body radius cannot be negative.");
 159345        SwiftThrowHelper.ThrowIfArgumentOutOfRange(
 159346            height <= Fixed64.Zero,
 159347            actualValue: null,
 159348            nameof(height),
 159349            "Body height must be positive.");
 159150        SwiftThrowHelper.ThrowIfArgumentOutOfRange(
 159151            rootToFootOffsetY < Fixed64.Zero,
 159152            actualValue: null,
 159153            nameof(rootToFootOffsetY),
 159154            "Root-to-foot offset cannot be negative.");
 55
 159056        Radius = radius;
 159057        Height = height;
 159058        RootToFootOffsetY = rootToFootOffsetY;
 159059    }
 60
 61    /// <inheritdoc/>
 62    public bool Equals(KinematicBodyShape other) =>
 289563        Radius == other.Radius
 289564        && Height == other.Height
 289565        && RootToFootOffsetY == other.RootToFootOffsetY;
 66
 67    /// <inheritdoc/>
 568    public override bool Equals(object? obj) => obj is KinematicBodyShape other && Equals(other);
 69
 70    /// <inheritdoc/>
 71    public override int GetHashCode()
 72    {
 337473        int hash = SwiftHashTools.CombineHashCodes(Radius.GetHashCode(), Height.GetHashCode());
 337474        return SwiftHashTools.CombineHashCodes(hash, RootToFootOffsetY.GetHashCode());
 75    }
 76
 77    /// <summary>
 78    /// Returns whether two shapes have exactly equal dimensions.
 79    /// </summary>
 288880    public static bool operator ==(KinematicBodyShape left, KinematicBodyShape right) => left.Equals(right);
 81
 82    /// <summary>
 83    /// Returns whether two shapes have different dimensions.
 84    /// </summary>
 185    public static bool operator !=(KinematicBodyShape left, KinematicBodyShape right) => !left.Equals(right);
 86
 2752087    internal bool IsValid => Height > Fixed64.Zero;
 88
 89    internal void Validate(string parameterName)
 90    {
 2678891        SwiftThrowHelper.ThrowIfArgument(
 2678892            !IsValid,
 2678893            parameterName,
 2678894            "Body shape must be initialized.");
 2678695    }
 96}