Package org.eclipse.gef.geometry.planar
Class Polyline
java.lang.Object
org.eclipse.gef.geometry.planar.Polyline
- All Implemented Interfaces:
Serializable,Cloneable,ICurve,IGeometry,IRotatable<Polyline>,IScalable<Polyline>,ITranslatable<Polyline>
Represents the geometric shape of a polyline.
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 within
PrecisionUtils) to compensate for rounding effects.- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclone()Overridden with public visibility as recommended withinCloneable.booleancontains(double x, double y) Checks whether the point that is represented by its x- and y-coordinates is contained within thisPolyline.booleanbooleanbooleanChecks whether thisPolylineand the one that is indirectly given via the sequence of points are regarded to be equal.final RectangleComputes the centroid of thisAbstractPointListBasedGeometry.final double[]Returns a double array which represents the sequence of coordinates of thePoints that make up thisAbstractPointListBasedGeometry.getCopy()Returns a new identical copy of thisIGeometry.Line[]Point[]doubleICurve[]getP1()getP2()final Point[]Returns a copy of thePoints that make up thisAbstractPointListBasedGeometry.getProjection(Point reference) getRotatedCCW(Angle alpha) getRotatedCCW(Angle angle, double cx, double cy) getRotatedCCW(Angle alpha, Point center) getRotatedCW(Angle alpha) getRotatedCW(Angle angle, double cx, double cy) getRotatedCW(Angle alpha, Point center) getScaled(double factor) Scales a copy of the calling object by the given factor relative to its centerPoint.getScaled(double factorX, double factorY) Scales a copy of the calling object by the given factors relative to its centerPoint.getScaled(double factor, double cx, double cy) Scales a copy of the calling object by the given factor relative to the given centerPoint(cx, cy).getScaled(double fx, double fy, double cx, double cy) Scales a copy of the calling object by the given factors relative to the given centerPoint(cx, cy).Scales a copy of the calling object by the given factors relative to the given centerPoint.Scales a copy of the calling object by the given factor relative to the given centerPoint.getTranslated(double dx, double dy) Translates a copy of this object by the given values in x and y direction.getTranslated(Point pt) Translates a copy of this object by the givenPoint.doublegetX1()Returns the startPoint's x coordinate.doublegetX2()Returns the endPoint's x coordinate.doublegetY1()Returns the startPoint's y coordinate.doublegetY2()Returns the endPoint's y coordinate.final inthashCode()booleanintersects(ICurve c) booleanRotates thisAbstractPointListBasedGeometrycounter-clockwise (CCW) by the givenAnglearound its centroid (seegetCentroid()).Rotates thisAbstractPointListBasedGeometryclockwise (CW) by the givenAnglearound its centroid (seegetCentroid()).scale(double factor) Scales the calling object by the given factor relative to its centerPoint.scale(double fx, double fy) Scales the calling object by the given factors relative to the given centerPoint.scale(double factor, double cx, double cy) Scales the calling object by the given factor relative to the given centerPoint(cx, cy).scale(double fx, double fy, double cx, double cy) Scales the calling object by the given factors relative to the given centerPoint(cx, cy).Scales the calling object by the given factors relative to the given centerPoint.Scales the calling object by the given factor relative to the given centerPoint.Line[]toBezier()Computes a list ofBezierCurves that approximate theICurve.toPath()Transforms thisPolylineinto aPolyBezier.toString()booleantranslate(double dx, double dy) Translates the object by the given values in x and y direction.Translates the object by the givenPoint.
-
Constructor Details
-
Polyline
public Polyline(double... coordinates) Constructs a newPolylinefrom a even-numbered sequence of coordinates. Similar toPolyline(Point...), only that coordinates of points rather thanPoints are provided.- Parameters:
coordinates- an alternating, even-numbered sequence of x- and y-coordinates, representing the points from which thePolylineis to be created
-
Polyline
-
Polyline
Constructs a newPolylinefrom the given sequence ofPoints. ThePolylinethat is created will be automatically closed, i.e. it will not only contain a segment between succeeding points of the sequence but as well back from the last to the first point.- Parameters:
points- a sequence of points, from which thePolylineis to be created
-
-
Method Details
-
contains
public boolean contains(double x, double y) Checks whether the point that is represented by its x- and y-coordinates is contained within thisPolyline.- Parameters:
x- the x coordinate of the point to testy- the y coordinate of the point to test- Returns:
trueif the point represented by its coordinates if contained within thisPolyline, otherwisefalse
-
contains
Description copied from interface:IGeometry -
equals
-
equals
-
getCopy
Description copied from interface:IGeometryReturns a new identical copy of thisIGeometry. -
getCurves
-
getIntersections
Description copied from interface:ICurve- Specified by:
getIntersectionsin interfaceICurve- Parameters:
c- TheICurveto compute intersection points with.- Returns:
- The points of intersection.
-
getLength
public double getLength()- Returns:
- The length of this
Polyline.
-
getOverlaps
Description copied from interface:ICurve- Specified by:
getOverlapsin interfaceICurve- Parameters:
c- The curve to compute overlaps with.- Returns:
- The segments where both curves overlap.
-
getP1
Description copied from interface:ICurve -
getP2
Description copied from interface:ICurve -
getProjection
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- Parameters:
reference- The referencePointfor which to return the projection.- Returns:
- The projection of the given reference
Pointonto thisICurve.
-
getTransformed
Default implementation returning a transformedPathrepresentation of thisIGeometry. Subclasses may override this method to return a more specific representation.- Specified by:
getTransformedin interfaceIGeometry- Parameters:
t- TheAffineTransformto be applied- Returns:
- a transformed
Pathrepresentation of thisIGeometry
-
getX1
public double getX1()Description copied from interface:ICurveReturns the startPoint's x coordinate. -
getX2
public double getX2()Description copied from interface:ICurveReturns the endPoint's x coordinate. -
getY1
public double getY1()Description copied from interface:ICurveReturns the startPoint's y coordinate. -
getY2
public double getY2()Description copied from interface:ICurveReturns the endPoint's y coordinate. -
intersects
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- Parameters:
c- TheICurveto test for intersections.- Returns:
trueif they intersect,falseotherwise
-
overlaps
Description copied from interface:ICurveTests if thisICurveand the givenICurveoverlap, i.e. whether an infinite set of intersection points exists. Two curves overlap if they touch (seeIGeometry.touches(IGeometry)) but not intersect (seeICurve.intersects(ICurve)). -
toBezier
Description copied from interface:ICurveComputes a list ofBezierCurves that approximate theICurve. For example, aLineor aBezierCurvein general could return a list with the curve itself as its only element. But anEllipseor anArcmay return a list of consecutiveBezierCurves which approximate theICurve.- Specified by:
toBezierin interfaceICurve- Returns:
- a list of
BezierCurves that approximate theICurve
-
toPath
Description copied from interface:IGeometry -
toPolyBezier
Transforms thisPolylineinto aPolyBezier.- Returns:
- a
PolyBezierrepresenting thisPolyline
-
toString
-
getBounds
Description copied from interface:IGeometry -
getCentroid
Computes the centroid of thisAbstractPointListBasedGeometry. The centroid is the "center of gravity", i.e. assuming aPolygonis spanned by thePoints of thisAbstractPointListBasedGeometryand it is made of a material of constant density, then it is in a balanced state, if you put it on a pin that is placed exactly on its centroid.- Returns:
- the center
Point(or centroid) of thisAbstractPointListBasedGeometry
-
getCoordinates
public final double[] getCoordinates()Returns a double array which represents the sequence of coordinates of thePoints that make up thisAbstractPointListBasedGeometry.- Returns:
- an array that alternately contains the x and y coordinates of
this
AbstractPointListBasedGeometry's points
-
getPoints
Returns a copy of thePoints that make up thisAbstractPointListBasedGeometry. -
getRotatedCCW
Description copied from interface:IRotatableRotates the calling object by specifiedAnglecounter-clock-wise (CCW) around its centerPoint. Does not necessarily return an object of the same type.- Specified by:
getRotatedCCWin interfaceIRotatable<T extends org.eclipse.gef.geometry.planar.AbstractPointListBasedGeometry<?>>- Parameters:
alpha- rotationAngle- Returns:
- an
IGeometryrepresenting the result of the rotation
-
getRotatedCCW
Description copied from interface:IRotatableRotates the calling object by the specifiedAnglecounter-clock-wise (CCW) around the specified centerPoint(cx, cy). Does not necessarily return an object of the same type.- Specified by:
getRotatedCCWin interfaceIRotatable<T extends org.eclipse.gef.geometry.planar.AbstractPointListBasedGeometry<?>>- Parameters:
angle- rotationAnglecx- x-coordinate of the relativePointfor the rotationcy- y-coordinate of the relativePointfor the rotation- Returns:
- an
IGeometryrepresenting the result of the rotation
-
getRotatedCCW
Description copied from interface:IRotatableRotates the calling object by the specifiedAnglecounter-clock-wise (CCW) around the specified centerPoint. Does not necessarily return an object of the same type.- Specified by:
getRotatedCCWin interfaceIRotatable<T extends org.eclipse.gef.geometry.planar.AbstractPointListBasedGeometry<?>>- Parameters:
alpha- rotationAnglecenter- relativePointfor the rotation- Returns:
- an
IGeometryrepresenting the result of the rotation
-
getRotatedCW
Description copied from interface:IRotatableRotates the calling object by specifiedAngleclock-wise (CW) around its centerPoint. Does not necessarily return an object of the same type.- Specified by:
getRotatedCWin interfaceIRotatable<T extends org.eclipse.gef.geometry.planar.AbstractPointListBasedGeometry<?>>- Parameters:
alpha- rotationAngle- Returns:
- an
IGeometryrepresenting the result of the rotation
-
getRotatedCW
Description copied from interface:IRotatableRotates the calling object by the specifiedAngleclock-wise (CW) around the specified centerPoint(cx, cy). Does not necessarily return an object of the same type.- Specified by:
getRotatedCWin interfaceIRotatable<T extends org.eclipse.gef.geometry.planar.AbstractPointListBasedGeometry<?>>- Parameters:
angle- rotationAnglecx- x-coordinate of the relativePointfor the rotationcy- y-coordinate of the relativePointfor the rotation- Returns:
- an
IGeometryrepresenting the result of the rotation
-
getRotatedCW
Description copied from interface:IRotatableRotates the calling object by the specifiedAngleclock-wise (CW) around the specified centerPoint. Does not necessarily return an object of the same type.- Specified by:
getRotatedCWin interfaceIRotatable<T extends org.eclipse.gef.geometry.planar.AbstractPointListBasedGeometry<?>>- Parameters:
alpha- rotationAnglecenter- relativePointfor the rotation- Returns:
- an
IGeometryrepresenting the result of the rotation
-
getScaled
Description copied from interface:IScalableScales a copy of the calling object by the given factor relative to its centerPoint. -
getScaled
Description copied from interface:IScalableScales a copy of the calling object by the given factors relative to its centerPoint. -
getScaled
Description copied from interface:IScalableScales a copy of the calling object by the given factor relative to the given centerPoint(cx, cy).- Specified by:
getScaledin interfaceIScalable<T extends org.eclipse.gef.geometry.planar.AbstractPointListBasedGeometry<?>>- Parameters:
factor- scale-factorcx- x-coordinate of the relativePointfor the scalingcy- y-coordinate of the relativePointfor the scaling- Returns:
- the new, scaled object
-
getScaled
Description copied from interface:IScalableScales a copy of the calling object by the given factors relative to the given centerPoint(cx, cy).- Specified by:
getScaledin interfaceIScalable<T extends org.eclipse.gef.geometry.planar.AbstractPointListBasedGeometry<?>>- Parameters:
fx- x-scale-factorfy- y-scale-factorcx- x-coordinate of the relativePointfor the scalingcy- y-coordinate of the relativePointfor the scaling- Returns:
- the new, scaled object
-
getScaled
Description copied from interface:IScalableScales a copy of the calling object by the given factors relative to the given centerPoint. -
getScaled
Description copied from interface:IScalableScales a copy of the calling object by the given factor relative to the given centerPoint. -
getTranslated
Description copied from interface:ITranslatableTranslates a copy of this object by the given values in x and y direction.- Specified by:
getTranslatedin interfaceITranslatable<T extends org.eclipse.gef.geometry.planar.AbstractPointListBasedGeometry<?>>- Parameters:
dx- x-translationdy- y-translation- Returns:
- a new, translated object
-
getTranslated
Description copied from interface:ITranslatableTranslates a copy of this object by the givenPoint.- Specified by:
getTranslatedin interfaceITranslatable<T extends org.eclipse.gef.geometry.planar.AbstractPointListBasedGeometry<?>>- Parameters:
pt- translationPoint- Returns:
- a new, translated object
-
rotateCCW
Rotates thisAbstractPointListBasedGeometrycounter-clockwise (CCW) by the givenAnglearound its centroid (seegetCentroid()).- Parameters:
alpha- the rotationAngle- Returns:
thisfor convenience- See Also:
-
rotateCCW
Rotates thisAbstractPointListBasedGeometrycounter-clockwise (CCW) by the givenAnglearound thePointspecified by the passed-in x and y coordinates. -
rotateCCW
-
rotateCW
Rotates thisAbstractPointListBasedGeometryclockwise (CW) by the givenAnglearound its centroid (seegetCentroid()).- Parameters:
alpha- the rotationAngle- Returns:
thisfor convenience- See Also:
-
rotateCW
Rotates thisAbstractPointListBasedGeometryclockwise (CW) by the givenAnglearound thePointspecified by the passed-in x and y coordinates. -
rotateCW
-
scale
Description copied from interface:IScalableScales the calling object by the given factor relative to its centerPoint. -
scale
Description copied from interface:IScalableScales the calling object by the given factors relative to the given centerPoint. -
scale
Description copied from interface:IScalableScales the calling object by the given factor relative to the given centerPoint(cx, cy). -
scale
Description copied from interface:IScalableScales the calling object by the given factors relative to the given centerPoint(cx, cy).- Specified by:
scalein interfaceIScalable<T extends org.eclipse.gef.geometry.planar.AbstractPointListBasedGeometry<?>>- Parameters:
fx- x-scale-factorfy- y-scale-factorcx- x-coordinate of the relativePointfor the scalingcy- y-coordinate of the relativePointfor the scaling- Returns:
thisfor convenience
-
scale
Description copied from interface:IScalableScales the calling object by the given factors relative to the given centerPoint. -
scale
Description copied from interface:IScalableScales the calling object by the given factor relative to the given centerPoint. -
translate
Description copied from interface:ITranslatableTranslates the object by the given values in x and y direction.- Specified by:
translatein interfaceITranslatable<T extends org.eclipse.gef.geometry.planar.AbstractPointListBasedGeometry<?>>- Parameters:
dx- x-translationdy- y-translation- Returns:
thisfor convenience
-
translate
Description copied from interface:ITranslatableTranslates the object by the givenPoint.- Specified by:
translatein interfaceITranslatable<T extends org.eclipse.gef.geometry.planar.AbstractPointListBasedGeometry<?>>- Parameters:
p- translationPoint- Returns:
thisfor convenience
-
clone
Overridden with public visibility as recommended withinCloneable. -
hashCode
public final int hashCode() -
touches
Description copied from interface:IGeometry
-