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
Use FromMinMax(Vector3d, Vector3d), FromCenterAndSize(Vector3d, Vector3d), or FromCenterAndScope(Vector3d, Vector3d) so construction intent is explicit at the call site.
Constructors
FixedBoundBox(BoundingBoxState)
Initializes a new instance of the FixedBoundBox class with the specified bounding box state.
[JsonConstructor]
public FixedBoundBox(FixedBoundBox.BoundingBoxState state)
Parameters
stateFixedBoundBox.BoundingBoxStateThe 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
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
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
Min
The minimum corner of the bounding box.
[JsonIgnore]
[MemoryPackIgnore]
public readonly Vector3d Min { get; }
Property Value
Proportions
The exact total size of the box.
[JsonIgnore]
[MemoryPackIgnore]
public Vector3d Proportions { get; set; }
Property Value
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
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
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
pointVector3d
Returns
ClosestPointOnSurface(Vector3d)
Finds the closest point on the surface of the bounding box to the specified point.
public Vector3d ClosestPointOnSurface(Vector3d point)
Parameters
pointVector3d
Returns
Contains(FixedBoundBox)
Tests another bounding box against this bounding box.
public FixedEnclosureType Contains(FixedBoundBox box)
Parameters
boxFixedBoundBox
Returns
Contains(FixedBoundFrustum)
Tests a bounding frustum against this bounding box.
public FixedEnclosureType Contains(FixedBoundFrustum frustum)
Parameters
frustumFixedBoundFrustum
Returns
Contains(FixedBoundSphere)
Tests a bounding sphere against this bounding box.
public FixedEnclosureType Contains(FixedBoundSphere sphere)
Parameters
sphereFixedBoundSphere
Returns
Contains(Vector3d)
Determines if a point is inside the bounding box (including boundaries).
public bool Contains(Vector3d point)
Parameters
pointVector3d
Returns
CopyCorners(Span<Vector3d>)
Copies this box's corners into the destination span in GetCorner(int) order.
public void CopyCorners(Span<Vector3d> destination)
Parameters
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
pointVector3dThe 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
otherFixedBoundBox
Returns
Equals(object?)
public override bool Equals(object? obj)
Parameters
objobject
Returns
FindClosestPointsBetweenBoxes(FixedBoundBox, FixedBoundBox)
Finds the closest points between two bounding boxes.
public static Vector3d FindClosestPointsBetweenBoxes(FixedBoundBox a, FixedBoundBox b)
Parameters
Returns
FromCenterAndScope(Vector3d, Vector3d)
Creates a bounding box from a center point and half-size scope.
public static FixedBoundBox FromCenterAndScope(Vector3d center, Vector3d scope)
Parameters
Returns
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
Returns
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
Returns
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
Returns
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
centerVector3drotationFixedQuaternionlocalAxisDirectionVector3daxisLengthFixed64radiusFixed64
Returns
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
Returns
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
centerVector3dThe midpoint between the base center and apex.
rotationFixedQuaternionThe cone rigid-frame rotation.
localAxisDirectionVector3dThe normalized local direction from the base center toward the apex.
heightFixed64The positive full base-to-apex height.
radiusFixed64The nonnegative base radius.
Returns
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
centerVector3dThe midpoint between the base center and apex.
axisDirectionVector3dThe normalized direction from the base center toward the apex.
heightFixed64The positive full base-to-apex height.
radiusFixed64The nonnegative base radius.
Returns
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
centerVector3drotationFixedQuaternionlocalAxisDirectionVector3daxisLengthFixed64radiusFixed64
Returns
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
Returns
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
apexVector3dThe cone apex.
baseCenterVector3dThe center of the cone's flat base.
axisDirectionVector3dThe normalized direction from apex to base.
baseRadiusFixed64The nonnegative base radius.
Returns
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
axisDirectionis zero or not normalized.- ArgumentOutOfRangeException
baseRadiusis negative.
FromMinMax(Vector3d, Vector3d)
Creates a normalized bounding box from minimum and maximum corners.
public static FixedBoundBox FromMinMax(Vector3d min, Vector3d max)
Parameters
Returns
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
sourceOriginVector3dsourceRotationFixedQuaternionsourceLocalMinVector3dsourceLocalMaxVector3dtargetOriginVector3dtargetRotationFixedQuaternion
Returns
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
indexint
Returns
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
GetPointOnSurfaceTowardsObject(Vector3d)
Finds the closest point on the surface of the bounding box towards a specified object position.
public Vector3d GetPointOnSurfaceTowardsObject(Vector3d objectPosition)
Parameters
objectPositionVector3d
Returns
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
otherFixedBoundBox
Returns
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
boxFixedBoundBox
Returns
Intersects(FixedBoundFrustum)
Checks whether a bounding frustum intersects this bounding box.
public bool Intersects(FixedBoundFrustum frustum)
Parameters
frustumFixedBoundFrustum
Returns
Intersects(FixedBoundSphere)
Checks whether a bounding sphere intersects this bounding box, including boundary-only contact.
public bool Intersects(FixedBoundSphere sphere)
Parameters
sphereFixedBoundSphere
Returns
IntersectsStrict(FixedBoundBox)
Checks whether another bounding box overlaps this bounding box with positive volume on every axis.
public bool IntersectsStrict(FixedBoundBox box)
Parameters
boxFixedBoundBox
Returns
IntersectsStrict(FixedBoundSphere)
Checks whether a bounding sphere overlaps this bounding box with positive volume.
public bool IntersectsStrict(FixedBoundSphere sphere)
Parameters
sphereFixedBoundSphere
Returns
Orient(Vector3d, Vector3d?)
Orients the bounding box with the given center and size.
public void Orient(Vector3d center, Vector3d? size)
Parameters
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
pointVector3d
Returns
Resize(Vector3d)
Resizes the bounding box to the specified size, keeping the same center.
public void Resize(Vector3d size)
Parameters
sizeVector3d
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
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
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
Returns
Operators
operator ==(FixedBoundBox, FixedBoundBox)
Determines whether two FixedBoundBox instances are equal.
public static bool operator ==(FixedBoundBox left, FixedBoundBox right)
Parameters
leftFixedBoundBoxrightFixedBoundBox
Returns
operator !=(FixedBoundBox, FixedBoundBox)
Determines whether two FixedBoundBox instances are not equal.
public static bool operator !=(FixedBoundBox left, FixedBoundBox right)
Parameters
leftFixedBoundBoxrightFixedBoundBox