Interval

final case class Interval[T](left: Mark[T], right: Mark[T])

Interval

Companion:
object
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any

Value members

Concrete methods

def canonical(using Domain[T]): Interval[T]

Canonical

Canonical

A canonical form of an interval is where the interval is closed on both starting and finishing sides:

[a-, a+]

Deflate

Deflate

Applies succ and pred functions to the left and right boundaries of an interval reducing it it.

When deflating, the operation might produce an empty interval, where left boundary is greater than the right boundary.

 [a-, a+] -> [succ(a-), pred(a+)]

Example:
 deflate([1, 2]) = [2, 1]

Deflate the left side of the interval

Deflate the left side of the interval

 [a-, a+] -> [succ(a-), a+]

Example:
 deflateLeft([1, 2]) = [2, 2]

Deflate the right side of the interval

Deflate the right side of the interval

 [a-, a+] -> [a-, pred(a+)]

Example:
 deflateRight([1, 2]) = [1, 1]

Inflate

Inflate

Applies pred and succ functions to the left and right boundaries of an interval extending it.

 [a-, a+] -> [pred(a-), succ(a+)]

Example:
 inflate([1, 2]) = [0, 3]

Inflate only the left side of the interval

Inflate only the left side of the interval

 [a-, a+] -> [pred(a-), a+]

Example:
 inflateLeft([1, 2]) = [0, 2]

Inflate only the right side of the interval

Inflate only the right side of the interval

 [a-, a+] -> [a-, succ(a+)]

Example:
 inflateLeft([1, 2]) = [0, 3]
def isEmpty(using ordM: Ordering[Mark[T]]): Boolean

Returns true if the interval is empty and false otherwise.

Returns true if the interval is empty and false otherwise.

def isPoint(using ordM: Ordering[Mark[T]]): Boolean

Returns true if the interval is degenerate (a point) or false otherwise.

Returns true if the interval is degenerate (a point) or false otherwise.

def isProper(using ordM: Ordering[Mark[T]]): Boolean

Returns true if the interval is proper and false otherwise.

Returns true if the interval is proper and false otherwise.

def nonEmpty(using Ordering[Mark[T]]): Boolean

Returns true if the interval is non-empty and false otherwise.

Returns true if the interval is non-empty and false otherwise.

def nonPoint(using Ordering[Mark[T]]): Boolean

Returns true if the interval is not a point and false otherwise.

Returns true if the interval is not a point and false otherwise.

def nonProper(using Ordering[Mark[T]]): Boolean

Returns true, if interval is not proper and false otherwise.

Returns true, if interval is not proper and false otherwise.

def normalize(using Domain[T]): Interval[T]

Normalize

Normalize

Reduces the amount of succ and pred operations so that the interval is represented in one of the following ways:

 [a-, a+]
 [a-, a+)
 (a-, a+)
 (a-, a+]
def swap: Interval[T]

Swap left and right boundary.

Swap left and right boundary.

Can be used to create an empty interval out of a non-empty one or vice-versa.

 [a-, a+] -> [a+, a-]

Inherited methods

final def after(b: Interval[T])(using Ordering[Mark[T]]): Boolean

After, IsPrecededBy (B)

After, IsPrecededBy (B)

Inherited from:
BasicRel (hidden)
final def before(b: Interval[T])(using ordM: Ordering[Mark[T]]): Boolean

Before, Precedes (b)

Before, Precedes (b)

 PP (Point-Point):
 {p}; {q}
 p < q

 PI (Point-Interval):
 {p}; {a-, a+}
 p < a-

 II (Interval-Interval):
 {a-, a+}; {b-, b+}
 a- < b-
 a- < b+
 a+ < b-
 a+ < b+

 a- < a+ < b- < b+

 Relation                  AAAAA
 before(a,b)      b        :   : BBBBBBBBB  |  a+ < b-
Inherited from:
BasicRel (hidden)
final def contains(b: Interval[T])(using ordM: Ordering[Mark[T]]): Boolean

Contains, ProperlyIncludes (D)

Contains, ProperlyIncludes (D)

Inherited from:
BasicRel (hidden)
final def during(b: Interval[T])(using ordM: Ordering[Mark[T]]): Boolean

During, ProperlyIncludedIn (d)

During, ProperlyIncludedIn (d)

 PI (Point-Interval):
 {p}; {a-, a+}
 a- < p < a+

 II (Interval-Interval):
 {a-, a+}; {b-; b+}
 a- > b-
 a- < b+
 a+ > b-
 a+ < b+

 b- < a- < a+ < b+

 Relation                  AAAAA
 during(a,b)      d|D    BBBBBBBBB          |  a- > b- ; a+ < b+
Inherited from:
BasicRel (hidden)
final def equalsTo(b: Interval[T])(using ordM: Ordering[Mark[T]]): Boolean

Equals (e)

Equals (e)

A = B

 PP (Point-Point):
 {p}; {q}
 p = q

 II (Interval-Interval):
 {a-, a+}; {b-; b+}
 a- = b-
 a- < b+
 a+ > b-
 a+ = b+

 a- = b- < a+ = b+

 Relation                  AAAAA
 equalsTo(a, b)   e        BBBBB            |  a- = b- ; a+ = b+
Inherited from:
BasicRel (hidden)
final def finishes(b: Interval[T])(using ordM: Ordering[Mark[T]]): Boolean

Finishes, Ends (f)

Finishes, Ends (f)

 PI (Point-Interval):
 {p}; {a-, a+}
 p = a+

 II (Interval-Interval):
 {a-, a+}; {b-; b+}
 a- > b-
 a- < b+
 a+ > b-
 a+ = b+

 b- < a- < a+ = b+

 Relation                  AAAAA
 finishes(a,b)    f|F  BBBBBBBBB            |  a+ = b+ ; a- > b-
Inherited from:
BasicRel (hidden)
final def gap(b: Interval[T])(using ordM: Ordering[Mark[T]], domT: Domain[T]): Interval[T]

Gap (Complement)

Gap (Complement)

  • A ∥ B

A gap between two intervals a and b: a ∥ b := [succ(min(a+, b+)), pred(max(a-, b-))].

 A ∥ B := [succ(min(a+, b+)), pred(max(a-, b-))]

 [***********]                          | [5,10]
                        [***********]   | [15,20]
               [******]                 | [11,14]
--+-----------+-+------+-+-----------+-- |
 5          10 11    14 15         20   |

Laws:

  • Commutative: A ∥ B = B ∥ A
Inherited from:
BasicOps (hidden)
final def intersection(b: Interval[T])(using ordM: Ordering[Mark[T]], domT: Domain[T]): Interval[T]

Intersection

Intersection

  • A ∩ B
  • A & B

An intersection of two intervals a and b is defined as the interval c, such that c = a ∩ b := [max(a-, b-), min(a+, b+)].

 A ∩ B := [max(a-, b-), min(a+, b+)]

                 [******************]   | [5,10]
 [**********************]               | [1,7]
                 [******]               | [5,7]
--+---------------+------+-----------+-- |
 1               5      7          10   |

Laws:

  • Commutative: A & B = B & A
  • Associative: (A & B) & C = A & (B & C)
Inherited from:
BasicOps (hidden)
final def intersects(b: Interval[T])(using ordM: Ordering[Mark[T]]): Boolean

Intersects

Intersects

Two intervals a and b are intersecting if:

 a- <= b+
 b- <= a+

 Relation                  AAAAA
 meets(a,b)       m|M      :   BBBBBBBBB    |  a+ = b-
 overlaps(a,b)    o|O      : BBBBBBBBB      |  a- < b- < a+ ; a+ < b+
 starts(a,b)      s|S      BBBBBBBBB        |  a- = b- ; a+ < b+
 during(a,b)      d|D    BBBBBBBBB          |  a- > b- ; a+ < b+
 finishes(a,b)    f|F  BBBBBBBBB            |  a+ = b+ ; a- > b-
 equals(a, b)     e        BBBBB            |  a- = b- ; a+ = b+
Inherited from:
ExtendedRel (hidden)
final def isAdjacent[T1 >: T : Domain](b: Interval[T])(implicit evidence$1: Domain[T1], ordM: Ordering[Mark[T]]): Boolean

IsAdjacent

IsAdjacent

Two intervals a and b are adjacent if:

 succ(a+) = b- OR succ(b+) = a-

 before | b
 after  | B
Inherited from:
ExtendedRel (hidden)
final def isDisjoint(b: Interval[T])(using ordM: Ordering[Mark[T]]): Boolean

IsDisjoint

IsDisjoint

Checks if there A and B are disjoint.

A and B are disjoint if A does not intersect B.

 a+ < b-
 a- > b+

before | b after | B }}}

Inherited from:
ExtendedRel (hidden)
final def isFinishedBy(b: Interval[T])(using ordM: Ordering[Mark[T]]): Boolean

IsFinishedBy (F)

IsFinishedBy (F)

Inherited from:
BasicRel (hidden)
final def isGreater(b: Interval[T])(using ordM: Ordering[Mark[T]]): Boolean

IsGreater

IsGreater

Checks whether A is greater-than B (Order Relation)

A > B

 b- < a-
Inherited from:
ExtendedRel (hidden)
final def isIntersectedBy(b: Interval[T])(using ordM: Ordering[Mark[T]]): Boolean

IsIntersectedBy

IsIntersectedBy

Inherited from:
ExtendedRel (hidden)
final def isLess(b: Interval[T])(using ordM: Ordering[Mark[T]]): Boolean

IsLess

IsLess

Checks whether A is less-than B (Order Relation)

A < B

 a- < b-
Inherited from:
ExtendedRel (hidden)
final def isMergedBy[T1 >: T : Domain](b: Interval[T])(implicit evidence$3: Domain[T1], ordM: Ordering[Mark[T]]): Boolean

IsMergedBy

IsMergedBy

Inherited from:
ExtendedRel (hidden)
final def isMetBy(b: Interval[T])(using Ordering[Mark[T]]): Boolean

IsMetBy (M)

IsMetBy (M)

Inherited from:
BasicRel (hidden)
final def isOverlappedBy(b: Interval[T])(using Ordering[Mark[T]]): Boolean

IsOverlappedBy (O)

IsOverlappedBy (O)

Inherited from:
BasicRel (hidden)
final def isStartedBy(b: Interval[T])(using ordM: Ordering[Mark[T]]): Boolean

IsStartedBy (S)

IsStartedBy (S)

Inherited from:
BasicRel (hidden)
final def isSubset(b: Interval[T])(using ordM: Ordering[Mark[T]]): Boolean

IsSubset

IsSubset

Checks whether A is a subset of B

A ⊆ B

 a- >= b-
 a+ <= b+

 starts   | s
 during   | d
 finishes | f
 equals   | e
Inherited from:
ExtendedRel (hidden)
final def isSuperset(b: Interval[T])(using ordM: Ordering[Mark[T]]): Boolean

IsSuperset

IsSuperset

Checks whether A is a superset of B

A ⊇ B

 b- >= a-
 b+ <= a+

 is-started-by  | S
 contains       | D
 is-finished-by | F
 equals         | e
Inherited from:
ExtendedRel (hidden)
final def meets(b: Interval[T])(using ordM: Ordering[Mark[T]]): Boolean

Meets (m)

Meets (m)

 II (Interval-Interval):
 {a-, a+}; {b-; b+}
 a- < b-
 a- < b+
 a+ = b-
 a+ < b+

 a- < a+ = b- < b+

 Relation                  AAAAA
 meets(a,b)       m        :   BBBBBBBBB    |  a+ = b-
Inherited from:
BasicRel (hidden)
final def merges[T1 >: T : Domain](b: Interval[T])(implicit evidence$2: Domain[T1], ordM: Ordering[Mark[T]]): Boolean

Merges

Merges

Two intervals a and b can be merged, if they are adjacent or intersect.

 a- <= b+
 b- <= a+
 OR
 succ(a+) = b- OR succ(b+) = a-

 intersects(a,b)
 isAdjacent(a,b)
Inherited from:
ExtendedRel (hidden)
final def minus(b: Interval[T])(using ordM: Ordering[Mark[T]], domT: Domain[T]): Interval[T]

Minus

Minus

Subtraction of two intervals, a minus b returns:

  • [a-, min(pred(b-), a+)] if (a- < b-) and (a+ <= b+)
  • [max(succ(b+), a-), a+] if (a- >= b-) and (a+ > b+)

NOTE: a.minus(b) is defined if and only if:

  • (a) a and b are disjoint;
  • (b) a contains either b- or b+ but not both;
  • (c) either b.starts(a) or b.finishes(a) is true;

NOTE: a.minus(b) is undefined if:

  • either a.starts(b) or a.finishes(b);
  • either a or b is properly included in the other;
Example #1: ((a- < b-) AND (a+ <= b+))   | [a-, min(pred(b-), a+)]

 [**********************]               | [1,10]
           [************************]   | [5,15]
 [*******]                              | [1,4]
--+-------+-+------------+-----------+-- |
 1       4 5           10          15   |

Example #2: ((a- >= b-) AND (a+ > b+))   | [max(succ(b+), a-), a+]

           [************************]   | [5,15]
 [**********************]               | [1,10]
                          [*********]   | [11,15]
--+---------+------------+-+---------+-- |
 1         5           10          15   |
Inherited from:
BasicOps (hidden)
final def overlaps(b: Interval[T])(using ordM: Ordering[Mark[T]]): Boolean

Overlaps (o)

Overlaps (o)

 II (Interval-Interval):
 {a-, a+}; {b-; b+}
 a- < b-
 a- < b+
 a+ > b-
 a+ < b+

 a- < b- < a+ < b+

 Relation                  AAAAA
 overlaps(a,b)    o        : BBBBBBBBB      |  a- < b- < a+ ; a+ < b+
Inherited from:
BasicRel (hidden)
def productElementNames: Iterator[String]
Inherited from:
Product
def productIterator: Iterator[Any]
Inherited from:
Product
final def span(b: Interval[T])(using ordM: Ordering[Mark[T]], domT: Domain[T]): Interval[T]

Span

Span

  • A # B

A span of two intervals a and b: a # b := [min(a-, b-), max(a+, b+)].

 A # B := [min(a-, b-), max(a+, b+)]

Example #1:

                 [******************]   | [5,10]
 [**********************]               | [1,7]
 [**********************************]   | [1,10]
--+---------------+------+-----------+-- |
 1               5      7          10   |

Example #2: (disjoint Intervals):

 [***************]                      | [1,5]
                        [***********]   | [7,10]
 [**********************************]   | [1,10]
--+---------------+------+-----------+-- |
 1               5      7          10   |

Laws:

  • Commutative: A # B = B # A
  • Associative: (A # B) # C = A # (B # C)
Inherited from:
BasicOps (hidden)
final def starts(b: Interval[T])(using ordM: Ordering[Mark[T]]): Boolean

Starts, Begins (s)

Starts, Begins (s)

 PI (Point-Interval):
 {p}; {a-, a+}
 p = a-

 II (Interval-Interval):
 {a-, a+}; {b-; b+}
 a- = b-
 a- < b+
 a+ > b-
 a+ < b+

 a- = b- < a+ < b+

 Relation                  AAAAA
 starts(a,b)      s|S      BBBBBBBBB        |  a- = b- ; a+ < b+
Inherited from:
BasicRel (hidden)
def union(b: Interval[T])(using ordM: Ordering[Mark[T]], domT: Domain[T]): Interval[T]

Union

Union

  • A ∪ B

A union of two intervals a and b: [min(a-,b-), max(a+,b+)] if merges(a, b) and undefined otherwise.

NOTE: merges means that the intervals are adjacent or intersecting.

 A union B := [min(a-,b-), max(a+,b+)] if merges(a, b) else ∅

Example #1:

 [***************]                      | [1,5]
                    [***************]   | [6,10]
 [**********************************]   | [1,10]
--+---------------+--+---------------+-- |
 1               5  6              10   |

Example #2: (disjoint and non-adjacent Intervals):

 [***********]                          | [1,4]
                    [***************]   | [6,10]
                                        | ∅
--+-----------+------+---------------+-- |
 1           4      6              10   |

Laws:

  • Commutative: A ∪ B = B ∪ A
Inherited from:
BasicOps (hidden)