< Summary

Information
Class: Trailblazer.Pathing.PathQuery
Assembly: Trailblazer
File(s): /home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Pathing/Query/PathQuery.cs
Line coverage
100%
Covered lines: 60
Uncovered lines: 0
Coverable lines: 60
Total lines: 140
Line coverage: 100%
Branch coverage
100%
Covered branches: 22
Total branches: 22
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%
WithStartState(...)100%11100%
Equals(...)100%1616100%
Equals(...)100%22100%
GetHashCode()100%11100%
op_Equality(...)100%11100%
op_Inequality(...)100%11100%

File(s)

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

#LineLine coverage
 1//=======================================================================
 2// PathQuery.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 complete immutable caller intent for one navigation query.
 16/// </summary>
 17public readonly struct PathQuery : IEquatable<PathQuery>
 18{
 19    /// <summary>Gets the requested start endpoint.</summary>
 20    public NavigationEndpoint Start { get; }
 21
 22    /// <summary>Gets the requested destination endpoint.</summary>
 23    public NavigationEndpoint End { get; }
 24
 25    /// <summary>Gets the exact agent profile used to evaluate traversal.</summary>
 26    public NavigationAgentProfile Agent { get; }
 27
 28    /// <summary>Gets the exact query-specific navigation-area policy identity.</summary>
 29    public NavigationAreaPolicyKey AreaPolicy { get; }
 30
 31    /// <summary>Gets the exact start medium and allowed target media.</summary>
 32    public TraversalIntent Traversal { get; }
 33
 34    /// <summary>Gets the selected search algorithm.</summary>
 35    public PathAlgorithm Algorithm { get; }
 36
 37    /// <summary>Gets the finite work budget shared by the complete query.</summary>
 38    public NavigationWorkBudget Budget { get; }
 39
 40    /// <summary>Gets whether explicit or generated traversal transitions may be used.</summary>
 41    public bool AllowTransitions { get; }
 42
 43    /// <summary>Gets the options used when <see cref="Algorithm"/> is <see cref="PathAlgorithm.FlowField"/>.</summary>
 44    public FlowFieldQueryOptions FlowField { get; }
 45
 46    /// <summary>
 47    /// Creates complete immutable navigation query intent.
 48    /// </summary>
 49    /// <exception cref="ArgumentException">Thrown when a nested value is invalid or incompatible with the algorithm.</e
 50    /// <exception cref="ArgumentOutOfRangeException">Thrown when the algorithm is unknown.</exception>
 51    public PathQuery(
 52        NavigationEndpoint start,
 53        NavigationEndpoint end,
 54        NavigationAgentProfile agent,
 55        NavigationAreaPolicyKey areaPolicy,
 56        TraversalIntent traversal,
 57        PathAlgorithm algorithm,
 58        NavigationWorkBudget budget,
 59        bool allowTransitions,
 60        FlowFieldQueryOptions flowField = default)
 61    {
 203162        agent.Validate(nameof(agent));
 203063        areaPolicy.Validate(nameof(areaPolicy));
 203064        traversal.Validate(nameof(traversal));
 203065        SwiftThrowHelper.ThrowIfArgumentOutOfRange(
 203066            algorithm is not PathAlgorithm.AStar and not PathAlgorithm.FlowField,
 203067            (int)algorithm,
 203068            nameof(algorithm),
 203069            "Path algorithm is unknown.");
 202970        SwiftThrowHelper.ThrowIfArgument(
 202971            algorithm == PathAlgorithm.AStar && flowField != default,
 202972            nameof(flowField),
 202973            "A* queries cannot carry flow-field-specific options.");
 202874        SwiftThrowHelper.ThrowIfArgument(
 202875            (traversal.TargetMedia & ~agent.AllowedMedia) != 0,
 202876            nameof(traversal),
 202877            "Target media must be a subset of the agent's allowed media.");
 78
 202779        Start = start;
 202780        End = end;
 202781        Agent = agent;
 202782        AreaPolicy = areaPolicy;
 202783        Traversal = traversal;
 202784        Algorithm = algorithm;
 202785        Budget = budget;
 202786        AllowTransitions = allowTransitions;
 202787        FlowField = flowField;
 202788    }
 89
 90    internal PathQuery WithStartState(
 91        Vector3d position,
 8792        TraversalMedium startMedium) => new(
 8793        new NavigationEndpoint(
 8794            position,
 8795            Start.MapId,
 8796            Start.Resolution,
 8797            Start.MaxResolutionDistance),
 8798        End,
 8799        Agent,
 87100        AreaPolicy,
 87101        new TraversalIntent(startMedium, Traversal.TargetMedia),
 87102        Algorithm,
 87103        Budget,
 87104        AllowTransitions,
 87105        FlowField);
 106
 107    /// <inheritdoc/>
 108    public bool Equals(PathQuery other) =>
 1070109        Start == other.Start
 1070110        && End == other.End
 1070111        && Agent == other.Agent
 1070112        && AreaPolicy == other.AreaPolicy
 1070113        && Traversal == other.Traversal
 1070114        && Algorithm == other.Algorithm
 1070115        && Budget == other.Budget
 1070116        && AllowTransitions == other.AllowTransitions
 1070117        && FlowField == other.FlowField;
 118
 119    /// <inheritdoc/>
 79120    public override bool Equals(object? obj) => obj is PathQuery other && Equals(other);
 121
 122    /// <inheritdoc/>
 123    public override int GetHashCode()
 124    {
 1432125        int hash = SwiftHashTools.CombineHashCodes(Start.GetHashCode(), End.GetHashCode());
 1432126        hash = SwiftHashTools.CombineHashCodes(hash, Agent.GetHashCode());
 1432127        hash = SwiftHashTools.CombineHashCodes(hash, AreaPolicy.GetHashCode());
 1432128        hash = SwiftHashTools.CombineHashCodes(hash, Traversal.GetHashCode());
 1432129        hash = SwiftHashTools.CombineHashCodes(hash, (int)Algorithm);
 1432130        hash = SwiftHashTools.CombineHashCodes(hash, Budget.GetHashCode());
 1432131        hash = SwiftHashTools.CombineHashCodes(hash, AllowTransitions ? 1 : 0);
 1432132        return SwiftHashTools.CombineHashCodes(hash, FlowField.GetHashCode());
 133    }
 134
 135    /// <summary>Returns whether two queries have exactly equal intent.</summary>
 991136    public static bool operator ==(PathQuery left, PathQuery right) => left.Equals(right);
 137
 138    /// <summary>Returns whether two queries differ.</summary>
 1139    public static bool operator !=(PathQuery left, PathQuery right) => !left.Equals(right);
 140}