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 TypeMethodDescriptionint
begin()
Returns the value of thebegin
record component.int
center()
Returns the center of this Interval.boolean
contains
(int value) Returns whether the given value is within [begin, begin + length).int
distance
(int point) Calculates the distance to givenpoint
.int
end()
Returns the end of this Interval.final boolean
Indicates 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 int
getRightMostIntervalIndex
(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 int
hashCode()
Returns a hash code value for this object.boolean
intersects
(Interval interval) boolean
isEmpty()
Checks whether the Interval has zero length.boolean
isLeadingOf
(Interval interval) boolean
isTrailingOf
(Interval interval) int
length()
Returns the value of thelength
record component.final String
toString()
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 aInterval
record class.- Parameters:
begin
- the value for thebegin
record componentlength
- the value for thelength
record 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:
true
if 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 inputInterval
and 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
begin
andlength
. - 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:
true
if thisInterval
is empty.- Since:
- 3.13
-
intersects
-
isLeadingOf
- Parameters:
interval
- The Interval to compare with.- Returns:
true
if this interval leads the giveninterval
, i.e. for horizontal intervalisLeadingOf()
returnstrue
if this interval begins at the left of the given interval.- Since:
- 3.13
-
isTrailingOf
- Parameters:
interval
- The Interval to compare with.- Returns:
true
if this interval trails the giveninterval
, i.e. for horizontal intervalisTrailingOf()
returnstrue
if 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
-1
if 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 thebegin
record component.- Returns:
- the value of the
begin
record component
-
length
public int length()Returns the value of thelength
record component.- Returns:
- the value of the
length
record component
-