| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="NumericRange.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System; |
| | | 8 | | using System.Numerics; |
| | | 9 | | |
| | | 10 | | namespace MyNet.Primitives.Intervals; |
| | | 11 | | |
| | | 12 | | /// <summary> |
| | | 13 | | /// Represents a closed numeric interval where both the start and end boundaries are defined and are inclusive. This cla |
| | | 14 | | /// </summary> |
| | 39 | 15 | | public sealed class NumericRange<T>(T start, T end) : NumericInterval<T, NumericRange<T>>(new IntervalBoundary<T>(start) |
| | | 16 | | where T : struct, INumber<T>, IMinMaxValue<T> |
| | | 17 | | { |
| | | 18 | | /// <summary> |
| | | 19 | | /// Gets the start boundary of the interval, which is guaranteed to be inclusive. This property returns an <see cref |
| | | 20 | | /// </summary> |
| | 6 | 21 | | IntervalBoundary<T> IBoundedInterval<T>.Start => Start!.Value; |
| | | 22 | | |
| | | 23 | | /// <summary> |
| | | 24 | | /// Gets the end boundary of the interval, which is guaranteed to be inclusive. This property returns an <see cref=" |
| | | 25 | | /// </summary> |
| | 3 | 26 | | IntervalBoundary<T> IBoundedInterval<T>.End => End!.Value; |
| | | 27 | | |
| | | 28 | | /// <inheritdoc /> |
| | | 29 | | protected override NumericRange<T> Create(IntervalBoundary<T>? start, IntervalBoundary<T>? end) => |
| | 9 | 30 | | !start.HasValue || !end.HasValue |
| | 9 | 31 | | ? throw new InvalidOperationException("NumericRange must be bounded.") |
| | 9 | 32 | | : !start.Value.IsInclusive || !end.Value.IsInclusive |
| | 9 | 33 | | ? throw new InvalidOperationException("NumericRange only supports inclusive boundaries.") |
| | 9 | 34 | | : new(start.Value.Value, end.Value.Value); |
| | | 35 | | } |
| | | 36 | | |