edu.gwu.geometry
Class LineSegment

java.lang.Object
  |
  +--edu.gwu.geometry.LineSegment
All Implemented Interfaces:
java.lang.Comparable

public class LineSegment
extends java.lang.Object
implements java.lang.Comparable

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.

See Also:
Comparable

Constructor Summary
LineSegment()
           
LineSegment(Pointd p1, Pointd p2)
           
 
Method Summary
 int compareTo(java.lang.Object obj)
          Method compareTo implements the Comparableinterface.
 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 to set the current sweep line for comparisons.
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

LineSegment

public LineSegment(Pointd p1,
                   Pointd p2)

LineSegment

public LineSegment()
Method Detail

setsweepx

public static void setsweepx(double x)
Use setsweepx or setVerticalSweepLine to set the current sweep line for comparisons.
Parameters:
x - a double value

setVerticalSweepLine

public static void setVerticalSweepLine(double x)
Call setVerticalSweepLine with the current x-value of the sweep-line to enable line-segment comparisons.
Parameters:
x - a double value

getPoint1

public Pointd getPoint1()
Call getPoint1 to end the first end-point.
Returns:
a Pointd value

getPoint2

public Pointd getPoint2()
Call getPoint2 to end the second end-point.
Returns:
a Pointd value

getSlope

public double getSlope()

getIntercept

public double getIntercept()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
The class implements equals consistent with compareTo.
Overrides:
equals in class java.lang.Object
Parameters:
obj - an Object value
Returns:
a boolean value

compareTo

public int compareTo(java.lang.Object obj)
Method compareTo implements the Comparableinterface. 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.
Specified by:
compareTo in interface java.lang.Comparable
Parameters:
obj - an Object value
Returns:
an int value