math.geom2d.polygon
Interface Polygon2D

All Superinterfaces:
CirculinearDomain2D, CirculinearShape2D, Domain2D, GeometricObject2D, Shape2D
All Known Implementing Classes:
HRectangle2D, MultiPolygon2D, Rectangle2D, SimplePolygon2D

public interface Polygon2D
extends CirculinearDomain2D

Represent any class made of a finite set of simply connected edges. This include simple polygons, multiple polygons, or more specialized shapes like rectangles, squares... The boundary of a polygon is a collection of LinearRing2D.


Field Summary
 
Fields inherited from interface math.geom2d.Shape2D
ACCURACY
 
Method Summary
 void addVertex(Point2D point)
          Adds a vertex as last vertex of this polygon.
 double area()
          Returns the signed area of the polygon.
 CirculinearContourArray2D<? extends LinearRing2D> boundary()
          Overrides the definition of boundary() such that the boundary of a polygon is defined as a set of LinearRing2D.
 Point2D centroid()
          Returns the centroid (center of mass) of the polygon.
 Polygon2D clip(Box2D box)
          Clip the shape with the given box, and returns a new shape.
 int closestVertexIndex(Point2D point)
          Returns the index of the closest vertex to the input point.
 Polygon2D complement()
          Returns the complementary polygon.
 java.util.Collection<? extends LinearRing2D> contours()
          Returns the set of contours that enclose this domain.
 int edgeNumber()
          Returns the number of edges of the polygon
 java.util.Collection<? extends LineSegment2D> edges()
          Return the edges as line segments of the polygon
 void insertVertex(int index, Point2D point)
          Inserts a vertex at the specified position.
 void removeVertex(int index)
          Removes the vertex at the given index.
 void setVertex(int i, Point2D point)
          Sets the position of the i-th vertex
 Polygon2D transform(AffineTransform2D trans)
          Returns the new Polygon created by an affine transform of this polygon.
 Point2D vertex(int i)
          Returns the i-th vertex of the polygon.
 int vertexNumber()
          Returns the number of vertices of the polygon
 java.util.Collection<Point2D> vertices()
          Returns the vertices (singular points) of the polygon
 
Methods inherited from interface math.geom2d.circulinear.CirculinearDomain2D
transform
 
Methods inherited from interface math.geom2d.circulinear.CirculinearShape2D
buffer
 
Methods inherited from interface math.geom2d.domain.Domain2D
asPolygon, draw, fill
 
Methods inherited from interface math.geom2d.Shape2D
boundingBox, contains, contains, distance, distance, isBounded, isEmpty
 
Methods inherited from interface math.geom2d.GeometricObject2D
almostEquals
 

Method Detail

vertices

java.util.Collection<Point2D> vertices()
Returns the vertices (singular points) of the polygon


vertex

Point2D vertex(int i)
Returns the i-th vertex of the polygon.

Parameters:
i - index of the vertex, between 0 and the number of vertices

setVertex

void setVertex(int i,
               Point2D point)
Sets the position of the i-th vertex

Parameters:
i - the vertex index
point - the new position of the vertex
Throws:
java.lang.UnsupportedOperationException - if this polygon implementation does not support vertex modification

addVertex

void addVertex(Point2D point)
Adds a vertex as last vertex of this polygon.

Parameters:
point - the position of the new vertex
Throws:
java.lang.UnsupportedOperationException - if this polygon implementation does not support vertex modification

insertVertex

void insertVertex(int index,
                  Point2D point)
Inserts a vertex at the specified position.

Parameters:
index - index at which the specified vertex is to be inserted
point - the position of the new vertex
Throws:
java.lang.UnsupportedOperationException - if this polygon implementation does not support vertex modification

removeVertex

void removeVertex(int index)
Removes the vertex at the given index.

Parameters:
index - index of the vertex to remove
Throws:
java.lang.UnsupportedOperationException - if this polygon implementation does not support vertex modification

vertexNumber

int vertexNumber()
Returns the number of vertices of the polygon

Since:
0.6.3

closestVertexIndex

int closestVertexIndex(Point2D point)
Returns the index of the closest vertex to the input point.


edges

java.util.Collection<? extends LineSegment2D> edges()
Return the edges as line segments of the polygon


edgeNumber

int edgeNumber()
Returns the number of edges of the polygon


centroid

Point2D centroid()
Returns the centroid (center of mass) of the polygon.


area

double area()
Returns the signed area of the polygon.


boundary

CirculinearContourArray2D<? extends LinearRing2D> boundary()
Overrides the definition of boundary() such that the boundary of a polygon is defined as a set of LinearRing2D.

Specified by:
boundary in interface CirculinearDomain2D
Specified by:
boundary in interface Domain2D
Returns:
the boundary of the domain

contours

java.util.Collection<? extends LinearRing2D> contours()
Description copied from interface: Domain2D
Returns the set of contours that enclose this domain. The result is a collection of shapes that implement the Contour2D interface.

Specified by:
contours in interface CirculinearDomain2D
Specified by:
contours in interface Domain2D
See Also:
Contour2D

complement

Polygon2D complement()
Returns the complementary polygon.

Specified by:
complement in interface CirculinearDomain2D
Specified by:
complement in interface Domain2D
Returns:
the polygon complementary to this

transform

Polygon2D transform(AffineTransform2D trans)
Returns the new Polygon created by an affine transform of this polygon.

Specified by:
transform in interface Domain2D
Specified by:
transform in interface Shape2D
Parameters:
trans - an affine transform
Returns:
the transformed shape

clip

Polygon2D clip(Box2D box)
Description copied from interface: Shape2D
Clip the shape with the given box, and returns a new shape. The box must be bounded.

Specified by:
clip in interface Domain2D
Specified by:
clip in interface Shape2D
Parameters:
box - the clipping box
Returns:
the clipped shape