public class LineSegment extends Object implements AbstractLineSegment
Modifier and Type | Field and Description |
---|---|
protected int |
begin
Start position of the line.
|
protected int |
end
End position of the line.
|
Constructor and Description |
---|
LineSegment()
Initializes the line segment as invalid, with begin being set to INF and
end being set to -INF.
|
LineSegment(int begin,
int end)
Initializes the line segment with the given begin and end.
|
Modifier and Type | Method and Description |
---|---|
boolean |
boundariesEqual(AbstractLineSegment l)
Returns true if the boundaries of the two line segments are equal.
|
static boolean |
boundariesEqual(AbstractLineSegment l1,
AbstractLineSegment l2)
Returns true if the boundaries of the two line segments are equal.
|
int |
getBegin()
Returns the begin position of the line.
|
int |
getEnd()
Returns the end position of the line.
|
static LineSegment |
intersection(AbstractLineSegment l1,
AbstractLineSegment l2)
Returns a new line which is the union of the two lines.
|
boolean |
isValid()
Returns true if this line is valid (its begin is smaller or equal to its
end).
|
static boolean |
isValid(AbstractLineSegment line)
Returns true if the given line is valid (its begin is smaller or equal to
its end).
|
int |
length()
Returns the length of the line segment.
|
static int |
length(AbstractLineSegment line)
Returns the length of the line segment.
|
void |
normalize()
Swaps begin and end if the line is not valid.
|
static LineSegment |
normalize(AbstractLineSegment line)
Normalizes the line segment by swapping begin and end if they are in the
wrong order.
|
static int[] |
normalizedBounds(AbstractLineSegment line)
Returns the boundaries of the normalized line as a two-element array --
normalization means that begin and end are swapped if end is larger than
begin.
|
boolean |
overlaps(AbstractLineSegment l)
Returns true if the boundaries of the two line segments overlap.
|
static boolean |
overlaps(AbstractLineSegment l1,
AbstractLineSegment l2)
Returns true if the boundaries of the two line segments overlap.
|
void |
setBegin(int begin)
Sets the start position of the line.
|
void |
setEnd(int end)
Sets the end position of the line.
|
static LineSegment |
union(AbstractLineSegment l1,
AbstractLineSegment l2)
Returns a new line which is the union of the two lines.
|
protected int begin
protected int end
public LineSegment()
public LineSegment(int begin, int end)
begin
- is the begin.end
- is then end.public static final boolean isValid(AbstractLineSegment line)
line
- is the line that should be checked for validity.public static final int length(AbstractLineSegment line)
line
- is the line segment of which the (absolute) length is calculated.public static final LineSegment normalize(AbstractLineSegment line)
line
- is the abstract line segment to be normalized.public static final int[] normalizedBounds(AbstractLineSegment line)
line
- is the line of which the (normalized) bounds are returned.public static final LineSegment union(AbstractLineSegment l1, AbstractLineSegment l2)
l1
- is the fist line segment for forming the union.l2
- is the second line segment for forming the union.public static final LineSegment intersection(AbstractLineSegment l1, AbstractLineSegment l2)
l1
- is the fist line segment for forming the union.l2
- is the second line segment for forming the union.public static final boolean boundariesEqual(AbstractLineSegment l1, AbstractLineSegment l2)
l1
- is the fist line segment for comparison.l2
- is the second line segment for comparison.public static final boolean overlaps(AbstractLineSegment l1, AbstractLineSegment l2)
l1
- is the first line segment for comparison.l2
- is the second line segment for comparison.public final int getBegin()
getBegin
in interface AbstractLineSegment
public final int getEnd()
getEnd
in interface AbstractLineSegment
public final void setBegin(int begin)
begin
- is the new start position of the line.public final void setEnd(int end)
end
- is the new end position of the line.public final boolean isValid()
public final boolean boundariesEqual(AbstractLineSegment l)
l
- is the line segment for comparison.public final boolean overlaps(AbstractLineSegment l)
l
- is the line segment for comparison.public final void normalize()
public final int length()
Copyright (C) 2013, 2014 Raphael Dickfelder, Jan Göpfert, Benjamin Paassen, Andreas Stöckel, licensed under the AGPL v. 3: http://openresearch.cit-ec.de/projects/scie