Skip to content

Repository files navigation

.NET CoreNuGet version

Interval

Generic library of types to describe interval of any points that can be compared to eachother. The library is as small as possible to be useful. I've created it to use in my own implimentation of Iterval Centered Tree. To do it I was need a couple of additional operation which I've implemented in external library of Interval Operations on purpose to keep this library clear.

Each boundary contains method CompareToPoint it allows to get position of point compare to boundary. For example point 0 with comparison to open lower bound of 0 will be less but for closed lower bound it will be equal. Infinity lower bound will be always less than any point but Infinity upper bound will be greater than any point.

Model

alternative text

Usage

Interval

Interval type is generic type and can have boundaries point of any type, but for comparison operation you will need to have comparer class for point type

varinterval=newInterval<int>(lowerBound: ...,upperBound: ...);

Interval Boundaries

Each of interval boundaries can be one of three possible types. It enable to have up to nine different intervals.

Closed Interval

Both boundaries points are inculded to theinterval

[a, b] = {x | a <= x <= b}

varclosedInterval=newInterval<int>(lowerBound:newClosedLowerBound<int>(0),upperBound:newClosedUpperBound<int>(10));

Open Interval

Both boundaries points are not inculded to the interval

(a, b) = {x | a < x < b}

varopenInterval=newInterval<int>(lowerBound:newOpenLowerBound<int>(0),upperBound:newOpenUpperBound<int>(10));

Infinity Interval

This interval include any point

(∞, ∞) = {x | ∞ < x < ∞}

varinfinityInterval=newInterval<int>(lowerBound:newInfinityLowerBound<int>(),upperBound:newInfinityUpperBound<int>());

And you can combine bounds

Open Closed Interval

Lower boundary point is not included to the interval, upper bound is included to the interval

(a, b] = {x | a < x <= b}

varopenClosedInterval=newInterval<int>(lowerBound:newOpenLowerBound<int>(0),upperBound:newClosedUpperBound<int>(10));

Closed Open Interval

Lower boundary point is included to the interval, upper bound is not

[a, b) = {x | a <= x < b}

varclosedOpenInterval=newInterval<int>(lowerBound:newClosedLowerBound<int>(0),upperBound:newOpenUpperBound<int>(10));

Infinity Open Interval

Lower boundary is infinity and any point of the interval is more than it boundary, upper boundary point is not included to the interval

(∞, a) = {x | ∞ < x < b}

varinfinityOpenInterval=newInterval<int>(lowerBound:newInfinityLowerBound<int>(),upperBound:newOpenUpperBound<int>(10));

Infinity Closed Interval

Lower boundary is infinity and any point of the interval is more than it boundary, upper boundary point is included to the interval

(∞, a) = {x | ∞ < x <= b}

varinfinityClosedInterval=newInterval<int>(lowerBound:newInfinityLowerBound<int>(),upperBound:newClosedUpperBound<int>(10));

Open Infinity Interval

Lower boundary point is not included to the interval, upper bound is infinity and any point of interval is less that it boundary

(a, ∞) = {x | a < x < ∞}

varopenInfinityInterval=newInterval<int>(lowerBound:newOpenLowerBound<int>(0),upperBound:newInfinityUpperBound<int>(10));

Closed Infinity Interval

Lower boundary point is included to the interval, upper bound is infinity and any point of interval is less that it boundary

[a, ∞) = {x | a <= x < ∞}

varclosedInfinityInterval=newInterval<int>(lowerBound:newClosedLowerBound<int>(0),upperBound:newInfinityUpperBound<int>(10));

Boundary Operation

Every boundary can be compared to point by CompareToPoint method. Methor returns -1 boundary at the left, 1 if the boundary at the right and 0 if point on the boundary.

newClosedLowerBound<int>(10).CompareToPoint(point:10,comparer:Comparer<int>.Default);// == 0 - point is on the boundary

Every lower boundary can be compared to another lower boundary by Comapre method

newClosedLowerBound<int>(10).Compare(another:newOpenLowerBound<int>(11),comparer:Comparer<int>.Default);// == 0 - point is on the boundary

And every upper boundary can be compared to another upper boundary by Comapre method

newOpenUpperBound<int>(10).Compare(another:newClosedUpperBound<int>(11),comparer:Comparer<int>.Default);// == 0 - point is on the boundary

Interval Operation

About

Library for creating and comparing intervals. Library support three types of boundaries: open, closed and infinity for both sides.

Resources

Stars

1 star

Watchers

6 watching

Forks

Releases

Packages

Used by

Contributors

Languages