Shape
, Cloneable
Line2D.Double
, Line2D.Float
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.
Nested Classes
static class
A line segment specified with double coordinates.
static class
A line segment specified with float coordinates.
Constructors
protected
This is an abstract class that cannot be instantiated directly.
Creates a new object of the same class as this object.
boolean
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
Tests if a given Point2D
is inside the boundary of this Line2D
.
boolean
Tests if the interior of this Line2D
entirely contains the specified Rectangle2D
.
Returns an integer
Rectangle
that completely encloses the
Shape
.
Returns the start Point2D
of this Line2D
.
Returns the end Point2D
of this Line2D
.
Returns an iteration object that defines the boundary of this Line2D
.
Returns an iteration object that defines the boundary of this flattened Line2D
.
abstract double
Returns the X coordinate of the start point in double precision.
abstract double
Returns the X coordinate of the end point in double precision.
abstract double
Returns the Y coordinate of the start point in double precision.
abstract double
Returns the Y coordinate of the end point in double precision.
boolean
intersects(double x, double y, double w, double h)
Tests if the interior of the Shape
intersects the interior of a specified rectangular area.
boolean
Tests if the interior of the Shape
intersects the interior of a specified Rectangle2D
.
boolean
Tests if the line segment from (x1,y1)
to (x2,y2)
intersects this line segment.
boolean
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
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
Returns the distance from a Point2D
to this line.
double
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
Returns the square of the distance from a specified Point2D
to this line.
double
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
Returns the distance from a Point2D
to this line segment.
double
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
Returns the square of the distance from a Point2D
to this line segment.
int
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
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 end points of this Line2D
to the specified double coordinates.
void
Sets the location of the end points of this Line2D
to the same as those end points of the specified Line2D
.
void
Sets the location of the end points of this Line2D
to the specified Point2D
coordinates.
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.
public abstract double getX1()
Returns the X coordinate of the start point in double precision.
Line2D
object.
public abstract double getY1()
Returns the Y coordinate of the start point in double precision.
Line2D
object.
Returns the start Point2D
of this Line2D
.
Point2D
of this Line2D
.
public abstract double getX2()
Returns the X coordinate of the end point in double precision.
Line2D
object.
public abstract double getY2()
Returns the Y coordinate of the end point in double precision.
Line2D
object.
Returns the end Point2D
of this Line2D
.
Point2D
of this Line2D
.
public abstract void setLine(double x1, double y1, double x2, double y2)
Sets the location of the end points of this Line2D
to the specified double coordinates.
x1
- the X coordinate of the start point
y1
- the Y coordinate of the start point
x2
- the X coordinate of the end point
y2
- the Y coordinate of the end point
Sets the location of the end points of this Line2D
to the specified Point2D
coordinates.
p1
- the start Point2D
of the line segment
p2
- the end Point2D
of the line segment
Sets the location of the end points of this Line2D
to the same as those end points of the specified Line2D
.
l
- the specified Line2D
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 return value can be either 1, -1, or 0 and indicates in which direction the specified line must pivot around its first end point,
(x1,y1)
, in order to point at the specified point
(px,py)
.
A return value of 1 indicates that the line segment must turn in the direction that takes the positive X axis towards the negative Y axis. In the default coordinate system used by Java 2D, this direction is counterclockwise.
A return value of -1 indicates that the line segment must turn in the direction that takes the positive X axis towards the positive Y axis. In the default coordinate system, this direction is clockwise.
A return value of 0 indicates that the point lies exactly on the line segment. Note that an indicator value of 0 is rare and not useful for determining collinearity because of floating point rounding issues.
If the point is colinear with the line segment, but not between the end points, then the value will be -1 if the point lies "beyond (x1,y1)
" or 1 if the point lies "beyond (x2,y2)
".
x1
- the X coordinate of the start point of the specified line segment
y1
- the Y coordinate of the start point of the specified line segment
x2
- the X coordinate of the end point of the specified line segment
y2
- the Y coordinate of the end point of the specified line segment
px
- the X coordinate of the specified point to be compared with the specified line segment
py
- the Y coordinate of the specified point to be compared with the specified line segment
public int relativeCCW(double px, double py)
px
- the X coordinate of the specified point to be compared with this Line2D
py
- the Y coordinate of the specified point to be compared with this Line2D
Line2D
p
- the specified Point2D
to be compared with this Line2D
Point2D
with respect to this Line2D
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)
.
x1
- the X coordinate of the start point of the first specified line segment
y1
- the Y coordinate of the start point of the first specified line segment
x2
- the X coordinate of the end point of the first specified line segment
y2
- the Y coordinate of the end point of the first specified line segment
x3
- the X coordinate of the start point of the second specified line segment
y3
- the Y coordinate of the start point of the second specified line segment
x4
- the X coordinate of the end point of the second specified line segment
y4
- the Y coordinate of the end point of the second specified line segment
true
if the first specified line segment and the second specified line segment intersect each other; false
otherwise.
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.
x1
- the X coordinate of the start point of the specified line segment
y1
- the Y coordinate of the start point of the specified line segment
x2
- the X coordinate of the end point of the specified line segment
y2
- the Y coordinate of the end point of the specified line segment
true
if this line segment and the specified line segment intersect each other; false
otherwise.
Tests if the specified line segment intersects this line segment.
l
- the specified Line2D
true
if this line segment and the specified line segment intersect each other; false
otherwise.
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. The distance measured is the distance between the specified point and the closest point between the specified end points. If the specified point intersects the line segment in between the end points, this method returns 0.0.
x1
- the X coordinate of the start point of the specified line segment
y1
- the Y coordinate of the start point of the specified line segment
x2
- the X coordinate of the end point of the specified line segment
y2
- the Y coordinate of the end point of the specified line segment
px
- the X coordinate of the specified point being measured against the specified line segment
py
- the Y coordinate of the specified point being measured against the specified line segment
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. The distance measured is the distance between the specified point and the closest point between the specified end points. If the specified point intersects the line segment in between the end points, this method returns 0.0.
x1
- the X coordinate of the start point of the specified line segment
y1
- the Y coordinate of the start point of the specified line segment
x2
- the X coordinate of the end point of the specified line segment
y2
- the Y coordinate of the end point of the specified line segment
px
- the X coordinate of the specified point being measured against the specified line segment
py
- the Y coordinate of the specified point being measured against the specified line segment
public double ptSegDistSq(double px, double py)
Returns the square of the distance from a point to this line segment. The distance measured is the distance between the specified point and the closest point between the current line's end points. If the specified point intersects the line segment in between the end points, this method returns 0.0.
px
- the X coordinate of the specified point being measured against this line segment
py
- the Y coordinate of the specified point being measured against this line segment
Returns the square of the distance from a Point2D
to this line segment. The distance measured is the distance between the specified point and the closest point between the current line's end points. If the specified point intersects the line segment in between the end points, this method returns 0.0.
pt
- the specified Point2D
being measured against this line segment.
Point2D
to the current line segment.
public double ptSegDist(double px, double py)
Returns the distance from a point to this line segment. The distance measured is the distance between the specified point and the closest point between the current line's end points. If the specified point intersects the line segment in between the end points, this method returns 0.0.
px
- the X coordinate of the specified point being measured against this line segment
py
- the Y coordinate of the specified point being measured against this line segment
Returns the distance from a Point2D
to this line segment. The distance measured is the distance between the specified point and the closest point between the current line's end points. If the specified point intersects the line segment in between the end points, this method returns 0.0.
pt
- the specified Point2D
being measured against this line segment
Point2D
to the current line segment.
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. The distance measured is the distance between the specified point and the closest point on the infinitely-extended line defined by the specified coordinates. If the specified point intersects the line, this method returns 0.0.
x1
- the X coordinate of the start point of the specified line
y1
- the Y coordinate of the start point of the specified line
x2
- the X coordinate of the end point of the specified line
y2
- the Y coordinate of the end point of the specified line
px
- the X coordinate of the specified point being measured against the specified line
py
- the Y coordinate of the specified point being measured against the specified line
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. The distance measured is the distance between the specified point and the closest point on the infinitely-extended line defined by the specified coordinates. If the specified point intersects the line, this method returns 0.0.
x1
- the X coordinate of the start point of the specified line
y1
- the Y coordinate of the start point of the specified line
x2
- the X coordinate of the end point of the specified line
y2
- the Y coordinate of the end point of the specified line
px
- the X coordinate of the specified point being measured against the specified line
py
- the Y coordinate of the specified point being measured against the specified line
public double ptLineDistSq(double px, double py)
Returns the square of the distance from a point to this line. The distance measured is the distance between the specified point and the closest point on the infinitely-extended line defined by this Line2D
. If the specified point intersects the line, this method returns 0.0.
px
- the X coordinate of the specified point being measured against this line
py
- the Y coordinate of the specified point being measured against this line
Returns the square of the distance from a specified Point2D
to this line. The distance measured is the distance between the specified point and the closest point on the infinitely-extended line defined by this Line2D
. If the specified point intersects the line, this method returns 0.0.
pt
- the specified Point2D
being measured against this line
Point2D
to the current line.
public double ptLineDist(double px, double py)
Returns the distance from a point to this line. The distance measured is the distance between the specified point and the closest point on the infinitely-extended line defined by this Line2D
. If the specified point intersects the line, this method returns 0.0.
px
- the X coordinate of the specified point being measured against this line
py
- the Y coordinate of the specified point being measured against this line
Returns the distance from a Point2D
to this line. The distance measured is the distance between the specified point and the closest point on the infinitely-extended line defined by this Line2D
. If the specified point intersects the line, this method returns 0.0.
pt
- the specified Point2D
being measured
Point2D
to the current line.
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.
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.
public boolean intersects(double x, double y, double w, double h)
Tests if the interior of the
Shape
intersects the interior of a specified rectangular area. The rectangular area is considered to intersect the
Shape
if any point is contained in both the interior of the
Shape
and the specified rectangular area.
The Shape.intersects()
method allows a Shape
implementation to conservatively return true
when:
Shape
intersect, butThis means that for some
Shapes
this method might return
true
even though the rectangular area does not intersect the
Shape
. The
Area
class performs more accurate computations of geometric intersection than most
Shape
objects and therefore can be used if a more precise answer is required.
intersects
in interface Shape
x
- the X coordinate of the upper-left corner of the specified rectangular area
y
- the Y coordinate of the upper-left corner of the specified rectangular area
w
- the width of the specified rectangular area
h
- the height of the specified rectangular area
true
if the interior of the Shape
and the interior of the rectangular area intersect, or are both highly likely to intersect and intersection calculations would be too expensive to perform; false
otherwise.
Tests if the interior of the
Shape
intersects the interior of a specified
Rectangle2D
. The
Shape.intersects()
method allows a
Shape
implementation to conservatively return
true
when:
Rectangle2D
and the Shape
intersect, butThis means that for some
Shapes
this method might return
true
even though the
Rectangle2D
does not intersect the
Shape
. The
Area
class performs more accurate computations of geometric intersection than most
Shape
objects and therefore can be used if a more precise answer is required.
intersects
in interface Shape
r
- the specified Rectangle2D
true
if the interior of the Shape
and the interior of the specified Rectangle2D
intersect, or are both highly likely to intersect and intersection calculations would be too expensive to perform; false
otherwise.
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.
contains
in interface Shape
x
- the X coordinate of the upper-left corner of the specified rectangular area
y
- the Y coordinate of the upper-left corner of the specified rectangular area
w
- the width of the specified rectangular area
h
- the height of the specified rectangular area
false
because a Line2D
contains no area.
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.
Returns an integer
Rectangle
that completely encloses the
Shape
. Note that there is no guarantee that the returned
Rectangle
is the smallest bounding box that encloses the
Shape
, only that the
Shape
lies entirely within the indicated
Rectangle
. The returned
Rectangle
might also fail to completely enclose the
Shape
if the
Shape
overflows the limited range of the integer data type. The
getBounds2D
method generally returns a tighter bounding box due to its greater flexibility in representation.
Note that the definition of insideness can lead to situations where points on the defining outline of the shape
may not be considered contained in the returned bounds
object, but only in cases where those points are also not considered contained in the original shape
.
If a point
is inside the shape
according to the contains(point)
method, then it must be inside the returned Rectangle
bounds object according to the contains(point)
method of the bounds
. Specifically:
shape.contains(x,y)
requires bounds.contains(x,y)
If a point
is not inside the shape
, then it might still be contained in the bounds
object:
bounds.contains(x,y)
does not imply shape.contains(x,y)
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.
getPathIterator
in interface Shape
at
- the specified AffineTransform
PathIterator
that defines the boundary of this Line2D
.
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.
getPathIterator
in interface Shape
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 end points. Since a Line2D
object is always flat, this parameter is ignored.
PathIterator
that defines the boundary of the flattened Line2D
Creates a new object of the same class as this object.
clone
in class Object
OutOfMemoryError
- if there is not enough memory.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4