Java Platform 1.2

java.awt.geom
Class Line2D

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

public abstract class Line2D
extends Object
implements Shape, Cloneable

This Line2D represents a line segment in (x, y) coordinate space.

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


Inner Class Summary
static class Line2D.Double
          A line segment specified with double coordinates.
static class Line2D.Float
          A line segment specified with float coordinates.
 
Constructor Summary
protected 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)
          Tests if a specified coordinate is inside the boundary of this Line2D.
 boolean contains(double x, double y, double w, double h)
          Tests if the interior of this Line2D entirely contains the specified set of rectangular coordinates.
 boolean contains(Point2D p)
          Tests if a given Point2D is inside the boundary of this Line2D.
 boolean contains(Rectangle2D r)
          Tests if the interior of this Line2D entirely contains the specified Rectangle2D.
 Rectangle getBounds()
          Returns the bounding box of this Line2D.
abstract  Point2D getP1()
          Returns the starting Point2D of this Line2D.
abstract  Point2D getP2()
          Returns the end Point2D of this Line2D.
 PathIterator getPathIterator(AffineTransform at)
          Returns an iteration object that defines the boundary of this Line2D.
 PathIterator getPathIterator(AffineTransform at, double flatness)
          Returns an iteration object that defines the boundary of this flattened Line2D.
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)
          Tests if this Line2D intersects the interior of a specified set of rectangular coordinates.
 boolean intersects(Rectangle2D r)
          Tests if this Line2D intersects the interior of a specified Rectangle2D.
 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 specified 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).
 double ptLineDist(double PX, double PY)
          Returns the distance from a point to this line.
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(Point2D pt)
          Returns the distance from a Point2D to this line.
 double ptLineDistSq(double PX, double PY)
          Returns the square of 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(Point2D pt)
          Returns the square of the distance from a specified Point2D to this line.
 double ptSegDist(double PX, double PY)
          Returns the distance from a point to this line segment.
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(Point2D pt)
          Returns the distance from a Point2D to this line segment.
 double ptSegDistSq(double PX, double PY)
          Returns the square of 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(Point2D pt)
          Returns the square of the distance from a Point2D to this line segment.
 int relativeCCW(double PX, double PY)
          Returns an indicator of where the specified point (PX, PY) lies with respect to this line segment.
static int relativeCCW(double X1, double Y1, double X2, double Y2, double PX, double PY)
          Returns an indicator of where the specified point (PX, PY) lies with respect to the line segment from (X1, Y1) to (X2, Y2).
 int relativeCCW(Point2D p)
          Returns an indicator of where the specified Point2D 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 Line2D to the specified double coordinates.
 void setLine(Line2D l)
          Sets the location of the endpoints of this Line2D to the same as those endpoints of the specified Line2D.
 void setLine(Point2D p1, Point2D p2)
          Sets the location of the endpoints of this Line2D to the specified Point2D 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 accessory 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.
Returns:
the X coordinate of this Line2D object's starting point.

getY1

public abstract double getY1()
Returns the Y coordinate of the start point in double precision.
Returns:
the Y coordinate of this Line2D object's starting point.

getP1

public abstract Point2D getP1()
Returns the starting Point2D of this Line2D.
Returns:
the starting Point2D of this Line2D.

getX2

public abstract double getX2()
Returns the X coordinate of the end point in double precision.
Returns:
the X coordinate of this Line2D object's starting point.

getY2

public abstract double getY2()
Returns the Y coordinate of the end point in double precision.
Returns:
the Y coordinate of this Line2D object's starting point.

getP2

public abstract Point2D getP2()
Returns the end Point2D of this Line2D.
Returns:
a Point2D that is the endpoint of this Line2D.

setLine

public abstract void setLine(double X1,
                             double Y1,
                             double X2,
                             double Y2)
Sets the location of the endpoints of this Line2D to the specified double coordinates.
Parameters:
X1, Y1 - the first specified coordinate
X2, Y2 - the second specified coordinate

setLine

public void setLine(Point2D p1,
                    Point2D p2)
Sets the location of the endpoints of this Line2D to the specified Point2D coordinates.
Parameters:
p1, p2 - the specified Point2D objects

setLine

public void setLine(Line2D l)
Sets the location of the endpoints of this Line2D to the same as those endpoints of the specified Line2D.
Parameters:
l - the specified Line2D

relativeCCW

public static int relativeCCW(double X1,
                              double Y1,
                              double X2,
                              double Y2,
                              double PX,
                              double PY)
Returns an indicator of where the specified point (PX, PY) lies with respect to the line segment from (X1, Y1) to (X2, Y2). The value is 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)". Note that an indicator value of 0 is rare and not useful for determining colinearity because of floating point rounding issues.
Parameters:
X1, Y1 - the coordinates of the beginning of the specified line segment
X2, Y2 - the coordinates of the end of the specified line segment
PX, PY - the coordinates of the specified point to be compared with the specified line segment
Returns:
an integer that indicates the position of the third specified coordinates with respect to the line segment formed by the first two specified coordinates.

relativeCCW

public int relativeCCW(double PX,
                       double PY)
Returns an indicator of where the specified point (PX, PY) lies with respect to this line segment. The value is 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 is -1 if the point lies "beyond (x1, y1)" or 1 if the point lies "beyond (x2, y2)". Note that an indicator value of 0 is rare and not useful for determining colinearity because of floating point rounding issues.
Parameters:
PX, PY - the coordinates of the specified point to be compared with the current line segment
Returns:
an integer that indicates the position of the specified coordinates with respect to the current line segment.

relativeCCW

public int relativeCCW(Point2D p)
Returns an indicator of where the specified Point2D lies with respect to this line segment. The value is 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 is -1 if the point lies "beyond (x1, y1)" or 1 if the point lies "beyond (x2, y2)". Note that an indicator value of 0 is rare and not useful for determining colinearity because of floating point rounding issues.
Parameters:
p - the specified Point2D to be compared with the current line segment
Returns:
an integer that indicates the position of the Point2D with respect to the current line segment.

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).
Parameters:
X1, Y1 - the coordinates of the beginning of the first specified line segment
X2, Y2 - the coordinates of the end of the first specified line segment
X3, Y3 - the coordinates of the beginning of the second specified line segment
X4, Y4 - the coordinates of the end of the second specified line segment
Returns:
true if the first specified line segment and the second specified line segment intersect each other; false otherwise.

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.
Parameters:
X1, Y1 - the coordinates of the beginning of the specified line segment
X2, Y2 - the coordinates of the end of the specified line segment
Returns:
if this line segment and the specified line segment intersect each other; false otherwise.

intersectsLine

public boolean intersectsLine(Line2D l)
Tests if the specified line segment intersects this line segment.
Parameters:
l - the specified Line2D
Returns:
true if this line segment and the specified line segment intersect each other; false otherwise.

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, Y1 - the coordinates of the beginning of the specified line segment
X2, Y2 - the coordinates of the end of the specified line segment
PX, PY - the coordinates of the specified point being measured
Returns:
a double value that is the square of the distance from the specified point to the specified line segment.

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, Y1 - the coordinates of the beginning of the specified line segment
X2, Y2 - the coordinates of the end of the specified line segment
PX, PY - the coordinates of the specified point being measured
Returns:
a double value that is the distance from the specified point to the specified line segment.

ptSegDistSq

public double ptSegDistSq(double PX,
                          double PY)
Returns the square of the distance from a point to this line segment.
Parameters:
PX, PY - the coordinates of the specified point being measured
Returns:
a double value that is the square of the distance from a specified point to the current line segment.

ptSegDistSq

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

ptSegDist

public double ptSegDist(double PX,
                        double PY)
Returns the distance from a point to this line segment.
Parameters:
PX, PY - the coordinates of the specified point being measured
Returns:
a double value that is the distance from a specified point to the current line segment.

ptSegDist

public double ptSegDist(Point2D pt)
Returns the distance from a Point2D to this line segment.
Parameters:
pt - the specified Point2D being measured
Returns:
a double value that is the distance from a specified Point2D to the current line segment.

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, Y1 - the coordinates of the beginning of the specified line segment
X2, Y2 - the coordinates of the end of the specified line segment
PX, PY - the coordinates of the specified point being measured
Returns:
a double value that is the square of the distance from a specified point to a specified line segment.

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, Y1 - the coordinates of the beginning of the specified line segment
X2, Y2 - the coordinates of the end of the specified line segment
PX, PY - the coordinates of the specified point being measured
Returns:
a double value that is the distance from a specified point to a specified line segment.

ptLineDistSq

public double ptLineDistSq(double PX,
                           double PY)
Returns the square of the distance from a point to this line.
Parameters:
PX, PY - the coordinates of the specified point being measured
Returns:
a double value that is the square of the distance from a specified point to the current line segment.

ptLineDistSq

public double ptLineDistSq(Point2D pt)
Returns the square of the distance from a specified Point2D to this line.
Parameters:
pt - the specified Point2D being measured
Returns:
a double value that is the square of the distance from a specified Point2D to the current line segment.

ptLineDist

public double ptLineDist(double PX,
                         double PY)
Returns the distance from a point to this line.
Parameters:
PX, PY - the coordinates of the specified point being measured
Returns:
a double value that is the distance from a specified point to the current line segment.

ptLineDist

public double ptLineDist(Point2D pt)
Returns the distance from a Point2D to this line.
Parameters:
pt - the specified Point2D being measured
Returns:
a double value that is the distance from a specified Point2D to the current line segment.

contains

public boolean contains(double x,
                        double y)
Tests if a specified coordinate is inside the boundary of this Line2D. This method is required to implement the Shape interface, but in the case of Line2D objects it always returns false since a line contains no area.
Specified by:
contains in interface Shape
Parameters:
x, y - the coordinates of the specified point
Returns:
false because a Line2D contains no area.

contains

public boolean contains(Point2D p)
Tests if a given Point2D is inside the boundary of this Line2D. This method is required to implement the Shape interface, but in the case of Line2D objects it always returns false since a line contains no area.
Specified by:
contains in interface Shape
Parameters:
p - the specified Point2D to be tested
Returns:
false because a Line2D contains no area.

intersects

public boolean intersects(double x,
                          double y,
                          double w,
                          double h)
Tests if this Line2D intersects the interior of a specified set of rectangular coordinates.
Specified by:
intersects in interface Shape
Parameters:
x, y - the coordinates of the top-left corner of the specified rectangular area
w - the width of the specified rectangular area
h - the height of the specified rectangular area
Returns:
true if this Line2D intersects the interior of the specified set of rectangular coordinates; false otherwise.

intersects

public boolean intersects(Rectangle2D r)
Tests if this Line2D intersects the interior of a specified Rectangle2D.
Specified by:
intersects in interface Shape
Parameters:
r - the specified Rectangle2D to be tested
Returns:
true if this Line2D intersects the interior of the specified Rectangle2D; false otherwise.

contains

public boolean contains(double x,
                        double y,
                        double w,
                        double h)
Tests if the interior of this Line2D entirely contains the specified set of rectangular coordinates. This method is required to implement the Shape interface, but in the case of Line2D objects it always returns false since a line contains no area.
Specified by:
contains in interface Shape
Parameters:
x, y - the coordinates of the top-left corner of the specified rectangular area
w - the width of the specified rectangular area
h - the height of the specified rectangular area
Returns:
false because a Line2D contains no area.

contains

public boolean contains(Rectangle2D r)
Tests if the interior of this Line2D entirely contains the specified Rectangle2D. This method is required to implement the Shape interface, but in the case of Line2D objects it always returns false since a line contains no area.
Specified by:
contains in interface Shape
Parameters:
r - the specified Rectangle2D to be tested
Returns:
false because a Line2D contains no area.

getBounds

public Rectangle getBounds()
Returns the bounding box of this Line2D.
Specified by:
getBounds in interface Shape
Returns:
a Rectangle that is the bounding box of the Line2D.

getPathIterator

public PathIterator getPathIterator(AffineTransform at)
Returns an iteration object that defines the boundary of this Line2D. The iterator for this class is not multi-threaded safe, which means that this Line2D class does not guarantee that modifications to the geometry of this Line2D object do not affect any iterations of that geometry that are already in process.
Specified by:
getPathIterator in interface Shape
Parameters:
at - the specified AffineTransform
Returns:
a PathIterator that defines the boundary of this Line2D.

getPathIterator

public PathIterator getPathIterator(AffineTransform at,
                                    double flatness)
Returns an iteration object that defines the boundary of this flattened Line2D. The iterator for this class is not multi-threaded safe, which means that this Line2D class does not guarantee that modifications to the geometry of this Line2D object do not affect any iterations of that geometry that are already in process.
Specified by:
getPathIterator in interface Shape
Parameters:
at - the specified AffineTransform
flatness - the maximum amount that the control points for a given curve can vary from colinear before a subdivided curve is replaced by a straight line connecting the endpoints. Since a Line2D object is always flat, this parameter is ignored.
Returns:
a PathIterator that defines the boundary of the flattened Line2D

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

Submit a bug or feature Version 1.2 of Java Platform API Specification
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.