Package org.eclipse.gef.geometry.planar
Class Line
- java.lang.Object
-
- org.eclipse.gef.geometry.planar.BezierCurve
-
- org.eclipse.gef.geometry.planar.Line
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,ICurve
,IGeometry
,IRotatable<BezierCurve>
,IScalable<BezierCurve>
,ITranslatable<BezierCurve>
public class Line extends BezierCurve
Represents the geometric shape of a line (or linear curve). Note that while all manipulations (e.g. within shrink, expand) within this class are based on double precision, all comparisons (e.g. within contains, intersects, equals, etc.) are based on a limited precision (with an accuracy defined withinPrecisionUtils
) to compensate for rounding effects.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
clone()
Overridden with public visibility as recommended withinCloneable
.boolean
contains(Point p)
boolean
equals(double x1, double y1, double x2, double y2)
Tests whether thisLine
is equal to the line given implicitly by the given point coordinates.Point
get(double t)
Computes thePoint
on thisBezierCurve
at parameter value t, which is expected to lie in the parameterBezierCurve.Interval
[0;1]
.Rectangle
getBounds()
Line
getCopy()
Returns a newLine
, which has the same start and end point coordinates as this one.Angle
getDirectionCCW()
Returns the counter-clockwise angle between the x axis and thisLine
.Angle
getDirectionCW()
Returns the clockwise angle between the x axis and thisLine
.Point
getIntersection(Line l)
Returns the single intersection point between thisLine
and the given one, in case it exists.Point[]
getIntersections(BezierCurve curve)
Returns thePoint
s of intersection of this and the given otherBezierCurve
.double
getLength()
Point[]
getPoints()
Point
getProjection(Point p)
Line
getTransformed(AffineTransform t)
int
hashCode()
boolean
intersects(ICurve c)
boolean
intersects(Line l)
Provides an optimized version of theBezierCurve.intersects(ICurve)
method.boolean
overlaps(BezierCurve c)
Checks if thisBezierCurve
and the given otherBezierCurve
overlap, i.e. an infinite set of intersectionPoint
s exists.boolean
overlaps(Line l)
Line
setLine(double x1, double y1, double x2, double y2)
Initializes thisLine
with the given start and end point coordinatesLine
setLine(Line l)
Initializes thisLine
with the start and end point coordinates of the given one.Line
setLine(Point p1, Point p2)
Initializes thisLine
with the start and end point coordinates provided by the given pointsLine
setX1(double x1)
Line
setX2(double x2)
Line
setY1(double y1)
Line
setY2(double y2)
Path
toPath()
java.lang.String
toString()
boolean
touches(IGeometry g)
boolean
touches(Line l)
Tests whether thisLine
and the given one share at least one common point.-
Methods inherited from class org.eclipse.gef.geometry.planar.BezierCurve
contains, equals, getClipped, getControlBounds, getDerivative, getElevated, getIntersections, getOffset, getOverlap, getOverlaps, getP1, getP2, getParameterAt, getPoint, getRotatedCCW, getRotatedCCW, getRotatedCCW, getRotatedCW, getRotatedCW, getRotatedCW, getScaled, getScaled, getScaled, getScaled, getScaled, getScaled, getTranslated, getTranslated, getX1, getX2, getY1, getY2, overlaps, rotateCCW, rotateCCW, rotateCCW, rotateCW, rotateCW, rotateCW, scale, scale, scale, scale, scale, scale, setP1, setP2, setPoint, split, toBezier, toCubic, toLine, toLineStrip, toLineStrip, toPoints, toQuadratic, translate, translate
-
-
-
-
Constructor Detail
-
Line
public Line(double... coordinates)
Constructs a newLine
from the given coordinate values.- Parameters:
coordinates
- A varargs of 4 doubles, providing the x and y coordinates of the start point, followed by those of the end point- See Also:
BezierCurve(double[])
-
Line
public Line(double x1, double y1, double x2, double y2)
- Parameters:
x1
- the x-coordinate of the start pointy1
- the y-coordinate of the start pointx2
- the x-coordinate of the end pointy2
- the y-coordinate of the end point
-
Line
public Line(Point... points)
- Parameters:
points
- A varargs of two points serving as the start and end point of this line
-
-
Method Detail
-
equals
public boolean equals(double x1, double y1, double x2, double y2)
Tests whether thisLine
is equal to the line given implicitly by the given point coordinates.- Parameters:
x1
- the x-coordinate of the start point of the line to testy1
- the y-coordinate of the start point of the line to testx2
- the x-coordinate of the end point of the line to testy2
- the y-coordinate of the end point of the line to test- Returns:
true
if the given start and end point coordinates are (imprecisely) equal to thisLine
's start and end point coordinates
-
get
public Point get(double t)
Description copied from class:BezierCurve
Computes thePoint
on thisBezierCurve
at parameter value t, which is expected to lie in the parameterBezierCurve.Interval
[0;1]
.- Overrides:
get
in classBezierCurve
- Parameters:
t
- the parameter value for which thisBezierCurve
is evaluated- Returns:
- the
Point
on thisBezierCurve
at the given parameter value
-
getBounds
public Rectangle getBounds()
- Specified by:
getBounds
in interfaceIGeometry
- Overrides:
getBounds
in classBezierCurve
- Returns:
- A new
Rectangle
object that fully encloses thisIGeometry
- See Also:
IGeometry.getBounds()
-
getCopy
public Line getCopy()
Returns a newLine
, which has the same start and end point coordinates as this one.- Specified by:
getCopy
in interfaceIGeometry
- Overrides:
getCopy
in classBezierCurve
- Returns:
- a new
Line
with the same start and end point coordinates
-
getDirectionCCW
public Angle getDirectionCCW()
Returns the counter-clockwise angle between the x axis and thisLine
.- Returns:
- Returns the counter-clockwise angle between the x axis and this
Line
.
-
getDirectionCW
public Angle getDirectionCW()
Returns the clockwise angle between the x axis and thisLine
.- Returns:
- Returns the clockwise angle between the x axis and this
Line
.
-
getIntersection
public Point getIntersection(Line l)
Returns the single intersection point between thisLine
and the given one, in case it exists. Note that even in caseintersects(org.eclipse.gef.geometry.planar.ICurve)
returns true, there may not be a single intersection point in case both lines overlap in more than one point.- Parameters:
l
- the Line, for which to compute the intersection point- Returns:
- the single intersection point between this
Line
and the given one, in case it intersects,null
instead
-
getIntersections
public Point[] getIntersections(BezierCurve curve)
Description copied from class:BezierCurve
Returns thePoint
s of intersection of this and the given otherBezierCurve
.- Overrides:
getIntersections
in classBezierCurve
- Parameters:
curve
- theBezierCurve
which is searched forPoint
s of intersection with thisBezierCurve
- Returns:
- the
Point
s of intersection of thisBezierCurve
and the given otherBezierCurve
-
getLength
public double getLength()
- Returns:
- The distance between start and end points.
- See Also:
Point.getDistance(Point)
-
getPoints
public Point[] getPoints()
- Overrides:
getPoints
in classBezierCurve
- Returns:
- an array with two
Point
s, whose x and y coordinates match those of thisLine
's start and end point
-
getProjection
public Point getProjection(Point p)
Description copied from interface:ICurve
Returns a projection of the given referencePoint
onto thisICurve
, i.e. aPoint
on thisICurve
that is closest to the given referencePoint
. Note, that- Specified by:
getProjection
in interfaceICurve
- Overrides:
getProjection
in classBezierCurve
- Parameters:
p
- The referencePoint
for which to return the projection.- Returns:
- The projection of the given reference
Point
onto thisICurve
.
-
getTransformed
public Line getTransformed(AffineTransform t)
Default implementation returning a transformedPath
representation of thisIGeometry
. Subclasses may override this method to return a more specific representation.- Specified by:
getTransformed
in interfaceIGeometry
- Overrides:
getTransformed
in classBezierCurve
- Parameters:
t
- TheAffineTransform
to be applied- Returns:
- a transformed
Path
representation of thisIGeometry
- See Also:
IGeometry.getTransformed(AffineTransform)
-
intersects
public boolean intersects(ICurve c)
Description copied from interface:ICurve
Tests if thisICurve
and the givenICurve
intersect, i.e. whether a final set of intersection points exists. Two curves intersect if they touch (seeIGeometry.touches(IGeometry)
) but do not overlap (seeICurve.overlaps(ICurve)
).- Specified by:
intersects
in interfaceICurve
- Overrides:
intersects
in classBezierCurve
- Parameters:
c
- TheICurve
to test for intersections.- Returns:
true
if they intersect,false
otherwise
-
intersects
public boolean intersects(Line l)
Provides an optimized version of theBezierCurve.intersects(ICurve)
method.- Parameters:
l
- TheLine
to test for intersections.- Returns:
- see
BezierCurve.intersects(ICurve)
-
overlaps
public boolean overlaps(BezierCurve c)
Description copied from class:BezierCurve
Checks if thisBezierCurve
and the given otherBezierCurve
overlap, i.e. an infinite set of intersectionPoint
s exists.- Overrides:
overlaps
in classBezierCurve
- Parameters:
c
- theBezierCurve
to check for an overlapping segment with thisBezierCurve
- Returns:
true
if this and the given otherBezierCurve
overlap, otherwisefalse
-
overlaps
public boolean overlaps(Line l)
Tests whether thisLine
and the given otherLine
overlap, i.e. they share an infinite number ofPoint
s.- Parameters:
l
- the otherLine
to test for overlap with thisLine
- Returns:
true
if thisLine
and the otherLine
overlap, otherwisefalse
- See Also:
ICurve.overlaps(ICurve)
-
setLine
public Line setLine(double x1, double y1, double x2, double y2)
Initializes thisLine
with the given start and end point coordinates- Parameters:
x1
- the x-coordinate of the start pointy1
- the y-coordinate of the start pointx2
- the x-coordinate of the end pointy2
- the y-coordinate of the end point- Returns:
this
for convenience
-
setLine
public Line setLine(Line l)
Initializes thisLine
with the start and end point coordinates of the given one.- Parameters:
l
- theLine
whose start and end point coordinates should be used for initialization- Returns:
this
for convenience
-
setLine
public Line setLine(Point p1, Point p2)
Initializes thisLine
with the start and end point coordinates provided by the given points
-
setX1
public Line setX1(double x1)
-
setX2
public Line setX2(double x2)
-
setY1
public Line setY1(double y1)
-
setY2
public Line setY2(double y2)
-
toPath
public Path toPath()
Description copied from class:BezierCurve
- Specified by:
toPath
in interfaceIGeometry
- Overrides:
toPath
in classBezierCurve
- Returns:
- a
Path
approximating thisBezierCurve
usingLine
segments
-
toString
public java.lang.String toString()
- Overrides:
toString
in classBezierCurve
-
touches
public boolean touches(Line l)
Tests whether thisLine
and the given one share at least one common point.
-
clone
public java.lang.Object clone()
Overridden with public visibility as recommended withinCloneable
.- Overrides:
clone
in classjava.lang.Object
-
hashCode
public final int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
- See Also:
Object.hashCode()
-
-