Table of Contents

Struct Bounds<T>

Namespace
LfrlAnvil
Assembly
LfrlAnvil.Core.dll

A lightweight representation of a generic range of values between Min and Max.

public readonly struct Bounds<T> : IEquatable<Bounds<T>> where T : IComparable<T>

Type Parameters

T

Value type.

Implements
Inherited Members
Extension Methods

Constructors

Bounds(T, T)

Creates a new Bounds<T> instance.

public Bounds(T min, T max)

Parameters

min T

Minimum value.

max T

Maximum value.

Exceptions

ArgumentException

When min is greater than max.

Properties

Max

Maximum value in this range.

public T Max { get; }

Property Value

T

Min

Minimum value is this range.

public T Min { get; }

Property Value

T

Methods

Clamp(T)

Clamps the value to this [Min, Max] range.

[Pure]
public T Clamp(T value)

Parameters

value T

Value to clamp.

Returns

T

Clamped value.

Contains(Bounds<T>)

Checks whether or not this [Min, Max] range contains the provided other range.

[Pure]
public bool Contains(Bounds<T> other)

Parameters

other Bounds<T>

Range to check.

Returns

bool

true when this range contains the provided other range, otherwise false.

Contains(T)

Checks whether or not this [Min, Max] range contains the provided value.

[Pure]
public bool Contains(T value)

Parameters

value T

Value to check.

Returns

bool

true when this range contains the provided value, otherwise false.

ContainsExclusively(Bounds<T>)

Checks whether or not this exclusive (Min, Max) range contains the provided other range.

[Pure]
public bool ContainsExclusively(Bounds<T> other)

Parameters

other Bounds<T>

Range to check.

Returns

bool

true when this exclusive range contains the provided other range, otherwise false.

ContainsExclusively(T)

Checks whether or not this exclusive (Min, Max) range contains the provided value.

[Pure]
public bool ContainsExclusively(T value)

Parameters

value T

Value to check.

Returns

bool

true when this exclusive range contains the provided value, otherwise false.

Equals(Bounds<T>)

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

[Pure]
public bool Equals(Bounds<T> other)

Parameters

other Bounds<T>

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.

[Pure]
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.

GetHashCode()

Returns the hash code for this instance.

[Pure]
public override int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

GetIntersection(Bounds<T>)

Attempts to extract an intersection between this [Min, Max] range and the provided other range.

[Pure]
public Bounds<T>? GetIntersection(Bounds<T> other)

Parameters

other Bounds<T>

Range to check.

Returns

Bounds<T>?

New Bounds<T> instance or null when the two ranges do not intersect.

Intersects(Bounds<T>)

Checks whether or not this [Min, Max] range intersects with the provided other range.

[Pure]
public bool Intersects(Bounds<T> other)

Parameters

other Bounds<T>

Range to check.

Returns

bool

true when this range intersects with the provided other range, otherwise false.

MergeWith(Bounds<T>)

Attempts to merge this [Min, Max] range with the provided other range.

[Pure]
public Bounds<T>? MergeWith(Bounds<T> other)

Parameters

other Bounds<T>

Range to merge.

Returns

Bounds<T>?

New Bounds<T> instance or null when the two ranges do not intersect.

Remove(Bounds<T>)

Attempts to split this [Min, Max] range in two by removing the provided other range.

[Pure]
public Pair<Bounds<T>?, Bounds<T>?> Remove(Bounds<T> other)

Parameters

other Bounds<T>

Range to remove.

Returns

Pair<Bounds<T>?, Bounds<T>?>

Pair of Bounds<T> instances when other range is exclusively contained by this range, otherwise pair with both values equal to null when other range contains this range, otherwise pair with Second value equal to null.

SetMax(T)

Creates a new Bounds<T> instance with different max value.

[Pure]
public Bounds<T> SetMax(T max)

Parameters

max T

Maximum value.

Returns

Bounds<T>

New Bounds<T> instance with unchanged Min.

Exceptions

ArgumentException

When Min is greater than max.

SetMin(T)

Creates a new Bounds<T> instance with different min value.

[Pure]
public Bounds<T> SetMin(T min)

Parameters

min T

Minimum value.

Returns

Bounds<T>

New Bounds<T> instance with unchanged Max.

Exceptions

ArgumentException

When min is greater than Max.

SplitAt(T)

Attempts to split this [Min, Max] range in two at the provided value point.

[Pure]
public Pair<Bounds<T>, Bounds<T>?> SplitAt(T value)

Parameters

value T

Value to split at.

Returns

Pair<Bounds<T>, Bounds<T>?>

Pair of Bounds<T> instances when value is exclusively contained by this range, otherwise pair with the Second value equal to null.

ToString()

Returns a string representation of this Bounds<T> instance.

[Pure]
public override string ToString()

Returns

string

String representation.

Operators

operator ==(Bounds<T>, Bounds<T>)

Checks if a is equal to b.

[Pure]
public static bool operator ==(Bounds<T> a, Bounds<T> b)

Parameters

a Bounds<T>

First operand.

b Bounds<T>

Second operand.

Returns

bool

true when operands are equal, otherwise false.

operator !=(Bounds<T>, Bounds<T>)

Checks if a is not equal to b.

[Pure]
public static bool operator !=(Bounds<T> a, Bounds<T> b)

Parameters

a Bounds<T>

First operand.

b Bounds<T>

Second operand.

Returns

bool

true when operands are not equal, otherwise false.