CodePlexProject Hosting for Open Source Software

Interval<T> represents an interval of values delimited by a lower bound and an upper bound. It gives support for
set theory operations.

It also provides the base class for types requiring support of set theory operations, such as the Period class that would derive for example from Interval<DateTimeOffset?>.

The following class diagram describes the model of Interval<T>:

- An Interval<T> is represented by a LowerBound and an UpperBound:
*]-3 ; 1[*- The LowerBound must be lower than or equal the UpperBound

*[1; -3[ => exception* - Singleton and Empty intervals must define the same BoundDirection, respectively the Closed and Opened direction.

*[0; 0[ => exception* - Set operations are implemented internally by considering the lowest and upmost values of T type. These values are determined in the following order:
- If T is a enumeration, the lowest and upmost values are represented respectively by the lowest and upmost underlying values of the enumeration.

In case of enumeration decorated with the Flags attribute, the upmost value is then represented by the combination of all underlying values of the enumeration. - If T is exposing the NegativeInfinity and PositiveInfinity fields, they represents respectively the lowest and upmost values, as for Single, Double.
- if T is exposing the MinValue and MaxValue fields, they represents respectively the lowest and upmost values, as for Int32, Byte, DateTime, Char…
- otherwise, default(T) represents the lowest and upmost values.
- As a consequence, default(T) could be used to represent the universe interval and the default empty interval. By convention in this case only, the default empty interval is composed of Closed boundaries; otherwise, it is composed of Opened boundaries.
- As another consequence, default(T) could be used to represent the universe and the singleton of the default value. In such case the interval represents then an universe and a singleton.

- The lowest and upmost values could also be overridden by using the static method OverrideBounds.

- If T is a enumeration, the lowest and upmost values are represented respectively by the lowest and upmost underlying values of the enumeration.
- The intersection of two or more intervals represents the
__common__elements that belong to these intervals. The intersection is an associative operation

*intersection of ]-3; 1[ and [-1; 3] => [-1; 1[*

*intersection of [-1; 3] and ]-3; 1[ => [-1; 1[* - The union of two or more intervals represents the elements that belong to these intervals. The union is an associative operation.

The union could be performed by considering the highest or the lowest denominator. By default the highest denominator is considered.

*union of ]-3; 1[ and [-1; 3] with*__highest__denominator => ]-3; 3]

*union of ]-3; 1[ and [-1; 3] with*__lowest__denominator => ]-3; -1[ and [-1; 1[ and [1; 3] - The complement of one or several intervals represents the elements that do not belong to these intervals.

*complement of ]-3; 1[ => ]¥ ; –3] and [1; ¥ [* - The difference of one interval with another one, also known as the relative complement, represents elements belonging to the first interval but do not belong to the second interval. The
difference is
__not__an associative operation.

*difference of ]-3; 1[ with [-1; 3] => ]-3; -1[*

*difference of [-1; 3] with ]-3; 1[ => [1; 3]* - The De Morgan's laws are respected:

*(A U B)*^{c}= A^{c}∩ B^{c}

(A ∩ B)^{c}= A^{c}U B^{c} - The complement laws are respected (where
represents the universe set):*U*

*A U A*^{c}=**U**

A ∩ A^{c}= Ø

Ø^{c}=**U**

**U**^{c}= Ø - The Involution or double complement law is respected:

*A*=^{c}^{c}*A* - Relationships between relative and absolute complements are respected:

*A - B = A ∩ B*^{c}

(A - B)^{c}= A^{c}U B

- The LowerBound must be lower than or equal the UpperBound
- A Bound<T> is represented by a Value, a BoundType and a BoundDirection:
*[-3;*- Infinit bounds support only opened direction

*[¥ ; or ;¥ ] =>exception*

- Infinit bounds support only opened direction
- IntervalCollection<T> is a read-only collection adding navigation support among set theory operations.
- Interval static class completes the set theory operations accessible from the Interval<T>.

Last edited Jan 9, 2012 at 8:57 PM by odanvin, version 2