< Summary

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

File(s)

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

#LineLine coverage
 1//=======================================================================
 2// NavigationEndpoint.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/// Describes one immutable world-space endpoint of a path query.
 16/// </summary>
 17public readonly struct NavigationEndpoint : IEquatable<NavigationEndpoint>
 18{
 19    /// <summary>
 20    /// Gets the exact requested foot position in world space.
 21    /// </summary>
 22    public Vector3d Position { get; }
 23
 24    /// <summary>
 25    /// Gets the optional stable map identifier used to filter endpoint candidates.
 26    /// </summary>
 27    public string? MapId { get; }
 28
 29    /// <summary>
 30    /// Gets the endpoint resolution policy.
 31    /// </summary>
 32    public EndpointResolutionPolicy Resolution { get; }
 33
 34    /// <summary>
 35    /// Gets the non-negative maximum resolution distance in world units.
 36    /// </summary>
 37    public Fixed64 MaxResolutionDistance { get; }
 38
 39    /// <summary>
 40    /// Creates an immutable navigation endpoint.
 41    /// </summary>
 42    /// <exception cref="ArgumentException">Thrown when a supplied map identifier is empty or whitespace.</exception>
 43    /// <exception cref="ArgumentOutOfRangeException">Thrown when the policy is unknown or the distance is negative.</ex
 44    public NavigationEndpoint(
 45        Vector3d position,
 46        string? mapId = null,
 47        EndpointResolutionPolicy resolution = EndpointResolutionPolicy.Strict,
 48        Fixed64 maxResolutionDistance = default)
 49    {
 236850        SwiftThrowHelper.ThrowIfArgument(
 236851            mapId != null && string.IsNullOrWhiteSpace(mapId),
 236852            nameof(mapId),
 236853            "Map identifier cannot be empty or whitespace.");
 236754        SwiftThrowHelper.ThrowIfArgumentOutOfRange(
 236755            resolution is not EndpointResolutionPolicy.Strict and not EndpointResolutionPolicy.NearestNavigable,
 236756            (int)resolution,
 236757            nameof(resolution),
 236758            "Endpoint resolution policy is unknown.");
 236659        SwiftThrowHelper.ThrowIfArgumentOutOfRange(
 236660            maxResolutionDistance < Fixed64.Zero,
 236661            actualValue: null,
 236662            nameof(maxResolutionDistance),
 236663            "Maximum resolution distance cannot be negative.");
 64
 236565        Position = position;
 236566        MapId = mapId;
 236567        Resolution = resolution;
 236568        MaxResolutionDistance = maxResolutionDistance;
 236569    }
 70
 71    /// <inheritdoc/>
 72    public bool Equals(NavigationEndpoint other) =>
 378573        Position == other.Position
 378574        && string.Equals(MapId, other.MapId, StringComparison.Ordinal)
 378575        && Resolution == other.Resolution
 378576        && MaxResolutionDistance == other.MaxResolutionDistance;
 77
 78    /// <inheritdoc/>
 20979    public override bool Equals(object? obj) => obj is NavigationEndpoint other && Equals(other);
 80
 81    /// <inheritdoc/>
 82    public override int GetHashCode()
 83    {
 480484        int mapIdHash = MapId == null
 480485            ? 0
 480486            : SwiftHashTools.GetDeterministicStringEqualityComparer().GetHashCode(MapId);
 480487        int hash = SwiftHashTools.CombineHashCodes(Position.X.GetHashCode(), Position.Y.GetHashCode());
 480488        hash = SwiftHashTools.CombineHashCodes(hash, Position.Z.GetHashCode());
 480489        hash = SwiftHashTools.CombineHashCodes(hash, mapIdHash);
 480490        hash = SwiftHashTools.CombineHashCodes(hash, (int)Resolution);
 480491        return SwiftHashTools.CombineHashCodes(hash, MaxResolutionDistance.GetHashCode());
 92    }
 93
 94    /// <summary>
 95    /// Returns whether two endpoints have exactly equal values.
 96    /// </summary>
 357297    public static bool operator ==(NavigationEndpoint left, NavigationEndpoint right) => left.Equals(right);
 98
 99    /// <summary>
 100    /// Returns whether two endpoints differ.
 101    /// </summary>
 1102    public static bool operator !=(NavigationEndpoint left, NavigationEndpoint right) => !left.Equals(right);
 103
 104}