Description
In issue #44 it became apparent that functions to work with ranges would be useful, including adding functions to get the length of a range.
After playing around with the existing simple structure and the TRangeEx
advanced record it seems that newer advanced records would be useful.
We can't adapt TRangeEx
because its constructor doesn't normalise the range so that the smallest value is the lowest. Changing the behaviour of that constructor isn't viable since doing that could break existing code.
So two new advanced records are proposed: TDoubleRange
and TIntegerRange
.
Each should have the following attributes and methods:
- The range should be normalised so that the lower bound <= the upper bound. This should be enforced by the constructor.
- The range should be immutable => the fields should be hidden and accessed via read-only properties.
- There should be a
Contains
method. - There should be a
Length
method. - There should be a
Constrain
method to ensure a value fits into range.
We will allow a range of zero length where the upper and lower bounds are the same.
Question: should we have an enumeration that allows us to specify whether the bounds and inclusive or exclusive? If so should that be an immutable property of the range or should it just be passed to relevant functions. Should such a property only be applied to real ranges and not to integer ranges.
Sub-issues
Metadata
Metadata
Assignees
Projects
Status