Table of Contents

Struct BoundsRange<T>

Namespace
LfrlAnvil
Assembly
LfrlAnvil.Core.dll

A lightweight representation of a generic collection of ranges of values.

public readonly struct BoundsRange<T> : IReadOnlyList<Bounds<T>>, IReadOnlyCollection<Bounds<T>>, IEnumerable<Bounds<T>>, IEnumerable, IEquatable<BoundsRange<T>> where T : IComparable<T>

Type Parameters

T

Value type.

Implements
Inherited Members
Extension Methods

Constructors

BoundsRange(Bounds<T>)

Creates a new BoundsRange<T> instance from a single Bounds<T> instance.

public BoundsRange(Bounds<T> value)

Parameters

value Bounds<T>

Single range.

BoundsRange(IEnumerable<Bounds<T>>)

Creates a new BoundsRange<T> instance from a collection of Bounds<T> instances.

public BoundsRange(IEnumerable<Bounds<T>> range)

Parameters

range IEnumerable<Bounds<T>>

Collection of ranges.

Exceptions

ArgumentException

When range is not ordered.

Fields

Empty

Represents an empty collection of ranges.

public static readonly BoundsRange<T> Empty

Field Value

BoundsRange<T>

Properties

Count

Specifies the number of ranges in this collection.

public int Count { get; }

Property Value

int

this[int]

Gets a single Bounds<T> range at the specified 0-based position.

public Bounds<T> this[int index] { get; }

Parameters

index int

0-based range position.

Property Value

Bounds<T>

Exceptions

IndexOutOfRangeException

When index is less than 0 or greater than or equal to Count.

Methods

Complement()

Complements this collection of ranges within its own minimum and maximum range of values.

[Pure]
public BoundsRange<T> Complement()

Returns

BoundsRange<T>

New BoundsRange<T> instance or Empty when this collection of ranges is empty.

Complement(BoundsRange<T>)

Complements this collection of ranges within the provided container collection of ranges.

[Pure]
public BoundsRange<T> Complement(BoundsRange<T> container)

Parameters

container BoundsRange<T>

Collection of ranges to complement this collection of ranges in.

Returns

BoundsRange<T>

New BoundsRange<T> instance.

Complement(Bounds<T>)

Complements this collection of ranges within the provided container range.

[Pure]
public BoundsRange<T> Complement(Bounds<T> container)

Parameters

container Bounds<T>

Range to complement this collection of ranges in.

Returns

BoundsRange<T>

New BoundsRange<T> instance.

Contains(BoundsRange<T>)

Checks whether or not this collection contains the provided other collection of ranges.

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

Parameters

other BoundsRange<T>

Collection of ranges to check.

Returns

bool

true when this collection contains the provided other collection of ranges, otherwise false.

Contains(Bounds<T>)

Checks whether or not this collection contains the provided value range.

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

Parameters

value Bounds<T>

Range to check.

Returns

bool

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

Contains(T)

Checks whether or not this collection contains the provided value.

[Pure]
public bool Contains(T value)

Parameters

value T

Value to check.

Returns

bool

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

Equals(BoundsRange<T>)

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

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

Parameters

other BoundsRange<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.

FindBounds(T)

Attempts to find Bounds<T> from this collection that contains the provided value.

[Pure]
public Bounds<T>? FindBounds(T value)

Parameters

value T

Value to check.

Returns

Bounds<T>?

Bounds<T> from this collection that contains the provided value or null when value is not contained by this collection.

FindBoundsIndex(T)

Attempts to find a 0-based position of Bounds<T> from this collection that contains the provided value.

[Pure]
public int FindBoundsIndex(T value)

Parameters

value T

Value to check.

Returns

int

0-based position of Bounds<T> that contains the provided value, otherwise the result will be negative and will be equal to the bitwise complement of an index of the nearest Bounds<T> whose Min is larger than the provided value.

Flatten()

Attempts to create a new Bounds<T> instance by extracting the minimum and maximum values from this collection.

[Pure]
public Bounds<T>? Flatten()

Returns

Bounds<T>?

New Bounds<T> instance or null when this collection is empty.

GetEnumerator()

Returns an enumerator that iterates through the collection.

[Pure]
public IEnumerator<Bounds<T>> GetEnumerator()

Returns

IEnumerator<Bounds<T>>

An enumerator that can be used to iterate through the collection.

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(BoundsRange<T>)

Attempts to extract an intersection between this collection of ranges and the provided other collection of ranges.

[Pure]
public BoundsRange<T> GetIntersection(BoundsRange<T> other)

Parameters

other BoundsRange<T>

Collection of ranges to check.

Returns

BoundsRange<T>

New BoundsRange<T> instance or Empty when the two collections of ranges do not intersect.

GetIntersection(Bounds<T>)

Attempts to extract an intersection between this collection of ranges and the provided value range.

[Pure]
public BoundsRange<T> GetIntersection(Bounds<T> value)

Parameters

value Bounds<T>

Range to check.

Returns

BoundsRange<T>

New BoundsRange<T> instance or Empty when the ranges do not intersect.

Intersects(BoundsRange<T>)

Checks whether or not this collection intersects with the provided other collection of ranges.

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

Parameters

other BoundsRange<T>

Collection of ranges to check.

Returns

bool

true when this collection intersects with the provided other collection of ranges, otherwise false.

Intersects(Bounds<T>)

Checks whether or not this collection intersects with the provided value range.

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

Parameters

value Bounds<T>

Range to check.

Returns

bool

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

MergeWith(BoundsRange<T>)

Merges this collection of ranges with the provided other collections of ranges.

[Pure]
public BoundsRange<T> MergeWith(BoundsRange<T> other)

Parameters

other BoundsRange<T>

Collections of ranges to merge.

Returns

BoundsRange<T>

New BoundsRange<T> instance.

MergeWith(Bounds<T>)

Merges this collection of ranges with the provided value range.

[Pure]
public BoundsRange<T> MergeWith(Bounds<T> value)

Parameters

value Bounds<T>

Range to merge.

Returns

BoundsRange<T>

New BoundsRange<T> instance.

Normalize(Func<T, T, bool>)

Creates a new BoundsRange<T> instance by invoking the provided normalizePredicate on each pair of (previous-bounds-maximum, current-bounds-minimum): when the predicate returns true, then [previous-bounds-minimum, previous-bounds-maximum] and [current-bounds-minimum, current-bounds-maximum] will be merged together into a single [previous-minimum, current-maximum] range.

[Pure]
public BoundsRange<T> Normalize(Func<T, T, bool> normalizePredicate)

Parameters

normalizePredicate Func<T, T, bool>

Normalization predicate.

Returns

BoundsRange<T>

New BoundsRange<T> instance.

Remove(BoundsRange<T>)

Removes the provided other collection of ranges from this collection of ranges.

[Pure]
public BoundsRange<T> Remove(BoundsRange<T> other)

Parameters

other BoundsRange<T>

Collections of ranges to remove.

Returns

BoundsRange<T>

New BoundsRange<T> instance.

Remove(Bounds<T>)

Removes the provided value range from this collection of ranges.

[Pure]
public BoundsRange<T> Remove(Bounds<T> value)

Parameters

value Bounds<T>

Range to remove.

Returns

BoundsRange<T>

New BoundsRange<T> instance.

ToString()

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

[Pure]
public override string ToString()

Returns

string

String representation.

Operators

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

Checks if a is equal to b.

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

Parameters

a BoundsRange<T>

First operand.

b BoundsRange<T>

Second operand.

Returns

bool

true when operands are equal, otherwise false.

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

Checks if a is not equal to b.

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

Parameters

a BoundsRange<T>

First operand.

b BoundsRange<T>

Second operand.

Returns

bool

true when operands are not equal, otherwise false.