Table of Contents

Struct FixedBoundBox

Namespace
FixedMathSharp.Geometry
Assembly
FixedMathSharp.dll

Represents a normalized three-dimensional axis-aligned bounding box.

[MemoryPackable(GenerateType.Object)]
public struct FixedBoundBox : IEquatable<FixedBoundBox>, IMemoryPackable<FixedBoundBox>, IMemoryPackFormatterRegister
Implements
IMemoryPackable<FixedBoundBox>
IMemoryPackFormatterRegister
Inherited Members

Remarks

Constructors

FixedBoundBox(BoundingBoxState)

Initializes a new instance of the FixedBoundBox class with the specified bounding box state.

[JsonConstructor]
public FixedBoundBox(FixedBoundBox.BoundingBoxState state)

Parameters

state FixedBoundBox.BoundingBoxState

The state that defines the position, size, and orientation of the bounding box.

Fields

CornerCount

The number of stable corners exposed by GetCorner(int) and CopyCorners(Span<Vector3d>).

public const int CornerCount = 8

Field Value

int

Properties

Center

The center of the bounding box, rounded to the nearest-even Q32.32 lattice point.

[JsonIgnore]
[MemoryPackIgnore]
public Vector3d Center { get; set; }

Property Value

Vector3d

Remarks

Assigning a different center preserves a conservative half-extent. An odd raw-unit span can therefore expand by one raw unit so the assigned center remains exact and the previous box is not under-represented.

Exceptions

OverflowException

An assigned center would place an endpoint outside the scalar domain.

Max

The maximum corner of the bounding box.

[JsonIgnore]
[MemoryPackIgnore]
public readonly Vector3d Max { get; }

Property Value

Vector3d

Min

The minimum corner of the bounding box.

[JsonIgnore]
[MemoryPackIgnore]
public readonly Vector3d Min { get; }

Property Value

Vector3d

Proportions

The exact total size of the box.

[JsonIgnore]
[MemoryPackIgnore]
public Vector3d Proportions { get; set; }

Property Value

Vector3d

Remarks

Assigned values are normalized by absolute component value and divided outward. An odd raw-unit size therefore expands by one raw unit. Reading this property throws rather than returning a saturated value when an exact component span is not representable by Fixed64.

Exceptions

OverflowException

A component span is not representable, or an assigned size would place an endpoint outside the scalar domain.

Scope

The smallest representable half-extent that conservatively contains the box around Center.

[JsonIgnore]
[MemoryPackIgnore]
public Vector3d Scope { get; }

Property Value

Vector3d

Exceptions

OverflowException

A conservative half-extent is outside the representable scalar domain.

State

Gets or sets the current normalized bounding box state, including its minimum and maximum coordinates.

[JsonInclude]
[MemoryPackInclude]
public FixedBoundBox.BoundingBoxState State { get; }

Property Value

FixedBoundBox.BoundingBoxState

Methods

ClampPoint(Vector3d)

Clamps a point to this bounding box, returning the point unchanged when it is already inside.

public Vector3d ClampPoint(Vector3d point)

Parameters

point Vector3d

Returns

Vector3d

ClosestPointOnSurface(Vector3d)

Finds the closest point on the surface of the bounding box to the specified point.

public Vector3d ClosestPointOnSurface(Vector3d point)

Parameters

point Vector3d

Returns

Vector3d

Contains(FixedBoundBox)

Tests another bounding box against this bounding box.

public FixedEnclosureType Contains(FixedBoundBox box)

Parameters

box FixedBoundBox

Returns

FixedEnclosureType

Contains(FixedBoundFrustum)

Tests a bounding frustum against this bounding box.

public FixedEnclosureType Contains(FixedBoundFrustum frustum)

Parameters

frustum FixedBoundFrustum

Returns

FixedEnclosureType

Contains(FixedBoundSphere)

Tests a bounding sphere against this bounding box.

public FixedEnclosureType Contains(FixedBoundSphere sphere)

Parameters

sphere FixedBoundSphere

Returns

FixedEnclosureType

Contains(Vector3d)

Determines if a point is inside the bounding box (including boundaries).

public bool Contains(Vector3d point)

Parameters

point Vector3d

Returns

bool

CopyCorners(Span<Vector3d>)

Copies this box's corners into the destination span in GetCorner(int) order.

public void CopyCorners(Span<Vector3d> destination)

Parameters

destination Span<Vector3d>

DistanceToSurface(Vector3d)

Calculates the shortest distance from a given point to the surface of the bounding box. If the point lies inside the box, the distance is zero.

public Fixed64 DistanceToSurface(Vector3d point)

Parameters

point Vector3d

The point from which to calculate the distance.

Returns

Fixed64

The shortest distance from the point to the surface of the bounding box. If the point is inside the box, the method returns zero.

Remarks

The method finds the closest point on the box's surface by clamping the given point to the box's bounds and returns the Euclidean distance between them. This ensures accurate distance calculations, even near corners or edges.

Equals(FixedBoundBox)

public bool Equals(FixedBoundBox other)

Parameters

other FixedBoundBox

Returns

bool

Equals(object?)

public override bool Equals(object? obj)

Parameters

obj object

Returns

bool

FindClosestPointsBetweenBoxes(FixedBoundBox, FixedBoundBox)

Finds the closest points between two bounding boxes.

public static Vector3d FindClosestPointsBetweenBoxes(FixedBoundBox a, FixedBoundBox b)

Parameters

a FixedBoundBox
b FixedBoundBox

Returns

Vector3d

FromCenterAndScope(Vector3d, Vector3d)

Creates a bounding box from a center point and half-size scope.

public static FixedBoundBox FromCenterAndScope(Vector3d center, Vector3d scope)

Parameters

center Vector3d
scope Vector3d

Returns

FixedBoundBox

Remarks

Negative scope components are normalized by absolute value.

Exceptions

OverflowException

A scope magnitude is not representable, or the centered box would place an endpoint outside the scalar domain.

FromCenterAndScopeClippedToDomain(Vector3d, Vector3d)

Creates the representable-domain intersection of a box described by a center point and half-size scope.

public static FixedBoundBox FromCenterAndScopeClippedToDomain(Vector3d center, Vector3d scope)

Parameters

center Vector3d
scope Vector3d

Returns

FixedBoundBox

Remarks

Negative scope components are normalized by absolute value. Endpoints outside the scalar domain are explicitly clipped to MinValue or MaxValue.

Exceptions

OverflowException

A scope magnitude is not representable.

FromCenterAndSize(Vector3d, Vector3d)

Creates a bounding box from a center point and total size.

public static FixedBoundBox FromCenterAndSize(Vector3d center, Vector3d size)

Parameters

center Vector3d
size Vector3d

Returns

FixedBoundBox

Remarks

Negative size components are normalized by absolute value. Odd raw-unit sizes are divided outward and therefore expand by one raw unit.

Exceptions

OverflowException

The centered box would place an endpoint outside the scalar domain.

FromCenterAndSizeClippedToDomain(Vector3d, Vector3d)

Creates the representable-domain intersection of a box described by a center point and total size.

public static FixedBoundBox FromCenterAndSizeClippedToDomain(Vector3d center, Vector3d size)

Parameters

center Vector3d
size Vector3d

Returns

FixedBoundBox

Remarks

Negative size components are normalized by absolute value and odd raw- unit sizes divide outward. Endpoints outside the scalar domain are explicitly clipped to MinValue or MaxValue.

FromCenteredCapsuleClippedToDomain(Vector3d, FixedQuaternion, Vector3d, Fixed64, Fixed64)

Creates the representable-domain intersection of a centered capsule's tight axis-aligned bounds without materializing its rotated axis.

public static FixedBoundBox FromCenteredCapsuleClippedToDomain(Vector3d center, FixedQuaternion rotation, Vector3d localAxisDirection, Fixed64 axisLength, Fixed64 radius)

Parameters

center Vector3d
rotation FixedQuaternion
localAxisDirection Vector3d
axisLength Fixed64
radius Fixed64

Returns

FixedBoundBox

FromCenteredCapsuleClippedToDomain(Vector3d, Vector3d, Fixed64, Fixed64)

Creates the representable-domain intersection of a centered capsule's tight axis-aligned bounds from its full center-axis length.

public static FixedBoundBox FromCenteredCapsuleClippedToDomain(Vector3d center, Vector3d axisDirection, Fixed64 axisLength, Fixed64 radius)

Parameters

center Vector3d
axisDirection Vector3d
axisLength Fixed64
radius Fixed64

Returns

FixedBoundBox

FromCenteredFiniteConeClippedToDomain(Vector3d, FixedQuaternion, Vector3d, Fixed64, Fixed64)

Creates the representable-domain intersection of a centered finite cone's axis-aligned bounds without materializing its rotated axis.

public static FixedBoundBox FromCenteredFiniteConeClippedToDomain(Vector3d center, FixedQuaternion rotation, Vector3d localAxisDirection, Fixed64 height, Fixed64 radius)

Parameters

center Vector3d

The midpoint between the base center and apex.

rotation FixedQuaternion

The cone rigid-frame rotation.

localAxisDirection Vector3d

The normalized local direction from the base center toward the apex.

height Fixed64

The positive full base-to-apex height.

radius Fixed64

The nonnegative base radius.

Returns

FixedBoundBox

FromCenteredFiniteConeClippedToDomain(Vector3d, Vector3d, Fixed64, Fixed64)

Creates the representable-domain intersection of a centered finite cone's tight axis-aligned bounds from its full height.

public static FixedBoundBox FromCenteredFiniteConeClippedToDomain(Vector3d center, Vector3d axisDirection, Fixed64 height, Fixed64 radius)

Parameters

center Vector3d

The midpoint between the base center and apex.

axisDirection Vector3d

The normalized direction from the base center toward the apex.

height Fixed64

The positive full base-to-apex height.

radius Fixed64

The nonnegative base radius.

Returns

FixedBoundBox

FromCenteredFiniteCylinderClippedToDomain(Vector3d, FixedQuaternion, Vector3d, Fixed64, Fixed64)

Creates the representable-domain intersection of a centered finite cylinder's tight axis-aligned bounds without materializing its rotated axis.

public static FixedBoundBox FromCenteredFiniteCylinderClippedToDomain(Vector3d center, FixedQuaternion rotation, Vector3d localAxisDirection, Fixed64 axisLength, Fixed64 radius)

Parameters

center Vector3d
rotation FixedQuaternion
localAxisDirection Vector3d
axisLength Fixed64
radius Fixed64

Returns

FixedBoundBox

FromCenteredFiniteCylinderClippedToDomain(Vector3d, Vector3d, Fixed64, Fixed64)

Creates the representable-domain intersection of a centered finite cylinder's tight axis-aligned bounds from its full axis length.

public static FixedBoundBox FromCenteredFiniteCylinderClippedToDomain(Vector3d center, Vector3d axisDirection, Fixed64 axisLength, Fixed64 radius)

Parameters

center Vector3d
axisDirection Vector3d
axisLength Fixed64
radius Fixed64

Returns

FixedBoundBox

FromFiniteConeClippedToDomain(Vector3d, Vector3d, Vector3d, Fixed64)

Creates the representable-domain intersection of the tight axis-aligned bounds of a finite cone with a flat circular base.

public static FixedBoundBox FromFiniteConeClippedToDomain(Vector3d apex, Vector3d baseCenter, Vector3d axisDirection, Fixed64 baseRadius)

Parameters

apex Vector3d

The cone apex.

baseCenter Vector3d

The center of the cone's flat base.

axisDirection Vector3d

The normalized direction from apex to base.

baseRadius Fixed64

The nonnegative base radius.

Returns

FixedBoundBox

Remarks

Base-disk extents account for the exact squared length of a representably normalized axis. They are rounded outward so broad-phase bounds cannot omit a boundary point. Coordinates beyond the scalar domain are clipped.

Exceptions

ArgumentException

axisDirection is zero or not normalized.

ArgumentOutOfRangeException

baseRadius is negative.

FromMinMax(Vector3d, Vector3d)

Creates a normalized bounding box from minimum and maximum corners.

public static FixedBoundBox FromMinMax(Vector3d min, Vector3d max)

Parameters

min Vector3d
max Vector3d

Returns

FixedBoundBox

FromRelativeRotatedBoundsClippedToDomain(Vector3d, FixedQuaternion, Vector3d, Vector3d, Vector3d, FixedQuaternion)

Creates conservative target-frame bounds for a rotated source-frame box, clipping only final target-frame endpoints to the scalar domain.

public static FixedBoundBox FromRelativeRotatedBoundsClippedToDomain(Vector3d sourceOrigin, FixedQuaternion sourceRotation, Vector3d sourceLocalMin, Vector3d sourceLocalMax, Vector3d targetOrigin, FixedQuaternion targetRotation)

Parameters

sourceOrigin Vector3d
sourceRotation FixedQuaternion
sourceLocalMin Vector3d
sourceLocalMax Vector3d
targetOrigin Vector3d
targetRotation FixedQuaternion

Returns

FixedBoundBox

Remarks

Conceptually transforms every source local point as targetRotation^-1 * (sourceOrigin + sourceRotation * point - targetOrigin). Source endpoints are normalized component-wise before the exact projection. Intermediate world points are never materialized.

GetCorner(int)

Gets a stable corner without allocating.

public Vector3d GetCorner(int index)

Parameters

index int

Returns

Vector3d

Remarks

Corner order is: min/min/min, max/min/min, min/max/min, max/max/min, min/min/max, max/min/max, min/max/max, max/max/max.

GetHashCode()

public override int GetHashCode()

Returns

int

GetPointOnSurfaceTowardsObject(Vector3d)

Finds the closest point on the surface of the bounding box towards a specified object position.

public Vector3d GetPointOnSurfaceTowardsObject(Vector3d objectPosition)

Parameters

objectPosition Vector3d

Returns

Vector3d

GetVolumeExpansionCost(FixedBoundBox)

Gets the exact additional volume required for this box's union with other, floored to integer world units and clamped to MaxValue.

public long GetVolumeExpansionCost(FixedBoundBox other)

Parameters

other FixedBoundBox

Returns

long

Remarks

The three endpoint spans and both volumes remain in exact unsigned 192-bit arithmetic. This metric is suitable for spatial-index insertion heuristics even when either box has an unrepresentable Proportions component.

Intersects(FixedBoundBox)

Checks whether another bounding box intersects this bounding box, including boundary-only contact.

public bool Intersects(FixedBoundBox box)

Parameters

box FixedBoundBox

Returns

bool

Intersects(FixedBoundFrustum)

Checks whether a bounding frustum intersects this bounding box.

public bool Intersects(FixedBoundFrustum frustum)

Parameters

frustum FixedBoundFrustum

Returns

bool

Intersects(FixedBoundSphere)

Checks whether a bounding sphere intersects this bounding box, including boundary-only contact.

public bool Intersects(FixedBoundSphere sphere)

Parameters

sphere FixedBoundSphere

Returns

bool

IntersectsStrict(FixedBoundBox)

Checks whether another bounding box overlaps this bounding box with positive volume on every axis.

public bool IntersectsStrict(FixedBoundBox box)

Parameters

box FixedBoundBox

Returns

bool

IntersectsStrict(FixedBoundSphere)

Checks whether a bounding sphere overlaps this bounding box with positive volume.

public bool IntersectsStrict(FixedBoundSphere sphere)

Parameters

sphere FixedBoundSphere

Returns

bool

Orient(Vector3d, Vector3d?)

Orients the bounding box with the given center and size.

public void Orient(Vector3d center, Vector3d? size)

Parameters

center Vector3d
size Vector3d?

Exceptions

OverflowException

The requested bounds would place an endpoint outside the scalar domain.

ProjectPoint(Vector3d)

Projects a point into the bounding box by clamping it to the box extents.

public Vector3d ProjectPoint(Vector3d point)

Parameters

point Vector3d

Returns

Vector3d

Resize(Vector3d)

Resizes the bounding box to the specified size, keeping the same center.

public void Resize(Vector3d size)

Parameters

size Vector3d

Exceptions

OverflowException

The requested size would place an endpoint outside the scalar domain.

SetBoundingBox(Vector3d, Vector3d)

Configures the bounding box with the specified center and scope (half-size).

public void SetBoundingBox(Vector3d center, Vector3d scope)

Parameters

center Vector3d
scope Vector3d

Remarks

Negative scope components are normalized by absolute value.

Exceptions

OverflowException

A scope magnitude is not representable, or the requested bounds would place an endpoint outside the scalar domain.

SetMinMax(Vector3d, Vector3d)

Sets the normalized bounds of the bounding box by specifying its minimum and maximum points.

public void SetMinMax(Vector3d min, Vector3d max)

Parameters

min Vector3d
max Vector3d

Union(FixedBoundBox, FixedBoundBox)

Creates a new bounding box that is the union of two bounding boxes.

public static FixedBoundBox Union(FixedBoundBox a, FixedBoundBox b)

Parameters

a FixedBoundBox
b FixedBoundBox

Returns

FixedBoundBox

Operators

operator ==(FixedBoundBox, FixedBoundBox)

Determines whether two FixedBoundBox instances are equal.

public static bool operator ==(FixedBoundBox left, FixedBoundBox right)

Parameters

left FixedBoundBox
right FixedBoundBox

Returns

bool

operator !=(FixedBoundBox, FixedBoundBox)

Determines whether two FixedBoundBox instances are not equal.

public static bool operator !=(FixedBoundBox left, FixedBoundBox right)

Parameters

left FixedBoundBox
right FixedBoundBox

Returns

bool