Package org.eclipse.draw2d.geometry
Record Class Interval
java.lang.Object
java.lang.Record
org.eclipse.draw2d.geometry.Interval
- All Implemented Interfaces:
- Serializable
Represents interval in 1-dimensional space.
- Since:
- 3.13
- See Also:
- 
Field SummaryFields
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionintbegin()Returns the value of thebeginrecord component.intcenter()Returns the center of this Interval.booleancontains(int value) Returns whether the given value is within [begin, begin + length).intdistance(int point) Calculates the distance to givenpoint.intend()Returns the end of this Interval.final booleanIndicates whether some other object is "equal to" this one.getCopy()Returns a new Interval which has the exact same parameters as this Interval.getIntersection(Interval interval) static intgetRightMostIntervalIndex(Interval[] intervals, int value) We can use this method for example for span support.growLeading(int delta) Calculates a new interval where its leading direction has been increased by the givendelta(ex., grow left for horizontal interval).growTrailing(int delta) Calculates a new interval where its trailing direction has been increased by the givendelta(ex., grow right for horizontal interval).final inthashCode()Returns a hash code value for this object.booleanintersects(Interval interval) booleanisEmpty()Checks whether the Interval has zero length.booleanisLeadingOf(Interval interval) booleanisTrailingOf(Interval interval) intlength()Returns the value of thelengthrecord component.final StringtoString()Returns a string representation of this record class.
- 
Field Details- 
INFINITE
 
- 
- 
Constructor Details- 
Intervalpublic Interval()Creates a new Interval with zero length and starting at the origin.- Since:
- 3.13
 
- 
IntervalCreates a new Interval exact same parameters as the given Interval.- Parameters:
- interval- The interval to copy
- Since:
- 3.13
 
- 
Intervalpublic Interval(int begin, int length) Creates an instance of aIntervalrecord class.- Parameters:
- begin- the value for the- beginrecord component
- length- the value for the- lengthrecord component
 
 
- 
- 
Method Details- 
centerpublic int center()Returns the center of this Interval. The center is the middle of the begin and the end.- Returns:
- the center of this Interval.
- Since:
- 3.13
 
- 
containspublic boolean contains(int value) Returns whether the given value is within [begin, begin + length).- Parameters:
- value- A position somewhere within 1-dimensional space.
- Returns:
- trueif the value is contained by this interval.
- Since:
- 3.13
 
- 
distancepublic int distance(int point) Calculates the distance to givenpoint. Example:Let x=[10, 100]: distance for point 3 is 7. distance for point 10 is 0. distance for point 50 is 0. distance for point 110 is 0. distance for point 150 is 40.- Parameters:
- point- the point to calculate the distance to.
- Returns:
- the calculated distance.
- Since:
- 3.13
 
- 
endpublic int end()Returns the end of this Interval. The end is the sum of the begin and the length of this Interval.- Returns:
- end of this Interval
- Since:
- 3.13
 
- 
getCopyReturns a new Interval which has the exact same parameters as this Interval.- Returns:
- copy of this Interval
- Since:
- 3.13
 
- 
getIntersectionCalculates the intersection of the inputIntervaland thisInterval. I.e. the interval that is shared by both Intervals. If both Intervals are disjoint, an empty Interval is returned.- Parameters:
- interval- The Interval to intersect with.
- Returns:
- The intersection of the input Interval and this Interval.
- Since:
- 3.13
 
- 
growLeadingCalculates a new interval where its leading direction has been increased by the givendelta(ex., grow left for horizontal interval).- Parameters:
- delta- the value to increase the interval to.
- Returns:
- The new interval with adjusted beginandlength.
- Since:
- 3.13
 
- 
growTrailingCalculates a new interval where its trailing direction has been increased by the givendelta(ex., grow right for horizontal interval).- Parameters:
- delta- the value to increase the interval to.
- Returns:
- The new interval with adjusted length.
- Since:
- 3.13
 
- 
isEmptypublic boolean isEmpty()Checks whether the Interval has zero length.- Returns:
- trueif this- Intervalis empty.
- Since:
- 3.13
 
- 
intersects
- 
isLeadingOf- Parameters:
- interval- The Interval to compare with.
- Returns:
- trueif this interval leads the given- interval, i.e. for horizontal interval- isLeadingOf()returns- trueif this interval begins at the left of the given interval.
- Since:
- 3.13
 
- 
isTrailingOf- Parameters:
- interval- The Interval to compare with.
- Returns:
- trueif this interval trails the given- interval, i.e. for horizontal interval- isTrailingOf()returns- trueif this interval ends at the right of the given interval.
- Since:
- 3.13
 
- 
getRightMostIntervalIndexWe can use this method for example for span support.- Parameters:
- intervals- sorted, disjoint array of intervals
- Returns:
- index of rightmost interval that contains given value in its right
         half or -1if there is not such interval.
- Since:
- 3.13
 
- 
toStringReturns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
- 
hashCodepublic final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
- 
equalsIndicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with '=='.
- 
beginpublic int begin()Returns the value of thebeginrecord component.- Returns:
- the value of the beginrecord component
 
- 
lengthpublic int length()Returns the value of thelengthrecord component.- Returns:
- the value of the lengthrecord component
 
 
-