< Summary

Information
Class: Trailblazer.Navigation.NavigatorOccupancyTracker
Assembly: Trailblazer
File(s): /home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Navigation/Navigator/Occupancy/NavigatorOccupancyTracker.cs
Line coverage
100%
Covered lines: 52
Uncovered lines: 0
Coverable lines: 52
Total lines: 111
Line coverage: 100%
Branch coverage
100%
Covered branches: 34
Total branches: 34
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Update(...)100%1414100%
UpdateAfterRootProjection(...)100%1212100%
TryResolveVoxel(...)100%88100%

File(s)

/home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Navigation/Navigator/Occupancy/NavigatorOccupancyTracker.cs

#LineLine coverage
 1//=======================================================================
 2// NavigatorOccupancyTracker.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 FixedMathSharp;
 9using GridForge.Configuration;
 10using GridForge.Grids;
 11using GridForge.Grids.Topology;
 12
 13namespace Trailblazer.Navigation;
 14
 15internal static class NavigatorOccupancyTracker
 16{
 17    public static void Update(
 18        GridWorld world,
 19        Navigator navigator,
 20        Vector3d position,
 21        Vector3d lastPosition,
 22        bool init)
 23    {
 31524        if (!init && position == lastPosition)
 2425            return;
 26
 29127        bool voxelFound = TryResolveVoxel(
 29128            world,
 29129            position,
 29130            out VoxelGrid? curGrid,
 29131            out Voxel? curVoxel);
 29132        if (!voxelFound)
 533            return;
 34
 28635        if (curGrid!.TryAddVoxelOccupant(curVoxel!, navigator) == false)
 36        {
 3137            TrailblazerLogger.Channel.Warn($"Navigator {navigator.GlobalId} failed to register occupancy in voxel {curVo
 3138            return;
 39        }
 40
 25541        bool lastVoxelFound = TryResolveVoxel(
 25542            world,
 25543            lastPosition,
 25544            out VoxelGrid? lastGrid,
 25545            out Voxel? lastVoxel);
 46
 25547        if (!lastVoxelFound || curVoxel == lastVoxel)
 25348            return;
 49
 250        lastGrid!.TryRemoveVoxelOccupant(lastVoxel!, navigator);
 251    }
 52
 53    public static void UpdateAfterRootProjection(
 54        GridWorld world,
 55        Navigator navigator,
 56        Vector3d oldPosition,
 57        Vector3d newPosition)
 58    {
 859        bool oldVoxelFound = TryResolveVoxel(
 860            world,
 861            oldPosition,
 862            out VoxelGrid? oldGrid,
 863            out Voxel? oldVoxel);
 864        bool newVoxelFound = TryResolveVoxel(
 865            world,
 866            newPosition,
 867            out VoxelGrid? newGrid,
 868            out Voxel? newVoxel);
 69
 870        if (oldVoxelFound && newVoxelFound && oldVoxel == newVoxel)
 171            return;
 72
 773        if (oldVoxelFound)
 674            oldGrid!.TryRemoveVoxelOccupant(oldVoxel!, navigator);
 75
 776        if (newVoxelFound && newGrid!.TryAddVoxelOccupant(newVoxel!, navigator) == false)
 277            TrailblazerLogger.Channel.Warn($"Navigator {navigator.GlobalId} failed to register occupancy in voxel {newVo
 778    }
 79
 80    internal static bool TryResolveVoxel(
 81        GridWorld world,
 82        Vector3d position,
 83        out VoxelGrid? grid,
 84        out Voxel? voxel)
 85    {
 63186        voxel = null;
 63187        if (world.TryGetGrid(position, out grid))
 88        {
 59089            if (!grid!.TryGetClosestVoxel(position, out voxel))
 90            {
 191                grid = null;
 192                return false;
 93            }
 94        }
 4195        else if (!world.TryGetClosestGridAndVoxel(position, out grid, out voxel))
 96        {
 197            return false;
 98        }
 99
 629100        grid!.Configuration.TryNormalize(out NormalizedGridConfiguration binding);
 629101        binding.TryGetCellPrism(voxel!.Index, out GridCellPrism prism);
 629102        if (!prism.Contains(position))
 103        {
 11104            grid = null;
 11105            voxel = null;
 11106            return false;
 107        }
 108
 618109        return true;
 110    }
 111}