< Summary

Information
Class: SwiftCollections.Query.SwiftFixedSpatialHash<T>
Assembly: SwiftCollections.FixedMathSharp
File(s): /home/runner/work/SwiftCollections/SwiftCollections/src/SwiftCollections.FixedMathSharp/Query/SpatialHash/SwiftFixedSpatialHash.cs
Line coverage
100%
Covered lines: 17
Uncovered lines: 0
Coverable lines: 17
Total lines: 60
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
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%22100%
GetCellRange(...)100%11100%
ToCell(...)100%11100%

File(s)

/home/runner/work/SwiftCollections/SwiftCollections/src/SwiftCollections.FixedMathSharp/Query/SpatialHash/SwiftFixedSpatialHash.cs

#LineLine coverage
 1//=======================================================================
 2// SwiftFixedSpatialHash.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 System;
 10
 11namespace SwiftCollections.Query;
 12
 13/// <summary>
 14/// Represents a fixed-point spatial hash optimized for deterministic broad-phase spatial queries.
 15/// </summary>
 16public class SwiftFixedSpatialHash<T> : SwiftSpatialHash<T, FixedBoundVolume>
 17{
 18    /// <summary>
 19    /// Initializes a new instance of the <see cref="SwiftFixedSpatialHash{T}"/> class with the specified capacity and c
 20    /// </summary>
 21    public SwiftFixedSpatialHash(int capacity, Fixed64 cellSize)
 622        : this(capacity, cellSize, SwiftSpatialHashOptions.Default) { }
 23
 24    /// <summary>
 25    /// Initializes a new instance of the <see cref="SwiftFixedSpatialHash{T}"/> class with the specified capacity, cell
 26    /// </summary>
 27    public SwiftFixedSpatialHash(int capacity, Fixed64 cellSize, SwiftSpatialHashOptions options)
 628        : base(capacity, new FixedBoundVolumeCellMapper(cellSize), options) { }
 29
 30    private sealed class FixedBoundVolumeCellMapper : ISpatialHashCellMapper<FixedBoundVolume>
 31    {
 32        private readonly Fixed64 _cellSize;
 33
 434        public FixedBoundVolumeCellMapper(Fixed64 cellSize)
 35        {
 436            if (cellSize <= Fixed64.Zero)
 237                throw new ArgumentOutOfRangeException(nameof(cellSize), cellSize, "Cell size must be greater than zero."
 38
 239            _cellSize = cellSize;
 240        }
 41
 42        public void GetCellRange(FixedBoundVolume bounds, out SwiftSpatialHashCellIndex minCell, out SwiftSpatialHashCel
 43        {
 444            minCell = new SwiftSpatialHashCellIndex(
 445                ToCell(bounds.Min.X),
 446                ToCell(bounds.Min.Y),
 447                ToCell(bounds.Min.Z));
 48
 449            maxCell = new SwiftSpatialHashCellIndex(
 450                ToCell(bounds.Max.X),
 451                ToCell(bounds.Max.Y),
 452                ToCell(bounds.Max.Z));
 453        }
 54
 55        private int ToCell(Fixed64 value)
 56        {
 2457            return (value / _cellSize).FloorToInt();
 58        }
 59    }
 60}