Class Interval<TPoint, TSpan, TEndpoint, T>
Represents an interval with bounded/unbounded and inclusive/exclusive end points.
Inheritance
Implements
Namespace: Microsoft.Psi
Assembly: Microsoft.Psi.dll
Syntax
public abstract class Interval<TPoint, TSpan, TEndpoint, T> : object, IInterval<TPoint, TSpan, TEndpoint, T> where TPoint : IComparable where TEndpoint : IIntervalEndpoint<TPoint> where T : Interval<TPoint, TSpan, TEndpoint, T>
Type Parameters
Name | Description |
---|---|
TPoint | Type of point values. |
TSpan | Type of spans between point values. |
TEndpoint | Explicit endpoint type (instance of IIntervalEndpoint{TPoint}). |
T | Concrete type implementing this interface. |
Constructors
View SourceInterval(TEndpoint, TEndpoint)
Initializes a new instance of the Interval<TPoint, TSpan, TEndpoint, T> class.
Declaration
protected Interval(TEndpoint left, TEndpoint right)
Parameters
Type | Name | Description |
---|---|---|
TEndpoint | left | Left interval endpoint. |
TEndpoint | right | Right interval endpoint. |
Properties
View SourceCenter
Gets a value indicating the center of the interval.
Declaration
public virtual TPoint Center { get; }
Property Value
Type | Description |
---|---|
TPoint |
Remarks
Throws when interval is unbounded.
IsClosed
Gets a value indicating whether Left and Right are both inclusive.
Declaration
public bool IsClosed { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsDegenerate
Gets a value indicating whether the interval represents a single point.
Declaration
public bool IsDegenerate { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Remarks
Same as !IsProper.
IsEmpty
Gets a value indicating whether the interval represents a single point with closed endpoints.
Declaration
public bool IsEmpty { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Remarks
Same as !IsProperty.
IsFinite
Gets a value indicating whether the interval is bounded at both ends.
Declaration
public bool IsFinite { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsHalfBounded
Gets a value indicating whether the interval is unbounded at one end.
Declaration
public bool IsHalfBounded { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Remarks
Same as !Left.Bounded || !Right.Bounded.
IsNegative
Gets a value indicating whether the interval is negative.
Declaration
public bool IsNegative { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsOpen
Gets a value indicating whether neither Left nor Right are inclusive.
Declaration
public bool IsOpen { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Left
Gets left endpoint value.
Declaration
public TPoint Left { get; }
Property Value
Type | Description |
---|---|
TPoint |
Remarks
For convenience (same as LeftEnpoint.Point).
LeftEndpoint
Gets left interval endpoint.
Declaration
public TEndpoint LeftEndpoint { get; }
Property Value
Type | Description |
---|---|
TEndpoint |
PointMaxValue
Gets the point maximum value.
Declaration
protected abstract TPoint PointMaxValue { get; }
Property Value
Type | Description |
---|---|
TPoint |
PointMinValue
Gets the point minimum value.
Declaration
protected abstract TPoint PointMinValue { get; }
Property Value
Type | Description |
---|---|
TPoint |
Right
Gets right endpoint value.
Declaration
public TPoint Right { get; }
Property Value
Type | Description |
---|---|
TPoint |
Remarks
For convenience (same as LeftEnpoint.Point).
RightEndpoint
Gets right interval endpoint.
Declaration
public TEndpoint RightEndpoint { get; }
Property Value
Type | Description |
---|---|
TEndpoint |
Span
Gets the span (or "diameter") of the interval.
Declaration
public TSpan Span { get; }
Property Value
Type | Description |
---|---|
TSpan |
SpanMaxValue
Gets the span maximum value.
Declaration
protected abstract TSpan SpanMaxValue { get; }
Property Value
Type | Description |
---|---|
TSpan |
SpanMinValue
Gets the span minimum value.
Declaration
protected abstract TSpan SpanMinValue { get; }
Property Value
Type | Description |
---|---|
TSpan |
SpanZeroValue
Gets the span zero value.
Declaration
protected abstract TSpan SpanZeroValue { get; }
Property Value
Type | Description |
---|---|
TSpan |
Methods
View SourceComparePoints(TPoint, TPoint)
Compare points.
Declaration
protected abstract int ComparePoints(TPoint a, TPoint b)
Parameters
Type | Name | Description |
---|---|---|
TPoint | a | First point. |
TPoint | b | Second point. |
Returns
Type | Description |
---|---|
System.Int32 | Less (-1), greater (+1) or equal (0). |
Coverage(IEnumerable<Interval<TPoint, TSpan, TEndpoint, T>>, Func<TEndpoint, TEndpoint, T>, Interval<TPoint, TSpan, TEndpoint, T>)
Determine coverage from minimum left to maximum right.
Declaration
protected static T Coverage(IEnumerable<Interval<TPoint, TSpan, TEndpoint, T>> intervals, Func<TEndpoint, TEndpoint, T> ctor, Interval<TPoint, TSpan, TEndpoint, T> empty)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<Interval<TPoint, TSpan, TEndpoint, T>> | intervals | Sequence of intervals. |
Func<TEndpoint, TEndpoint, T> | ctor | Constructor function for interval type. |
Interval<TPoint, TSpan, TEndpoint, T> | empty | Empty instance. |
Returns
Type | Description |
---|---|
T | Interval from minimum left to maximum right value (or empty). |
Remarks
Returns empty interval when sequence is empty or contains only empty intervals.
Difference(TPoint, TPoint)
Determine span between two given points.
Declaration
protected abstract TSpan Difference(TPoint x, TPoint y)
Parameters
Type | Name | Description |
---|---|---|
TPoint | x | First point. |
TPoint | y | Second point. |
Returns
Type | Description |
---|---|
TSpan | Span between points. |
Intersection(IEnumerable<Interval<TPoint, TSpan, TEndpoint, T>>, Func<TEndpoint, TEndpoint, T>, Interval<TPoint, TSpan, TEndpoint, T>)
Determine intersection of intervals.
Declaration
protected static T Intersection(IEnumerable<Interval<TPoint, TSpan, TEndpoint, T>> intervals, Func<TEndpoint, TEndpoint, T> ctor, Interval<TPoint, TSpan, TEndpoint, T> empty)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<Interval<TPoint, TSpan, TEndpoint, T>> | intervals | Sequence of intervals. |
Func<TEndpoint, TEndpoint, T> | ctor | Constructor function for interval type. |
Interval<TPoint, TSpan, TEndpoint, T> | empty | Empty instance. |
Returns
Type | Description |
---|---|
T | Intersection of intervals. |
Remarks
Returns empty interval when sequence is empty or contains only empty intervals.
IntersectsWith(IInterval<TPoint, TSpan, TEndpoint, T>)
Determine whether this interval intersects another.
Declaration
public bool IntersectsWith(IInterval<TPoint, TSpan, TEndpoint, T> other)
Parameters
Type | Name | Description |
---|---|---|
IInterval<TPoint, TSpan, TEndpoint, T> | other | Other interval. |
Returns
Type | Description |
---|---|
System.Boolean | Whether there is an intersection. |
Remarks
Same as !Disjoint(...)
IsDisjointFrom(IInterval<TPoint, TSpan, TEndpoint, T>)
Determine whether this interval is disjoint with another.
Declaration
public bool IsDisjointFrom(IInterval<TPoint, TSpan, TEndpoint, T> other)
Parameters
Type | Name | Description |
---|---|---|
IInterval<TPoint, TSpan, TEndpoint, T> | other | Other interval. |
Returns
Type | Description |
---|---|
System.Boolean | Whether there is an intersection. |
Remarks
Same as !Intersects(...)
IsProperSubsetOf(IInterval<TPoint, TSpan, TEndpoint, T>)
Determine whether this interval is a proper subset of another.
Declaration
public bool IsProperSubsetOf(IInterval<TPoint, TSpan, TEndpoint, T> other)
Parameters
Type | Name | Description |
---|---|---|
IInterval<TPoint, TSpan, TEndpoint, T> | other | Other interval. |
Returns
Type | Description |
---|---|
System.Boolean | Whether this is a subset of the other. |
Remarks
Subset and not equal (see IsSubsetOf(IInterval<TPoint, TSpan, TEndpoint, T>)).
IsSubsetOf(IInterval<TPoint, TSpan, TEndpoint, T>)
Determine whether this interval is a subset of another.
Declaration
public bool IsSubsetOf(IInterval<TPoint, TSpan, TEndpoint, T> other)
Parameters
Type | Name | Description |
---|---|---|
IInterval<TPoint, TSpan, TEndpoint, T> | other | Other interval. |
Returns
Type | Description |
---|---|
System.Boolean | Whether this is a subset of the other. |
Remarks
Subset may be equal (see IsProperSubsetOf(IInterval<TPoint, TSpan, TEndpoint, T>)).
Merge(IEnumerable<Interval<TPoint, TSpan, TEndpoint, T>>, Func<TEndpoint, TEndpoint, T>)
Merges a specified set of intervals into a set of non-overlapping intervals that cover the specified intervals.
Declaration
protected static IEnumerable<T> Merge(IEnumerable<Interval<TPoint, TSpan, TEndpoint, T>> intervals, Func<TEndpoint, TEndpoint, T> ctor)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<Interval<TPoint, TSpan, TEndpoint, T>> | intervals | A set of intervals to cover. |
Func<TEndpoint, TEndpoint, T> | ctor | Constructor function for interval type. |
Returns
Type | Description |
---|---|
IEnumerable<T> | A set of non-overlapping intervals that cover the given intervals. |
NegateSpan(TSpan)
Negate span.
Declaration
protected abstract TSpan NegateSpan(TSpan span)
Parameters
Type | Name | Description |
---|---|---|
TSpan | span | Span to be negated. |
Returns
Type | Description |
---|---|
TSpan | Negated span. |
PointIsWithin(TPoint)
Determines whether a point is within the interval.
Declaration
public bool PointIsWithin(TPoint point)
Parameters
Type | Name | Description |
---|---|---|
TPoint | point | Point value to be tested. |
Returns
Type | Description |
---|---|
System.Boolean | Whether the point is within the interval. |
Remarks
Taking into account the inclusive/exclusive endpoints.
Scale(TSpan, TSpan)
Scale endpoints by span distances.
Declaration
public abstract T Scale(TSpan left, TSpan right)
Parameters
Type | Name | Description |
---|---|---|
TSpan | left | Span by which to scale left. |
TSpan | right | Span by which to scale right. |
Returns
Type | Description |
---|---|
T | Scaled interval. |
Scale(TSpan, TSpan, Func<TPoint, Boolean, Boolean, TPoint, Boolean, Boolean, T>)
Scale by a span distance (helper for concrete instances).
Declaration
protected T Scale(TSpan left, TSpan right, Func<TPoint, bool, bool, TPoint, bool, bool, T> ctor)
Parameters
Type | Name | Description |
---|---|---|
TSpan | left | Span by which to scale left. |
TSpan | right | Span by which to scale right. |
Func<TPoint, System.Boolean, System.Boolean, TPoint, System.Boolean, System.Boolean, T> | ctor | Constructor function for concrete instance (T). |
Returns
Type | Description |
---|---|
T | Constructed T. |
Remarks
Calls ctor
function with constructor args.
Scale(Double, Double, Func<TPoint, Boolean, Boolean, TPoint, Boolean, Boolean, T>)
Scale by a factor (helper for concrete instances).
Declaration
protected T Scale(double left, double right, Func<TPoint, bool, bool, TPoint, bool, bool, T> ctor)
Parameters
Type | Name | Description |
---|---|---|
System.Double | left | Factor by which to scale left. |
System.Double | right | Factor by which to scale right. |
Func<TPoint, System.Boolean, System.Boolean, TPoint, System.Boolean, System.Boolean, T> | ctor | Constructor function for concrete instance (T). |
Returns
Type | Description |
---|---|
T | Constructed T. |
Remarks
Calls ctor
function with constructor args.
Scale(Single, Single)
Scale endpoints by factors.
Declaration
public abstract T Scale(float left, float right)
Parameters
Type | Name | Description |
---|---|---|
Single | left | Factor by which to scale left. |
Single | right | Factor by which to scale right. |
Returns
Type | Description |
---|---|
T | Scaled interval. |
ScaleCenter(TSpan)
Scale center point by a span distance (helper for concrete instances).
Declaration
public T ScaleCenter(TSpan span)
Parameters
Type | Name | Description |
---|---|---|
TSpan | span | Span by which to scale. |
Returns
Type | Description |
---|---|
T | Constructed interval. |
ScaleCenter(Single)
Scale center point by a factor (helper for concrete instances).
Declaration
public T ScaleCenter(float factor)
Parameters
Type | Name | Description |
---|---|---|
Single | factor | Factor by which to scale. |
Returns
Type | Description |
---|---|
T | Constructed interval. |
ScaleLeft(TSpan)
Scale left point by a span distance.
Declaration
public T ScaleLeft(TSpan span)
Parameters
Type | Name | Description |
---|---|---|
TSpan | span | Span by which to scale. |
Returns
Type | Description |
---|---|
T | Constructed interval. |
ScaleLeft(Single)
Scale left point by a factor (helper for concrete instances).
Declaration
public T ScaleLeft(float factor)
Parameters
Type | Name | Description |
---|---|---|
Single | factor | Factor by which to scale. |
Returns
Type | Description |
---|---|
T | Constructed interval. |
ScaleRight(TSpan)
Scale right point by a span distance (helper for concrete instances).
Declaration
public T ScaleRight(TSpan span)
Parameters
Type | Name | Description |
---|---|---|
TSpan | span | Span by which to scale. |
Returns
Type | Description |
---|---|
T | Constructed interval. |
ScaleRight(Single)
Scale right point by a factor (helper for concrete instances).
Declaration
public T ScaleRight(float factor)
Parameters
Type | Name | Description |
---|---|---|
Single | factor | Factor by which to scale. |
Returns
Type | Description |
---|---|
T | Constructed interval. |
ScaleSpan(TSpan, Double)
Scale a span by a given factor.
Declaration
protected abstract TSpan ScaleSpan(TSpan span, double factor)
Parameters
Type | Name | Description |
---|---|---|
TSpan | span | Span value. |
System.Double | factor | Factor by which to scale. |
Returns
Type | Description |
---|---|
TSpan | Scaled span. |
Translate(TSpan)
Translate by a span distance.
Declaration
public abstract T Translate(TSpan span)
Parameters
Type | Name | Description |
---|---|---|
TSpan | span | Span by which to translate. |
Returns
Type | Description |
---|---|
T | Translated interval. |
Remarks
Unbound points do not change.
Translate(TSpan, Func<TPoint, Boolean, Boolean, TPoint, Boolean, Boolean, T>)
Translate by a span distance (helper for concrete instances).
Declaration
protected T Translate(TSpan span, Func<TPoint, bool, bool, TPoint, bool, bool, T> ctor)
Parameters
Type | Name | Description |
---|---|---|
TSpan | span | Span by which to translate. |
Func<TPoint, System.Boolean, System.Boolean, TPoint, System.Boolean, System.Boolean, T> | ctor | Constructor function for concrete instance (T). |
Returns
Type | Description |
---|---|
T | Constructed T. |
Remarks
Calls ctor
function with constructor args.
TranslatePoint(TPoint, TSpan)
Translate point by given span.
Declaration
protected abstract TPoint TranslatePoint(TPoint point, TSpan span)
Parameters
Type | Name | Description |
---|---|---|
TPoint | point | Point value. |
TSpan | span | Span by which to translate. |
Returns
Type | Description |
---|---|
TPoint | Translated point. |
Operators
View SourceAddition(Interval<TPoint, TSpan, TEndpoint, T>, TSpan)
Translate by a span distance.
Declaration
public static T operator +(Interval<TPoint, TSpan, TEndpoint, T> interval, TSpan span)
Parameters
Type | Name | Description |
---|---|---|
Interval<TPoint, TSpan, TEndpoint, T> | interval | Interval to translate. |
TSpan | span | Span by which to translate. |
Returns
Type | Description |
---|---|
T | Translated interval. |
Remarks
Unbound points do not change.
Subtraction(Interval<TPoint, TSpan, TEndpoint, T>, TSpan)
Translate by a span distance.
Declaration
public static T operator -(Interval<TPoint, TSpan, TEndpoint, T> interval, TSpan span)
Parameters
Type | Name | Description |
---|---|---|
Interval<TPoint, TSpan, TEndpoint, T> | interval | Interval to translate. |
TSpan | span | Span by which to translate. |
Returns
Type | Description |
---|---|
T | Translated interval. |
Remarks
Unbound points do not change.