com.sun.electric.database.geometry
Class DBMath

java.lang.Object
  extended by com.sun.electric.database.geometry.GenMath
      extended by com.sun.electric.database.geometry.DBMath

public class DBMath
extends GenMath

This class is a collection of math utilities used for Database Units. It overrides several important methods from GenMath used when comparing doubles.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.sun.electric.database.geometry.GenMath
GenMath.MutableBoolean, GenMath.MutableDouble, GenMath.MutableInteger, GenMath.MutableLong
 
Field Summary
static double GRID
          Number of grid points per unit
 
Fields inherited from class com.sun.electric.database.geometry.GenMath
MATID, MAX_SMALL_COORD, MIN_SMALL_COORD
 
Constructor Summary
DBMath()
           
 
Method Summary
static boolean areEquals(double a, double b)
          Method to compare two double-precision database values.
static boolean areEquals(java.awt.geom.Point2D a, java.awt.geom.Point2D b)
          Method to compare two double-precision database coordinates within an approximate epsilon.
static double getEpsilon()
          To return private epsilon used for calculation.
static void gridAlign(java.awt.geom.Point2D pt, double alignment)
          Method to snap a point to the nearest database-space grid unit.
static double gridToLambda(double gridValue)
          Method to convert a database value from grid units to lambda units.
static boolean hasRemainder(double a, double divisor)
          Method to calcular remainder for doubles and avoid rounding errors by calculating the remainder for integers instead.
static boolean isGreaterThan(double a, double b)
          Method to determine if one value is greater than another, but counting for rounding error
static boolean isGreaterThanOrEqualTo(double a, double b)
          Method to determine if one value is greater than or equal to another, but counting for rounding error
static boolean isInBetween(double x, double a, double b)
          Method to determine if a value is between two given values including the boundary.
static boolean isLessThan(double a, double b)
          Method to determine if one value is less than another, but counting for rounding error
static boolean isLessThanOrEqualTo(double a, double b)
          Method to determine if one value is less than or equal to another, but counting for rounding error
static boolean isOnLine(java.awt.geom.Point2D end1, java.awt.geom.Point2D end2, java.awt.geom.Point2D pt)
          Method to tell whether a point is on a given line segment.
static long lambdaToGrid(double lambdaValue)
          Method to convert a database value from lambda units to grid units.
static long lambdaToSizeGrid(double lambdaValue)
          Method to convert a database size value from lambda units to grid units.
static boolean pointInRect(java.awt.geom.Point2D pt, java.awt.geom.Rectangle2D bounds)
          Method to tell whether a point is inside of a bounds, compensating for possible database precision errors.
static boolean pointInsideRect(java.awt.geom.Point2D pt, java.awt.geom.Rectangle2D bounds)
          Method to determine if point is completely inside a bound and not along its boundary.
static boolean rectsIntersect(java.awt.geom.Rectangle2D r1, java.awt.geom.Rectangle2D r2)
          Method to tell whether two Rectangle2D objects intersect.
static double round(double lambdaValue)
          Method to round a database value to database precision.
static double roundShapeCoord(double v)
          Method to round coordinate to shape grid.
static void transformRect(java.awt.geom.Rectangle2D bounds, java.awt.geom.AffineTransform xform)
          Method to transform a Rectangle2D by a given transformation.
 
Methods inherited from class com.sun.electric.database.geometry.GenMath
addPoints, addToBag, addToBag, addToBag, arcBBox, arcconnects, ceilInt, ceilLong, clipLine, clipLine, clipPoly, closestPointToLine, closestPointToSegment, computeArcCenter, cos, cosSmall, countInBag, distBetweenPoints, distToLine, doublesClose, doublesEqual, doublesEqual, doublesLessThan, figureAngle, figureAngle, figureAngleRadians, findCenters, findCenters, floorInt, floorLong, getArea, getAreaOfPoints, getQTreeBox, getQuadrants, getX, getY, intersect, intersectRadians, isNinetyDegreeRotation, isSmallInt, isSmallInt, objectsReallyEqual, packXY, polarToXY, primeSince, rint, roundInt, roundLong, sin, sinSmall, toNearest, transformStringsIntoVector, transformVectorIntoValues, unsignedIntValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GRID

public static final double GRID
Number of grid points per unit

See Also:
Constant Field Values
Constructor Detail

DBMath

public DBMath()
Method Detail

getEpsilon

public static double getEpsilon()
To return private epsilon used for calculation. This might problably be removed

Returns:
epsilon

pointInRect

public static boolean pointInRect(java.awt.geom.Point2D pt,
                                  java.awt.geom.Rectangle2D bounds)
Method to tell whether a point is inside of a bounds, compensating for possible database precision errors. The reason that this is necessary is that Rectangle2D.contains requires that the point be INSIDE of the bounds, whereas this method accepts a point that is ON the bounds.

Parameters:
pt - the point in question
bounds - the bounds being tested
Returns:
true if the point is basically within the bounds, within some epsilon.

pointInsideRect

public static boolean pointInsideRect(java.awt.geom.Point2D pt,
                                      java.awt.geom.Rectangle2D bounds)
Method to determine if point is completely inside a bound and not along its boundary.

Parameters:
pt - the Point in question.
bounds - the bounds to test.
Returns:
true if the point is inside the bounds.

areEquals

public static boolean areEquals(double a,
                                double b)
Method to compare two double-precision database values.

Parameters:
a - the first number.
b - the second number.
Returns:
true if the numbers are approximately equal (to a few decimal places).

isInBetween

public static boolean isInBetween(double x,
                                  double a,
                                  double b)
Method to determine if a value is between two given values including the boundary.

Parameters:
x - the value to test.
a - one end of the boundary.
b - the other end of the boundary.
Returns:
true if the value is inside of the boundary.

isGreaterThan

public static boolean isGreaterThan(double a,
                                    double b)
Method to determine if one value is greater than another, but counting for rounding error

Parameters:
a - the first number.
b - the second number.
Returns:
true if first number is greater than the second number.

isLessThan

public static boolean isLessThan(double a,
                                 double b)
Method to determine if one value is less than another, but counting for rounding error

Parameters:
a - the first number.
b - the second number.
Returns:
true if first number is less than the second number.

isGreaterThanOrEqualTo

public static boolean isGreaterThanOrEqualTo(double a,
                                             double b)
Method to determine if one value is greater than or equal to another, but counting for rounding error

Parameters:
a - the first number.
b - the second number.
Returns:
true if first number is greater than or equal to the second number.

isLessThanOrEqualTo

public static boolean isLessThanOrEqualTo(double a,
                                          double b)
Method to determine if one value is less than or equal to another, but counting for rounding error

Parameters:
a - the first number.
b - the second number.
Returns:
true if first number is less than or equal to the second number.

round

public static double round(double lambdaValue)
Method to round a database value to database precision.

Parameters:
lambdaValue - the value to round in lambda units.
Returns:
the return value in lambda units is an approximation of x rounded to GRID.

lambdaToGrid

public static long lambdaToGrid(double lambdaValue)
Method to convert a database value from lambda units to grid units.

Parameters:
lambdaValue - the value to round in lambda unit.
Returns:
the return value in grid units.

lambdaToSizeGrid

public static long lambdaToSizeGrid(double lambdaValue)
Method to convert a database size value from lambda units to grid units. Result is always even number.

Parameters:
lambdaValue - the value to round in lambda unit.
Returns:
the return value in grid units which is even number.

gridToLambda

public static double gridToLambda(double gridValue)
Method to convert a database value from grid units to lambda units.

Parameters:
gridValue - the value in grid unit.
Returns:
the return value in lambda units.

roundShapeCoord

public static double roundShapeCoord(double v)
Method to round coordinate to shape grid. Shape grid values are is k*2^(-20), where k in [-2^52..+2^52]. All shape grid values in range [-2^32..+2^32] can be exactly represented by double value. Values larger thaan 2^32 may be rounded.


gridAlign

public static void gridAlign(java.awt.geom.Point2D pt,
                             double alignment)
Method to snap a point to the nearest database-space grid unit.

Parameters:
pt - the point to be snapped.
alignment - the alignment value to use.

areEquals

public static boolean areEquals(java.awt.geom.Point2D a,
                                java.awt.geom.Point2D b)
Method to compare two double-precision database coordinates within an approximate epsilon.

Parameters:
a - the first point.
b - the second point.
Returns:
true if the points are approximately equal.

isOnLine

public static boolean isOnLine(java.awt.geom.Point2D end1,
                               java.awt.geom.Point2D end2,
                               java.awt.geom.Point2D pt)
Method to tell whether a point is on a given line segment.

Parameters:
end1 - the first end of the line segment.
end2 - the second end of the line segment.
pt - the point in question.
Returns:
true if the point is on the line segment.

hasRemainder

public static boolean hasRemainder(double a,
                                   double divisor)
Method to calcular remainder for doubles and avoid rounding errors by calculating the remainder for integers instead.

Parameters:
a - the numerator
divisor - the denominator.
Returns:
the remainder from the division.

transformRect

public static void transformRect(java.awt.geom.Rectangle2D bounds,
                                 java.awt.geom.AffineTransform xform)
Method to transform a Rectangle2D by a given transformation.

Parameters:
bounds - the Rectangle to transform. It is transformed "in place" (its coordinates are overwritten).
xform - the transformation matrix.

rectsIntersect

public static boolean rectsIntersect(java.awt.geom.Rectangle2D r1,
                                     java.awt.geom.Rectangle2D r2)
Method to tell whether two Rectangle2D objects intersect. If one of the rectangles has zero size, then standard "intersect()" fails.

Parameters:
r1 - the first rectangle.
r2 - the second rectangle.
Returns:
true if they overlap.