< Summary

Information
Class: Trailblazer.Pathing.NavigationAreaPolicy
Assembly: Trailblazer
File(s): /home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Pathing/Traversal/NavigationAreaPolicy.cs
Line coverage
100%
Covered lines: 34
Uncovered lines: 0
Coverable lines: 34
Total lines: 79
Line coverage: 100%
Branch coverage
100%
Covered branches: 16
Total branches: 16
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%
get_RuleCount()100%11100%
TryGetRule(...)100%22100%
get_RetainedBytes()100%11100%
ContentEquals(...)100%1010100%

File(s)

/home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Pathing/Traversal/NavigationAreaPolicy.cs

#LineLine coverage
 1//=======================================================================
 2// NavigationAreaPolicy.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 System.Collections.Generic;
 10
 11namespace Trailblazer.Pathing;
 12
 13/// <summary>
 14/// Stores one immutable direct-indexed navigation-area policy snapshot.
 15/// </summary>
 16public sealed class NavigationAreaPolicy
 17{
 18    private const int MaximumRuleCount = ushort.MaxValue + 1;
 19    private readonly NavigationAreaRule[] _rules;
 20    private readonly long _retainedBytes;
 21
 22    /// <summary>Creates a policy by copying rules whose indices are stable area IDs.</summary>
 19623    public NavigationAreaPolicy(
 19624        NavigationAreaPolicyKey key,
 19625        IReadOnlyList<NavigationAreaRule> rules)
 26    {
 19627        key.Validate(nameof(key));
 19628        SwiftThrowHelper.ThrowIfNull(rules, nameof(rules));
 19629        SwiftThrowHelper.ThrowIfArgument(
 19630            rules.Count == 0 || rules.Count > MaximumRuleCount,
 19631            nameof(rules),
 19632            "A policy requires between one and 65,536 direct-indexed rules.");
 33
 19534        Key = key;
 19535        _rules = new NavigationAreaRule[rules.Count];
 187236        for (int i = 0; i < rules.Count; i++)
 74137            _rules[i] = rules[i];
 19538        _retainedBytes = checked(
 19539            48L
 19540            + ((long)key.PolicyId.Length * sizeof(char))
 19541            + ((long)_rules.Length * 24L));
 19542    }
 43
 44    /// <summary>Gets the exact immutable policy identity.</summary>
 45    public NavigationAreaPolicyKey Key { get; }
 46
 47    /// <summary>Gets the number of configured direct-indexed area rules.</summary>
 402648    public int RuleCount => _rules.Length;
 49
 50    /// <summary>Attempts to resolve an area rule without allocation or lookup hashing.</summary>
 51    public bool TryGetRule(NavigationAreaId area, out NavigationAreaRule rule)
 52    {
 23156853        int index = area.Value;
 23156854        if (index < _rules.Length)
 55        {
 23156656            rule = _rules[index];
 23156657            return true;
 58        }
 59
 260        rule = default;
 261        return false;
 62    }
 63
 129064    internal long RetainedBytes => _retainedBytes;
 65
 66    internal bool ContentEquals(NavigationAreaPolicy other)
 67    {
 310168        if (ReferenceEquals(this, other))
 309069            return true;
 1170        if (!Key.Equals(other.Key) || _rules.Length != other._rules.Length)
 271            return false;
 3472        for (int i = 0; i < _rules.Length; i++)
 73        {
 1374            if (!_rules[i].Equals(other._rules[i]))
 575                return false;
 76        }
 477        return true;
 78    }
 79}