com.sun.electric.database.geometry
Class PolyMerge

java.lang.Object
  extended by com.sun.electric.database.geometry.GeometryHandler
      extended by com.sun.electric.database.geometry.PolyMerge

public class PolyMerge
extends GeometryHandler

This is the Polygon Merging facility.

Initially, call:
PolyMerge merge = new PolyMerge();
The returned value is used in subsequent calls.

For every polygon, call:
merge.addPolygon(layer, poly);
where "layer" is a layer and "poly" is a polygon to be added.

You can also subtract a polygon by calling:
merge.subtract(layer, poly);

To combine two different merges, use:
merge.addMerge(addmerge, trans)
to add the merge information in "addmerge" (transformed by "trans")

At end of merging, call:
merge.getMergedPoints(layer)
for each layer, and it returns an array of PolyBases on that layer.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.sun.electric.database.geometry.GeometryHandler
GeometryHandler.GHMode
 
Field Summary
 
Fields inherited from class com.sun.electric.database.geometry.GeometryHandler
areaSort, shapeSort
 
Constructor Summary
PolyMerge()
          Method to create a new "merge" object.
 
Method Summary
 void add(Layer key, java.lang.Object value)
          Method to add a PolyBase to the merged collection.
 void addAll(GeometryHandler subMerge, java.awt.geom.AffineTransform trans)
          Method to add another Merge to this one.
 void addLayer(Layer fromLayer, Layer toLayer)
          Method to add one Layer to another in this merge.
 void addMerge(PolyMerge other, java.awt.geom.AffineTransform trans)
          Method to add another Merge to this one.
 void addPolygon(Layer layer, PolyBase poly)
          Method to add a PolyBase to the merged collection.
 void addRectangle(Layer layer, java.awt.geom.Rectangle2D rect)
          Method to add a Rectangle to the merged collection.
 boolean arcPolyFits(Layer layer, java.awt.geom.Point2D headLoc, java.awt.geom.Point2D tailLoc, double wid, GenMath.MutableBoolean headExtend, GenMath.MutableBoolean tailExtend)
          Method to see if an arc fits in this merge with or without end extension.
 boolean contains(Layer layer, java.awt.geom.Point2D pt)
          Method to determine whether a point exists in the merge.
 boolean contains(Layer layer, PolyBase poly)
          Method to determine whether a polygon exists in the merge.
 boolean contains(Layer layer, java.awt.geom.Rectangle2D rect)
          Method to determine whether a rectangle exists in the merge.
 void deleteLayer(Layer layer)
          Method to delete all geometry on a given layer.
 java.awt.geom.Area exclusive(Layer layer, PolyBase poly)
           
 double getAreaOfLayer(Layer layer)
          Method to return the area on a given layer.
static java.util.List<PolyBase> getAreaPoints(java.awt.geom.Area area, Layer layer, boolean simple)
          Method to return a list of polygons in this merge for a given layer.
 java.util.List<PolyBase> getMergedPoints(Layer layer, boolean simple)
          Method to return list of Polys on a given Layer in this Merge.
 java.util.Collection<PolyBase> getObjects(java.lang.Object layer, boolean modified, boolean simple)
          To retrieve leave elements from internal structure
 void insetLayer(Layer source, Layer dest, double amount)
          Method to inset one layer by a given amount and create a second layer.
 void intersectLayers(Layer sourceA, Layer sourceB, Layer dest)
          Method to intersect two layers in this merge and produce a third.
 boolean intersects(Layer layer, PolyBase poly)
          Method to determine whether a polygon intersects a layer in the merge.
 boolean isEmpty(Layer layer)
          Method to tell whether there is any valid geometry on a given layer of this merge.
 void subtract(java.lang.Object layer, java.lang.Object poly)
          Method to subtract a PolyBase from the merged collection.
 void subtractLayers(Layer sourceA, Layer sourceB, Layer dest)
          Method to subtract one layer from another and produce a third.
 void subtractMerge(PolyMerge other)
          Method to subtract another Merge to this one.
 
Methods inherited from class com.sun.electric.database.geometry.GeometryHandler
createGeometryHandler, getKeySet, getTreeObjects, postProcess, subtractAll
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PolyMerge

public PolyMerge()
Method to create a new "merge" object.

Method Detail

add

public void add(Layer key,
                java.lang.Object value)
Method to add a PolyBase to the merged collection.

Overrides:
add in class GeometryHandler
Parameters:
key - the layer that this PolyBase sits on.
value - the PolyBase to merge. If value is only Shape type then it would take the bounding box. This might not be precise enough!.

addRectangle

public void addRectangle(Layer layer,
                         java.awt.geom.Rectangle2D rect)
Method to add a Rectangle to the merged collection.

Parameters:
layer - the layer that this Poly sits on.
rect - the Rectangle to merge.

addPolygon

public void addPolygon(Layer layer,
                       PolyBase poly)
Method to add a PolyBase to the merged collection.

Parameters:
layer - the layer that this Poly sits on.
poly - the PolyBase to merge.

subtract

public void subtract(java.lang.Object layer,
                     java.lang.Object poly)
Method to subtract a PolyBase from the merged collection.

Overrides:
subtract in class GeometryHandler
Parameters:
layer - the layer that this PolyBase sits on.
poly - the PolyBase to merge.

addAll

public void addAll(GeometryHandler subMerge,
                   java.awt.geom.AffineTransform trans)
Method to add another Merge to this one.

Overrides:
addAll in class GeometryHandler
Parameters:
subMerge - the other Merge to add in.
trans - a transformation on the other Merge.

addMerge

public void addMerge(PolyMerge other,
                     java.awt.geom.AffineTransform trans)
Method to add another Merge to this one.

Parameters:
other - the other Merge to add in.
trans - a transformation on the other Merge.

addLayer

public void addLayer(Layer fromLayer,
                     Layer toLayer)
Method to add one Layer to another in this merge.

Parameters:
fromLayer - the other Layer to add in.
toLayer - the destination layer that will contain the union of itself and "fromLayer".

intersects

public boolean intersects(Layer layer,
                          PolyBase poly)
Method to determine whether a polygon intersects a layer in the merge.

Parameters:
layer - the layer to test.
poly - the polygon to examine.
Returns:
true if any part of the polygon exists in that layer.

intersectLayers

public void intersectLayers(Layer sourceA,
                            Layer sourceB,
                            Layer dest)
Method to intersect two layers in this merge and produce a third.

Parameters:
sourceA - the first Layer to intersect.
sourceB - the second Layer to intersect.
dest - the destination layer to place the intersection of the first two. If there is no intersection, all geometry on this layer is cleared.

subtractLayers

public void subtractLayers(Layer sourceA,
                           Layer sourceB,
                           Layer dest)
Method to subtract one layer from another and produce a third.

Parameters:
sourceA - the first Layer.
sourceB - the second Layer, which gets subtracted from the first.
dest - the destination layer to place the sourceA - sourceB. If there is nothing left, all geometry on the layer is cleared.

subtractMerge

public void subtractMerge(PolyMerge other)
Method to subtract another Merge to this one.

Parameters:
other - the other Merge to subtract.

insetLayer

public void insetLayer(Layer source,
                       Layer dest,
                       double amount)
Method to inset one layer by a given amount and create a second layer.

Parameters:
source - the Layer to inset.
dest - the destination layer to place the inset geometry.
amount - the distance to inset the layer.

deleteLayer

public void deleteLayer(Layer layer)
Method to delete all geometry on a given layer.

Parameters:
layer - the Layer to clear in this merge.

isEmpty

public boolean isEmpty(Layer layer)
Method to tell whether there is any valid geometry on a given layer of this merge.

Parameters:
layer - the layer to test.
Returns:
true if there is no valid geometry on the given layer in this merge.

contains

public boolean contains(Layer layer,
                        java.awt.geom.Rectangle2D rect)
Method to determine whether a rectangle exists in the merge.

Parameters:
layer - the layer being tested.
rect - the rectangle being tested.
Returns:
true if all of the rectangle is inside of the merge on the given layer.

contains

public boolean contains(Layer layer,
                        PolyBase poly)
Method to determine whether a polygon exists in the merge.

Parameters:
layer - the layer being tested.
poly - the polygon being tested.
Returns:
true if all of the polygon is inside of the merge on the given layer.

exclusive

public java.awt.geom.Area exclusive(Layer layer,
                                    PolyBase poly)

arcPolyFits

public boolean arcPolyFits(Layer layer,
                           java.awt.geom.Point2D headLoc,
                           java.awt.geom.Point2D tailLoc,
                           double wid,
                           GenMath.MutableBoolean headExtend,
                           GenMath.MutableBoolean tailExtend)
Method to see if an arc fits in this merge with or without end extension.

Parameters:
layer - the layer of the arc being examined.
headLoc - the head location of the arc.
tailLoc - the tail location of the arc.
wid - the width of the arc.
headExtend - the head extension of the arc (is set false if extension not possible).
tailExtend - the tail extension of the arc (is set false if extension not possible).
Returns:
true if the arc fits in the merge. May change "noHeadExtend" and "noTailExtend". Returns false if the arc cannot fit.

getAreaOfLayer

public double getAreaOfLayer(Layer layer)
Method to return the area on a given layer.

Parameters:
layer - the layer to query.
Returns:
the area of geometry on the given layer.

contains

public boolean contains(Layer layer,
                        java.awt.geom.Point2D pt)
Method to determine whether a point exists in the merge.

Parameters:
layer - the layer being tested.
pt - the point being tested.
Returns:
true if the point is inside of the merge on the given layer.

getObjects

public java.util.Collection<PolyBase> getObjects(java.lang.Object layer,
                                                 boolean modified,
                                                 boolean simple)
Description copied from class: GeometryHandler
To retrieve leave elements from internal structure

Overrides:
getObjects in class GeometryHandler
Parameters:
layer - current layer under analysis
modified - to avoid retrieving original polygons
simple - to obtain simple polygons

getMergedPoints

public java.util.List<PolyBase> getMergedPoints(Layer layer,
                                                boolean simple)
Method to return list of Polys on a given Layer in this Merge.

Parameters:
layer - the layer in question.
simple -
Returns:
the list of Polys that describes this Merge.

getAreaPoints

public static java.util.List<PolyBase> getAreaPoints(java.awt.geom.Area area,
                                                     Layer layer,
                                                     boolean simple)
Method to return a list of polygons in this merge for a given layer.

Parameters:
area - the Area object that describes the merge.
layer - the desired Layer.
simple - true for simple polygons, false to allow complex ones.
Returns:
a List of PolyBase objects that describes the layer in the merge.