Skip to content

Commit e54ecf1

Browse files
author
Mykyta Zotov
committed
Feature: Refine distance calculation and improve exception messages in RangeData
1 parent 002b025 commit e54ecf1

4 files changed

Lines changed: 7 additions & 9 deletions

File tree

src/Domain/Intervals.NET.Domain.Extensions/Variable/RangeDomainExtensions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ public static RangeValue<double> Span<TRangeValue, TDomain>(this Range<TRangeVal
122122
return HandleSingleStepCase(range, domain);
123123
}
124124

125-
var distance = domain.Distance(firstStep, lastStep);
125+
// Note: IRangeDomain.Distance returns long, but for variable-step domains we interpret
126+
// this as the number of complete steps and add 1.0 to get the span including boundaries
127+
var distance = (double)domain.Distance(firstStep, lastStep);
126128
return distance + 1.0;
127129

128130
// Local functions

src/Intervals.NET.Data/Extensions/RangeDataExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ private static void ValidateDomainEquality<TRangeType, TDataType, TRangeDomain>(
5353
where TRangeType : IComparable<TRangeType>
5454
where TRangeDomain : IRangeDomain<TRangeType>
5555
{
56-
if (!left.Domain.Equals(right.Domain))
56+
if (!EqualityComparer<TRangeDomain>.Default.Equals(left.Domain, right.Domain))
5757
{
5858
throw new ArgumentException(
5959
$"Cannot {operationName} RangeData objects with different domain instances. " +

src/Intervals.NET.Data/RangeData.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,12 @@ public RangeData(Range<TRangeType> range, IEnumerable<TDataType> data, TRangeDom
7373
/// The point within the range for which to retrieve the data element.
7474
/// </param>
7575
/// <exception cref="IndexOutOfRangeException">
76-
/// Thrown if the calculated index is outside the bounds of the data collection.
76+
/// Thrown if no data element is available for the specified point, for example because the point is
77+
/// outside the range or the underlying data sequence does not provide a value for that point.
7778
/// </exception>
7879
public TDataType this[TRangeType point] => TryGet(point, out var data)
7980
? data!
80-
: throw new IndexOutOfRangeException($"The point {point} is outside the bounds of the range data.");
81+
: throw new IndexOutOfRangeException($"No data element is available for point {point} in this RangeData (point may be outside the range or the underlying data sequence may be too short).");
8182

8283
/// <summary>
8384
/// Gets the data elements corresponding to the specified sub-range within the range,

tests/Intervals.NET.Data.Tests/RangeDataTests.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,6 @@ public void SubRangeIndexer_OpenRange_EmptyRange_ReturnsEmpty()
166166
[Fact]
167167
public void SubRangeIndexer_OpenRange_SinglePointRange_ThrowsArgumentException()
168168
{
169-
// Arrange
170-
var range = Range.Closed<int>(0, 10);
171-
var data = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
172-
var rangeData = new RangeData<int, int, IntegerFixedStepDomain>(range, data, _domain);
173-
174169
// Act - Get (5, 5) → should throw because (5, 5) is invalid (start == end with both exclusive)
175170
var exception = Record.Exception(() => Range.Open(5, 5));
176171

0 commit comments

Comments
 (0)