< Summary

Information
Class: SwiftCollections.Query.FixedBoundVolume
Assembly: SwiftCollections.FixedMathSharp
File(s): /home/runner/work/SwiftCollections/SwiftCollections/src/SwiftCollections.FixedMathSharp/Query/Shared/Volume/FixedBoundVolume.cs
Line coverage
100%
Covered lines: 20
Uncovered lines: 0
Coverable lines: 20
Total lines: 154
Line coverage: 100%
Branch coverage
100%
Covered branches: 14
Total branches: 14
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%
get_Max()100%11100%
get_Center()100%11100%
get_Size()100%11100%
get_Volume()100%11100%
Union(...)100%11100%
Intersects(...)100%1010100%
GetCost(...)100%11100%
BoundsEquals(...)100%22100%
Equals(...)100%11100%
Equals(...)100%22100%
op_Equality(...)100%11100%
op_Inequality(...)100%11100%
GetHashCode()100%11100%
ToString()100%11100%

File(s)

/home/runner/work/SwiftCollections/SwiftCollections/src/SwiftCollections.FixedMathSharp/Query/Shared/Volume/FixedBoundVolume.cs

#LineLine coverage
 1//=======================================================================
 2// FixedBoundVolume.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;
 9using System.Runtime.CompilerServices;
 10using FixedMathSharp;
 11using FixedMathSharp.Geometry;
 12
 13namespace SwiftCollections.Query;
 14
 15/// <summary>
 16/// Represents an axis-aligned bounding box (AABB) in 3D space using fixed-point math.
 17/// </summary>
 18/// <remarks>
 19/// Construction normalizes swapped endpoints. Derived center and size semantics
 20/// are inherited from <see cref="FixedBoundBox"/>.
 21/// </remarks>
 22public struct FixedBoundVolume : IBoundVolume<FixedBoundVolume>, IEquatable<FixedBoundVolume>
 23{
 24    private FixedBoundBox _bounds;
 25
 26    /// <summary>
 27    /// Initializes a new instance of the <see cref="FixedBoundVolume"/> struct.
 28    /// </summary>
 29    /// <param name="min">One endpoint of the volume.</param>
 30    /// <param name="max">The opposite endpoint of the volume.</param>
 31    public FixedBoundVolume(Vector3d min, Vector3d max)
 32    {
 14333        _bounds = FixedBoundBox.FromMinMax(min, max);
 14334    }
 35
 36    /// <summary>
 37    /// Gets the minimum point of the bounding volume.
 38    /// </summary>
 89639    public Vector3d Min => _bounds.Min;
 40
 41    /// <summary>
 42    /// Gets the maximum point of the bounding volume.
 43    /// </summary>
 84944    public Vector3d Max => _bounds.Max;
 45
 46    /// <summary>
 47    /// Gets the nearest-even Q32.32 center point of the bounding volume.
 48    /// </summary>
 5749    public Vector3d Center => _bounds.Center;
 50
 51    /// <summary>
 52    /// Gets the exact axis-aligned size of the bounding volume.
 53    /// </summary>
 54    /// <exception cref="OverflowException">
 55    /// A positive component span is outside the representable scalar domain.
 56    /// </exception>
 457    public Vector3d Size => _bounds.Proportions;
 58
 59    /// <summary>
 60    /// Gets the volume of the bounding box.
 61    /// </summary>
 62    /// <exception cref="OverflowException">
 63    /// A positive component span is outside the representable scalar domain.
 64    /// </exception>
 65    public Fixed64 Volume
 66    {
 67        get
 68        {
 169            Vector3d size = Size;
 170            return size.X * size.Y * size.Z;
 71        }
 72    }
 73
 74    /// <summary>
 75    /// Creates a new volume that represents the union of this volume and the specified volume.
 76    /// </summary>
 77    /// <remarks>
 78    /// The resulting volume is the smallest axis-aligned bounding box that fully contains both input volumes.
 79    /// </remarks>
 80    /// <param name="other">
 81    /// The volume to combine with this volume.
 82    /// The resulting volume will encompass both this volume and the specified volume.
 83    /// </param>
 84    /// <returns>A new FixedBoundVolume that contains both this volume and the specified volume.</returns>
 85    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 86    public FixedBoundVolume Union(FixedBoundVolume other)
 87    {
 788        return new FixedBoundVolume(Vector3d.Min(Min, other.Min), Vector3d.Max(Max, other.Max));
 89    }
 90
 91    /// <summary>
 92    /// Determines whether this volume intersects with the specified volume.
 93    /// </summary>
 94    /// <param name="other">The volume to test for intersection with this volume.</param>
 95    /// <returns>true if the volumes intersect; otherwise, false.</returns>
 96    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 97    public bool Intersects(FixedBoundVolume other)
 98    {
 12499        return !(Min.X > other.Max.X || Max.X < other.Min.X ||
 124100                 Min.Y > other.Max.Y || Max.Y < other.Min.Y ||
 124101                 Min.Z > other.Max.Z || Max.Z < other.Min.Z);
 102    }
 103
 104    /// <summary>
 105    /// Calculates the additional volume required to expand the current volume to fully contain the specified volume.
 106    /// </summary>
 107    /// <param name="other">The volume to be encompassed by the current volume.</param>
 108    /// <returns>
 109    /// The floored additional volume needed to contain the specified volume,
 110    /// clamped to <see cref="long.MaxValue"/>. Returns 0 when the current volume
 111    /// already contains the specified volume.
 112    /// </returns>
 113    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 114    public long GetCost(FixedBoundVolume other)
 115    {
 4116        return _bounds.GetVolumeExpansionCost(other._bounds);
 117    }
 118
 119    /// <summary>
 120    /// Determines whether the bounds of this volume are equal to those of the specified volume.
 121    /// </summary>
 122    /// <param name="other">A <see cref="FixedBoundVolume"/> to compare with the current volume.</param>
 123    /// <returns>true if both the minimum and maximum bounds of the volumes are equal; otherwise, false.</returns>
 124    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 125    public bool BoundsEquals(FixedBoundVolume other)
 126    {
 8127        return Min == other.Min && Max == other.Max;
 128    }
 129
 130    /// <inheritdoc/>
 4131    public bool Equals(FixedBoundVolume other) => BoundsEquals(other);
 132
 133    /// <inheritdoc/>
 2134    public override bool Equals(object obj) => obj is FixedBoundVolume other && BoundsEquals(other);
 135
 136    /// <summary>
 137    /// Determines whether two BoundVolume instances are equal.
 138    /// </summary>
 4139    public static bool operator ==(FixedBoundVolume left, FixedBoundVolume right) => left.Equals(right);
 140
 141    /// <summary>
 142    /// Determines whether two BoundVolume instances are not equal.
 143    /// </summary>
 2144    public static bool operator !=(FixedBoundVolume left, FixedBoundVolume right) => !(left == right);
 145
 146    /// <inheritdoc/>
 2147    public override int GetHashCode() => HashCode.Combine(Min, Max);
 148
 149    /// <summary>
 150    /// Returns a string that represents the current object, including the minimum and maximum values.
 151    /// </summary>
 152    /// <returns>A string in the format "Min: {Min}, Max: {Max}" that displays the minimum and maximum values of the obj
 1153    public override string ToString() => $"Min: {Min}, Max: {Max}";
 154}