Prototype for LinearRange objects
To create an empty LinearRange:
var linear_range = new LinearRange();
To create a LinearRange contains integers from start to start+length excluded (i.e. [start, start+length) integers):
var linear_range = new LinearRange(start, length);
To create a copy of a LinearRange:
var linear_range2 = new LinearRange (linear_range1);
start, length. Integers. start and length of the range to
create
linear_range1. LinearRange object. Range to copy.
none.
ECMerge 2.1
LinearRange objects represents an interval in
integers' space for which you provide a start and a length. It
lets you compute intersections, containment tests and other
useful operations.
There is no order enforced on the start and end of the
LinearRange (i.e. length may be negative) but a function
order() is provided to have start and length always
such that start<=end if it is necessary for your
needs.
Property | Description |
is_empty | Boolean. Read-Only. True if this range is empty (i.e. length == 0). |
start | Integer. Start of the range. Modifying start also modifies end, keeping length untouched, such that end = length + start. |
end | Integer. End of the range. Modifyng end also modifies length, such that length = end - start |
length | Integer. Length of the range. Modifyng length also modifies end, such that end = length + start |
contains
empty
enlarge_to_contain
intersection
order
Creating a LinearRange containing integers from 5 to 9 (excluded).
var linear_range = new LinearRange (5, 4);
none.
function contains (range)
function contains (start, length)
returns a Boolean
range. LinearRange object.
Range that we test to know if it is contained by this
object.
start, lengh. Integers. Start and length as if
contains (LinearRange (start, length)) was called.
LinearRange object.
ECMerge 2.1
Returns true if the tested range is actually contained in this object. A range is considered contained inside another object:
Logs whether a range is contained by another (true in this case):
log (LinearRange (100, 10).contains (LinearRange (105, 5)));
LinearRange object
function empty ( )
none.
LinearRange object
ECMerge 2.1
Sets length and start to 0 (zero).
LinearRange object
function enlarge_to_contain (range)
function enlarge_to_contain (start, length)
range. LinearRange object.
Range that we to include in this object.
start, lengh. Integers. Start and length as
if enlarge_to_contain (LinearRange (start,
length)) was called.
LinearRange object.
ECMerge 2.1
Modifies this object such that all the integers in range are also included in this object.
Enlarges a range with another then logs the result:
var range = LinearRange (25, 50);
range.enlarge_to_contain (23, 40);
log ("start=" + range.start +", length=" +
range.length);
which prints:
start=23, length=52
LinearRange object
function intersection (range)
returns a LinearRange object
range. LinearRange object. Range for which we want to compute the intersection with this object.
LinearRange object.
ECMerge 2.1
Computes the intersection between this object and range and returns the result as a LinearRange object.
Intersects a range with another then logs the result:
var range = LinearRange (25, 50).intersection
(LinearRange (23, 40));
log ("start=" + range.start +", length=" +
range.length);
which prints:
start=25, length=38
LinearRange object
function order ( )
none.
LinearRange object.
ECMerge 2.1
Ensures that start is before or equal to end (and as such that length is positive or zero).
Re-orders a range with negative length then logs the result:
var range = LinearRange (25, -50);
ranger.order ();
log ("start=" + range.start +", length=" +
range.length);
which prints:
start=-25, length=50
LinearRange object