Struct Size
- Namespace
- Gloam.Core.Primitives
- Assembly
- Gloam.Core.dll
Represents a size in 2D space with width and height dimensions
public readonly struct Size : IEquatable<Size>
- Implements
- Inherited Members
- Extension Methods
Constructors
Size(int, int)
Initializes a new Size with the specified width and height
public Size(int width, int height)
Parameters
Properties
Area
Gets the total area (width * height)
public int Area { get; }
Property Value
Empty
Gets a Size with zero width and height
public static Size Empty { get; }
Property Value
Height
Gets the height component
public int Height { get; }
Property Value
IsEmpty
Gets whether this size has zero area
public bool IsEmpty { get; }
Property Value
IsSquare
Gets whether this size represents a square (width == height)
public bool IsSquare { get; }
Property Value
Unit
Gets a Size representing a single unit (1x1)
public static Size Unit { get; }
Property Value
Width
Gets the width component
public int Width { get; }
Property Value
Methods
Clamp(Size, Size)
Clamps the size to be within the specified minimum and maximum bounds
public Size Clamp(Size minimum, Size maximum)
Parameters
Returns
Equals(Size)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(Size other)
Parameters
other
SizeAn object to compare with this object.
Returns
Equals(object?)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object? obj)
Parameters
obj
objectThe object to compare with the current instance.
Returns
- bool
true if
obj
and this instance are the same type and represent the same value; otherwise, false.
FillBounds(Size)
Creates a Size that fills the specified bounds while maintaining aspect ratio (may exceed bounds)
public Size FillBounds(Size bounds)
Parameters
bounds
Size
Returns
FitWithin(Size)
Creates a Size that fits within the specified bounds while maintaining aspect ratio
public Size FitWithin(Size bounds)
Parameters
bounds
Size
Returns
FromVector2(Vector2)
Creates a Size from a Vector2, taking the floor of fractional components
public static Size FromVector2(Vector2 vector)
Parameters
vector
Vector2
Returns
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
Intersect(Size)
Creates a Size that represents the intersection of two sizes (minimum of each dimension)
public Size Intersect(Size other)
Parameters
other
Size
Returns
ToDetailedString()
Returns a string representation with area information
public string ToDetailedString()
Returns
ToPosition()
Converts to a Position with Width as X and Height as Y
public Position ToPosition()
Returns
ToString()
Returns the fully qualified type name of this instance.
public override string ToString()
Returns
- string
The fully qualified type name.
ToVector2()
Converts the size to a Vector2 with width as X and height as Y
public Vector2 ToVector2()
Returns
Union(Size)
Expands the size to include the specified size
public Size Union(Size other)
Parameters
other
Size
Returns
WithHeight(int)
Creates a new Size with the specified height, keeping the same width
public Size WithHeight(int newHeight)
Parameters
newHeight
int
Returns
WithWidth(int)
Creates a new Size with the specified width, keeping the same height
public Size WithWidth(int newWidth)
Parameters
newWidth
int
Returns
Operators
operator +(Size, Size)
Adds two sizes component-wise
public static Size operator +(Size left, Size right)
Parameters
Returns
operator /(Size, int)
Divides a size by a divisor
public static Size operator /(Size size, int divisor)
Parameters
Returns
operator ==(Size, Size)
public static bool operator ==(Size left, Size right)
Parameters
Returns
explicit operator Size(Vector2)
Explicit conversion from Vector2
public static explicit operator Size(Vector2 vector)
Parameters
vector
Vector2
Returns
implicit operator Vector2(Size)
Implicit conversion to Vector2
public static implicit operator Vector2(Size size)
Parameters
size
Size
Returns
operator !=(Size, Size)
public static bool operator !=(Size left, Size right)
Parameters
Returns
operator *(Size, int)
Scales a size by a factor
public static Size operator *(Size size, int scale)
Parameters
Returns
operator *(Size, float)
Scales a size by a fractional factor
public static Size operator *(Size size, float scale)
Parameters
Returns
operator *(int, Size)
Scales a size by a factor
public static Size operator *(int scale, Size size)
Parameters
Returns
operator -(Size, Size)
Subtracts two sizes component-wise
public static Size operator -(Size left, Size right)