Search this API

y.geom
Class BorderLine

java.lang.Object
  extended by y.geom.BorderLine

public class BorderLine
extends java.lang.Object

This class can be used to easily model an orthogonal border line or sky-line. It provides methods for measuring the distance between different BorderLine instances, merging multiple instances, modifying and efficiently moving them around.

 

Nested Class Summary
static class BorderLine.Segment
          The handle of a segment of a borderline.
 
Constructor Summary
BorderLine(double value)
          Creates a new BorderLine with the given value from -Double.MAX_VALUE to +Double.MAX_VALUE.
BorderLine(double min, double max, double value)
          Creates a new BorderLine from a single segment.
BorderLine(double min, double max, double valueAtMin, double valueAtMax)
          Creates a new BorderLine from a single segment.
 
Method Summary
 void addOffset(double delta)
          Adds the given offset to the segments' positions.
 void addValueOffset(double delta)
          Adds the given offset to the current values of the whole borderline.
 void adoptValues(BorderLine other)
          Convenience method that copies the actual data from the given argument to this instance.
 BorderLine createCopy(boolean negateValues, boolean negateOffsets)
          Creates a copy of this borderline.
 BorderLine createMax(BorderLine other)
          Merges this borderline with the given borderline using the "maximum" policy.
 BorderLine createMin(BorderLine other)
          Merges this borderline with the given borderline using the "minimum" policy.
 BorderLine.Segment firstSegment()
          Returns the first segment or null if there is no such segment.
 double getDistanceTo(BorderLine greater)
          Calculates the minimal distance between this borderline and the other one.
 double getMax()
          Returns the greatest position of this borderline
 double getMax(BorderLine.Segment s)
          Returns the maximum position of the given segment.
 double getMaxValue()
          Returns the maximum value that is set on this borderline
 double getMaxValue(double from, double to)
          Calculates the maximum value in the interval from->to.
 double getMin()
          Returns the smallest position of this borderline
 double getMin(BorderLine.Segment s)
          Returns the minimum position of the given segment.
 double getMinValue()
          Returns the minimum value that is set on this borderline
 double getMinValue(double from, double to)
          Calculates the minimum value in the interval from->to.
 BorderLine.Segment getSegmentAt(double pos)
          Returns the segment at the given position.
 double getSlope(BorderLine.Segment s)
          Returns the slope of the given segment.
 double getValue(BorderLine.Segment s)
          Returns the value of the minimum of the given segment.
 double getValueAt(BorderLine.Segment segment, double pos)
          Returns the value that is set on this borderline at the specified position.
 double getValueAt(double pos)
          Returns the value that is set on this borderline at the specified position.
 double getValueAt(ListCell cell, double pos)
          Returns the value that is set on this borderline at the specified position.
 void grow(double toMin, double toMax, boolean positive)
          Grows this borderline horizontally, so that the values of the borderline stay the same however their start and end points are moved in the direction of toMin and toMax.
 BorderLine.Segment lastSegment()
          Returns the last segment or null if there is no such segment.
 void mergeWithMax(BorderLine other)
          Merges this borderline with the given borderline using the "maximum" policy.
 void mergeWithMin(BorderLine other)
          Merges this borderline with the given borderline using the "minimum" policy.
 BorderLine.Segment next(BorderLine.Segment s)
          Returns the next segment or null if there is no such segment.
 BorderLine.Segment prev(BorderLine.Segment s)
          Returns the previous segment or null if there is no such segment.
 void setMaxValue(double min, double max, double value)
          Assures that all values in the given interval are greater or equal than the given value.
 void setMinValue(double min, double max, double value)
          Assures that all values in the given interval are less or equal than the given value.
 void setSloped(double min, double max, double value, double slope)
          Sets a specific interval to a slope starting at a given value.
 void setValue(double min, double max, double value)
          Sets a specific interval described by min and max to a given value.
 java.lang.String toString()
          Returns a lengthy String representation of this borderline.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BorderLine

public BorderLine(double value)
Creates a new BorderLine with the given value from -Double.MAX_VALUE to +Double.MAX_VALUE.

Parameters:
value - the value of the segment

BorderLine

public BorderLine(double min,
                  double max,
                  double value)
Creates a new BorderLine from a single segment.

Parameters:
min - the beginning of this borderline
max - the ending of this borderline
value - the value of the segment

BorderLine

public BorderLine(double min,
                  double max,
                  double valueAtMin,
                  double valueAtMax)
Creates a new BorderLine from a single segment.

Parameters:
min - the beginning of this borderline
max - the ending of this borderline
valueAtMin - the value of the segment at the beginning of this borderline
valueAtMax - the value of the segment at the ending of this borderline
Method Detail

createCopy

public BorderLine createCopy(boolean negateValues,
                             boolean negateOffsets)
Creates a copy of this borderline. Optionally negates the values or offsets.

Parameters:
negateValues - whether the values are negated
negateOffsets - whether the offsets are negated
Returns:
the copy of the borderline

setMinValue

public void setMinValue(double min,
                        double max,
                        double value)
Assures that all values in the given interval are less or equal than the given value.

Parameters:
min - the lower end of the interval
max - the upper end of the interval
value - the greatest possible value for the interval

setMaxValue

public void setMaxValue(double min,
                        double max,
                        double value)
Assures that all values in the given interval are greater or equal than the given value.

Parameters:
min - the lower end of the interval
max - the upper end of the interval
value - the smallest possible value for the interval

adoptValues

public void adoptValues(BorderLine other)
Convenience method that copies the actual data from the given argument to this instance.

Parameters:
other - the argument to retrieve the values from

setValue

public void setValue(double min,
                     double max,
                     double value)
Sets a specific interval described by min and max to a given value.

Parameters:
min - the left side of the interval.
max - the right side of the interval.
value - the value for the whole interval.

setSloped

public void setSloped(double min,
                      double max,
                      double value,
                      double slope)
Sets a specific interval to a slope starting at a given value.

Parameters:
min - the left side of the interval.
max - the right side of the interval.
value - the value at min where the slope starts.
slope - the slope of the segment in the given interval.
Throws:
java.lang.IllegalArgumentException - if min is greater than max.

addValueOffset

public void addValueOffset(double delta)
Adds the given offset to the current values of the whole borderline. This method has complexity O(1).

Parameters:
delta - the delta to add to the values

addOffset

public void addOffset(double delta)
Adds the given offset to the segments' positions. This method has complexity O(1).

Parameters:
delta - the delta to add to the positions

getMin

public double getMin()
Returns the smallest position of this borderline


getMax

public double getMax()
Returns the greatest position of this borderline


getMinValue

public double getMinValue()
Returns the minimum value that is set on this borderline

Returns:
the value

getMaxValue

public double getMaxValue()
Returns the maximum value that is set on this borderline

Returns:
the value

getValueAt

public double getValueAt(double pos)
Returns the value that is set on this borderline at the specified position.

Parameters:
pos - the position
Returns:
the value
Throws:
java.lang.IndexOutOfBoundsException - if the position is outside of the borderline.

getValueAt

public double getValueAt(ListCell cell,
                         double pos)
Returns the value that is set on this borderline at the specified position. The position must lie within the range of the segment that is stored in cell.

Parameters:
cell - The list cell containing the segment whose value shall be returned.
pos - the position
Returns:
the value
Throws:
java.lang.IllegalArgumentException - if pos is outside the segment's range that is stored in cell.

getValueAt

public double getValueAt(BorderLine.Segment segment,
                         double pos)
Returns the value that is set on this borderline at the specified position. The position must lie within the range of the segment.

Parameters:
segment - The segment whose value shall be returned.
pos - the position where the value will be retrieved.
Returns:
the value
Throws:
java.lang.IllegalArgumentException - if pos is outside the segment's range.

createMax

public BorderLine createMax(BorderLine other)
Merges this borderline with the given borderline using the "maximum" policy. That means the resulting borderline will have greater value of both borderline on each position. If you imagine each borderline as a the upper border of a plane, the resulting borderline will be the upper border of the merged planes.

Parameters:
other - the other borderline
Returns:
a new borderline that is the result of the merge

createMin

public BorderLine createMin(BorderLine other)
Merges this borderline with the given borderline using the "minimum" policy. That means the resulting borderline will have smaller value of both borderline on each position. If you imagine each borderline as a the lower border of a plane, the resulting borderline will be the lower border of the merged planes.

Parameters:
other - the other borderline
Returns:
a new borderline that is the result of the merge

mergeWithMax

public void mergeWithMax(BorderLine other)
Merges this borderline with the given borderline using the "maximum" policy.

Parameters:
other - the other borderline

mergeWithMin

public void mergeWithMin(BorderLine other)
Merges this borderline with the given borderline using the "minimum" policy.

Parameters:
other - the other borderline

getValue

public double getValue(BorderLine.Segment s)
Returns the value of the minimum of the given segment. If the segment's slope is 0, it's the value of the whole segment. In case the slope differs from 0, it's the value of the start of the slope.

Parameters:
s - the segment

getMin

public double getMin(BorderLine.Segment s)
Returns the minimum position of the given segment.

Parameters:
s - the segment

getSlope

public double getSlope(BorderLine.Segment s)
Returns the slope of the given segment.

Parameters:
s - the segment

getSegmentAt

public BorderLine.Segment getSegmentAt(double pos)
Returns the segment at the given position.

Parameters:
pos - the position

getMax

public double getMax(BorderLine.Segment s)
Returns the maximum position of the given segment.

Parameters:
s - the segment

firstSegment

public BorderLine.Segment firstSegment()
Returns the first segment or null if there is no such segment.


lastSegment

public BorderLine.Segment lastSegment()
Returns the last segment or null if there is no such segment.


prev

public BorderLine.Segment prev(BorderLine.Segment s)
Returns the previous segment or null if there is no such segment.


next

public BorderLine.Segment next(BorderLine.Segment s)
Returns the next segment or null if there is no such segment.


getMaxValue

public double getMaxValue(double from,
                          double to)
Calculates the maximum value in the interval from->to.

 
If the from value is larger or equal to the to value, the algorithm always returns -Double.MAX_VALUE.

getMinValue

public double getMinValue(double from,
                          double to)
Calculates the minimum value in the interval from->to.

 
If the from value is larger or equal to the to value, the algorithm always returns Double.MAX_VALUE.

getDistanceTo

public double getDistanceTo(BorderLine greater)
Calculates the minimal distance between this borderline and the other one. The other one is treated as if the values were all greater.


toString

public java.lang.String toString()
Returns a lengthy String representation of this borderline.

Overrides:
toString in class java.lang.Object

grow

public void grow(double toMin,
                 double toMax,
                 boolean positive)
Grows this borderline horizontally, so that the values of the borderline stay the same however their start and end points are moved in the direction of toMin and toMax. This is useful for scenarios where a borderline is needed that consists of an enlarged border.

Note that this method normalizes the segments, i.e., it transforms each segment with slope != 0 to a segment with slope == 0.

Parameters:
toMin - the delta by which the border should be extended towards -Infinity
toMax - the delta by which the border should be extended towards +Infinity
positive - whether the borderline should be interpreted to point in positive direction. This influences the direction into which a segment's border is extended.

© Copyright 2000-2021,
yWorks GmbH.
All rights reserved.