Package snap.geom
Class Polygon
java.lang.Object
snap.geom.Shape
snap.geom.Polygon
- All Implemented Interfaces:
Cloneable
A Shape subclass to represent a simple geometric polygon.
-
Field Summary
Fields inherited from class snap.geom.Shape
_bounds, WIND_EVEN_ODD, WIND_NON_ZERO
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addPoint
(double aX, double aY) Adds a point at given x/y.void
clear()
Clears the polygon.clone()
Standard clone implementation.double
getAngle
(int anIndex) Returns the interior angle at given point index.protected Rect
Returns the shape bounds.Polygon[]
getConvexPolygonsWithMaxSideCount
(int aMax) Returns an array of polygons that are convex with max number of vertices.static Polygon[]
getConvexPolygonsWithMaxSideCount
(Shape aShape, int aMax) Returns an array of convex polygons for given max side count.double
getExtAngle
(int anIndex) Returns the exterior angle at given point index.double
Returns the sum of exterior angles.Returns the last point.double
Returns the last x point.double
Returns the last y point.getPathIter
(Transform aTrans) Returns the path iterator.getPoint
(int anIndex) Returns the point at given index.double[]
Returns the raw points array.int
Returns the point count.int
getPointIndexForXY
(double aX, double aY, double aRad) Returns index of point at given x/y within given radius.double
getPointX
(int anIndex) Returns the x at given point index.double
getPointY
(int anIndex) Returns the y at given point index.boolean
isClosed()
Returns whether the polygon is closed.boolean
isConvex()
Returns whether polygon is convex.boolean
Returns whether polygon has no intersecting lines.void
setClosed
(boolean aValue) Sets whether the polygon is closed.void
setPoint
(int anIndex, double aX, double aY) Sets a point at given point index to given x/y.void
setPointArray
(double[] thePoints) Sets the points.splitConvex
(int aMax) Splits this polygon into the first convex polygon and the remainder polygon and returns the remainder.Methods inherited from class snap.geom.Shape
addShapes, contains, contains, contains, contains, containsSeg, copyFor, copyFor, copyForBounds, crossesSeg, getArcLength, getBounds, getCrossings, getDistance, getFlattenedShape, getFlattenedShape, getHeight, getNotSelfIntersectingShape, getSvgString, getWidth, getX, getY, intersectShapes, intersectsSeg, intersectsShape, intersectsShape, intersectsXY, isFlat, isMultiCycle, isSingleCycle, shapeChanged, subtractShapes, toString
-
Constructor Details
-
Polygon
public Polygon()Constructor. -
Polygon
public Polygon(double... theCoords) Creates a new Polygon from given x y coords. -
Polygon
Creates a new Polygon from given x y coords.
-
-
Method Details
-
getPointArray
public double[] getPointArray()Returns the raw points array. -
setPointArray
public void setPointArray(double[] thePoints) Sets the points. -
getPointCount
public int getPointCount()Returns the point count. -
getPointX
public double getPointX(int anIndex) Returns the x at given point index. -
getPointY
public double getPointY(int anIndex) Returns the y at given point index. -
getPoint
Returns the point at given index. -
addPoint
public void addPoint(double aX, double aY) Adds a point at given x/y. -
setPoint
public void setPoint(int anIndex, double aX, double aY) Sets a point at given point index to given x/y. -
isClosed
public boolean isClosed()Returns whether the polygon is closed. -
setClosed
public void setClosed(boolean aValue) Sets whether the polygon is closed. -
getLastPoint
Returns the last point. -
getLastPointX
public double getLastPointX()Returns the last x point. -
getLastPointY
public double getLastPointY()Returns the last y point. -
clear
public void clear()Clears the polygon. -
getPointIndexForXY
public int getPointIndexForXY(double aX, double aY, double aRad) Returns index of point at given x/y within given radius. -
isSelfIntersecting
public boolean isSelfIntersecting()Returns whether polygon has no intersecting lines.- Overrides:
isSelfIntersecting
in classShape
-
isConvex
public boolean isConvex()Returns whether polygon is convex. -
getAngle
public double getAngle(int anIndex) Returns the interior angle at given point index. -
getExtAngle
public double getExtAngle(int anIndex) Returns the exterior angle at given point index. -
getExtAngleSum
public double getExtAngleSum()Returns the sum of exterior angles. -
getConvexPolygonsWithMaxSideCount
Returns an array of polygons that are convex with max number of vertices. -
splitConvex
Splits this polygon into the first convex polygon and the remainder polygon and returns the remainder. -
getBoundsImpl
Returns the shape bounds.- Overrides:
getBoundsImpl
in classShape
-
getPathIter
Returns the path iterator.- Specified by:
getPathIter
in classShape
-
clone
Standard clone implementation. -
getConvexPolygonsWithMaxSideCount
Returns an array of convex polygons for given max side count.
-