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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier 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
-
Interval
public Interval()Creates a new Interval with zero length and starting at the origin.- Since:
- 3.13
-
Interval
Creates a new Interval exact same parameters as the given Interval.- Parameters:
interval- The interval to copy- Since:
- 3.13
-
Interval
public Interval(int begin, int length) Creates an instance of aIntervalrecord class.- Parameters:
begin- the value for thebeginrecord componentlength- the value for thelengthrecord component
-
-
Method Details
-
center
public 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
-
contains
public 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
-
distance
public 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
-
end
public 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
-
getCopy
Returns a new Interval which has the exact same parameters as this Interval.- Returns:
- copy of this Interval
- Since:
- 3.13
-
getIntersection
Calculates 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
-
growLeading
Calculates 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
-
growTrailing
Calculates 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
-
isEmpty
public boolean isEmpty()Checks whether the Interval has zero length.- Returns:
trueif thisIntervalis empty.- Since:
- 3.13
-
intersects
-
isLeadingOf
- Parameters:
interval- The Interval to compare with.- Returns:
trueif this interval leads the giveninterval, i.e. for horizontal intervalisLeadingOf()returnstrueif 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 giveninterval, i.e. for horizontal intervalisTrailingOf()returnstrueif this interval ends at the right of the given interval.- Since:
- 3.13
-
getRightMostIntervalIndex
We 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
-
toString
Returns 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. -
hashCode
public 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. -
equals
Indicates 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 '=='. -
begin
public int begin()Returns the value of thebeginrecord component.- Returns:
- the value of the
beginrecord component
-
length
public int length()Returns the value of thelengthrecord component.- Returns:
- the value of the
lengthrecord component
-