com.partnersoft.geometry
Class Polygon

java.lang.Object
  extended by com.partnersoft.geometry.Polygon

public class Polygon
extends java.lang.Object

A single, DoubleBuffer-based polygon.

Author:
Paul Reavis Copyright 2002 Partner Software, Inc.

Field Summary
 DoubleBuffer coords
           
 
Constructor Summary
Polygon()
           
Polygon(DoubleBuffer buffy)
           
Polygon(int size)
           
 
Method Summary
 void addVertex(double x, double y)
           
 Polygon clipToLine(Line clipEdge)
          Clips along a single infinite edge.
 Polygon clipToRectangle(double minX, double minY, double maxX, double maxY)
          Clips the polygon to the given rectangle.
 java.lang.Object clone()
           
static boolean containsDegenerateSegments(DoubleBuffer coords)
           
 Point getCentroid()
           
 Rectangle getExtents()
           
 double getLength()
           
 int getVertexCount()
           
 boolean isDegenerate()
           
static boolean isDegenerate(DoubleBuffer coords)
           
 boolean isInside(double x, double y)
           
 void reduceDetail(double granularity)
           
static void reduceDetail(DoubleBuffer coords, double granularity)
          Attempts to reduce the complexity of the line by eliminating points which add nothing to the detail at a certain granularity.
 TriangleArray tessellate()
          Converts the polygon into a set of triangles.
 void tessellate(TriangleArray results)
          Converts the polygon into a set of triangles.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

coords

public DoubleBuffer coords
Constructor Detail

Polygon

public Polygon()

Polygon

public Polygon(int size)

Polygon

public Polygon(DoubleBuffer buffy)
Method Detail

clone

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

reduceDetail

public final void reduceDetail(double granularity)

reduceDetail

public static final void reduceDetail(DoubleBuffer coords,
                                      double granularity)
Attempts to reduce the complexity of the line by eliminating points which add nothing to the detail at a certain granularity. Granularity is defined as a discretizing parameter - it sets up a grid of that cell size and points which fall into the same grid cell are regarded as identical. May reduce it to a single point, so watch out.


isDegenerate

public static final boolean isDegenerate(DoubleBuffer coords)

containsDegenerateSegments

public static final boolean containsDegenerateSegments(DoubleBuffer coords)

addVertex

public void addVertex(double x,
                      double y)

getCentroid

public final Point getCentroid()

getLength

public final double getLength()

getExtents

public final Rectangle getExtents()

isInside

public boolean isInside(double x,
                        double y)

getVertexCount

public int getVertexCount()

clipToRectangle

public Polygon clipToRectangle(double minX,
                               double minY,
                               double maxX,
                               double maxY)
Clips the polygon to the given rectangle. Returns zero or more polygons. Uses the Sutherland-Hodgman algorithm (Foley, van Dam et. al pg 128).


clipToLine

public Polygon clipToLine(Line clipEdge)
Clips along a single infinite edge. The edge is described as a line segment; anything to the left as you proceed from x1,y1 to x2,y2 is considered "inside". Also part of Sutherland-Hodgman algorithm.


isDegenerate

public final boolean isDegenerate()

tessellate

public TriangleArray tessellate()
Converts the polygon into a set of triangles.


tessellate

public void tessellate(TriangleArray results)
Converts the polygon into a set of triangles.