com.sun.electric.database.geometry
Class PolyBase

java.lang.Object
  extended by com.sun.electric.database.geometry.PolyBase
All Implemented Interfaces:
PolyNodeMerge, java.awt.Shape
Direct Known Subclasses:
Poly

public class PolyBase
extends java.lang.Object
implements java.awt.Shape, PolyNodeMerge

The Poly class describes an extended set of points that can be outlines, filled shapes, curves, text, and more. The Poly also contains a Layer and some connectivity information.


Nested Class Summary
static class PolyBase.PolyBaseTree
           
 
Field Summary
protected  java.awt.geom.Rectangle2D bounds
          the bounds of the points
protected  java.awt.geom.Point2D[] points
          the points
static int X
          represents X axis
static int Y
          represents Y axis
static int Z
          represents Z axis
 
Constructor Summary
PolyBase(double cX, double cY, double width, double height)
          The constructor creates a new Poly that describes a rectangle.
PolyBase(java.awt.geom.Point2D[] points)
          The constructor creates a new Poly given an array of points.
PolyBase(java.awt.geom.Rectangle2D rect)
          The constructor creates a new Poly that describes a rectangle.
 
Method Summary
 void clipArc(double lx, double hx, double ly, double hy)
          Method to clip a curved polygon (CIRCLE, THICKCIRCLE, DISC, CIRCLEARC, or THICKCIRCLEARC) against the rectangle lx <= X <= hx and ly <= Y <= hy.
 java.awt.geom.Point2D closestPoint(java.awt.geom.Point2D pt)
          Method to find the point on this polygon closest to a given point.
 boolean compare(java.lang.Object obj, java.lang.StringBuffer buffer)
          Initiative CrossLibCopy.
 boolean contains(double x, double y)
          Method to tell whether a point is inside of this Poly.
 boolean contains(double lX, double lY, double w, double h)
          Method to tell whether a rectangle is inside of this Poly.
 boolean contains(java.awt.geom.Point2D p)
          Method to tell whether a point is inside of this Poly.
 boolean contains(java.awt.geom.Rectangle2D r)
          Method to tell whether a rectangle is inside of this Poly.
static int cropBox(java.awt.geom.Rectangle2D bounds, java.awt.geom.Rectangle2D PUBox)
          Method to crop the box in the reference parameters (lx-hx, ly-hy) against the box in (bx-ux, by-uy).
static int cropBoxComplete(java.awt.geom.Rectangle2D bounds, java.awt.geom.Rectangle2D PUBox)
          Method to crop the box in the reference parameters (lx-hx, ly-hy) against the box in (bx-ux, by-uy).
 double getArea()
          Method to compute the area of this Poly.
 java.awt.Rectangle getBounds()
          Deprecated. this is only implemented because Poly extends Shape. You should be using getBounds2D() instead.
 java.awt.geom.Rectangle2D getBounds2D()
          Method to return the bounds of this Poly.
 java.awt.geom.Rectangle2D getBox()
          Method to return a Rectangle that describes the orthogonal box in this Poly.
 EPoint getCenter()
          Method to return the center of the bounding box containing this PolyBase
 double getCenterX()
          Method to return the X center coordinate of this Poly.
 double getCenterY()
          Method to return the Y center coordinate of this Poly.
 Layer getLayer()
          Method to return the layer associated with this Poly.
 Layer getLayerOrPseudoLayer()
          Method to return the layer or pseudo-layer associated with this Poly.
static java.util.List<PolyBase> getLoopsFromArea(java.awt.geom.Area area, Layer layer)
           
 double getMaxLength()
          Method to compute longest edge.
 double getMaxSize()
          Method to compute the maximum size of this Polygon.
 double getMinSize()
          Method to compute the minimum size of this Polygon.
 java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform at)
          Method to return a PathIterator for this Poly after a transformation.
 java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform at, double flatness)
          Method to return a PathIterator with a particular flatness for this Poly after a transformation.
 double getPerimeter()
          Method to compute the perimeter of this Poly.
 java.awt.geom.Point2D[] getPoints()
          Method to return the points associated with this Poly.
static java.util.List<PolyBase> getPointsFromComplex(java.awt.geom.Area area, Layer layer)
           
static java.util.List<PolyBase> getPointsInArea(java.awt.geom.Area area, Layer layer, boolean simple, boolean includeLastPoint)
          Static method to get PolyBase elements associated with an Area.
 PolyBase getPolygon()
          Method to satisfy the PolyMerge interface by return the polygon (this object).
static java.util.List<PolyBase.PolyBaseTree> getPolyTrees(java.awt.geom.Area area, Layer layer)
           
 PortProto getPort()
          Method to return the PortProto associated with this Poly.
 Poly.Type getStyle()
          Method to return the style associated with this Poly.
protected  double getTextScale(EditWindow0 wnd, java.awt.font.GlyphVector gv, Poly.Type style, double lX, double hX, double lY, double hY)
          Method to return the scaling factor between database and screen for the given text.
static java.util.List<PolyBase.PolyBaseTree> getTreesFromLoops(java.util.List<PolyBase> list)
           
 void gridToLambda()
          Method to convert points from grid units to lambda units.
static int halfCropBox(java.awt.geom.Rectangle2D bounds, java.awt.geom.Rectangle2D limit)
          Method to crop the box in the reference parameters (lx-hx, ly-hy) against the box in (bx-ux, by-uy).
 boolean intersects(double x, double y, double w, double h)
          Method to tell whether a rectangle intersects this Poly.
 boolean intersects(PolyBase polyOther)
          Method to tell whether this Poly intersects another one.
 boolean intersects(java.awt.geom.Rectangle2D r)
          Method to tell whether a rectangle intersects this Poly.
 boolean isInside(java.awt.geom.Point2D pt)
           
 boolean isInside(java.awt.geom.Rectangle2D bounds)
          Method to tell whether a coordinates of this Poly are inside of a Rectangle2D.
 boolean isPointOnCorner(java.awt.geom.Point2D point)
          Method to check if point is part of the point set that defines the polygon
 boolean isPseudoLayer()
          Method to tell if the layer associated with this Poly is a pseudo-layer.
 void lambdaToGrid()
          Method to convert points from lambda units to grid units.
static java.awt.geom.Point2D[] makePoints(double lX, double hX, double lY, double hY)
          Method to create an array of Points that describes a Rectangle.
static java.awt.geom.Point2D[] makePoints(java.awt.geom.Rectangle2D rect)
          Method to create an array of Points that describes a Rectangle.
 double polyDistance(double x, double y)
          Method to report the distance of a point to this Poly.
 double polyDistance(java.awt.geom.Rectangle2D otherBounds)
          Method to report the distance of a rectangle or point to this Poly.
 boolean polySame(PolyBase polyOther)
          Method to compare this Poly to another.
 void reducePortPoly(PortInst pi, double wid, int angle)
          Method to reduce this Poly by the proper amount presuming that it describes a port connected to an arc.
static Poly.Type rotateType(Poly.Type origType, ElectricObject eObj)
          Method to rotate a text Type according to the rotation of the object on which it resides.
 void roundPoints()
          Attempt to control rounding errors in input libraries
 double separation(PolyBase polyOther)
          Method to return the distance between this Poly and another.
 double separationBox(PolyBase polyOther)
          Method to calculate fast distance between two manhattan polygons that do not intersect
 void setLayer(Layer layer)
          Method to set the layer associated with this Poly.
 void setPoint(int pt, double x, double y)
          Method to change the value of a point in the PolyBase.
 void setPort(PortProto pp)
          Method to set the PortProto associated with this Poly.
 void setStyle(Poly.Type style)
          Method to set the style associated with this Poly.
 void transform(java.awt.geom.AffineTransform af)
          Method to transformed the points in this Poly.
static Poly.Type unRotateType(Poly.Type origType, ElectricObject eObj)
          Method to unrotate a text Type according to the rotation of the object on which it resides.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

points

protected java.awt.geom.Point2D[] points
the points


bounds

protected java.awt.geom.Rectangle2D bounds
the bounds of the points


X

public static final int X
represents X axis

See Also:
Constant Field Values

Y

public static final int Y
represents Y axis

See Also:
Constant Field Values

Z

public static final int Z
represents Z axis

See Also:
Constant Field Values
Constructor Detail

PolyBase

public PolyBase(java.awt.geom.Point2D[] points)
The constructor creates a new Poly given an array of points.

Parameters:
points - the array of coordinates.

PolyBase

public PolyBase(double cX,
                double cY,
                double width,
                double height)
The constructor creates a new Poly that describes a rectangle.

Parameters:
cX - the center X coordinate of the rectangle.
cY - the center Y coordinate of the rectangle.
width - the width of the rectangle.
height - the height of the rectangle.

PolyBase

public PolyBase(java.awt.geom.Rectangle2D rect)
The constructor creates a new Poly that describes a rectangle.

Parameters:
rect - the Rectangle2D of the rectangle.
Method Detail

makePoints

public static java.awt.geom.Point2D[] makePoints(double lX,
                                                 double hX,
                                                 double lY,
                                                 double hY)
Method to create an array of Points that describes a Rectangle.

Parameters:
lX - the low X coordinate of the rectangle.
hX - the high X coordinate of the rectangle.
lY - the low Y coordinate of the rectangle.
hY - the high Y coordinate of the rectangle.
Returns:
an array of 4 Points that describes the Rectangle.

makePoints

public static java.awt.geom.Point2D[] makePoints(java.awt.geom.Rectangle2D rect)
Method to create an array of Points that describes a Rectangle.

Parameters:
rect - the Rectangle.
Returns:
an array of 4 Points that describes the Rectangle.

getStyle

public Poly.Type getStyle()
Method to return the style associated with this Poly. The style controls how the points are interpreted (FILLED, CIRCLE, etc.)

Returns:
the style associated with this Poly.

setStyle

public void setStyle(Poly.Type style)
Method to set the style associated with this Poly. The style controls how the points are interpreted (FILLED, CIRCLE, etc.)

Parameters:
style - the style associated with this Poly.

getPoints

public java.awt.geom.Point2D[] getPoints()
Method to return the points associated with this Poly.

Returns:
the points associated with this Poly.

getLayer

public Layer getLayer()
Method to return the layer associated with this Poly.

Returns:
the layer associated with this Poly.

getLayerOrPseudoLayer

public Layer getLayerOrPseudoLayer()
Method to return the layer or pseudo-layer associated with this Poly.

Returns:
the layer or pseudo-layer associated with this Poly.

setLayer

public void setLayer(Layer layer)
Method to set the layer associated with this Poly.

Parameters:
layer - the layer associated with this Poly.

isPseudoLayer

public boolean isPseudoLayer()
Method to tell if the layer associated with this Poly is a pseudo-layer.

Returns:
true if the layer associated with this Poly is a pseudo-layer.

getPort

public PortProto getPort()
Method to return the PortProto associated with this Poly. This applies to ports on Nodes and Exports on Cells.

Returns:
the PortProto associated with this Poly.

setPort

public void setPort(PortProto pp)
Method to set the PortProto associated with this Poly. This applies to ports on Nodes and Exports on Cells.

Parameters:
pp - the PortProto associated with this Poly.

transform

public void transform(java.awt.geom.AffineTransform af)
Method to transformed the points in this Poly.

Parameters:
af - transformation to apply.

lambdaToGrid

public void lambdaToGrid()
Method to convert points from lambda units to grid units.


gridToLambda

public void gridToLambda()
Method to convert points from grid units to lambda units.


getBox

public java.awt.geom.Rectangle2D getBox()
Method to return a Rectangle that describes the orthogonal box in this Poly.

Returns:
the Rectangle that describes this Poly. If the Poly is not an orthogonal box, returns null. IT IS NOT PERMITTED TO MODIFY THE RETURNED RECTANGLE (because it is taken from the internal bounds of the Poly).

getMinSize

public double getMinSize()
Method to compute the minimum size of this Polygon. Only works with manhattan geometry.

Returns:
the minimum dimension.

getMaxSize

public double getMaxSize()
Method to compute the maximum size of this Polygon. Only works with manhattan geometry.


polySame

public boolean polySame(PolyBase polyOther)
Method to compare this Poly to another.

Parameters:
polyOther - the other Poly to compare.
Returns:
true if the Polys are the same.

isInside

public boolean isInside(java.awt.geom.Point2D pt)

isInside

public boolean isInside(java.awt.geom.Rectangle2D bounds)
Method to tell whether a coordinates of this Poly are inside of a Rectangle2D.

Parameters:
bounds - the Rectangle2D in question.
Returns:
true if this Poly is completely inside of the bounds.

isPointOnCorner

public boolean isPointOnCorner(java.awt.geom.Point2D point)
Method to check if point is part of the point set that defines the polygon

Parameters:
point -
Returns:
true if found in points set

reducePortPoly

public void reducePortPoly(PortInst pi,
                           double wid,
                           int angle)
Method to reduce this Poly by the proper amount presuming that it describes a port connected to an arc. This Poly is modified in place to reduce its size.

Parameters:
pi - the PortInst that describes this Poly.
wid - the width of the arc connected to this port-poly. This should be the base width, not the actual width stored in memory.
angle - the angle of the arc connected to this port-poly. If negative, do not consider arc angle.

rotateType

public static Poly.Type rotateType(Poly.Type origType,
                                   ElectricObject eObj)
Method to rotate a text Type according to the rotation of the object on which it resides.

Parameters:
origType - the original text Type.
eObj - the ElectricObject on which the text resides.
Returns:
the new text Type that accounts for the rotation.

unRotateType

public static Poly.Type unRotateType(Poly.Type origType,
                                     ElectricObject eObj)
Method to unrotate a text Type according to the rotation of the object on which it resides. Unrotation implies converting apparent anchor information to actual stored anchor information on a transformed node. For example, if the node is rotated, and the anchor appears to be at the bottom, then the actual anchor that is stored with the node will be different (and when transformed will appear to be at the bottom).

Parameters:
origType - the original text Type.
eObj - the ElectricObject on which the text resides.
Returns:
the new text Type that accounts for the rotation.

getTextScale

protected double getTextScale(EditWindow0 wnd,
                              java.awt.font.GlyphVector gv,
                              Poly.Type style,
                              double lX,
                              double hX,
                              double lY,
                              double hY)
Method to return the scaling factor between database and screen for the given text.

Parameters:
wnd - the window with the text.
gv - the GlyphVector describing the text.
style - the anchor information for the text.
lX - the low X bound of the polygon containing the text.
hX - the high X bound of the polygon containing the text.
lY - the low Y bound of the polygon containing the text.
hY - the high Y bound of the polygon containing the text.
Returns:
the scale of the text (from database to screen).

polyDistance

public double polyDistance(double x,
                           double y)
Method to report the distance of a point to this Poly.

Parameters:
x - coordinate of a point.
y - coordinate of a point.
Returns:
the distance of the point to the Poly. The method returns a negative amount if the point is a direct hit on or inside the polygon (the more negative, the closer to the center).

polyDistance

public double polyDistance(java.awt.geom.Rectangle2D otherBounds)
Method to report the distance of a rectangle or point to this Poly.

Parameters:
otherBounds - the area to test for distance to the Poly.
Returns:
the distance of the area to the Poly. The method returns a negative amount if the point/area is a direct hit on or inside the polygon (the more negative, the closer to the center).

separationBox

public double separationBox(PolyBase polyOther)
Method to calculate fast distance between two manhattan polygons that do not intersect

Parameters:
polyOther - the other polygon being examined with this.
Returns:
non-negative distance if both polygons are manhattan types, -1 if at least one of them is not manhattan.

separation

public double separation(PolyBase polyOther)
Method to return the distance between this Poly and another.

Parameters:
polyOther - the other Poly to consider.
Returns:
the distance between them (returns 0 if they touch or overlap).

closestPoint

public java.awt.geom.Point2D closestPoint(java.awt.geom.Point2D pt)
Method to find the point on this polygon closest to a given point.

Parameters:
pt - the given point
Returns:
a point on this Poly that is closest.

contains

public boolean contains(double x,
                        double y)
Method to tell whether a point is inside of this Poly. This method is a requirement of the Shape implementation.

Specified by:
contains in interface java.awt.Shape
Parameters:
x - the X coordinate of the point.
y - the Y coordinate of the point.
Returns:
true if the point is inside the Poly.

contains

public boolean contains(java.awt.geom.Point2D p)
Method to tell whether a point is inside of this Poly. This method is a requirement of the Shape implementation.

Specified by:
contains in interface java.awt.Shape
Parameters:
p - the point.
Returns:
true if the point is inside the Poly.

contains

public boolean contains(double lX,
                        double lY,
                        double w,
                        double h)
Method to tell whether a rectangle is inside of this Poly. This method is a requirement of the Shape implementation.

Specified by:
contains in interface java.awt.Shape
Parameters:
lX - the X corner of the rectangle.
lY - the Y corner of the rectangle.
w - the width of the rectangle.
h - the height of the rectangle.
Returns:
true if the rectangle is inside the Poly.

contains

public boolean contains(java.awt.geom.Rectangle2D r)
Method to tell whether a rectangle is inside of this Poly. This method is a requirement of the Shape implementation.

Specified by:
contains in interface java.awt.Shape
Parameters:
r - the rectangle.
Returns:
true if the rectangle is inside the Poly.

intersects

public boolean intersects(double x,
                          double y,
                          double w,
                          double h)
Method to tell whether a rectangle intersects this Poly. This method is a requirement of the Shape implementation. THIS METHOD HAS NOT BEEN WRITTEN YET!!!

Specified by:
intersects in interface java.awt.Shape
Parameters:
x - the X corner of the rectangle.
y - the Y corner of the rectangle.
w - the width of the rectangle.
h - the height of the rectangle.
Returns:
true if the rectangle intersects the Poly.

intersects

public boolean intersects(java.awt.geom.Rectangle2D r)
Method to tell whether a rectangle intersects this Poly. This method is a requirement of the Shape implementation. THIS METHOD HAS NOT BEEN WRITTEN YET!!!

Specified by:
intersects in interface java.awt.Shape
Parameters:
r - the rectangle.
Returns:
true if the rectangle intersects the Poly.

intersects

public boolean intersects(PolyBase polyOther)
Method to tell whether this Poly intersects another one.

Parameters:
polyOther - the other Poly to test.
Returns:
true if polygons intersect (that is, if any of their lines intersect).

getPerimeter

public double getPerimeter()
Method to compute the perimeter of this Poly.

Returns:
the perimeter of this Poly.

getMaxLength

public double getMaxLength()
Method to compute longest edge.

Returns:
the longest edge in this PolyBase.

getArea

public double getArea()
Method to compute the area of this Poly.

Returns:
the area of this Poly. Return always a positive number

getCenterX

public double getCenterX()
Method to return the X center coordinate of this Poly.

Returns:
the X center coordinate of this Poly.

getCenterY

public double getCenterY()
Method to return the Y center coordinate of this Poly.

Returns:
the Y center coordinate of this Poly.

getCenter

public EPoint getCenter()
Method to return the center of the bounding box containing this PolyBase

Returns:
EPoint representing the center of the PolyBase bounding box.

getBounds2D

public java.awt.geom.Rectangle2D getBounds2D()
Method to return the bounds of this Poly.

Specified by:
getBounds2D in interface PolyNodeMerge
Specified by:
getBounds2D in interface java.awt.Shape
Returns:
the bounds of this Poly.

getBounds

public java.awt.Rectangle getBounds()
Deprecated. this is only implemented because Poly extends Shape. You should be using getBounds2D() instead.

Method to return the bounds of this Poly. Nobody really uses this, but it is necessary for the implementation of Shape.

Specified by:
getBounds in interface java.awt.Shape
Returns:
the bounds of this Poly.

setPoint

public void setPoint(int pt,
                     double x,
                     double y)
Method to change the value of a point in the PolyBase.

Parameters:
pt - the index of the point to change.
x - the new X value.
y - the new Y value.

roundPoints

public void roundPoints()
Attempt to control rounding errors in input libraries


getPointsInArea

public static java.util.List<PolyBase> getPointsInArea(java.awt.geom.Area area,
                                                       Layer layer,
                                                       boolean simple,
                                                       boolean includeLastPoint)
Static method to get PolyBase elements associated with an Area.

Parameters:
area - Java2D structure containing the geometrical information
layer - the Layer to examine.
simple - if true, polygons with inner loops will return in sample Poly.
includeLastPoint - true to include the last point.
Returns:
List of PolyBase elements.

getPolyTrees

public static java.util.List<PolyBase.PolyBaseTree> getPolyTrees(java.awt.geom.Area area,
                                                                 Layer layer)

getTreesFromLoops

public static java.util.List<PolyBase.PolyBaseTree> getTreesFromLoops(java.util.List<PolyBase> list)

getLoopsFromArea

public static java.util.List<PolyBase> getLoopsFromArea(java.awt.geom.Area area,
                                                        Layer layer)

getPointsFromComplex

public static java.util.List<PolyBase> getPointsFromComplex(java.awt.geom.Area area,
                                                            Layer layer)

getPathIterator

public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform at)
Method to return a PathIterator for this Poly after a transformation. This method is a requirement of the Shape implementation.

Specified by:
getPathIterator in interface java.awt.Shape
Parameters:
at - the transformation to apply.
Returns:
the PathIterator.

getPathIterator

public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform at,
                                                  double flatness)
Method to return a PathIterator with a particular flatness for this Poly after a transformation. This method is a requirement of the Shape implementation.

Specified by:
getPathIterator in interface java.awt.Shape
Parameters:
at - the transformation to apply.
flatness - the required flatness.
Returns:
the PathIterator.

compare

public boolean compare(java.lang.Object obj,
                       java.lang.StringBuffer buffer)
Initiative CrossLibCopy. It should be equals


cropBox

public static int cropBox(java.awt.geom.Rectangle2D bounds,
                          java.awt.geom.Rectangle2D PUBox)
Method to crop the box in the reference parameters (lx-hx, ly-hy) against the box in (bx-ux, by-uy). If the box is cropped into oblivion, returns 1. If the boxes overlap but cannot be cleanly cropped, returns -1. Otherwise the box is cropped and zero is returned


cropBoxComplete

public static int cropBoxComplete(java.awt.geom.Rectangle2D bounds,
                                  java.awt.geom.Rectangle2D PUBox)
Method to crop the box in the reference parameters (lx-hx, ly-hy) against the box in (bx-ux, by-uy). If the box is cropped into oblivion, returns 1. If the boxes overlap but cannot be cleanly cropped, returns -1. If boxes don't overlap, returns -2. Otherwise the box is cropped and zero is returned


halfCropBox

public static int halfCropBox(java.awt.geom.Rectangle2D bounds,
                              java.awt.geom.Rectangle2D limit)
Method to crop the box in the reference parameters (lx-hx, ly-hy) against the box in (bx-ux, by-uy). If the box is cropped into oblivion, returns 1. If the boxes overlap but cannot be cleanly cropped, returns -1. Otherwise the box is cropped and zero is returned


clipArc

public void clipArc(double lx,
                    double hx,
                    double ly,
                    double hy)
Method to clip a curved polygon (CIRCLE, THICKCIRCLE, DISC, CIRCLEARC, or THICKCIRCLEARC) against the rectangle lx <= X <= hx and ly <= Y <= hy. Adjusts the polygon to contain the visible portions.


getPolygon

public PolyBase getPolygon()
Method to satisfy the PolyMerge interface by return the polygon (this object).

Specified by:
getPolygon in interface PolyNodeMerge
Returns:
this object.