org.eclipse.birt.chart.internal.computations
Class Polygon

java.lang.Object
  extended byorg.eclipse.birt.chart.internal.computations.Polygon
All Implemented Interfaces:
IPolygon
Direct Known Subclasses:
RotatedRectangle

public class Polygon
extends java.lang.Object
implements IPolygon

PolyDefault is a default Poly implementation. It provides support for both complex and simple polygons. A complex polygon is a polygon that consists of more than one polygon. A simple polygon is a more traditional polygon that contains of one inner polygon and is just a collection of points.

Implementation Note: If a point is added to an empty PolyDefault object, it will create an inner polygon of type PolySimple.

Author:
Dan Bridenbecker, Solution Engineering, Inc.
See Also:
PolySimple

Constructor Summary
Polygon()
          Creates a new instance of PolyDefault
Polygon(boolean isHole)
           
 
Method Summary
 void add(double x, double y)
          Add a point to the first inner polygon.
 void add(IPolygon p)
          Add an inner polygon to this polygon - assumes that adding polygon does not have any inner polygons.
 void add(Point p)
          Add a point to the first inner polygon.
 void clear()
          Remove all of the points.
 boolean contains(Point loc)
           
 boolean equals(java.lang.Object obj)
          Return true if the given object is equal to this one.
 double getArea()
          Return the area of the polygon in square units.
 Rectangle getBounds()
          Returns the bounding rectangle of this polygon.
 IPolygon getInnerPoly(int polyIndex)
          Returns the polygon at this index.
 int getNumInnerPoly()
          Returns the number of inner polygons - inner polygons are assumed to return one here.
 int getNumPoints()
          Return the number points of the first inner polygon
 Point getPoint(int i)
           
 java.util.List getPoints()
          Returns the points
 double getX(int index)
          Return the X value of the point at the index in the first inner polygon
 double getY(int index)
          Return the Y value of the point at the index in the first inner polygon
 int hashCode()
          Return the hashCode of the object.
 IPolygon intersection(IPolygon p)
          Return a Poly that is the intersection of this polygon with the given polygon.
 boolean isContributing(int polyIndex)
          Return true if the given inner polygon is contributing to the set operation.
 boolean isEmpty()
          Return true if the polygon is empty
 boolean isHole()
          Return true if this polygon is a hole.
 void setContributing(int polyIndex, boolean contributes)
          Set whether or not this inner polygon is constributing to the set operation.
 void setIsHole(boolean isHole)
          Set whether or not this polygon is a hole.
 java.lang.String toString()
           
 IPolygon union(IPolygon p)
          Return a Poly that is the union of this polygon with the given polygon.
 IPolygon xor(IPolygon p)
          Return a Poly that is the exclusive-or of this polygon with the given polygon.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Polygon

public Polygon()
Creates a new instance of PolyDefault


Polygon

public Polygon(boolean isHole)
Method Detail

equals

public boolean equals(java.lang.Object obj)
Return true if the given object is equal to this one.


hashCode

public int hashCode()
Return the hashCode of the object.

Returns:
an integer value that is the same for two objects whenever their internal representation is the same (equals() is true)

toString

public java.lang.String toString()

clear

public void clear()
Remove all of the points. Creates an empty polygon.

Specified by:
clear in interface IPolygon

add

public void add(double x,
                double y)
Add a point to the first inner polygon.

Implementation Note: If a point is added to an empty Polygon object, it will create an inner polygon of type PolySimple.

Specified by:
add in interface IPolygon

add

public void add(Point p)
Add a point to the first inner polygon.

Implementation Note: If a point is added to an empty Polygon object, it will create an inner polygon of type PolySimple.

Specified by:
add in interface IPolygon

add

public void add(IPolygon p)
Add an inner polygon to this polygon - assumes that adding polygon does not have any inner polygons.

Specified by:
add in interface IPolygon
Throws:
java.lang.IllegalStateException - if the number of inner polygons is greater than zero and this polygon was designated a hole. This would break the assumption that only simple polygons can be holes.

isEmpty

public boolean isEmpty()
Return true if the polygon is empty

Specified by:
isEmpty in interface IPolygon

getBounds

public Rectangle getBounds()
Returns the bounding rectangle of this polygon. WARNING Not supported on complex polygons.

Specified by:
getBounds in interface IPolygon

getInnerPoly

public IPolygon getInnerPoly(int polyIndex)
Returns the polygon at this index.

Specified by:
getInnerPoly in interface IPolygon

getNumInnerPoly

public int getNumInnerPoly()
Returns the number of inner polygons - inner polygons are assumed to return one here.

Specified by:
getNumInnerPoly in interface IPolygon

getNumPoints

public int getNumPoints()
Return the number points of the first inner polygon

Specified by:
getNumPoints in interface IPolygon

getPoints

public java.util.List getPoints()
Returns the points

Specified by:
getPoints in interface IPolygon

getPoint

public Point getPoint(int i)
Specified by:
getPoint in interface IPolygon

getX

public double getX(int index)
Return the X value of the point at the index in the first inner polygon

Specified by:
getX in interface IPolygon

getY

public double getY(int index)
Return the Y value of the point at the index in the first inner polygon

Specified by:
getY in interface IPolygon

isHole

public boolean isHole()
Return true if this polygon is a hole. Holes are assumed to be inner polygons of a more complex polygon.

Specified by:
isHole in interface IPolygon
Throws:
java.lang.IllegalStateException - if called on a complex polygon.

setIsHole

public void setIsHole(boolean isHole)
Set whether or not this polygon is a hole. Cannot be called on a complex polygon.

Specified by:
setIsHole in interface IPolygon
Throws:
java.lang.IllegalStateException - if called on a complex polygon.

isContributing

public boolean isContributing(int polyIndex)
Return true if the given inner polygon is contributing to the set operation. This method should NOT be used outside the Clip algorithm.

Specified by:
isContributing in interface IPolygon

setContributing

public void setContributing(int polyIndex,
                            boolean contributes)
Set whether or not this inner polygon is constributing to the set operation. This method should NOT be used outside the Clip algorithm.

Specified by:
setContributing in interface IPolygon
Throws:
java.lang.IllegalStateException - if called on a complex polygon

intersection

public IPolygon intersection(IPolygon p)
Return a Poly that is the intersection of this polygon with the given polygon. The returned polygon could be complex.

Specified by:
intersection in interface IPolygon
Returns:
the returned Poly will be an instance of Polygon.

union

public IPolygon union(IPolygon p)
Return a Poly that is the union of this polygon with the given polygon. The returned polygon could be complex.

Specified by:
union in interface IPolygon
Returns:
the returned Poly will be an instance of Polygon.

xor

public IPolygon xor(IPolygon p)
Return a Poly that is the exclusive-or of this polygon with the given polygon. The returned polygon could be complex.

Specified by:
xor in interface IPolygon
Returns:
the returned Poly will be an instance of Polygon.

getArea

public double getArea()
Return the area of the polygon in square units.

Specified by:
getArea in interface IPolygon

contains

public boolean contains(Point loc)
Specified by:
contains in interface IPolygon


Copyright © 2005 Actuate Corp. All rights reserved.