< Summary

Information
Class: SwiftCollections.Query.SwiftSpatialHash<T>
Assembly: SwiftCollections
File(s): /home/runner/work/SwiftCollections/SwiftCollections/src/SwiftCollections/Query/SpatialHash/SwiftSpatialHash.BoundVolume.cs
Line coverage
94%
Covered lines: 18
Uncovered lines: 1
Coverable lines: 19
Total lines: 57
Line coverage: 94.7%
Branch coverage
50%
Covered branches: 3
Total branches: 6
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
.ctor(...)100%11100%
.ctor(...)50%6680%
GetCellRange(...)100%11100%
ToCell(...)100%11100%

File(s)

/home/runner/work/SwiftCollections/SwiftCollections/src/SwiftCollections/Query/SpatialHash/SwiftSpatialHash.BoundVolume.cs

#LineLine coverage
 1using System;
 2
 3namespace SwiftCollections.Query;
 4
 5/// <summary>
 6/// Represents a numerics-backed spatial hash optimized for high-churn broad-phase spatial queries.
 7/// </summary>
 8public class SwiftSpatialHash<TKey> : SwiftSpatialHash<TKey, BoundVolume>
 9    where TKey : notnull
 10{
 11    /// <summary>
 12    /// Initializes a new instance of the <see cref="SwiftSpatialHash{TKey}"/> class with the specified capacity and cel
 13    /// </summary>
 14    public SwiftSpatialHash(int capacity, float cellSize)
 115        : this(capacity, cellSize, SwiftSpatialHashOptions.Default)
 16    {
 117    }
 18
 19    /// <summary>
 20    /// Initializes a new instance of the <see cref="SwiftSpatialHash{TKey}"/> class with the specified capacity, cell s
 21    /// </summary>
 22    public SwiftSpatialHash(int capacity, float cellSize, SwiftSpatialHashOptions options)
 223        : base(capacity, new BoundVolumeCellMapper(cellSize), options)
 24    {
 225    }
 26
 27    private sealed class BoundVolumeCellMapper : ISpatialHashCellMapper<BoundVolume>
 28    {
 29        private readonly float _cellSize;
 30
 231        public BoundVolumeCellMapper(float cellSize)
 32        {
 233            if (float.IsNaN(cellSize) || float.IsInfinity(cellSize) || cellSize <= 0f)
 034                throw new ArgumentOutOfRangeException(nameof(cellSize), cellSize, "Cell size must be a finite positive v
 35
 236            _cellSize = cellSize;
 237        }
 38
 39        public void GetCellRange(BoundVolume bounds, out SwiftSpatialHashCellIndex minCell, out SwiftSpatialHashCellInde
 40        {
 541            minCell = new SwiftSpatialHashCellIndex(
 542                ToCell(bounds.Min.X),
 543                ToCell(bounds.Min.Y),
 544                ToCell(bounds.Min.Z));
 45
 546            maxCell = new SwiftSpatialHashCellIndex(
 547                ToCell(bounds.Max.X),
 548                ToCell(bounds.Max.Y),
 549                ToCell(bounds.Max.Z));
 550        }
 51
 52        private int ToCell(float value)
 53        {
 3054            return (int)MathF.Floor(value / _cellSize);
 55        }
 56    }
 57}