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.Objectclone()Overridden with public visibility as recommended withinCloneable.booleancontains(Point p)booleanequals(double x1, double y1, double x2, double y2)Tests whether thisLineis equal to the line given implicitly by the given point coordinates.Pointget(double t)Computes thePointon thisBezierCurveat parameter value t, which is expected to lie in the parameterBezierCurve.Interval[0;1].RectanglegetBounds()LinegetCopy()Returns a newLine, which has the same start and end point coordinates as this one.AnglegetDirectionCCW()Returns the counter-clockwise angle between the x axis and thisLine.AnglegetDirectionCW()Returns the clockwise angle between the x axis and thisLine.PointgetIntersection(Line l)Returns the single intersection point between thisLineand the given one, in case it exists.Point[]getIntersections(BezierCurve curve)Returns thePoints of intersection of this and the given otherBezierCurve.doublegetLength()Point[]getPoints()PointgetProjection(Point p)LinegetTransformed(AffineTransform t)inthashCode()booleanintersects(ICurve c)booleanintersects(Line l)Provides an optimized version of theBezierCurve.intersects(ICurve)method.booleanoverlaps(BezierCurve c)Checks if thisBezierCurveand the given otherBezierCurveoverlap, i.e. an infinite set of intersectionPoints exists.booleanoverlaps(Line l)LinesetLine(double x1, double y1, double x2, double y2)Initializes thisLinewith the given start and end point coordinatesLinesetLine(Line l)Initializes thisLinewith the start and end point coordinates of the given one.LinesetLine(Point p1, Point p2)Initializes thisLinewith the start and end point coordinates provided by the given pointsLinesetX1(double x1)LinesetX2(double x2)LinesetY1(double y1)LinesetY2(double y2)PathtoPath()java.lang.StringtoString()booleantouches(IGeometry g)booleantouches(Line l)Tests whether thisLineand 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 newLinefrom 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 thisLineis 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:
trueif 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:BezierCurveComputes thePointon thisBezierCurveat parameter value t, which is expected to lie in the parameterBezierCurve.Interval[0;1].- Overrides:
getin classBezierCurve- Parameters:
t- the parameter value for which thisBezierCurveis evaluated- Returns:
- the
Pointon thisBezierCurveat the given parameter value
-
getBounds
public Rectangle getBounds()
- Specified by:
getBoundsin interfaceIGeometry- Overrides:
getBoundsin classBezierCurve- Returns:
- A new
Rectangleobject 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:
getCopyin interfaceIGeometry- Overrides:
getCopyin classBezierCurve- Returns:
- a new
Linewith 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 thisLineand 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
Lineand the given one, in case it intersects,nullinstead
-
getIntersections
public Point[] getIntersections(BezierCurve curve)
Description copied from class:BezierCurveReturns thePoints of intersection of this and the given otherBezierCurve.- Overrides:
getIntersectionsin classBezierCurve- Parameters:
curve- theBezierCurvewhich is searched forPoints of intersection with thisBezierCurve- Returns:
- the
Points of intersection of thisBezierCurveand 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:
getPointsin classBezierCurve- Returns:
- an array with two
Points, whose x and y coordinates match those of thisLine's start and end point
-
getProjection
public Point getProjection(Point p)
Description copied from interface:ICurveReturns a projection of the given referencePointonto thisICurve, i.e. aPointon thisICurvethat is closest to the given referencePoint. Note, that- Specified by:
getProjectionin interfaceICurve- Overrides:
getProjectionin classBezierCurve- Parameters:
p- The referencePointfor which to return the projection.- Returns:
- The projection of the given reference
Pointonto thisICurve.
-
getTransformed
public Line getTransformed(AffineTransform t)
Default implementation returning a transformedPathrepresentation of thisIGeometry. Subclasses may override this method to return a more specific representation.- Specified by:
getTransformedin interfaceIGeometry- Overrides:
getTransformedin classBezierCurve- Parameters:
t- TheAffineTransformto be applied- Returns:
- a transformed
Pathrepresentation of thisIGeometry - See Also:
IGeometry.getTransformed(AffineTransform)
-
intersects
public boolean intersects(ICurve c)
Description copied from interface:ICurveTests if thisICurveand the givenICurveintersect, 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:
intersectsin interfaceICurve- Overrides:
intersectsin classBezierCurve- Parameters:
c- TheICurveto test for intersections.- Returns:
trueif they intersect,falseotherwise
-
intersects
public boolean intersects(Line l)
Provides an optimized version of theBezierCurve.intersects(ICurve)method.- Parameters:
l- TheLineto test for intersections.- Returns:
- see
BezierCurve.intersects(ICurve)
-
overlaps
public boolean overlaps(BezierCurve c)
Description copied from class:BezierCurveChecks if thisBezierCurveand the given otherBezierCurveoverlap, i.e. an infinite set of intersectionPoints exists.- Overrides:
overlapsin classBezierCurve- Parameters:
c- theBezierCurveto check for an overlapping segment with thisBezierCurve- Returns:
trueif this and the given otherBezierCurveoverlap, otherwisefalse
-
overlaps
public boolean overlaps(Line l)
Tests whether thisLineand the given otherLineoverlap, i.e. they share an infinite number ofPoints.- Parameters:
l- the otherLineto test for overlap with thisLine- Returns:
trueif thisLineand the otherLineoverlap, otherwisefalse- See Also:
ICurve.overlaps(ICurve)
-
setLine
public Line setLine(double x1, double y1, double x2, double y2)
Initializes thisLinewith 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:
thisfor convenience
-
setLine
public Line setLine(Line l)
Initializes thisLinewith the start and end point coordinates of the given one.- Parameters:
l- theLinewhose start and end point coordinates should be used for initialization- Returns:
thisfor convenience
-
setLine
public Line setLine(Point p1, Point p2)
Initializes thisLinewith 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:
toPathin interfaceIGeometry- Overrides:
toPathin classBezierCurve- Returns:
- a
Pathapproximating thisBezierCurveusingLinesegments
-
toString
public java.lang.String toString()
- Overrides:
toStringin classBezierCurve
-
touches
public boolean touches(Line l)
Tests whether thisLineand the given one share at least one common point.
-
clone
public java.lang.Object clone()
Overridden with public visibility as recommended withinCloneable.- Overrides:
clonein classjava.lang.Object
-
hashCode
public final int hashCode()
- Overrides:
hashCodein classjava.lang.Object- See Also:
Object.hashCode()
-
-