< 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
100%
Covered lines: 19
Uncovered lines: 0
Coverable lines: 19
Total lines: 64
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
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%11100%
.ctor(...)100%11100%
.ctor(...)100%66100%
GetCellRange(...)100%11100%
ToCell(...)100%11100%

File(s)

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

#LineLine coverage
 1//=======================================================================
 2// SwiftSpatialHash.BoundVolume.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;
 9
 10namespace SwiftCollections.Query;
 11
 12/// <summary>
 13/// Represents a numerics-backed spatial hash optimized for high-churn broad-phase spatial queries.
 14/// </summary>
 15public class SwiftSpatialHash<TKey> : SwiftSpatialHash<TKey, BoundVolume>
 16    where TKey : notnull
 17{
 18    /// <summary>
 19    /// Initializes a new instance of the <see cref="SwiftSpatialHash{TKey}"/> class with the specified capacity and cel
 20    /// </summary>
 21    public SwiftSpatialHash(int capacity, float cellSize)
 522        : this(capacity, cellSize, SwiftSpatialHashOptions.Default)
 23    {
 124    }
 25
 26    /// <summary>
 27    /// Initializes a new instance of the <see cref="SwiftSpatialHash{TKey}"/> class with the specified capacity, cell s
 28    /// </summary>
 29    public SwiftSpatialHash(int capacity, float cellSize, SwiftSpatialHashOptions options)
 630        : base(capacity, new BoundVolumeCellMapper(cellSize), options)
 31    {
 232    }
 33
 34    private sealed class BoundVolumeCellMapper : ISpatialHashCellMapper<BoundVolume>
 35    {
 36        private readonly float _cellSize;
 37
 638        public BoundVolumeCellMapper(float cellSize)
 39        {
 640            if (float.IsNaN(cellSize) || float.IsInfinity(cellSize) || cellSize <= 0f)
 441                throw new ArgumentOutOfRangeException(nameof(cellSize), cellSize, "Cell size must be a finite positive v
 42
 243            _cellSize = cellSize;
 244        }
 45
 46        public void GetCellRange(BoundVolume bounds, out SwiftSpatialHashCellIndex minCell, out SwiftSpatialHashCellInde
 47        {
 548            minCell = new SwiftSpatialHashCellIndex(
 549                ToCell(bounds.Min.X),
 550                ToCell(bounds.Min.Y),
 551                ToCell(bounds.Min.Z));
 52
 553            maxCell = new SwiftSpatialHashCellIndex(
 554                ToCell(bounds.Max.X),
 555                ToCell(bounds.Max.Y),
 556                ToCell(bounds.Max.Z));
 557        }
 58
 59        private int ToCell(float value)
 60        {
 3061            return (int)MathF.Floor(value / _cellSize);
 62        }
 63    }
 64}