Java Platform 1.2
Beta 4

Class java.awt.geom.Line2D

java.lang.Object
  |
  +--java.awt.geom.Line2D
Direct Known Subclasses:
Line2D.Double, Line2D.Float

public abstract class Line2D
extends Object
implements Shape, Cloneable
A line segment in (x, y) coordinate space. For the purposes of the Shape interface, a coordinate is considered to be inside or contained by this line segment if the coordinate lies exactly on the line segment.

This class is only the abstract superclass for all objects which store a 2D line segment. The actual storage representation of the coordinates is left to the subclass.


Inner Class Summary
static  Line2D.Double
          A line segment specified with double coordinates.
static  Line2D.Float
          A line segment specified with float coordinates.
 
Constructor Summary
Line2D()
          This is an abstract class that cannot be instantiated directly.
 
Method Summary
 Object clone()
          Creates a new object of the same class as this object.
 boolean contains(double x, double y, double w, double h)
          Test if the interior of the Shape entirely contains the given set of rectangular coordinates.
 boolean contains(double x, double y)
          Test if a given coordinate is inside the boundary of the shape.
 boolean contains(Point2D p)
          Test if a given Point is inside the boundary of the shape.
 boolean contains(Rectangle2D r)
          Test if the interior of the Shape entirely contains the given Rectangle.
 Rectangle getBounds()
          Return the bounding box of the shape.
abstract  Point2D getP1()
          Returns the start point.
abstract  Point2D getP2()
          Returns the end point.
 PathIterator getPathIterator(AffineTransform at, double flatness)
          Return an iteration object that defines the boundary of the flattened shape.
 PathIterator getPathIterator(AffineTransform at)
          Return an iteration object that defines the boundary of the shape.
abstract  double getX1()
          Returns the X coordinate of the start point in double precision.
abstract  double getX2()
          Returns the X coordinate of the end point in double precision.
abstract  double getY1()
          Returns the Y coordinate of the start point in double precision.
abstract  double getY2()
          Returns the Y coordinate of the end point in double precision.
 boolean intersects(double x, double y, double w, double h)
          Test if the Shape intersects the interior of a given set of rectangular coordinates.
 boolean intersects(Rectangle2D r)
          Test if the Shape intersects the interior of a given Rectangle.
 boolean intersectsLine(double X1, double Y1, double X2, double Y2)
          Tests if the line segment from (X1, Y1) to (X2, Y2) intersects this line segment.
 boolean intersectsLine(Line2D l)
          Tests if the given line segment intersects this line segment.
static boolean linesIntersect(double X1, double Y1, double X2, double Y2, double X3, double Y3, double X4, double Y4)
          Tests if the line segment from (X1, Y1) to (X2, Y2) intersects the line segment from (X3, Y3) to (X4, Y4).
static double ptLineDist(double X1, double Y1, double X2, double Y2, double PX, double PY)
          Returns the distance from a point to a line.
 double ptLineDist(double PX, double PY)
          Returns the distance from a point to this line.
 double ptLineDist(Point2D pt)
          Returns the distance from a point to this line.
static double ptLineDistSq(double X1, double Y1, double X2, double Y2, double PX, double PY)
          Returns the square of the distance from a point to a line.
 double ptLineDistSq(double PX, double PY)
          Returns the square of the distance from a point to this line.
 double ptLineDistSq(Point2D pt)
          Returns the square of the distance from a point to this line.
static double ptSegDist(double X1, double Y1, double X2, double Y2, double PX, double PY)
          Returns the distance from a point to a line segment.
 double ptSegDist(double PX, double PY)
          Returns the distance from a point to this line segment.
 double ptSegDist(Point2D pt)
          Returns the distance from a point to this line segment.
static double ptSegDistSq(double X1, double Y1, double X2, double Y2, double PX, double PY)
          Returns the square of the distance from a point to a line segment.
 double ptSegDistSq(double PX, double PY)
          Returns the square of the distance from a point to this line segment.
 double ptSegDistSq(Point2D pt)
          Returns the square of the distance from a point to this line segment.
static int relativeCCW(double X1, double Y1, double X2, double Y2, double PX, double PY)
          Return an indicator of where the specified point (PX, PY) lies with respect to the line segment from (X1, Y1) to (X2, Y2).
 int relativeCCW(double PX, double PY)
          Return an indicator of where the specified point (PX, PY) lies with respect to this line segment.
 int relativeCCW(Point2D p)
          Return an indicator of where the specified point lies with respect to this line segment.
abstract  void setLine(double X1, double Y1, double X2, double Y2)
          Sets the location of the endpoints of this line to the specified double coordinates.
 void setLine(Line2D l)
          Sets the location of the endpoints of this line to the same as those in the specified Line.
 void setLine(Point2D p1, Point2D p2)
          Sets the location of the endpoints of this line to the specified Point coordinates.
 
Methods inherited from class java.lang.Object
equals , finalize , getClass , hashCode , notify , notifyAll , toString , wait , wait , wait
 

Constructor Detail

Line2D

protected Line2D()
This is an abstract class that cannot be instantiated directly. Type-specific implementation subclasses are available for instantiation and provide a number of formats for storing the information necessary to satisfy the various accessor methods below.
See Also:
Line2D.Float, Line2D.Double
Method Detail

getX1

public abstract double getX1()
Returns the X coordinate of the start point in double precision.

getY1

public abstract double getY1()
Returns the Y coordinate of the start point in double precision.

getP1

public abstract Point2D getP1()
Returns the start point.

getX2

public abstract double getX2()
Returns the X coordinate of the end point in double precision.

getY2

public abstract double getY2()
Returns the Y coordinate of the end point in double precision.

getP2

public abstract Point2D getP2()
Returns the end point.

setLine

public abstract void setLine(double X1,
                             double Y1,
                             double X2,
                             double Y2)
Sets the location of the endpoints of this line to the specified double coordinates.

setLine

public void setLine(Point2D p1,
                    Point2D p2)
Sets the location of the endpoints of this line to the specified Point coordinates.

setLine

public void setLine(Line2D l)
Sets the location of the endpoints of this line to the same as those in the specified Line.

relativeCCW

public static int relativeCCW(double X1,
                              double Y1,
                              double X2,
                              double Y2,
                              double PX,
                              double PY)
Return an indicator of where the specified point (PX, PY) lies with respect to the line segment from (X1, Y1) to (X2, Y2). The value will be 1 if the line segment must turn counterclockwise to point at the specified point, -1 if it must turn clockwise, or 0 if the point lies exactly on the line segment. If the point is colinear with the line segment, but not between the endpoints, then the value will be -1 if the point lies "beyond (X1, Y1)" or 1 if the point lies "beyond (X2, Y2)".

relativeCCW

public int relativeCCW(double PX,
                       double PY)
Return an indicator of where the specified point (PX, PY) lies with respect to this line segment. The value will be 1 if the line segment must turn counterclockwise to point at the specified point, -1 if it must turn clockwise, or 0 if the point lies exactly on the line segment. If the point is colinear with the line segment, but not between the endpoints, then the value will be -1 if the point lies "beyond (x1, y1)" or 1 if the point lies "beyond (x2, y2)".

relativeCCW

public int relativeCCW(Point2D p)
Return an indicator of where the specified point lies with respect to this line segment. The value will be 1 if the line segment must turn counterclockwise to point at the specified point, -1 if it must turn clockwise, or 0 if the point lies exactly on the line segment. If the point is colinear with the line segment, but not between the endpoints, then the value will be -1 if the point lies "beyond (x1, y1)" or 1 if the point lies "beyond (x2, y2)".

linesIntersect

public static boolean linesIntersect(double X1,
                                     double Y1,
                                     double X2,
                                     double Y2,
                                     double X3,
                                     double Y3,
                                     double X4,
                                     double Y4)
Tests if the line segment from (X1, Y1) to (X2, Y2) intersects the line segment from (X3, Y3) to (X4, Y4).

intersectsLine

public boolean intersectsLine(double X1,
                              double Y1,
                              double X2,
                              double Y2)
Tests if the line segment from (X1, Y1) to (X2, Y2) intersects this line segment.

intersectsLine

public boolean intersectsLine(Line2D l)
Tests if the given line segment intersects this line segment.

ptSegDistSq

public static double ptSegDistSq(double X1,
                                 double Y1,
                                 double X2,
                                 double Y2,
                                 double PX,
                                 double PY)
Returns the square of the distance from a point to a line segment.
Parameters:
X1 - the x coordinate of the beginning of the line segment
Y1 - the y coordinate of the beginning of the line segment
X2 - the x coordinate of the end of the line segment
Y2 - the y coordinate of the end of the line segment
PX - the x coordinate of the point being measured
PY - the y coordinate of the point being measured

ptSegDist

public static double ptSegDist(double X1,
                               double Y1,
                               double X2,
                               double Y2,
                               double PX,
                               double PY)
Returns the distance from a point to a line segment.
Parameters:
X1 - the x coordinate of the beginning of the line segment
Y1 - the y coordinate of the beginning of the line segment
X2 - the x coordinate of the end of the line segment
Y2 - the y coordinate of the end of the line segment
PX - the x coordinate of the point being measured
PY - the y coordinate of the point being measured

ptSegDistSq

public double ptSegDistSq(double PX,
                          double PY)
Returns the square of the distance from a point to this line segment.
Parameters:
PX - the x coordinate of the point being measured
PY - the y coordinate of the point being measured

ptSegDistSq

public double ptSegDistSq(Point2D pt)
Returns the square of the distance from a point to this line segment.
Parameters:
pt - the point being measured

ptSegDist

public double ptSegDist(double PX,
                        double PY)
Returns the distance from a point to this line segment.
Parameters:
PX - the x coordinate of the point being measured
PY - the y coordinate of the point being measured

ptSegDist

public double ptSegDist(Point2D pt)
Returns the distance from a point to this line segment.
Parameters:
pt - the point being measured

ptLineDistSq

public static double ptLineDistSq(double X1,
                                  double Y1,
                                  double X2,
                                  double Y2,
                                  double PX,
                                  double PY)
Returns the square of the distance from a point to a line.
Parameters:
X1 - the x coordinate of the beginning of the line
Y1 - the y coordinate of the beginning of the line
X2 - the x coordinate of the end of the line
Y2 - the y coordinate of the end of the line
PX - the x coordinate of the point being measured
PY - the y coordinate of the point being measured

ptLineDist

public static double ptLineDist(double X1,
                                double Y1,
                                double X2,
                                double Y2,
                                double PX,
                                double PY)
Returns the distance from a point to a line.
Parameters:
X1 - the x coordinate of the beginning of the line
Y1 - the y coordinate of the beginning of the line
X2 - the x coordinate of the end of the line
Y2 - the y coordinate of the end of the line
PX - the x coordinate of the point being measured
PY - the y coordinate of the point being measured

ptLineDistSq

public double ptLineDistSq(double PX,
                           double PY)
Returns the square of the distance from a point to this line.
Parameters:
PX - the x coordinate of the point being measured
PY - the y coordinate of the point being measured

ptLineDistSq

public double ptLineDistSq(Point2D pt)
Returns the square of the distance from a point to this line.
Parameters:
pt - the point being measured

ptLineDist

public double ptLineDist(double PX,
                         double PY)
Returns the distance from a point to this line.
Parameters:
PX - the x coordinate of the point being measured
PY - the y coordinate of the point being measured

ptLineDist

public double ptLineDist(Point2D pt)
Returns the distance from a point to this line.
Parameters:
pt - the point being measured

contains

public boolean contains(double x,
                        double y)
Test if a given coordinate is inside the boundary of the shape. This method is required to implement the Shape interface, but in the case of Line2D objects it will always return false since a line contains no area.
Specified by:
contains in interface Shape

contains

public boolean contains(Point2D p)
Test if a given Point is inside the boundary of the shape. This method is required to implement the Shape interface, but in the case of Line2D objects it will always return false since a line contains no area.
Specified by:
contains in interface Shape

intersects

public boolean intersects(double x,
                          double y,
                          double w,
                          double h)
Test if the Shape intersects the interior of a given set of rectangular coordinates.
Specified by:
intersects in interface Shape

intersects

public boolean intersects(Rectangle2D r)
Test if the Shape intersects the interior of a given Rectangle.
Specified by:
intersects in interface Shape

contains

public boolean contains(double x,
                        double y,
                        double w,
                        double h)
Test if the interior of the Shape entirely contains the given set of rectangular coordinates. This method is required to implement the Shape interface, but in the case of Line2D objects it will always return false since a line contains no area.
Specified by:
contains in interface Shape

contains

public boolean contains(Rectangle2D r)
Test if the interior of the Shape entirely contains the given Rectangle. This method is required to implement the Shape interface, but in the case of Line2D objects it will always return false since a line contains no area.
Specified by:
contains in interface Shape

getBounds

public Rectangle getBounds()
Return the bounding box of the shape.
Specified by:
getBounds in interface Shape

getPathIterator

public PathIterator getPathIterator(AffineTransform at)
Return an iteration object that defines the boundary of the shape.
Specified by:
getPathIterator in interface Shape

getPathIterator

public PathIterator getPathIterator(AffineTransform at,
                                    double flatness)
Return an iteration object that defines the boundary of the flattened shape.
Specified by:
getPathIterator in interface Shape

clone

public Object clone()
Creates a new object of the same class as this object.
Returns:
a clone of this instance.
Throws:
OutOfMemoryError - if there is not enough memory.
Overrides:
clone in class Object
Since:
JDK1.2
See Also:
Cloneable

Java Platform 1.2
Beta 4

Submit a bug or feature
Submit comments/suggestions about new javadoc look
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.
This documentation was generated with a post-Beta4 version of Javadoc.