gwexpy.segments.Segment
- class gwexpy.segments.Segment(iterable=(), /)[source]
Bases:
segment,Generic[T]A tuple defining a semi-open interval
[start, end).Each Segment represents the range of values in a given interval, with general arithmetic supported for combining/comparing overlapping segments.
- Parameters:
start (float) – The start value of this Segment.
end (float) – The end value of this Segment.
Examples
>>> Segment(0, 10) & Segment(5, 15) Segment(5, 10) >>> Segment(0, 10) | Segment(5, 15) Segment(0, 15) >>> Segment(0, 10) - Segment(5, 15) Segment(0, 5) >>> Segment(0, 10) < Segment(5, 15) True >>> Segment(1, 2) in Segment(0, 10) True >>> Segment(1, 11) in Segment(0, 10) False >>> Segment(0, 1) Segment(0, 1) >>> Segment(1, 0) Segment(0, 1) >>> bool(Segment(0, 1)) True
- __init__()
Methods
__init__()connectsReturns True if ths segment and other touch but do not overlap
contractReturn a new segment whose bounds are given by adding x to the segment's lower bound and subtracting x from the segment's upper bound.
count(value, /)Return number of occurrences of value.
disjointReturns >0 if self covers an interval above other's interval, <0 if self covers an interval below other's, or 0 if the two intervals are not disjoint (intersect or touch).
index(value[, start, stop])Return first index of value.
intersectsReturn True if the intersection of self and other is not a null segment.
protractReturn a new segment whose bounds are given by subtracting x from the segment's lower bound and adding x to the segment's upper bound.
shiftReturn a new segment whose bounds are given by adding x to the segment's upper and lower bounds.
Attributes
endThe end of this segment.
startThe beginning of this segment.
- property start: T
The beginning of this segment.
- property end: T
The end of this segment.