com.partnersoft.geometry
Class Line

java.lang.Object
  extended by com.partnersoft.geometry.Line
All Implemented Interfaces:
java.io.Serializable

public class Line
extends java.lang.Object
implements java.io.Serializable

A double-precision line class.

Author:
Paul Reavis Copyright 1999 Partner Software, Inc.
See Also:
Serialized Form

Field Summary
 double x1
           
 double x2
           
 double y1
           
 double y2
           
 
Constructor Summary
Line()
           
Line(double x1, double y1, double x2, double y2)
           
 
Method Summary
 boolean clipToRectangle(Rectangle rectangle)
          Clip this line to rectangle.
 boolean equals(Line nother)
           
 boolean equals(java.lang.Object nother)
           
 Point getCenter()
           
 double getLength()
           
 double getSlope()
           
 double getX1()
           
 double getX2()
           
 double getY1()
           
 double getY2()
           
 Point intersect(Line nother)
          Finds the intersection point for the two lines.
 boolean isDegenerate()
           
 boolean isHorizontal()
           
 boolean isRightOf(double x, double y)
          Returns true if this line lies to the "right" of the given point, Imagine yourself walking from x1,y1 to x2, y2.
 boolean isVertical()
           
 void setToMatch(Line nother)
           
 void setX1(double newX)
           
 void setX2(double newX)
           
 void setY1(double newY)
           
 void setY2(double newY)
           
 double solveForX(double y)
          Finds the x for the given y.
 double solveForY(double x)
          Finds the y for the given x.
 void sortLeftToRight()
          Makes it run from left to right (so x1 <= x2)
 void swapEnds()
          Swaps ends (x1 and x2, y1 and y2)
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

x1

public double x1

y1

public double y1

x2

public double x2

y2

public double y2
Constructor Detail

Line

public Line()

Line

public Line(double x1,
            double y1,
            double x2,
            double y2)
Method Detail

getX1

public double getX1()

setX1

public void setX1(double newX)

getY1

public double getY1()

setY1

public void setY1(double newY)

getX2

public double getX2()

setX2

public void setX2(double newX)

getY2

public double getY2()

setY2

public void setY2(double newY)

setToMatch

public void setToMatch(Line nother)

toString

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

isDegenerate

public boolean isDegenerate()

isVertical

public boolean isVertical()

isHorizontal

public boolean isHorizontal()

getSlope

public double getSlope()

getLength

public double getLength()

equals

public boolean equals(Line nother)

equals

public boolean equals(java.lang.Object nother)
Overrides:
equals in class java.lang.Object

getCenter

public Point getCenter()

solveForX

public double solveForX(double y)
Finds the x for the given y.


solveForY

public double solveForY(double x)
Finds the y for the given x.


sortLeftToRight

public void sortLeftToRight()
Makes it run from left to right (so x1 <= x2)


intersect

public Point intersect(Line nother)
Finds the intersection point for the two lines.


swapEnds

public void swapEnds()
Swaps ends (x1 and x2, y1 and y2)


isRightOf

public boolean isRightOf(double x,
                         double y)
Returns true if this line lies to the "right" of the given point, Imagine yourself walking from x1,y1 to x2, y2. If the point is to your left, this message returns true.


clipToRectangle

public boolean clipToRectangle(Rectangle rectangle)
Clip this line to rectangle. Returns false if the line does not intersect the rectangle, and leaves x and y in an indeterminate state.