math.geom2d.polygon
Class MultiPolygon2D

java.lang.Object
  extended by math.geom2d.polygon.MultiPolygon2D
All Implemented Interfaces:
CirculinearDomain2D, CirculinearShape2D, Domain2D, GeometricObject2D, Polygon2D, Shape2D

public class MultiPolygon2D
extends java.lang.Object
implements Domain2D, Polygon2D

A polygonal domain whose boundary is composed of several disjoint continuous LinearRing2D.

Author:
dlegland

Field Summary
 
Fields inherited from interface math.geom2d.Shape2D
ACCURACY
 
Constructor Summary
MultiPolygon2D()
           
MultiPolygon2D(java.util.Collection<LinearRing2D> lines)
           
MultiPolygon2D(LinearRing2D... rings)
           
MultiPolygon2D(LinearRing2D ring)
           
MultiPolygon2D(SimplePolygon2D polygon)
           
 
Method Summary
 void addRing(LinearRing2D ring)
           
 void addVertex(Point2D position)
          Adds a vertex at the end of the last ring of this polygon.
 boolean almostEquals(GeometricObject2D obj, double eps)
          Checks if the two objects are similar up to a given threshold value.
 double area()
          Computes the signed area of the polygon.
 Polygon2D asPolygon(int n)
          Returns an approximation of the domain as a polygon, or a MultiPolygon.
 CirculinearContourArray2D<LinearRing2D> boundary()
          Returns the boundary of the set.
 Box2D boundingBox()
          Returns the bounding box of the shape.
 CirculinearDomain2D buffer(double dist)
          Computes the buffer of the shape, formed by the set of points located at a distance from the shape that is lower or equal to d.
 Point2D centroid()
          Computes the centroid (center of mass) of the polygon.
 void clearRings()
           
 Polygon2D clip(Box2D box)
          Clips the polygon with the specified box.
 MultiPolygon2D clone()
           
 int closestVertexIndex(Point2D point)
          Computes the index of the closest vertex to the input point.
 Polygon2D complement()
          Returns the domain which complements this domain in the plane.
 boolean contains(double x, double y)
          Checks if the shape contains the planar point defined by (x,y).
 boolean contains(Point2D point)
          Checks if the shape contains the given point.
 java.util.Collection<LinearRing2D> contours()
          Returns the set of contours that enclose this domain.
static MultiPolygon2D create(java.util.Collection<LinearRing2D> rings)
           
static MultiPolygon2D create(LinearRing2D... rings)
           
 double distance(double x, double y)
          Returns the distance of the shape to the given point, specified by x and y, or the distance of point to the frontier of the shape in the case of a plain (i.e. fillable) shape.
 double distance(Point2D p)
          Returns the distance of the shape to the given point, or the distance of point to the frontier of the shape in the case of a plain shape.
 void draw(java.awt.Graphics2D g2)
          Draws the boundary of the domain, using current Stroke and color.
 int edgeNumber()
          Returns the number of edges of the polygon
 java.util.Collection<LineSegment2D> edges()
          Return the edges as line segments of the polygon
 boolean equals(java.lang.Object obj)
           
 void fill(java.awt.Graphics2D g)
          Fills the interior of the domain, using the Graphics current Paint.
 LinearRing2D getRing(int index)
           
 void insertRing(int index, LinearRing2D ring)
           
 void insertVertex(int index, Point2D point)
          Inserts a vertex at the given position
 boolean isBounded()
          Returns true if the shape is bounded, that is if we can draw a finite rectangle enclosing the shape.
 boolean isEmpty()
          The MultiPolygon2D is empty either if it contains no ring, or if all rings are empty.
 void removeRing(LinearRing2D ring)
           
 void removeVertex(int i)
          Returns the i-th vertex of the polygon.
 int ringNumber()
           
 void setRing(int index, LinearRing2D ring)
           
 void setVertex(int i, Point2D point)
          Sets the position of the i-th vertex of this polygon.
 MultiPolygon2D transform(AffineTransform2D trans)
          Transforms the shape by an affine transform.
 CirculinearDomain2D transform(CircleInversion2D inv)
          Transforms the shape by a circle inversion.
 Point2D vertex(int i)
          Returns the i-th vertex of the polygon.
 int vertexNumber()
          Returns the total number of vertices in this polygon.
 java.util.Collection<Point2D> vertices()
          Returns the vertices (singular points) of the polygon
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultiPolygon2D

public MultiPolygon2D()

MultiPolygon2D

public MultiPolygon2D(LinearRing2D ring)

MultiPolygon2D

public MultiPolygon2D(LinearRing2D... rings)

MultiPolygon2D

public MultiPolygon2D(SimplePolygon2D polygon)

MultiPolygon2D

public MultiPolygon2D(java.util.Collection<LinearRing2D> lines)
Method Detail

create

public static MultiPolygon2D create(java.util.Collection<LinearRing2D> rings)

create

public static MultiPolygon2D create(LinearRing2D... rings)

addRing

public void addRing(LinearRing2D ring)

insertRing

public void insertRing(int index,
                       LinearRing2D ring)

removeRing

public void removeRing(LinearRing2D ring)

clearRings

public void clearRings()

getRing

public LinearRing2D getRing(int index)

setRing

public void setRing(int index,
                    LinearRing2D ring)

ringNumber

public int ringNumber()

area

public double area()
Computes the signed area of the polygon.

Specified by:
area in interface Polygon2D
Returns:
the signed area of the polygon.
Since:
0.9.1

centroid

public Point2D centroid()
Computes the centroid (center of mass) of the polygon.

Specified by:
centroid in interface Polygon2D
Returns:
the centroid of the polygon
Since:
0.9.1

edges

public java.util.Collection<LineSegment2D> edges()
Description copied from interface: Polygon2D
Return the edges as line segments of the polygon

Specified by:
edges in interface Polygon2D

edgeNumber

public int edgeNumber()
Description copied from interface: Polygon2D
Returns the number of edges of the polygon

Specified by:
edgeNumber in interface Polygon2D

vertices

public java.util.Collection<Point2D> vertices()
Description copied from interface: Polygon2D
Returns the vertices (singular points) of the polygon

Specified by:
vertices in interface Polygon2D

vertex

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

Specified by:
vertex in interface Polygon2D
Parameters:
i - index of the vertex, between 0 and the number of vertices minus one

setVertex

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

Specified by:
setVertex in interface Polygon2D
Parameters:
i - index of the vertex, between 0 and the number of vertices
point - the new position of the vertex

addVertex

public void addVertex(Point2D position)
Adds a vertex at the end of the last ring of this polygon.

Specified by:
addVertex in interface Polygon2D
Parameters:
position - the position of the new vertex
Throws:
java.lang.RuntimeException - if this MultiPolygon does not contain any ring

insertVertex

public void insertVertex(int index,
                         Point2D point)
Inserts a vertex at the given position

Specified by:
insertVertex in interface Polygon2D
Parameters:
index - index at which the specified vertex is to be inserted
point - the position of the new vertex

removeVertex

public void removeVertex(int i)
Returns the i-th vertex of the polygon.

Specified by:
removeVertex in interface Polygon2D
Parameters:
i - index of the vertex, between 0 and the number of vertices minus one

vertexNumber

public int vertexNumber()
Returns the total number of vertices in this polygon. The total number is computed as the sum of vertex number in each ring of the polygon.

Specified by:
vertexNumber in interface Polygon2D

closestVertexIndex

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

Specified by:
closestVertexIndex in interface Polygon2D

transform

public CirculinearDomain2D transform(CircleInversion2D inv)
Description copied from interface: CirculinearShape2D
Transforms the shape by a circle inversion. The result is still an instance a CirculinearShape2D.

Specified by:
transform in interface CirculinearDomain2D
Specified by:
transform in interface CirculinearShape2D
Parameters:
inv - the circle inversion
Returns:
the transformed shape

buffer

public CirculinearDomain2D buffer(double dist)
Description copied from interface: CirculinearShape2D
Computes the buffer of the shape, formed by the set of points located at a distance from the shape that is lower or equal to d.

Specified by:
buffer in interface CirculinearShape2D
Parameters:
dist - the maximal distance between a point of the buffer and the shape
Returns:
the buffer of the shape

asPolygon

public Polygon2D asPolygon(int n)
Description copied from interface: Domain2D
Returns an approximation of the domain as a polygon, or a MultiPolygon.

Specified by:
asPolygon in interface Domain2D
Returns:
a polygon

boundary

public CirculinearContourArray2D<LinearRing2D> boundary()
Description copied from interface: Domain2D
Returns the boundary of the set. This boundary is either a continuous non intersecting curve (connected domain), or a set of non intersecting continuous curve (one continuous non-intersection for each connected part of the domain).

The returned curve is oriented, with an interior and an exterior.

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

contours

public java.util.Collection<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
Specified by:
contours in interface Polygon2D
See Also:
Contour2D

complement

public Polygon2D complement()
Description copied from interface: Domain2D
Returns the domain which complements this domain in the plane.

Specified by:
complement in interface CirculinearDomain2D
Specified by:
complement in interface Domain2D
Specified by:
complement in interface Polygon2D
Returns:
the complement of this domain.

boundingBox

public Box2D boundingBox()
Description copied from interface: Shape2D
Returns the bounding box of the shape.

Specified by:
boundingBox in interface Shape2D
Returns:
the bounding box of the shape.

clip

public Polygon2D clip(Box2D box)
Clips the polygon with the specified box.

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

distance

public double distance(Point2D p)
Description copied from interface: Shape2D
Returns the distance of the shape to the given point, or the distance of point to the frontier of the shape in the case of a plain shape.

Specified by:
distance in interface Shape2D

distance

public double distance(double x,
                       double y)
Description copied from interface: Shape2D
Returns the distance of the shape to the given point, specified by x and y, or the distance of point to the frontier of the shape in the case of a plain (i.e. fillable) shape.

Specified by:
distance in interface Shape2D

isBounded

public boolean isBounded()
Description copied from interface: Shape2D
Returns true if the shape is bounded, that is if we can draw a finite rectangle enclosing the shape. For example, a straight line or a parabola are not bounded.

Specified by:
isBounded in interface Shape2D

isEmpty

public boolean isEmpty()
The MultiPolygon2D is empty either if it contains no ring, or if all rings are empty.

Specified by:
isEmpty in interface Shape2D
Returns:
true if the shape does not contain any point.

transform

public MultiPolygon2D transform(AffineTransform2D trans)
Description copied from interface: Shape2D
Transforms the shape by an affine transform. Subclasses may override the type of returned shape.

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

contains

public boolean contains(Point2D point)
Description copied from interface: Shape2D
Checks if the shape contains the given point.

Specified by:
contains in interface Shape2D

contains

public boolean contains(double x,
                        double y)
Description copied from interface: Shape2D
Checks if the shape contains the planar point defined by (x,y).

Specified by:
contains in interface Shape2D

draw

public void draw(java.awt.Graphics2D g2)
Description copied from interface: Domain2D
Draws the boundary of the domain, using current Stroke and color.

Specified by:
draw in interface Domain2D
Specified by:
draw in interface Shape2D
Parameters:
g2 - the Graphics to draw on

fill

public void fill(java.awt.Graphics2D g)
Description copied from interface: Domain2D
Fills the interior of the domain, using the Graphics current Paint.

Specified by:
fill in interface Domain2D
Parameters:
g - the Graphics to fill on

almostEquals

public boolean almostEquals(GeometricObject2D obj,
                            double eps)
Description copied from interface: GeometricObject2D
Checks if the two objects are similar up to a given threshold value. This method can be used to compare the results of geometric computations, that introduce errors due to numerical computations.

Specified by:
almostEquals in interface GeometricObject2D
Parameters:
obj - the object to compare
eps - a threshold value, for example the minimal coordinate difference
Returns:
true if both object have the same value up to the threshold

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

clone

public MultiPolygon2D clone()
Overrides:
clone in class java.lang.Object