Package org.eclipse.gef.geometry.planar
Class Polygon
java.lang.Object
org.eclipse.gef.geometry.planar.Polygon
- All Implemented Interfaces:
Serializable
,Cloneable
,IGeometry
,IRotatable<Polygon>
,IScalable<Polygon>
,IShape
,ITranslatable<Polygon>
Represents the geometric shape of a convex polygon.
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
-
Method Summary
Modifier and TypeMethodDescriptionclone()
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 thisPolygon
.boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
Checks whether thisPolygon
and the one that is indirectly given via the given array of points are regarded to be equal.double
getArea()
Computes the area of thisPolygon
.final Rectangle
Computes the centroid of thisAbstractPointListBasedGeometry
.final double[]
Returns a double array which represents the sequence of coordinates of thePoint
s that make up thisAbstractPointListBasedGeometry
.getCopy()
Returns a copy of thisPolygon
, which is made up by the same points.Line[]
final Point[]
Returns a copy of thePoint
s that make up thisAbstractPointListBasedGeometry
.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
.double
Computes the signed area of thisPolygon
.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
.Polygon[]
Naive, recursive ear-clipping algorithm to triangulate this simple, planarPolygon
.final int
hashCode()
Rotates thisAbstractPointListBasedGeometry
counter-clockwise (CCW) by the givenAngle
around its centroid (seegetCentroid()
).Rotates thisAbstractPointListBasedGeometry
clockwise (CW) by the givenAngle
around 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
.toPath()
toString()
boolean
translate
(double dx, double dy) Translates the object by the given values in x and y direction.Translates the object by the givenPoint
.
-
Constructor Details
-
Polygon
public Polygon(double... coordinates) Constructs a newPolygon
from a even-numbered sequence of coordinates. -
Polygon
Constructs a newPolygon
from the given sequence ofPoint
s. ThePolygon
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 thePolygon
is 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 thisPolygon
.- 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 thisPolygon
,false
otherwise
-
contains
Description copied from interface:IShape
-
contains
-
contains
Description copied from interface:IGeometry
-
contains
-
contains
- Parameters:
p
- ThePolyline
to test for containment.- Returns:
- true if it is contained, false otherwise
-
contains
-
equals
-
equals
Checks whether thisPolygon
and the one that is indirectly given via the given array of points are regarded to be equal. ThePolygon
s will be regarded equal, if they are characterized by the same segments. As aPolygon
is always regarded to be closed, the list of points may not have to correspond in each index value, they may also be shifted by a certain offset. Moreover, the vertices of two equallyPolygon
s may be reverted in order. -
getArea
public double getArea()Computes the area of thisPolygon
.- Returns:
- the area of this
Polygon
-
getCopy
Returns a copy of thisPolygon
, which is made up by the same points. -
getOutline
Description copied from interface:IShape
- Specified by:
getOutline
in interfaceIShape
- Returns:
- An
ICurve
representing thisIShape
's outline.
-
getOutlineSegments
Returns a sequence ofLine
s, representing the segments that are obtained by linking each two successive point of thisPolygon
(including the last and the first one).- Specified by:
getOutlineSegments
in interfaceIShape
- Returns:
- an array of
Line
s, representing the segments that make up thisPolygon
-
getSignedArea
public double getSignedArea()Computes the signed area of thisPolygon
. The sign of the area is negative for counter clockwise ordered vertices. It is positive for clockwise ordered vertices.- Returns:
- the signed area of this
Polygon
-
getTransformed
Default implementation returning a transformedPath
representation of thisIGeometry
. Subclasses may override this method to return a more specific representation.- Specified by:
getTransformed
in interfaceIGeometry
- Specified by:
getTransformed
in interfaceIShape
- Parameters:
t
- TheAffineTransform
to be applied- Returns:
- a transformed
Path
representation of thisIGeometry
- See Also:
-
getTriangulation
Naive, recursive ear-clipping algorithm to triangulate this simple, planarPolygon
.- Returns:
- triangulation
Polygon
s (triangles)
-
toPath
Description copied from interface:IGeometry
-
toString
-
getBounds
Description copied from interface:IGeometry
-
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
Returns a copy of thePoint
s that make up thisAbstractPointListBasedGeometry
. -
getRotatedCCW
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
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
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
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
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
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
Description copied from interface:IScalable
Scales a copy of the calling object by the given factor relative to its centerPoint
. -
getScaled
Description copied from interface:IScalable
Scales a copy of the calling object by the given factors relative to its centerPoint
. -
getScaled
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
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
Description copied from interface:IScalable
Scales a copy of the calling object by the given factors relative to the given centerPoint
. -
getScaled
Description copied from interface:IScalable
Scales a copy of the calling object by the given factor relative to the given centerPoint
. -
getTranslated
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
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
Rotates thisAbstractPointListBasedGeometry
counter-clockwise (CCW) by the givenAngle
around its centroid (seegetCentroid()
).- Parameters:
alpha
- the rotationAngle
- Returns:
this
for convenience- See Also:
-
rotateCCW
Rotates thisAbstractPointListBasedGeometry
counter-clockwise (CCW) by the givenAngle
around thePoint
specified by the passed-in x and y coordinates. -
rotateCCW
-
rotateCW
Rotates thisAbstractPointListBasedGeometry
clockwise (CW) by the givenAngle
around its centroid (seegetCentroid()
).- Parameters:
alpha
- the rotationAngle
- Returns:
this
for convenience- See Also:
-
rotateCW
Rotates thisAbstractPointListBasedGeometry
clockwise (CW) by the givenAngle
around thePoint
specified by the passed-in x and y coordinates. -
rotateCW
-
scale
Description copied from interface:IScalable
Scales the calling object by the given factor relative to its centerPoint
. -
scale
Description copied from interface:IScalable
Scales the calling object by the given factors relative to the given centerPoint
. -
scale
Description copied from interface:IScalable
Scales the calling object by the given factor relative to the given centerPoint
(cx, cy). -
scale
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
Description copied from interface:IScalable
Scales the calling object by the given factors relative to the given centerPoint
. -
scale
Description copied from interface:IScalable
Scales the calling object by the given factor relative to the given centerPoint
. -
translate
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
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
Overridden with public visibility as recommended withinCloneable
. -
hashCode
public final int hashCode() -
touches
Description copied from interface:IGeometry
-