< Summary

Information
Class: Chronicis.Client.Utilities.MapLayerVisibilityEvaluator
Assembly: Chronicis.Client
File(s): /home/runner/work/chronicis/chronicis/src/Chronicis.Client/Utilities/MapLayerVisibilityEvaluator.cs
Line coverage
100%
Covered lines: 23
Uncovered lines: 0
Coverable lines: 23
Total lines: 62
Line coverage: 100%
Branch coverage
100%
Covered branches: 18
Total branches: 18
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
GetEffectivelyVisibleLayerIds(...)100%88100%
IsEffectivelyVisible(...)100%1010100%

File(s)

/home/runner/work/chronicis/chronicis/src/Chronicis.Client/Utilities/MapLayerVisibilityEvaluator.cs

#LineLine coverage
 1using Chronicis.Shared.DTOs.Maps;
 2
 3namespace Chronicis.Client.Utilities;
 4
 5internal static class MapLayerVisibilityEvaluator
 6{
 7    public static HashSet<Guid> GetEffectivelyVisibleLayerIds(IReadOnlyCollection<MapLayerDto> layers)
 8    {
 8199        if (layers.Count == 0)
 10        {
 511            return [];
 12        }
 13
 81414        var layersById = new Dictionary<Guid, MapLayerDto>(layers.Count);
 810415        foreach (var layer in layers)
 16        {
 323817            layersById[layer.MapLayerId] = layer;
 18        }
 81419        var visibleLayerIds = new HashSet<Guid>();
 810420        foreach (var layer in layers)
 21        {
 323822            if (IsEffectivelyVisible(layer, layersById))
 23            {
 160724                visibleLayerIds.Add(layer.MapLayerId);
 25            }
 26        }
 27
 81428        return visibleLayerIds;
 29    }
 30
 31    public static bool IsEffectivelyVisible(MapLayerDto layer, IReadOnlyDictionary<Guid, MapLayerDto> layersById)
 32    {
 324333        if (!layer.IsEnabled)
 34        {
 81835            return false;
 36        }
 37
 242538        var visitedLayerIds = new HashSet<Guid> { layer.MapLayerId };
 242539        var currentParentId = layer.ParentLayerId;
 322940        while (currentParentId.HasValue)
 41        {
 162142            if (!layersById.TryGetValue(currentParentId.Value, out var parentLayer))
 43            {
 244                return false;
 45            }
 46
 161947            if (!visitedLayerIds.Add(currentParentId.Value))
 48            {
 149                return false;
 50            }
 51
 161852            if (!parentLayer.IsEnabled)
 53            {
 81454                return false;
 55            }
 56
 80457            currentParentId = parentLayer.ParentLayerId;
 58        }
 59
 160860        return true;
 61    }
 62}