com.sencha.gxt.chart.client.draw
Class Polygon

java.lang.Object
  extended by com.sencha.gxt.chart.client.draw.Polygon

public class Polygon
extends Object

Represents a polygon. Provides helper functions for intersection detection.


Constructor Summary
Polygon()
          Creates an empty polygon.
Polygon(Polygon polygon)
          Creates a clone of the given polygon.
Polygon(PrecisePoint... points)
          Creates a polygon using the given points.
Polygon(PreciseRectangle rectangle)
          Creates a polygon using the given rectangle
 
Method Summary
 void addVertex(double x, double y)
          Adds a vertex to the polygon using the given coordinates.
 void addVertex(PrecisePoint vertex)
          Adds the vertex to the polygon.
 boolean equals(Polygon polygon)
          Returns true if the vertices of the given polygon are exactly equal to this polygon.
 boolean equalsNoPrecision(Polygon polygon)
          Returns true if the vertices of the given polygon are nearly equal to this polygon.
 PrecisePoint getVertex(int index)
          Returns the vertex at the provided index.
 Polygon intersect(Polygon clipPolygon)
          Intersection of polygons calculated using the Sutherland-Hodgman algorithm.
 void removeVertex(int index)
          Removes the vertex at the given index.
 int size()
          Returns the number of vertices in the polygon
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Polygon

public Polygon()
Creates an empty polygon.


Polygon

public Polygon(Polygon polygon)
Creates a clone of the given polygon.

Parameters:
polygon - the polygon to clone

Polygon

public Polygon(PrecisePoint... points)
Creates a polygon using the given points.

Parameters:
points - the points to add to the polygon

Polygon

public Polygon(PreciseRectangle rectangle)
Creates a polygon using the given rectangle

Parameters:
rectangle - the rectangle used to create the polygon
Method Detail

addVertex

public void addVertex(double x,
                      double y)
Adds a vertex to the polygon using the given coordinates.

Parameters:
x - the x coordinate of the vertex
y - the y coordinate of the vertex

addVertex

public void addVertex(PrecisePoint vertex)
Adds the vertex to the polygon.

Parameters:
vertex - the vertex to be added

equals

public boolean equals(Polygon polygon)
Returns true if the vertices of the given polygon are exactly equal to this polygon.

Parameters:
polygon - the polygon to be compared
Returns:
true if the vertices of the given polygon are exactly equal to this polygon

equalsNoPrecision

public boolean equalsNoPrecision(Polygon polygon)
Returns true if the vertices of the given polygon are nearly equal to this polygon.

Parameters:
polygon - the polygon to be compared
Returns:
true if the vertices of the given polygon are nearly equal to this polygon

getVertex

public PrecisePoint getVertex(int index)
Returns the vertex at the provided index.

Parameters:
index - the index of the vertex
Returns:
the vertex at the provided vertex

intersect

public Polygon intersect(Polygon clipPolygon)
Intersection of polygons calculated using the Sutherland-Hodgman algorithm. The subject polygon is the polygon making the call and the passed polygon is the clip polygon and thus must be convex.

Parameters:
clipPolygon - must be convex
Returns:
the clipped polygon

removeVertex

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

Parameters:
index - the index to be removed

size

public int size()
Returns the number of vertices in the polygon

Returns:
the number of vertices in the polygon

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2011. All Rights Reserved.