Package org.eclipse.gef.geometry.planar
Class Polyline
- java.lang.Object
-
- org.eclipse.gef.geometry.planar.Polyline
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,ICurve
,IGeometry
,IRotatable<Polyline>
,IScalable<Polyline>
,ITranslatable<Polyline>
public class Polyline extends java.lang.Object implements ICurve
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 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(double x, double y)
Checks whether the point that is represented by its x- and y-coordinates is contained within thisPolyline
.boolean
contains(Point p)
boolean
equals(java.lang.Object o)
boolean
equals(Point... points)
Checks whether thisPolyline
and the one that is indirectly given via the sequence of points are regarded to be equal.Rectangle
getBounds()
Point
getCentroid()
Computes the centroid of thisAbstractPointListBasedGeometry
.double[]
getCoordinates()
Returns a double array which represents the sequence of coordinates of thePoint
s that make up thisAbstractPointListBasedGeometry
.Polyline
getCopy()
Returns a new identical copy of thisIGeometry
.Line[]
getCurves()
Point[]
getIntersections(ICurve c)
double
getLength()
ICurve[]
getOverlaps(ICurve c)
Point
getP1()
Point
getP2()
Point[]
getPoints()
Returns a copy of thePoint
s that make up thisAbstractPointListBasedGeometry
.Point
getProjection(Point reference)
T
getRotatedCCW(Angle alpha)
T
getRotatedCCW(Angle angle, double cx, double cy)
T
getRotatedCCW(Angle alpha, Point center)
T
getRotatedCW(Angle alpha)
T
getRotatedCW(Angle angle, double cx, double cy)
T
getRotatedCW(Angle alpha, Point center)
T
getScaled(double factor)
Scales a copy of the calling object by the given factor relative to its centerPoint
.T
getScaled(double factorX, double factorY)
Scales a copy of the calling object by the given factors relative to its centerPoint
.T
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).T
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).T
getScaled(double factorX, double factorY, Point center)
Scales a copy of the calling object by the given factors relative to the given centerPoint
.T
getScaled(double factor, Point center)
Scales a copy of the calling object by the given factor relative to the given centerPoint
.Polyline
getTransformed(AffineTransform t)
T
getTranslated(double dx, double dy)
Translates a copy of this object by the given values in x and y direction.T
getTranslated(Point pt)
Translates a copy of this object by the givenPoint
.double
getX1()
Returns the startPoint
's x coordinate.double
getX2()
Returns the endPoint
's x coordinate.double
getY1()
Returns the startPoint
's y coordinate.double
getY2()
Returns the endPoint
's y coordinate.int
hashCode()
boolean
intersects(ICurve c)
boolean
overlaps(ICurve c)
T
rotateCCW(Angle alpha)
Rotates thisAbstractPointListBasedGeometry
counter-clockwise (CCW) by the givenAngle
around its centroid (seegetCentroid()
).T
rotateCCW(Angle alpha, double cx, double cy)
T
rotateCCW(Angle alpha, Point center)
T
rotateCW(Angle alpha)
Rotates thisAbstractPointListBasedGeometry
clockwise (CW) by the givenAngle
around its centroid (seegetCentroid()
).T
rotateCW(Angle alpha, double cx, double cy)
T
rotateCW(Angle alpha, Point center)
T
scale(double factor)
Scales the calling object by the given factor relative to its centerPoint
.T
scale(double fx, double fy)
Scales the calling object by the given factors relative to the given centerPoint
.T
scale(double factor, double cx, double cy)
Scales the calling object by the given factor relative to the given centerPoint
(cx, cy).T
scale(double fx, double fy, double cx, double cy)
Scales the calling object by the given factors relative to the given centerPoint
(cx, cy).T
scale(double fx, double fy, Point center)
Scales the calling object by the given factors relative to the given centerPoint
.T
scale(double factor, Point center)
Scales the calling object by the given factor relative to the given centerPoint
.Line[]
toBezier()
Computes a list ofBezierCurve
s that approximate theICurve
.Path
toPath()
PolyBezier
toPolyBezier()
Transforms thisPolyline
into aPolyBezier
.java.lang.String
toString()
boolean
touches(IGeometry g)
T
translate(double dx, double dy)
Translates the object by the given values in x and y direction.T
translate(Point p)
Translates the object by the givenPoint
.
-
-
-
Constructor Detail
-
Polyline
public Polyline(double... coordinates)
Constructs a newPolyline
from a even-numbered sequence of coordinates. Similar toPolyline(Point...)
, only that coordinates of points rather thanPoint
s are provided.- Parameters:
coordinates
- an alternating, even-numbered sequence of x- and y-coordinates, representing the points from which thePolyline
is to be created
-
Polyline
public Polyline(Line[] segmentsArray)
-
Polyline
public Polyline(Point... points)
Constructs a newPolyline
from the given sequence ofPoint
s. ThePolyline
that 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 thePolyline
is to be created
-
-
Method Detail
-
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:
true
if the point represented by its coordinates if contained within thisPolyline
, otherwisefalse
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
equals
public boolean equals(Point... points)
-
getCopy
public Polyline getCopy()
Description copied from interface:IGeometry
Returns a new identical copy of thisIGeometry
.
-
getCurves
public Line[] getCurves()
-
getIntersections
public Point[] getIntersections(ICurve c)
Description copied from interface:ICurve
- Specified by:
getIntersections
in interfaceICurve
- Parameters:
c
- TheICurve
to compute intersection points with.- Returns:
- The points of intersection.
-
getLength
public double getLength()
- Returns:
- The length of this
Polyline
.
-
getOverlaps
public ICurve[] getOverlaps(ICurve c)
Description copied from interface:ICurve
- Specified by:
getOverlaps
in interfaceICurve
- Parameters:
c
- The curve to compute overlaps with.- Returns:
- The segments where both curves overlap.
-
getProjection
public Point getProjection(Point reference)
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
- Parameters:
reference
- The referencePoint
for which to return the projection.- Returns:
- The projection of the given reference
Point
onto thisICurve
.
-
getTransformed
public Polyline 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
- Parameters:
t
- TheAffineTransform
to be applied- Returns:
- a transformed
Path
representation of thisIGeometry
-
getX1
public double getX1()
Description copied from interface:ICurve
Returns the startPoint
's x coordinate.
-
getX2
public double getX2()
Description copied from interface:ICurve
Returns the endPoint
's x coordinate.
-
getY1
public double getY1()
Description copied from interface:ICurve
Returns the startPoint
's y coordinate.
-
getY2
public double getY2()
Description copied from interface:ICurve
Returns the endPoint
's y coordinate.
-
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
- Parameters:
c
- TheICurve
to test for intersections.- Returns:
true
if they intersect,false
otherwise
-
overlaps
public boolean overlaps(ICurve c)
Description copied from interface:ICurve
Tests if thisICurve
and the givenICurve
overlap, 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
public Line[] toBezier()
Description copied from interface:ICurve
Computes a list ofBezierCurve
s that approximate theICurve
. For example, aLine
or aBezierCurve
in general could return a list with the curve itself as its only element. But anEllipse
or anArc
may return a list of consecutiveBezierCurve
s which approximate theICurve
.- Specified by:
toBezier
in interfaceICurve
- Returns:
- a list of
BezierCurve
s that approximate theICurve
-
toPolyBezier
public PolyBezier toPolyBezier()
Transforms thisPolyline
into aPolyBezier
.- Returns:
- a
PolyBezier
representing thisPolyline
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getCentroid
public Point getCentroid()
Computes the centroid of thisAbstractPointListBasedGeometry
. The centroid is the "center of gravity", i.e. assuming aPolygon
is spanned by thePoint
s of thisAbstractPointListBasedGeometry
and 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 thePoint
s that make up thisAbstractPointListBasedGeometry
.- Returns:
- an array that alternately contains the x and y coordinates of
this
AbstractPointListBasedGeometry
's points
-
getPoints
public final Point[] getPoints()
Returns a copy of thePoint
s that make up thisAbstractPointListBasedGeometry
.
-
getRotatedCCW
public T getRotatedCCW(Angle alpha)
Description copied from interface:IRotatable
Rotates the calling object by specifiedAngle
counter-clock-wise (CCW) around its centerPoint
. Does not necessarily return an object of the same type.- Specified by:
getRotatedCCW
in interfaceIRotatable<T extends org.eclipse.gef.geometry.planar.AbstractPointListBasedGeometry<?>>
- Parameters:
alpha
- rotationAngle
- Returns:
- an
IGeometry
representing the result of the rotation
-
getRotatedCCW
public T getRotatedCCW(Angle angle, double cx, double cy)
Description copied from interface:IRotatable
Rotates the calling object by the specifiedAngle
counter-clock-wise (CCW) around the specified centerPoint
(cx, cy). Does not necessarily return an object of the same type.- Specified by:
getRotatedCCW
in interfaceIRotatable<T extends org.eclipse.gef.geometry.planar.AbstractPointListBasedGeometry<?>>
- Parameters:
angle
- rotationAngle
cx
- x-coordinate of the relativePoint
for the rotationcy
- y-coordinate of the relativePoint
for the rotation- Returns:
- an
IGeometry
representing the result of the rotation
-
getRotatedCCW
public T getRotatedCCW(Angle alpha, Point center)
Description copied from interface:IRotatable
Rotates the calling object by the specifiedAngle
counter-clock-wise (CCW) around the specified centerPoint
. Does not necessarily return an object of the same type.- Specified by:
getRotatedCCW
in interfaceIRotatable<T extends org.eclipse.gef.geometry.planar.AbstractPointListBasedGeometry<?>>
- Parameters:
alpha
- rotationAngle
center
- relativePoint
for the rotation- Returns:
- an
IGeometry
representing the result of the rotation
-
getRotatedCW
public T getRotatedCW(Angle alpha)
Description copied from interface:IRotatable
Rotates the calling object by specifiedAngle
clock-wise (CW) around its centerPoint
. Does not necessarily return an object of the same type.- Specified by:
getRotatedCW
in interfaceIRotatable<T extends org.eclipse.gef.geometry.planar.AbstractPointListBasedGeometry<?>>
- Parameters:
alpha
- rotationAngle
- Returns:
- an
IGeometry
representing the result of the rotation
-
getRotatedCW
public T getRotatedCW(Angle angle, double cx, double cy)
Description copied from interface:IRotatable
Rotates the calling object by the specifiedAngle
clock-wise (CW) around the specified centerPoint
(cx, cy). Does not necessarily return an object of the same type.- Specified by:
getRotatedCW
in interfaceIRotatable<T extends org.eclipse.gef.geometry.planar.AbstractPointListBasedGeometry<?>>
- Parameters:
angle
- rotationAngle
cx
- x-coordinate of the relativePoint
for the rotationcy
- y-coordinate of the relativePoint
for the rotation- Returns:
- an
IGeometry
representing the result of the rotation
-
getRotatedCW
public T getRotatedCW(Angle alpha, Point center)
Description copied from interface:IRotatable
Rotates the calling object by the specifiedAngle
clock-wise (CW) around the specified centerPoint
. Does not necessarily return an object of the same type.- Specified by:
getRotatedCW
in interfaceIRotatable<T extends org.eclipse.gef.geometry.planar.AbstractPointListBasedGeometry<?>>
- Parameters:
alpha
- rotationAngle
center
- relativePoint
for the rotation- Returns:
- an
IGeometry
representing the result of the rotation
-
getScaled
public T getScaled(double factor)
Description copied from interface:IScalable
Scales a copy of the calling object by the given factor relative to its centerPoint
.
-
getScaled
public T getScaled(double factorX, double factorY)
Description copied from interface:IScalable
Scales a copy of the calling object by the given factors relative to its centerPoint
.
-
getScaled
public T getScaled(double factor, double cx, double cy)
Description copied from interface:IScalable
Scales a copy of the calling object by the given factor relative to the given centerPoint
(cx, cy).- Specified by:
getScaled
in interfaceIScalable<T extends org.eclipse.gef.geometry.planar.AbstractPointListBasedGeometry<?>>
- Parameters:
factor
- scale-factorcx
- x-coordinate of the relativePoint
for the scalingcy
- y-coordinate of the relativePoint
for the scaling- Returns:
- the new, scaled object
-
getScaled
public T getScaled(double fx, double fy, double cx, double cy)
Description copied from interface:IScalable
Scales a copy of the calling object by the given factors relative to the given centerPoint
(cx, cy).- Specified by:
getScaled
in interfaceIScalable<T extends org.eclipse.gef.geometry.planar.AbstractPointListBasedGeometry<?>>
- Parameters:
fx
- x-scale-factorfy
- y-scale-factorcx
- x-coordinate of the relativePoint
for the scalingcy
- y-coordinate of the relativePoint
for the scaling- Returns:
- the new, scaled object
-
getScaled
public T getScaled(double factorX, double factorY, Point center)
Description copied from interface:IScalable
Scales a copy of the calling object by the given factors relative to the given centerPoint
.
-
getScaled
public T getScaled(double factor, Point center)
Description copied from interface:IScalable
Scales a copy of the calling object by the given factor relative to the given centerPoint
.
-
getTranslated
public T getTranslated(double dx, double dy)
Description copied from interface:ITranslatable
Translates a copy of this object by the given values in x and y direction.- Specified by:
getTranslated
in interfaceITranslatable<T extends org.eclipse.gef.geometry.planar.AbstractPointListBasedGeometry<?>>
- Parameters:
dx
- x-translationdy
- y-translation- Returns:
- a new, translated object
-
getTranslated
public T getTranslated(Point pt)
Description copied from interface:ITranslatable
Translates a copy of this object by the givenPoint
.- Specified by:
getTranslated
in interfaceITranslatable<T extends org.eclipse.gef.geometry.planar.AbstractPointListBasedGeometry<?>>
- Parameters:
pt
- translationPoint
- Returns:
- a new, translated object
-
rotateCCW
public T rotateCCW(Angle alpha)
Rotates thisAbstractPointListBasedGeometry
counter-clockwise (CCW) by the givenAngle
around its centroid (seegetCentroid()
).- Parameters:
alpha
- the rotationAngle
- Returns:
this
for convenience- See Also:
rotateCCW(Angle, Point)
-
rotateCCW
public T rotateCCW(Angle alpha, double cx, double cy)
Rotates thisAbstractPointListBasedGeometry
counter-clockwise (CCW) by the givenAngle
around thePoint
specified by the passed-in x and y coordinates.- Parameters:
alpha
- the rotationAngle
cx
- the x coordinate of thePoint
to rotate aroundcy
- the y coordinate of thePoint
to rotate around- Returns:
this
for convenience- See Also:
rotateCCW(Angle, Point)
-
rotateCW
public T rotateCW(Angle alpha)
Rotates thisAbstractPointListBasedGeometry
clockwise (CW) by the givenAngle
around its centroid (seegetCentroid()
).- Parameters:
alpha
- the rotationAngle
- Returns:
this
for convenience- See Also:
rotateCW(Angle, Point)
-
rotateCW
public T rotateCW(Angle alpha, double cx, double cy)
Rotates thisAbstractPointListBasedGeometry
clockwise (CW) by the givenAngle
around thePoint
specified by the passed-in x and y coordinates.- Parameters:
alpha
- the rotationAngle
cx
- the x coordinate of thePoint
to rotate aroundcy
- the y coordinate of thePoint
to rotate around- Returns:
this
for convenience- See Also:
rotateCW(Angle, Point)
-
scale
public T scale(double factor)
Description copied from interface:IScalable
Scales the calling object by the given factor relative to its centerPoint
.
-
scale
public T scale(double fx, double fy)
Description copied from interface:IScalable
Scales the calling object by the given factors relative to the given centerPoint
.
-
scale
public T scale(double factor, double cx, double cy)
Description copied from interface:IScalable
Scales the calling object by the given factor relative to the given centerPoint
(cx, cy).
-
scale
public T scale(double fx, double fy, double cx, double cy)
Description copied from interface:IScalable
Scales the calling object by the given factors relative to the given centerPoint
(cx, cy).- Specified by:
scale
in interfaceIScalable<T extends org.eclipse.gef.geometry.planar.AbstractPointListBasedGeometry<?>>
- Parameters:
fx
- x-scale-factorfy
- y-scale-factorcx
- x-coordinate of the relativePoint
for the scalingcy
- y-coordinate of the relativePoint
for the scaling- Returns:
this
for convenience
-
scale
public T scale(double fx, double fy, Point center)
Description copied from interface:IScalable
Scales the calling object by the given factors relative to the given centerPoint
.
-
scale
public T scale(double factor, Point center)
Description copied from interface:IScalable
Scales the calling object by the given factor relative to the given centerPoint
.
-
translate
public T translate(double dx, double dy)
Description copied from interface:ITranslatable
Translates the object by the given values in x and y direction.- Specified by:
translate
in interfaceITranslatable<T extends org.eclipse.gef.geometry.planar.AbstractPointListBasedGeometry<?>>
- Parameters:
dx
- x-translationdy
- y-translation- Returns:
this
for convenience
-
translate
public T translate(Point p)
Description copied from interface:ITranslatable
Translates the object by the givenPoint
.- Specified by:
translate
in interfaceITranslatable<T extends org.eclipse.gef.geometry.planar.AbstractPointListBasedGeometry<?>>
- Parameters:
p
- translationPoint
- Returns:
this
for convenience
-
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()
-
-