< Summary

Information
Class: Trailblazer.Pathing.AStarPathRequest
Assembly: Trailblazer
File(s): /home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Pathing/Search/AStar/AStarPathRequest.cs
Line coverage
97%
Covered lines: 45
Uncovered lines: 1
Coverable lines: 46
Total lines: 119
Line coverage: 97.8%
Branch coverage
70%
Covered branches: 14
Total branches: 20
Branch coverage: 70%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
TryCreate(...)100%22100%
Create(...)62.5%8896.42%
Equals(...)100%22100%
Equals(...)50%22100%
GetHashCode()66.66%66100%

File(s)

/home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Pathing/Search/AStar/AStarPathRequest.cs

#LineLine coverage
 1using FixedMathSharp;
 2using GridForge.Grids;
 3using System;
 4using System.Runtime.CompilerServices;
 5
 6namespace Trailblazer.Pathing;
 7
 8/// <summary>
 9/// A pathfinding request used for A* trail generation, including options for climb height, heuristic weighting,
 10/// and path smoothing. Implements value-based comparison and hashing for guide pooling.
 11/// </summary>
 12public class AStarPathRequest : PathRequest, IEquatable<AStarPathRequest>
 13{
 14    /// <summary>
 15    /// The maximum Y-axis height delta a unit can step or climb per voxel.
 16    /// Voxels exceeding this are ignored even if walkable and adjacent.
 17    /// </summary>
 18    public Fixed64 MaxClimbHeight { get; set; }
 19
 20    /// <summary>
 21    /// Gets or sets the heuristic method used for evaluating or guiding the algorithm.
 22    /// </summary>
 23    /// <remarks>
 24    /// Set this property to specify which heuristic strategy the algorithm should use.
 25    /// The selected heuristic can affect the performance and outcome of the algorithm.
 26    /// </remarks>
 27    public HeuristicMethod Heuristic { get; set; }
 28
 29    // Prevent external use of the default constructor to ensure proper initialization through factory methods.
 158030    private AStarPathRequest() { }
 31
 32    /// <summary>
 33    /// Attempts to create a new context-bound A* pathfinding request.
 34    /// </summary>
 35    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 36    public static bool TryCreate(
 37        TrailblazerWorldContext context,
 38        Vector3d origin,
 39        Vector3d destination,
 40        Fixed64 unitSize,
 41        out AStarPathRequest? request)
 42    {
 6143        request = Create(context, origin, destination, unitSize);
 6144        if (request == null)
 245            return false;
 5946        return true;
 47    }
 48
 49    /// <summary>
 50    /// Creates a context-bound A* pathfinding request.
 51    /// </summary>
 52    public static AStarPathRequest? Create(
 53        TrailblazerWorldContext context,
 54        Vector3d origin,
 55        Vector3d destination,
 56        Fixed64 unitSize,
 57        HeuristicMethod heuristic = HeuristicMethod.Manhattan,
 58        bool allowUnwalkableEndpoints = false,
 59        bool allowTraversalTransitions = false)
 60    {
 80361        PathRequestContextResolver.ThrowIfUnusable(context);
 80362        if (!SolidVoxelFinder.TryGetPathEdgeVoxels(
 80363            context,
 80364            origin,
 80365            destination,
 80366            out Voxel? startNode,
 80367            out Voxel? endNode,
 80368            unitSize,
 80369            allowUnwalkableEndpoints))
 70        {
 1371            return null;
 72        }
 73
 79074        if (startNode == null || endNode == null)
 075            return null;
 76
 79077        AStarPathRequest request = new()
 79078        {
 79079            Context = context,
 79080            Origin = origin,
 79081            StartNode = startNode,
 79082            TargetPosition = destination,
 79083            EndNode = endNode,
 79084            UnitSize = unitSize,
 79085            Heuristic = heuristic,
 79086            AllowUnwalkableEndpoints = allowUnwalkableEndpoints,
 79087            AllowTraversalTransitions = allowTraversalTransitions,
 79088            MaxClimbHeight = context.VoxelSize
 79089        };
 90
 79091        if (context.Pathing.TryGetMaxSearchSize(request.StartNode, request.EndNode, out int searchSize))
 79092            request.MaxPathSearchRange = searchSize;
 93
 79094        return request;
 95    }
 96
 97    /// <inheritdoc/>
 98    public override bool Equals(object? obj) =>
 399        obj is AStarPathRequest other && Equals(other);
 100
 101    /// <inheritdoc/>
 4102    public bool Equals(AStarPathRequest? other) => RequestCacheKey == other?.RequestCacheKey;
 103
 104    /// <inheritdoc/>
 105    public override int GetHashCode()
 106    {
 2885107        PathRequestHashBuilder hash = PathRequestHashBuilder.Create();
 2885108        hash.Add(StartNode?.SpawnToken ?? 0);
 2885109        hash.Add(EndNode?.SpawnToken ?? 0);
 2885110        hash.Add(UnitSize.GetHashCode());
 2885111        hash.Add(AllowUnwalkableEndpoints);
 2885112        hash.Add(AllowTraversalTransitions);
 2885113        hash.Add((int)Heuristic);
 2885114        hash.Add(MaxClimbHeight.GetHashCode());
 2885115        hash.Add(MaxPathSearchRange);
 2885116        hash.Add(AllowTraversalTransitions ? Context.Pathing.State.TransitionRegistryState.RegistryVersion : 0);
 2885117        return hash.ToHashCode();
 118    }
 119}