org.osm2world.core.math
Class PolygonXZ

Object
  extended by PolygonXZ
Direct Known Subclasses:
SimplePolygonXZ

public class PolygonXZ
extends Object


Field Summary
protected  List<VectorXZ> vertexLoop
          polygon vertices; first and last vertex are equal
 
Constructor Summary
PolygonXZ(List<VectorXZ> vertexLoop)
           
 
Method Summary
protected static void assertLoopProperty(List<VectorXZ> vertexLoop)
          checks that the first and last vertex of the vertex list are equal.
 SimplePolygonXZ asSimplePolygon()
          returns a polygon with the coordinates of this polygon that is an instance of SimplePolygonXZ.
 TriangleXZ asTriangleXZ()
          returns a triangle with the same vertices as this polygon.
 VectorXZ getCenter()
          returns the average of all vertex coordinates.
 LineSegmentXZ getClosestSegment(VectorXZ point)
          returns the polygon segment with minimum distance to a given point
 double getOutlineLength()
          returns the length of the polygon's outline.
 List<LineSegmentXZ> getSegments()
           
 VectorXZ getVertex(int index)
          returns the vertex at a position in the vertex sequence
 VectorXZ getVertexAfter(int index)
          returns the successor of the vertex at a position in the vertex sequence.
 VectorXZ getVertexBefore(int index)
          returns the predecessor of the vertex at a position in the vertex sequence.
 List<VectorXZ> getVertexCollection()
          returns a collection that contains all vertices of this polygon at least once.
 List<VectorXZ> getVertexLoop()
          returns the polygon's vertices.
 List<VectorXZ> getVertices()
          returns the polygon's vertices.
 Collection<VectorXZ> intersectionPositions(LineSegmentXZ lineSegment)
           
 Collection<LineSegmentXZ> intersectionSegments(LineSegmentXZ lineSegment)
           
 boolean intersects(LineSegmentXZ lineSegment)
           
 boolean intersects(PolygonXZ outlinePolygonXZ)
          returns true if there is an intersection between this polygon's and the parameter polygon's sides
 boolean intersects(VectorXZ segmentP1, VectorXZ segmentP2)
          returns true if there is an intersection between this polygon and the line segment defined by the parameter
 boolean isEquivalentTo(PolygonXZ other)
          returns true if the other polygon has the same vertices in the same order, possibly with a different start vertex
 boolean isSelfIntersecting()
          returns whether this polygon is self-intersecting
static boolean isSelfIntersecting(List<VectorXZ> polygonVertexLoop)
          returns true if the polygon defined by the polygonVertexLoop parameter is self-intersecting
 boolean isSimple()
          checks whether this polygon is simple
 PolygonXZ reverse()
           
 int size()
          returns the number of vertices in this polygon.
 String toString()
           
 PolygonXYZ xyz(double y)
           
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

vertexLoop

protected final List<VectorXZ> vertexLoop
polygon vertices; first and last vertex are equal

Constructor Detail

PolygonXZ

public PolygonXZ(List<VectorXZ> vertexLoop)
Parameters:
vertexLoop - vertices defining the polygon; first and last vertex must be equal
Throws:
InvalidGeometryException - if the polygon is self-intersecting or produces invalid area calculation results
Method Detail

size

public int size()
returns the number of vertices in this polygon. The duplicated first/last vertex is not counted twice, so the result is equivalent to getVertices().size().


getVertices

public List<VectorXZ> getVertices()
returns the polygon's vertices. Unlike getVertexLoop(), there is no duplication of the first/last vertex.


getVertexLoop

public List<VectorXZ> getVertexLoop()
returns the polygon's vertices. First and last vertex are equal.


getVertexCollection

public List<VectorXZ> getVertexCollection()
returns a collection that contains all vertices of this polygon at least once. Can be used if you don't care about whether the first/last vector is duplicated.


getVertex

public VectorXZ getVertex(int index)
returns the vertex at a position in the vertex sequence


getVertexAfter

public VectorXZ getVertexAfter(int index)
returns the successor of the vertex at a position in the vertex sequence. This wraps around the vertex loop, so the successor of the last vertex is the first vertex.


getVertexBefore

public VectorXZ getVertexBefore(int index)
returns the predecessor of the vertex at a position in the vertex sequence. This wraps around the vertex loop, so the predecessor of the first vertex is the last vertex.


getSegments

public List<LineSegmentXZ> getSegments()

getClosestSegment

public LineSegmentXZ getClosestSegment(VectorXZ point)
returns the polygon segment with minimum distance to a given point


intersects

public boolean intersects(VectorXZ segmentP1,
                          VectorXZ segmentP2)
returns true if there is an intersection between this polygon and the line segment defined by the parameter


intersects

public boolean intersects(LineSegmentXZ lineSegment)

intersects

public boolean intersects(PolygonXZ outlinePolygonXZ)
returns true if there is an intersection between this polygon's and the parameter polygon's sides


intersectionSegments

public Collection<LineSegmentXZ> intersectionSegments(LineSegmentXZ lineSegment)

intersectionPositions

public Collection<VectorXZ> intersectionPositions(LineSegmentXZ lineSegment)

isSelfIntersecting

public boolean isSelfIntersecting()
returns whether this polygon is self-intersecting


isSelfIntersecting

public static boolean isSelfIntersecting(List<VectorXZ> polygonVertexLoop)
returns true if the polygon defined by the polygonVertexLoop parameter is self-intersecting


isSimple

public boolean isSimple()
checks whether this polygon is simple


asSimplePolygon

public SimplePolygonXZ asSimplePolygon()
returns a polygon with the coordinates of this polygon that is an instance of SimplePolygonXZ. Only works if it actually isSimple()!


asTriangleXZ

public TriangleXZ asTriangleXZ()
returns a triangle with the same vertices as this polygon. Requires that the polygon is triangular!


xyz

public PolygonXYZ xyz(double y)

reverse

public PolygonXZ reverse()

getCenter

public VectorXZ getCenter()
returns the average of all vertex coordinates. The result is not necessarily contained by this polygon.


getOutlineLength

public double getOutlineLength()
returns the length of the polygon's outline. (This does not return the number of vertices, but the sum of distances between subsequent nodes.)


isEquivalentTo

public boolean isEquivalentTo(PolygonXZ other)
returns true if the other polygon has the same vertices in the same order, possibly with a different start vertex


assertLoopProperty

protected static void assertLoopProperty(List<VectorXZ> vertexLoop)
checks that the first and last vertex of the vertex list are equal.

Throws:
IllegalArgumentException - if first and last vertex aren't equal (this is usually a programming error, therefore InvalidGeometryException is not used)

toString

public String toString()
Overrides:
toString in class Object