Clips a position to this span's boundary.
Clips a position to this span's boundary. Note that the span's stop position is included. Thus the result is greater than or equal the start, and less than or equal (!) the stop.
For the special cases of Span.All
and Span.Void
, this
method returns the argument unchanged.
the point to clip
the clipped point
Checks if another span lies within the span.
Checks if another span lies within the span. The result is false
if either of the two spans is void.
second span
true
, if that.start >= this.span && that.stop <= this.stop
Checks if a position lies within the span.
Checks if a position lies within the span. Note that this returns
false
if this.stop == pos
.
true
, if start <= pos < stop
Construct the intersection between this and another span.
Construct the intersection between this and another span. If the two spans are
disjoint, the result will be empty. An empty result may be a Span
if the two spans
touched each other, or Span.Void
if they did not touch each other. If either span is
Span.All
, the other span is returned. If either span is void, Span.Void
will be
returned.
This method is commutative (a intersect b == b intersect a
).
the span to form the intersection with
the intersection span (possibly empty)
Checks if the span is empty.
Checks if the span is empty. A span is empty if it is
a Span
with start == stop
or if it is void.
true
, if start == stop
The span's length.
The span's length. For a void span, this is zero, otherwise it is
stop - start
.
Checks if the span is non empty.
Checks if the span is non empty. This is exactly the opposite
value of isEmpty
.
Checks if a two spans overlap each other.
Checks if a two spans overlap each other. Two spans overlap if the overlapping area
is greater than or equal to 1. This implies that if either span is empty, the result
will be false
.
This method is commutative (a overlaps b == b overlaps a
).
second span
true
, if the spans
overlap each other
Shifts the span, that is applies an offset to its start and stop.
Shifts the span, that is applies an offset to its start and stop.
For single sided open spans (Span.From
and Span.Until
) this
alters the only bounded value. For Span.All
and Span.Void
this returns the object unchanged.
the shift amount (the amount to be added to the span's positions)
the shifted span
the start position of the span. this is considered included in the interval
the stop position of the span. this is considered excluded in the interval
Subtracts a given span from this span.
Subtracts a given span from this span. Note that an empty span argument "cuts" this span,
e.g. Span.all subtract Span(30,30) == Seq(Span.until(30),Span.from(30))
the span to subtract
a collection of spans after the argument was subtracted. Unlike intersect
, this method
filters out empty spans, thus a span subtracted from itself produces an empty collection.
if that
is a Span
, the result might be two disjoint spans.
Substracts a given open span from this span.
Substracts a given open span from this span.
the span to subtract
the reduced span, possibly empty or void
Checks if a two spans overlap or touch each other.
Checks if a two spans overlap or touch each other. Two spans touch each other if they either overlap or they share a common point with each other (this span's start or stop is that span's start or stop).
This method is commutative (a touches b == b touches a
).
second span
true
, if the spans touch each other
Constructs a single span which contains both this
and that
span.
Constructs a single span which contains both this
and that
span. If the two spans
are disjoint, the result will be a span with start = min(this.start, that.start)
and
stop = max(this.stop, that.stop)
. If either span is void, the other span is returned.
If either span is Span.All
, Span.All
will be returned.
This method is commutative (a union b == b union a
).
the span to form the union with
the encompassing span
Compares the span's start to a given position
Compares the span's stop to a given position