Table of Contents

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

width int

The width dimension (must be >= 0)

height int

The height dimension (must be >= 0)

Properties

Area

Gets the total area (width * height)

public int Area { get; }

Property Value

int

Empty

Gets a Size with zero width and height

public static Size Empty { get; }

Property Value

Size

Height

Gets the height component

public int Height { get; }

Property Value

int

IsEmpty

Gets whether this size has zero area

public bool IsEmpty { get; }

Property Value

bool

IsSquare

Gets whether this size represents a square (width == height)

public bool IsSquare { get; }

Property Value

bool

Unit

Gets a Size representing a single unit (1x1)

public static Size Unit { get; }

Property Value

Size

Width

Gets the width component

public int Width { get; }

Property Value

int

Methods

Clamp(Size, Size)

Clamps the size to be within the specified minimum and maximum bounds

public Size Clamp(Size minimum, Size maximum)

Parameters

minimum Size
maximum Size

Returns

Size

Equals(Size)

Indicates whether the current object is equal to another object of the same type.

public bool Equals(Size other)

Parameters

other Size

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

Indicates whether this instance and a specified object are equal.

public override bool Equals(object? obj)

Parameters

obj object

The 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

Size

FitWithin(Size)

Creates a Size that fits within the specified bounds while maintaining aspect ratio

public Size FitWithin(Size bounds)

Parameters

bounds Size

Returns

Size

FromVector2(Vector2)

Creates a Size from a Vector2, taking the floor of fractional components

public static Size FromVector2(Vector2 vector)

Parameters

vector Vector2

Returns

Size

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

Size

ToDetailedString()

Returns a string representation with area information

public string ToDetailedString()

Returns

string

ToPosition()

Converts to a Position with Width as X and Height as Y

public Position ToPosition()

Returns

Position

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

Vector2

Union(Size)

Expands the size to include the specified size

public Size Union(Size other)

Parameters

other Size

Returns

Size

WithHeight(int)

Creates a new Size with the specified height, keeping the same width

public Size WithHeight(int newHeight)

Parameters

newHeight int

Returns

Size

WithWidth(int)

Creates a new Size with the specified width, keeping the same height

public Size WithWidth(int newWidth)

Parameters

newWidth int

Returns

Size

Operators

operator +(Size, Size)

Adds two sizes component-wise

public static Size operator +(Size left, Size right)

Parameters

left Size
right Size

Returns

Size

operator /(Size, int)

Divides a size by a divisor

public static Size operator /(Size size, int divisor)

Parameters

size Size
divisor int

Returns

Size

operator ==(Size, Size)

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

Parameters

left Size
right Size

Returns

bool

explicit operator Size(Vector2)

Explicit conversion from Vector2

public static explicit operator Size(Vector2 vector)

Parameters

vector Vector2

Returns

Size

implicit operator Vector2(Size)

Implicit conversion to Vector2

public static implicit operator Vector2(Size size)

Parameters

size Size

Returns

Vector2

operator !=(Size, Size)

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

Parameters

left Size
right Size

Returns

bool

operator *(Size, int)

Scales a size by a factor

public static Size operator *(Size size, int scale)

Parameters

size Size
scale int

Returns

Size

operator *(Size, float)

Scales a size by a fractional factor

public static Size operator *(Size size, float scale)

Parameters

size Size
scale float

Returns

Size

operator *(int, Size)

Scales a size by a factor

public static Size operator *(int scale, Size size)

Parameters

scale int
size Size

Returns

Size

operator -(Size, Size)

Subtracts two sizes component-wise

public static Size operator -(Size left, Size right)

Parameters

left Size
right Size

Returns

Size