public class Polygon extends java.lang.Object implements IShape
PrecisionUtils
) to compensate for rounding effects.Constructor and Description |
---|
Polygon(double... coordinates)
Constructs a new
Polygon from a even-numbered sequence of
coordinates. |
Polygon(Point... points)
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
clone()
Overridden with public visibility as recommended within
Cloneable
. |
boolean |
contains(double x,
double y)
Checks whether the point that is represented by its x- and y-coordinates
is contained within this
Polygon . |
boolean |
contains(IGeometry g)
|
boolean |
contains(Line line)
|
boolean |
contains(Point p)
|
boolean |
contains(Polygon p)
|
boolean |
contains(Polyline p)
|
boolean |
contains(Rectangle r)
|
boolean |
equals(java.lang.Object o) |
boolean |
equals(Point[] points)
Checks whether this
Polygon and the one that is indirectly given
via the given array of points are regarded to be equal. |
double |
getArea()
Computes the area of this
Polygon . |
Rectangle |
getBounds()
|
Point |
getCentroid()
Computes the centroid of this
AbstractPointListBasedGeometry . |
double[] |
getCoordinates()
Returns a double array which represents the sequence of coordinates of
the
Point s that make up this
AbstractPointListBasedGeometry . |
Polygon |
getCopy()
Returns a copy of this
Polygon , which is made up by the same
points. |
Polyline |
getOutline()
|
Line[] |
getOutlineSegments()
|
Point[] |
getPoints()
Returns a copy of the
Point s that make up this
AbstractPointListBasedGeometry . |
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
center
Point . |
T |
getScaled(double factorX,
double factorY)
Scales a copy of the calling object by the given factors relative to its
center
Point . |
T |
getScaled(double factor,
double cx,
double cy)
Scales a copy of the calling object by the given factor relative to the
given center
Point (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 center
Point (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 center
Point . |
T |
getScaled(double factor,
Point center)
Scales a copy of the calling object by the given factor relative to the
given center
Point . |
double |
getSignedArea()
Computes the signed area of this
Polygon . |
Polygon |
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 given
Point . |
Polygon[] |
getTriangulation()
Naive, recursive ear-clipping algorithm to triangulate this simple,
planar
Polygon . |
int |
hashCode() |
T |
rotateCCW(Angle alpha)
Rotates this
AbstractPointListBasedGeometry counter-clockwise
(CCW) by the given Angle around its centroid (see
getCentroid() ). |
T |
rotateCCW(Angle alpha,
double cx,
double cy)
|
T |
rotateCCW(Angle alpha,
Point center)
|
T |
rotateCW(Angle alpha)
Rotates this
AbstractPointListBasedGeometry clockwise (CW) by the
given Angle around its centroid (see getCentroid() ). |
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 center
Point . |
T |
scale(double fx,
double fy)
Scales the calling object by the given factors relative to the given
center
Point . |
T |
scale(double factor,
double cx,
double cy)
Scales the calling object by the given factor relative to the given
center
Point (cx, cy). |
T |
scale(double fx,
double fy,
double cx,
double cy)
Scales the calling object by the given factors relative to the given
center
Point (cx, cy). |
T |
scale(double fx,
double fy,
Point center)
Scales the calling object by the given factors relative to the given
center
Point . |
T |
scale(double factor,
Point center)
Scales the calling object by the given factor relative to the given
center
Point . |
Path |
toPath()
|
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 given
Point . |
public Polygon(double... coordinates)
Polygon
from a even-numbered sequence of
coordinates.coordinates
- an alternating, even-numbered sequence of x and y coordinates,
representing the Point
s from which the Polygon
is to be createdPolygon(Point...)
public Polygon(Point... points)
Polygon
from the given sequence of Point
s. The Polygon
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.points
- a sequence of points, from which the Polygon
is to be
created.public boolean contains(double x, double y)
Polygon
.x
- the x-coordinate of the point to testy
- the y-coordinate of the point to testtrue
if the point represented by its coordinates if
contained within this Polygon
, false
otherwisepublic boolean contains(Line line)
public boolean contains(Polygon p)
public boolean contains(Polyline p)
p
- The Polyline
to test for containment.public boolean contains(Rectangle r)
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public boolean equals(Point[] points)
Polygon
and the one that is indirectly given
via the given array of points are regarded to be equal. The
Polygon
s will be regarded equal, if they are characterized by the
same segments. As a Polygon
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
equally Polygon
s may be reverted in order.public double getArea()
Polygon
.Polygon
public Polygon getCopy()
Polygon
, which is made up by the same
points.public Polyline getOutline()
IShape
getOutline
in interface IShape
ICurve
representing this IShape
's outline.public Line[] getOutlineSegments()
Line
s, representing the segments that are
obtained by linking each two successive point of this Polygon
(including the last and the first one).getOutlineSegments
in interface IShape
Line
s, representing the segments that make up
this Polygon
public double getSignedArea()
Polygon
. The sign of the area is
negative for counter clockwise ordered vertices. It is positive for
clockwise ordered vertices.Polygon
public Polygon getTransformed(AffineTransform t)
Path
representation of this IGeometry
. Subclasses may override this
method to return a more specific representation.getTransformed
in interface IGeometry
getTransformed
in interface IShape
t
- The AffineTransform
to be appliedPath
representation of this
IGeometry
IGeometry.getTransformed(AffineTransform)
public Polygon[] getTriangulation()
Polygon
.Polygon
s (triangles)public Path toPath()
IGeometry
toPath
in interface IGeometry
Path
representation for this IGeometry
.IGeometry.toPath()
public java.lang.String toString()
toString
in class java.lang.Object
public Point getCentroid()
AbstractPointListBasedGeometry
. The
centroid is the "center of gravity", i.e. assuming a Polygon
is
spanned by the Point
s of this
AbstractPointListBasedGeometry
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.Point
(or centroid) of this
AbstractPointListBasedGeometry
public final double[] getCoordinates()
Point
s that make up this
AbstractPointListBasedGeometry
.AbstractPointListBasedGeometry
's pointspublic final Point[] getPoints()
Point
s that make up this
AbstractPointListBasedGeometry
.public T getRotatedCCW(Angle alpha)
IRotatable
Angle
counter-clock-wise
(CCW) around its center Point
. Does not necessarily return an
object of the same type.getRotatedCCW
in interface IRotatable<T extends org.eclipse.gef4.geometry.planar.AbstractPointListBasedGeometry<?>>
alpha
- rotation Angle
IGeometry
representing the result of the rotationpublic T getRotatedCCW(Angle angle, double cx, double cy)
IRotatable
Angle
counter-clock-wise (CCW) around the specified center Point
(cx,
cy). Does not necessarily return an object of the same type.getRotatedCCW
in interface IRotatable<T extends org.eclipse.gef4.geometry.planar.AbstractPointListBasedGeometry<?>>
angle
- rotation Angle
cx
- x-coordinate of the relative Point
for the rotationcy
- y-coordinate of the relative Point
for the rotationIGeometry
representing the result of the rotationpublic T getRotatedCCW(Angle alpha, Point center)
IRotatable
Angle
counter-clock-wise (CCW) around the specified center Point
. Does
not necessarily return an object of the same type.getRotatedCCW
in interface IRotatable<T extends org.eclipse.gef4.geometry.planar.AbstractPointListBasedGeometry<?>>
alpha
- rotation Angle
center
- relative Point
for the rotationIGeometry
representing the result of the rotationpublic T getRotatedCW(Angle alpha)
IRotatable
Angle
clock-wise (CW)
around its center Point
. Does not necessarily return an object of
the same type.getRotatedCW
in interface IRotatable<T extends org.eclipse.gef4.geometry.planar.AbstractPointListBasedGeometry<?>>
alpha
- rotation Angle
IGeometry
representing the result of the rotationpublic T getRotatedCW(Angle angle, double cx, double cy)
IRotatable
Angle
clock-wise (CW)
around the specified center Point
(cx, cy). Does not necessarily
return an object of the same type.getRotatedCW
in interface IRotatable<T extends org.eclipse.gef4.geometry.planar.AbstractPointListBasedGeometry<?>>
angle
- rotation Angle
cx
- x-coordinate of the relative Point
for the rotationcy
- y-coordinate of the relative Point
for the rotationIGeometry
representing the result of the rotationpublic T getRotatedCW(Angle alpha, Point center)
IRotatable
Angle
clock-wise (CW)
around the specified center Point
. Does not necessarily return an
object of the same type.getRotatedCW
in interface IRotatable<T extends org.eclipse.gef4.geometry.planar.AbstractPointListBasedGeometry<?>>
alpha
- rotation Angle
center
- relative Point
for the rotationIGeometry
representing the result of the rotationpublic T getScaled(double factor)
IScalable
Point
.public T getScaled(double factorX, double factorY)
IScalable
Point
.public T getScaled(double factor, double cx, double cy)
IScalable
Point
(cx, cy).getScaled
in interface IScalable<T extends org.eclipse.gef4.geometry.planar.AbstractPointListBasedGeometry<?>>
factor
- scale-factorcx
- x-coordinate of the relative Point
for the scalingcy
- y-coordinate of the relative Point
for the scalingpublic T getScaled(double fx, double fy, double cx, double cy)
IScalable
Point
(cx, cy).getScaled
in interface IScalable<T extends org.eclipse.gef4.geometry.planar.AbstractPointListBasedGeometry<?>>
fx
- x-scale-factorfy
- y-scale-factorcx
- x-coordinate of the relative Point
for the scalingcy
- y-coordinate of the relative Point
for the scalingpublic T getScaled(double factorX, double factorY, Point center)
IScalable
Point
.public T getScaled(double factor, Point center)
IScalable
Point
.public T getTranslated(double dx, double dy)
ITranslatable
getTranslated
in interface ITranslatable<T extends org.eclipse.gef4.geometry.planar.AbstractPointListBasedGeometry<?>>
dx
- x-translationdy
- y-translationpublic T getTranslated(Point pt)
ITranslatable
Point
.getTranslated
in interface ITranslatable<T extends org.eclipse.gef4.geometry.planar.AbstractPointListBasedGeometry<?>>
pt
- translation Point
public T rotateCCW(Angle alpha)
AbstractPointListBasedGeometry
counter-clockwise
(CCW) by the given Angle
around its centroid (see
getCentroid()
).alpha
- the rotation Angle
this
for conveniencerotateCCW(Angle, Point)
public T rotateCCW(Angle alpha, double cx, double cy)
AbstractPointListBasedGeometry
counter-clockwise
(CCW) by the given Angle
around the Point
specified by
the passed-in x and y coordinates.alpha
- the rotation Angle
cx
- the x coordinate of the Point
to rotate aroundcy
- the y coordinate of the Point
to rotate aroundthis
for conveniencerotateCCW(Angle, Point)
public T rotateCW(Angle alpha)
AbstractPointListBasedGeometry
clockwise (CW) by the
given Angle
around its centroid (see getCentroid()
).alpha
- the rotation Angle
this
for conveniencerotateCW(Angle, Point)
public T rotateCW(Angle alpha, double cx, double cy)
AbstractPointListBasedGeometry
clockwise (CW) by the
given Angle
around the Point
specified by the passed-in x
and y coordinates.alpha
- the rotation Angle
cx
- the x coordinate of the Point
to rotate aroundcy
- the y coordinate of the Point
to rotate aroundthis
for conveniencerotateCW(Angle, Point)
public T scale(double factor)
IScalable
Point
.public T scale(double fx, double fy)
IScalable
Point
.public T scale(double factor, double cx, double cy)
IScalable
Point
(cx, cy).public T scale(double fx, double fy, double cx, double cy)
IScalable
Point
(cx, cy).scale
in interface IScalable<T extends org.eclipse.gef4.geometry.planar.AbstractPointListBasedGeometry<?>>
fx
- x-scale-factorfy
- y-scale-factorcx
- x-coordinate of the relative Point
for the scalingcy
- y-coordinate of the relative Point
for the scalingthis
for conveniencepublic T scale(double fx, double fy, Point center)
IScalable
Point
.public T scale(double factor, Point center)
IScalable
Point
.public T translate(double dx, double dy)
ITranslatable
translate
in interface ITranslatable<T extends org.eclipse.gef4.geometry.planar.AbstractPointListBasedGeometry<?>>
dx
- x-translationdy
- y-translationthis
for conveniencepublic T translate(Point p)
ITranslatable
Point
.translate
in interface ITranslatable<T extends org.eclipse.gef4.geometry.planar.AbstractPointListBasedGeometry<?>>
p
- translation Point
this
for conveniencepublic java.lang.Object clone()
Cloneable
.clone
in class java.lang.Object
public final int hashCode()
hashCode
in class java.lang.Object
Object.hashCode()
Copyright (c) 2014 itemis AG, and others. All rights reserved.