TedToolkit.Mathematics.Interval
2026.6.23.1
dotnet add package TedToolkit.Mathematics.Interval --version 2026.6.23.1
NuGet\Install-Package TedToolkit.Mathematics.Interval -Version 2026.6.23.1
<PackageReference Include="TedToolkit.Mathematics.Interval" Version="2026.6.23.1" />
<PackageVersion Include="TedToolkit.Mathematics.Interval" Version="2026.6.23.1" />
<PackageReference Include="TedToolkit.Mathematics.Interval" />
paket add TedToolkit.Mathematics.Interval --version 2026.6.23.1
#r "nuget: TedToolkit.Mathematics.Interval, 2026.6.23.1"
#:package TedToolkit.Mathematics.Interval@2026.6.23.1
#addin nuget:?package=TedToolkit.Mathematics.Interval&version=2026.6.23.1
#tool nuget:?package=TedToolkit.Mathematics.Interval&version=2026.6.23.1
TedToolkit.Mathematics.Interval
TedToolkit.Mathematics.Interval provides explicit interval types and normalized interval sets for .NET.
Use it when your code needs correct boundary behavior instead of manually coordinating min, max, and inclusive/exclusive flags.
Installation
dotnet add package TedToolkit.Mathematics.Interval
Core Types
IntervalEnd<TData>
Represents one endpoint value together with its boundary type:
BoundaryType.CLOSEDBoundaryType.OPEN
Interval<TData>
Represents a single interval.
- endpoints are exposed as
MinandMax Create(start, end, out isReversed)orders the endpoints for youIsEmptyreports whether the interval contains no valuesIsInside,Clamp,GetRelationTo,IsAdjacentTo, andToIntervalSetexpose the main operations
TData must implement IComparable<TData>.
IntervalSet<TData>
Represents a normalized set of intervals.
When you construct it from multiple intervals:
- empty intervals are removed
- intervals are sorted
- overlapping or adjacent intervals are merged
It also provides Union, Intersect, and Difference.
RelationType
Represents the relationship between two operands:
DisjointOverlappingProperSupersetProperSubsetEqual
Basic Usage
using TedToolkit.Mathematics.Interval;
var closed = Interval<int>.Create(1, 5, out _);
var openLeft = Interval<int>.Create(
new IntervalEnd<int>(1, BoundaryType.OPEN),
new IntervalEnd<int>(5),
out _);
Console.WriteLine(closed.IsInside(1)); // True
Console.WriteLine(openLeft.IsInside(1)); // False
Console.WriteLine(closed.GetRelationTo(openLeft)); // ProperSuperset
String formatting follows mathematical interval notation:
Console.WriteLine(closed); // [1, 5]
Console.WriteLine(openLeft); // (1, 5]
Special cases:
- a singleton interval prints as the value itself, for example
1 - an empty interval prints as
Ø
Interval Sets
IntervalSet<TData> normalizes overlapping or adjacent intervals automatically:
var set = new IntervalSet<int>(
Interval<int>.Create(1, 2, out _),
Interval<int>.Create(2, 4, out _),
Interval<int>.Create(6, 8, out _));
Console.WriteLine(set); // [1, 4] ∪ [6, 8]
Set operations are available directly:
var left = new IntervalSet<int>(Interval<int>.Create(1, 4, out _), Interval<int>.Create(6, 8, out _));
var right = new IntervalSet<int>(Interval<int>.Create(3, 7, out _));
Console.WriteLine(left.Intersect(right)); // [3, 4] ∪ [6, 7]
Console.WriteLine(left.Union(right)); // [1, 8]
Difference preserves boundary correctness:
var current = new IntervalSet<int>(Interval<int>.Create(1, 6, out _));
var removed = new IntervalSet<int>(Interval<int>.Create(3, 4, out _));
Console.WriteLine(current.Difference(removed)); // [1, 3) ∪ (4, 6]
Notes
- Empty intervals are represented explicitly and participate in comparisons.
ClampthrowsInvalidOperationExceptionfor an empty interval.- Adjacency is value-based and takes boundary openness into account.
Target Frameworks
net6.0net7.0net8.0net9.0net10.0net472net48netstandard2.0netstandard2.1
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 is compatible. net48 is compatible. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2026.6.23.1 | 126 | 6/23/2026 |
| 2026.6.23 | 119 | 6/23/2026 |