< Summary

Information
Class: SwiftCollections.Query.FixedBoundVolume
Assembly: SwiftCollections
File(s): /home/runner/work/SwiftCollections/SwiftCollections/src/SwiftCollections/Query/BoundingVolume/Volume/FixedBoundVolume.cs
Line coverage
86%
Covered lines: 52
Uncovered lines: 8
Coverable lines: 60
Total lines: 158
Line coverage: 86.6%
Branch coverage
100%
Covered branches: 28
Total branches: 28
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%
get_Min()100%11100%
set_Min(...)100%210%
get_Max()100%11100%
set_Max(...)100%210%
get_Center()100%22100%
get_Size()100%22100%
get_Volume()100%22100%
RecalculateMeta()100%11100%
Union(...)100%44100%
Union(...)100%11100%
Intersects(...)100%1414100%
GetCost(...)100%44100%
ToString()100%11100%

File(s)

/home/runner/work/SwiftCollections/SwiftCollections/src/SwiftCollections/Query/BoundingVolume/Volume/FixedBoundVolume.cs

#LineLine coverage
 1using FixedMathSharp;
 2using System;
 3using System.Runtime.CompilerServices;
 4
 5namespace SwiftCollections.Query
 6{
 7    /// <summary>
 8    /// Represents an axis-aligned bounding box (AABB) in 3D space using Fixed-Point Math.
 9    /// </summary>
 10    public struct FixedBoundVolume : IBoundVolume
 11    {
 12        /// <summary>
 13        /// The minimum point of the bounding volume.
 14        /// </summary>
 15        private Vector3d _min;
 16
 17        /// <summary>
 18        /// The maximum point of the bounding volume.
 19        /// </summary>
 20        private Vector3d _max;
 21
 22        /// <summary>
 23        /// The center of the bounding volume as the midpoint of the minimum and maximum points.
 24        /// </summary>
 25        private Vector3d _center;
 26
 27        /// <summary>
 28        /// The size of the bounding volume as the difference between the maximum and minimum points.
 29        /// </summary>
 30        private Vector3d _size;
 31
 32        /// <summary>
 33        /// The volume of the bounding box, calculated as the product of its dimensions.
 34        /// </summary>
 35        private Fixed64 _volume;
 36
 37        /// <summary>
 38        /// Marks the bounding volume as dirty, indicating its properties need recalculation.
 39        /// </summary>
 40        private bool _isDirty;
 41
 42        public FixedBoundVolume(Vector3d min, Vector3d max)
 36591943        {
 36591944            _min = min;
 36591945            _max = max;
 46
 36591947            _isDirty = true;
 36591948            _center = default;
 36591949            _size = default;
 36591950            _volume = default;
 36591951        }
 52
 53        /// <inheritdoc cref="_min"/>
 54        public Vector3d Min
 55        {
 83319156            get => _min;
 57            private set
 058            {
 059                _isDirty = true;
 060                _min = value;
 061            }
 62        }
 63
 64        /// <inheritdoc cref="_max"/>
 65        public Vector3d Max
 66        {
 83319167            get => _max;
 68            private set
 069            {
 070                _isDirty = true;
 071                _max = value;
 072            }
 73        }
 74
 75        /// <inheritdoc cref="_center"/>
 76        public Vector3d Center
 77        {
 78            get
 479            {
 480                if (_isDirty)
 181                    RecalculateMeta();
 482                return _center;
 483            }
 84        }
 85
 86        /// <inheritdoc cref="_size"/>
 87        public Vector3d Size
 88        {
 89            get
 290            {
 291                if (_isDirty)
 192                    RecalculateMeta();
 293                return _size;
 294            }
 95        }
 96
 97        /// <inheritdoc cref="_volume"/>
 98        public Fixed64 Volume
 99        {
 100            get
 350405101            {
 350405102                if (_isDirty)
 350404103                    RecalculateMeta();
 350405104                return _volume;
 350405105            }
 106        }
 107
 108        /// <summary>
 109        /// Forces recalculation of the bounding volume's metadata, such as center, size, and volume.
 110        /// </summary>
 111        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 112        private void RecalculateMeta()
 350406113        {
 350406114            _center = (_min + _max) * Fixed64.Half;
 350406115            _size = _max - _min;
 350406116            _volume = _size.x * _size.y * _size.z;
 350406117            _isDirty = false;
 350406118        }
 119
 120        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 121        public IBoundVolume Union(IBoundVolume other)
 175314122        {
 175314123            if (other is not FixedBoundVolume otherBV)
 1124                throw new ArgumentException($"Mismatched bounding volume type detected!: {nameof(other)}");
 125
 175313126            return Union(otherBV);
 175313127        }
 128
 129        /// <inheritdoc cref="Union(IBoundVolume)"/>
 130        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 131        public FixedBoundVolume Union(FixedBoundVolume other)
 350516132        {
 350516133            return new FixedBoundVolume(Vector3d.Min(Min, other.Min), Vector3d.Max(Max, other.Max));
 350516134        }
 135
 136        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 137        public bool Intersects(IBoundVolume other)
 22281138        {
 22281139            if (other is not FixedBoundVolume otherBV)
 1140                throw new ArgumentException($"Mismatched bounding volume type detected!: {nameof(other)}");
 141
 22280142            return !(Min.x > otherBV.Max.x || Max.x < otherBV.Min.x ||
 22280143                     Min.y > otherBV.Max.y || Max.y < otherBV.Min.y ||
 22280144                     Min.z > otherBV.Max.z || Max.z < otherBV.Min.z);
 22280145        }
 146
 147        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 148        public int GetCost(IBoundVolume other)
 175203149        {
 175203150            if (other is not FixedBoundVolume otherBV)
 1151                throw new ArgumentException($"Mismatched bounding volume type detected!: {nameof(other)}");
 152
 175202153            return (Union(otherBV).Volume - otherBV.Volume).FloorToInt();
 175202154        }
 155
 1156        public override string ToString() => $"Min: {Min}, Max: {Max}";
 157    }
 158}