< Summary

Information
Class: Trailblazer.Pathing.NavigationAgentProfile
Assembly: Trailblazer
File(s): /home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Pathing/Query/NavigationAgentProfile.cs
Line coverage
100%
Covered lines: 50
Uncovered lines: 0
Coverable lines: 50
Total lines: 142
Line coverage: 100%
Branch coverage
100%
Covered branches: 12
Total branches: 12
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%1010100%
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/NavigationAgentProfile.cs

#LineLine coverage
 1//=======================================================================
 2// NavigationAgentProfile.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 immutable geometry and traversal capabilities for a navigation query.
 16/// </summary>
 17public readonly struct NavigationAgentProfile : IEquatable<NavigationAgentProfile>
 18{
 19    private const TraversalCapability KnownCapabilities =
 20        TraversalCapability.Jump
 21        | TraversalCapability.Climb
 22        | TraversalCapability.Swim
 23        | TraversalCapability.Fly
 24        | TraversalCapability.Teleport;
 25
 26    /// <summary>
 27    /// Gets the authoritative body geometry for the agent.
 28    /// </summary>
 29    public KinematicBodyShape Shape { get; }
 30
 31    /// <summary>
 32    /// Gets the maximum upward surface step allowed in world units.
 33    /// </summary>
 34    public Fixed64 MaxStepUp { get; }
 35
 36    /// <summary>
 37    /// Gets the maximum downward surface drop allowed in world units.
 38    /// </summary>
 39    public Fixed64 MaxDropDown { get; }
 40
 41    /// <summary>
 42    /// Gets the non-negative distance at which the agent is considered to have arrived.
 43    /// </summary>
 44    public Fixed64 ArrivalRadius { get; }
 45
 46    /// <summary>
 47    /// Gets the traversal media this agent may enter.
 48    /// </summary>
 49    public TraversalMedia AllowedMedia { get; }
 50
 51    /// <summary>
 52    /// Gets the additional traversal abilities available to the agent.
 53    /// </summary>
 54    public TraversalCapability Capabilities { get; }
 55
 56    /// <summary>
 57    /// Creates an immutable navigation agent profile.
 58    /// </summary>
 59    /// <exception cref="ArgumentException">Thrown when the body shape is invalid.</exception>
 60    /// <exception cref="ArgumentOutOfRangeException">Thrown when a distance is negative or flags contain unknown bits.<
 61    public NavigationAgentProfile(
 62        KinematicBodyShape shape,
 63        Fixed64 maxStepUp,
 64        Fixed64 maxDropDown,
 65        Fixed64 arrivalRadius,
 66        TraversalMedia allowedMedia,
 67        TraversalCapability capabilities)
 68    {
 161469        shape.Validate(nameof(shape));
 161370        SwiftThrowHelper.ThrowIfArgumentOutOfRange(
 161371            maxStepUp < Fixed64.Zero,
 161372            actualValue: null,
 161373            nameof(maxStepUp),
 161374            "Maximum step-up distance cannot be negative.");
 161275        SwiftThrowHelper.ThrowIfArgumentOutOfRange(
 161276            maxDropDown < Fixed64.Zero,
 161277            actualValue: null,
 161278            nameof(maxDropDown),
 161279            "Maximum drop-down distance cannot be negative.");
 161180        SwiftThrowHelper.ThrowIfArgumentOutOfRange(
 161181            arrivalRadius < Fixed64.Zero,
 161182            actualValue: null,
 161183            nameof(arrivalRadius),
 161184            "Arrival radius cannot be negative.");
 161085        SwiftThrowHelper.ThrowIfArgumentOutOfRange(
 161086            (allowedMedia & ~NavigationCell.KnownMedia) != 0,
 161087            (int)allowedMedia,
 161088            nameof(allowedMedia),
 161089            "Allowed media contains unknown flag bits.");
 160990        SwiftThrowHelper.ThrowIfArgumentOutOfRange(
 160991            (capabilities & ~KnownCapabilities) != 0,
 160992            (int)capabilities,
 160993            nameof(capabilities),
 160994            "Traversal capabilities contain unknown flag bits.");
 95
 160896        Shape = shape;
 160897        MaxStepUp = maxStepUp;
 160898        MaxDropDown = maxDropDown;
 160899        ArrivalRadius = arrivalRadius;
 1608100        AllowedMedia = allowedMedia;
 1608101        Capabilities = capabilities;
 1608102    }
 103
 104    /// <inheritdoc/>
 105    public bool Equals(NavigationAgentProfile other) =>
 2887106        Shape == other.Shape
 2887107        && MaxStepUp == other.MaxStepUp
 2887108        && MaxDropDown == other.MaxDropDown
 2887109        && ArrivalRadius == other.ArrivalRadius
 2887110        && AllowedMedia == other.AllowedMedia
 2887111        && Capabilities == other.Capabilities;
 112
 113    /// <inheritdoc/>
 212114    public override bool Equals(object? obj) => obj is NavigationAgentProfile other && Equals(other);
 115
 116    /// <inheritdoc/>
 117    public override int GetHashCode()
 118    {
 3372119        int hash = SwiftHashTools.CombineHashCodes(Shape.GetHashCode(), MaxStepUp.GetHashCode());
 3372120        hash = SwiftHashTools.CombineHashCodes(hash, MaxDropDown.GetHashCode());
 3372121        hash = SwiftHashTools.CombineHashCodes(hash, ArrivalRadius.GetHashCode());
 3372122        hash = SwiftHashTools.CombineHashCodes(hash, (int)AllowedMedia);
 3372123        return SwiftHashTools.CombineHashCodes(hash, (int)Capabilities);
 124    }
 125
 126    /// <summary>
 127    /// Returns whether two profiles have exactly equal values.
 128    /// </summary>
 2498129    public static bool operator ==(NavigationAgentProfile left, NavigationAgentProfile right) => left.Equals(right);
 130
 131    /// <summary>
 132    /// Returns whether two profiles differ.
 133    /// </summary>
 172134    public static bool operator !=(NavigationAgentProfile left, NavigationAgentProfile right) => !left.Equals(right);
 135
 732136    internal bool IsValid => Shape.IsValid;
 137
 138    internal void Validate(string parameterName)
 139    {
 25174140        Shape.Validate(parameterName);
 25173141    }
 142}