Table of Contents

Class CyclicRange<T>

Namespace
Utils.Range
Assembly
Utils.dll

Represents an inclusive range on a cyclic domain.

public class CyclicRange<T> : IRange<T> where T : IComparable<T>

Type Parameters

T

The value type of the cyclic range.

Inheritance
CyclicRange<T>
Implements
Derived
Inherited Members
Extension Methods

Remarks

A CyclicRange<T> where Start equals End represents a singleton — a range containing exactly one value. To represent the full cycle (all values from MinValue to MaxValue), use the FullCycle(T, T) factory method instead (#21).

Both Start and End must lie within [MinValue, MaxValue] (#20).

Constructors

CyclicRange(T, T, T, T)

Initializes a new instance of the CyclicRange<T> class.

public CyclicRange(T start, T end, T minValue, T maxValue)

Parameters

start T

The start boundary in the cycle. Must be within [minValue, maxValue].

end T

The end boundary in the cycle. Must be within [minValue, maxValue].

minValue T

The minimum representable value of the cycle.

maxValue T

The maximum representable value of the cycle.

Exceptions

ArgumentNullException

Thrown when any of the arguments is null (for reference types).

ArgumentException

Thrown when minValue exceeds maxValue, or when start or end lies outside [minValue, maxValue] (#20).

Properties

ContainsEnd

Gets a value indicating whether End belongs to the range.

public bool ContainsEnd { get; }

Property Value

bool

ContainsStart

Gets a value indicating whether Start belongs to the range.

public bool ContainsStart { get; }

Property Value

bool

End

Gets the end boundary of the range.

public T End { get; }

Property Value

T

MaxValue

Gets the maximum representable value in the cycle.

public T MaxValue { get; }

Property Value

T

MinValue

Gets the minimum representable value in the cycle.

public T MinValue { get; }

Property Value

T

Start

Gets the start boundary of the range.

public T Start { get; }

Property Value

T

Methods

Contains(IRange<T>)

Determines whether this range entirely contains another range.

public bool Contains(IRange<T> other)

Parameters

other IRange<T>

The range to test.

Returns

bool

true when other is fully contained; otherwise, false.

Contains(T)

Determines whether the supplied value belongs to the current range.

public virtual bool Contains(T value)

Parameters

value T

The value to test.

Returns

bool

true when the value is in range; otherwise, false.

FullCycle(T, T)

Creates a CyclicRange<T> that covers the complete cycle from minValue to maxValue, inclusive (#21).

public static CyclicRange<T> FullCycle(T minValue, T maxValue)

Parameters

minValue T

The minimum representable value of the cycle.

maxValue T

The maximum representable value of the cycle.

Returns

CyclicRange<T>

A cyclic range spanning the full domain.

Exceptions

ArgumentException

Thrown when minValue exceeds maxValue.

Intersect(IRange<T>)

Computes one or more intersections between this range and another range.

public IRange<T>[] Intersect(IRange<T> other)

Parameters

other IRange<T>

The range to intersect with.

Returns

IRange<T>[]

An array containing all intersection ranges. The array is empty when ranges are disjoint.

IsCompatibleWith(IRange<T>)

Determines whether the current range model is compatible with another range for aggregation in the same collection.

public bool IsCompatibleWith(IRange<T> other)

Parameters

other IRange<T>

The range to compare with.

Returns

bool

true when both ranges can coexist in the same Ranges<T>; otherwise, false.

Remarks

Two cyclic ranges are compatible when they share the same cycle bounds, determined by CompareTo(T) so that the ordering relation used for containment and intersection is consistent with the compatibility test (#22).

Overlap(IRange<T>)

Determines whether this range overlaps with another range.

public bool Overlap(IRange<T> other)

Parameters

other IRange<T>

The range to test.

Returns

bool

true when ranges overlap; otherwise, false.