java.lang.Object | +--edu.gwu.geometry.LineSegment
Class LineSegment
stores a line-segment (the two end-points)
and provides some supporting methods. The class implements the Comparable
interface, allowing line-segments to be compared by algorithms that use the
sweep-line method. To use the sweep-line method, algorithms must use a
vertical sweep-line and must provide this to the LineSegment
class every time the sweep-line is moved: this may be done by calling
the static setVerticalSweepLine
method below of the
class (since it sets a static variable). The comparisons support
inexact comparisons.
Comparable
Constructor Summary | |
LineSegment()
|
|
LineSegment(Pointd p1,
Pointd p2)
|
Method Summary | |
int |
compareTo(java.lang.Object obj)
Method compareTo implements the Comparable interface. |
boolean |
equals(java.lang.Object obj)
The class implements equals consistent with compareTo . |
double |
getIntercept()
|
Pointd |
getPoint1()
Call getPoint1 to end the first end-point. |
Pointd |
getPoint2()
Call getPoint2 to end the second end-point. |
double |
getSlope()
|
static void |
setsweepx(double x)
Use setsweepx or setVerticalSweepLine |
static void |
setVerticalSweepLine(double x)
Call setVerticalSweepLine with the current x-value of
the sweep-line to enable line-segment comparisons. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public LineSegment(Pointd p1, Pointd p2)
public LineSegment()
Method Detail |
public static void setsweepx(double x)
setsweepx
or setVerticalSweepLine to set the
current sweep line for comparisons.
- Parameters:
x
- a double
value
public static void setVerticalSweepLine(double x)
setVerticalSweepLine
with the current x-value of
the sweep-line to enable line-segment comparisons.x
- a double
valuepublic Pointd getPoint1()
getPoint1
to end the first end-point.Pointd
valuepublic Pointd getPoint2()
getPoint2
to end the second end-point.Pointd
valuepublic double getSlope()
public double getIntercept()
public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
consistent with compareTo
.equals
in class java.lang.Object
obj
- an Object
valueboolean
valuepublic int compareTo(java.lang.Object obj)
compareTo
implements the Comparable
interface.
The comparison involves a vertical sweep-line so that one line-segment
is "less" if it is below the other to the immediate right of the sweep line.compareTo
in interface java.lang.Comparable
obj
- an Object
valueint
value