Struct Size3D
Represents a 3D float-valued extent with a Width (X), Height (Y), and Depth (Z) component. Intended as the canonical "size" type for any volumetric measurement: 3D shape dimensions, mesh bounds, framing extents, room dimensions, scaled object footprints.
Implements
Inherited Members
Namespace: Scylla.Core.Util.Geom
Assembly: ScyllaCore.dll
Syntax
[Serializable]
public struct Size3D : IEquatable<Size3D>
Remarks
Size3D is a value type (struct) and is fully serializable by
Unity's Inspector. Equality uses
Approximately(float, float, float) so two
instances that differ only by floating-point rounding compare equal.
Implicit conversions to and from UnityEngine.Vector3 make it interoperate cleanly with every Unity API that takes or returns a vector. An explicit conversion to UnityEngine.Vector3Int rounds via RoundToInt(float); an explicit conversion from UnityEngine.Vector3Int widens losslessly to float.
Arithmetic operators (+, -, *, /) operate component-wise.
Division by zero follows standard C# float semantics and produces
PositiveInfinity or NaN; no exception is
thrown.
If you need a truly integer-valued extent (voxel grids, chunk indices), use UnityEngine.Vector3Int directly. A typed integer-extent struct can be added back later if a concrete use case appears.
Constructors
Size3D(float)
Initializes a uniform Size3D where all three components share the same
value (IsCube will return true).
Declaration
public Size3D(float size)
Parameters
| Type | Name | Description |
|---|---|---|
| float | size | Common value assigned to all three components. |
Size3D(float, float, float)
Initializes a new Size3D with the specified component values.
Declaration
public Size3D(float width, float height, float depth)
Parameters
| Type | Name | Description |
|---|---|---|
| float | width | Extent along the X axis. |
| float | height | Extent along the Y axis. |
| float | depth | Extent along the Z axis. |
Size3D(Vector3)
Initializes a new Size3D from a UnityEngine.Vector3, mapping its
x, y, z components to Width, Height,
Depth respectively. No precision is lost.
Declaration
public Size3D(Vector3 size)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | size | The UnityEngine.Vector3 to convert. |
Size3D(Vector3Int)
Initializes a new Size3D from a UnityEngine.Vector3Int, widening each
integer component to float without loss.
Declaration
public Size3D(Vector3Int size)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3Int | size | The UnityEngine.Vector3Int to convert. |
Fields
Depth
Extent along the Z axis. May be negative.
Declaration
[SerializeField]
public float Depth
Field Value
| Type | Description |
|---|---|
| float |
Empty
A Size3D with all three components set to zero.
Declaration
public static readonly Size3D Empty
Field Value
| Type | Description |
|---|---|
| Size3D |
Height
Extent along the Y axis. May be negative.
Declaration
[SerializeField]
public float Height
Field Value
| Type | Description |
|---|---|
| float |
One
A Size3D with all three components set to one (unit cube).
Declaration
public static readonly Size3D One
Field Value
| Type | Description |
|---|---|
| Size3D |
Width
Extent along the X axis. May be negative.
Declaration
[SerializeField]
public float Width
Field Value
| Type | Description |
|---|---|
| float |
Properties
IsCube
true when all three components are approximately equal. Use to test whether
this size represents a uniform cube.
Declaration
public bool IsCube { get; }
Property Value
| Type | Description |
|---|---|
| bool |
IsEmpty
true when all three components are approximately zero (using
Approximately(float, float, float)).
Declaration
public bool IsEmpty { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Max
The largest of the three components.
Declaration
public float Max { get; }
Property Value
| Type | Description |
|---|---|
| float |
Min
The smallest of the three components.
Declaration
public float Min { get; }
Property Value
| Type | Description |
|---|---|
| float |
Volume
Total volume, computed as Width × Height × Depth. May be negative if an odd number of components are negative.
Declaration
public float Volume { get; }
Property Value
| Type | Description |
|---|---|
| float |
Methods
Clamp(in Size3D, in Size3D, in Size3D)
Returns a Size3D whose components are clamped per-axis between the
corresponding components of min and max.
Declaration
public static Size3D Clamp(in Size3D value, in Size3D min, in Size3D max)
Parameters
| Type | Name | Description |
|---|---|---|
| Size3D | value | The size to clamp. |
| Size3D | min | Lower per-component bound. |
| Size3D | max | Upper per-component bound. |
Returns
| Type | Description |
|---|---|
| Size3D | The clamped size. |
Cube(float)
Returns a uniform Size3D where all three components equal
size. Convenience static equivalent to new Size3D(size).
Declaration
public static Size3D Cube(float size)
Parameters
| Type | Name | Description |
|---|---|---|
| float | size |
Returns
| Type | Description |
|---|---|
| Size3D | A new uniform size. |
Equals(Size3D)
Determines whether two Size3D values are approximately equal using Approximately(float, float, float) on all three components.
Declaration
public bool Equals(Size3D other)
Parameters
| Type | Name | Description |
|---|---|---|
| Size3D | other |
Returns
| Type | Description |
|---|---|
| bool |
Equals(object)
Declaration
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj |
Returns
| Type | Description |
|---|---|
| bool |
Overrides
GetHashCode()
Computes a hash code from the three components. Note: because Equals(Size3D) uses approximate equality, two equal sizes may produce different hash codes in rare edge cases. Avoid relying on Size3D as a dictionary key when source values may have come from different float computations.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| int |
Overrides
Lerp(in Size3D, in Size3D, float)
Linearly interpolates between two sizes component-wise. t is not
clamped; values outside [0, 1] extrapolate.
Declaration
public static Size3D Lerp(in Size3D a, in Size3D b, float t)
Parameters
| Type | Name | Description |
|---|---|---|
| Size3D | a | Start size. |
| Size3D | b | End size. |
| float | t | Interpolation factor. |
Returns
| Type | Description |
|---|---|
| Size3D | The interpolated size. |
ToString()
Returns a string in the format (Width, Height, Depth) for debugging,
logging, and Inspector display.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string |
Overrides
WithDepth(float)
Returns a copy of this size with Depth replaced by
depth. Width and Height are
preserved unchanged. Useful for fluent construction when you need to modify
a single axis.
Declaration
public Size3D WithDepth(float depth)
Parameters
| Type | Name | Description |
|---|---|---|
| float | depth | The new value for the Depth component. |
Returns
| Type | Description |
|---|---|
| Size3D | A new Size3D with Depth set to |
WithHeight(float)
Returns a copy of this size with Height replaced by
height. Width and Depth are
preserved unchanged. Useful for fluent construction when you need to modify
a single axis.
Declaration
public Size3D WithHeight(float height)
Parameters
| Type | Name | Description |
|---|---|---|
| float | height | The new value for the Height component. |
Returns
| Type | Description |
|---|---|
| Size3D | A new Size3D with Height set to |
WithWidth(float)
Returns a copy of this size with Width replaced by
width. Height and Depth are
preserved unchanged. Useful for fluent construction when you need to modify
a single axis.
Declaration
public Size3D WithWidth(float width)
Parameters
| Type | Name | Description |
|---|---|---|
| float | width | The new value for the Width component. |
Returns
| Type | Description |
|---|---|
| Size3D | A new Size3D with Width set to |
Operators
operator +(Size3D, Size3D)
Component-wise addition.
Declaration
public static Size3D operator +(Size3D a, Size3D b)
Parameters
| Type | Name | Description |
|---|---|---|
| Size3D | a | |
| Size3D | b |
Returns
| Type | Description |
|---|---|
| Size3D |
operator /(Size3D, float)
Uniform division by a scalar. Standard C# float-division semantics apply: division by zero produces PositiveInfinity or NaN rather than throwing.
Declaration
public static Size3D operator /(Size3D size, float scalar)
Parameters
| Type | Name | Description |
|---|---|---|
| Size3D | size | |
| float | scalar |
Returns
| Type | Description |
|---|---|
| Size3D |
operator ==(Size3D, Size3D)
Approximate equality via Equals(Size3D).
Declaration
public static bool operator ==(Size3D left, Size3D right)
Parameters
| Type | Name | Description |
|---|---|---|
| Size3D | left | |
| Size3D | right |
Returns
| Type | Description |
|---|---|
| bool |
explicit operator Vector3Int(Size3D)
Explicit conversion to UnityEngine.Vector3Int; each component is rounded via RoundToInt(float). Use this when a Unity API requires an integer vector and you accept the rounding.
Declaration
public static explicit operator Vector3Int(Size3D size)
Parameters
| Type | Name | Description |
|---|---|---|
| Size3D | size |
Returns
| Type | Description |
|---|---|
| Vector3Int |
explicit operator Size3D(Vector3Int)
Explicit conversion from UnityEngine.Vector3Int (lossless widening to float).
Declaration
public static explicit operator Size3D(Vector3Int vector)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3Int | vector |
Returns
| Type | Description |
|---|---|
| Size3D |
implicit operator Vector3(Size3D)
Implicit conversion to UnityEngine.Vector3.
Declaration
public static implicit operator Vector3(Size3D size)
Parameters
| Type | Name | Description |
|---|---|---|
| Size3D | size |
Returns
| Type | Description |
|---|---|
| Vector3 |
implicit operator Size3D(Vector3)
Implicit conversion from UnityEngine.Vector3.
Declaration
public static implicit operator Size3D(Vector3 vector)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | vector |
Returns
| Type | Description |
|---|---|
| Size3D |
operator !=(Size3D, Size3D)
Negation of operator ==(Size3D, Size3D).
Declaration
public static bool operator !=(Size3D left, Size3D right)
Parameters
| Type | Name | Description |
|---|---|---|
| Size3D | left | |
| Size3D | right |
Returns
| Type | Description |
|---|---|
| bool |
operator *(Size3D, Size3D)
Component-wise multiplication.
Declaration
public static Size3D operator *(Size3D a, Size3D b)
Parameters
| Type | Name | Description |
|---|---|---|
| Size3D | a | |
| Size3D | b |
Returns
| Type | Description |
|---|---|
| Size3D |
operator *(Size3D, float)
Uniform scaling by a scalar.
Declaration
public static Size3D operator *(Size3D size, float scalar)
Parameters
| Type | Name | Description |
|---|---|---|
| Size3D | size | |
| float | scalar |
Returns
| Type | Description |
|---|---|
| Size3D |
operator *(float, Size3D)
Uniform scaling by a scalar (left-hand-side overload).
Declaration
public static Size3D operator *(float scalar, Size3D size)
Parameters
| Type | Name | Description |
|---|---|---|
| float | scalar | |
| Size3D | size |
Returns
| Type | Description |
|---|---|
| Size3D |
operator -(Size3D, Size3D)
Component-wise subtraction.
Declaration
public static Size3D operator -(Size3D a, Size3D b)
Parameters
| Type | Name | Description |
|---|---|---|
| Size3D | a | |
| Size3D | b |
Returns
| Type | Description |
|---|---|
| Size3D |