public class GenMath
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
GenMath.MutableBoolean
Class to define a Boolean object that can be modified.
|
static class |
GenMath.MutableDouble
Class to define an Double-like object that can be modified.
|
static class |
GenMath.MutableInteger
Class to define an Integer-like object that can be modified.
|
static class |
GenMath.MutableLong
Class to define a Long-like object that can be modified.
|
Modifier and Type | Field and Description |
---|---|
static java.awt.geom.AffineTransform |
MATID
A transformation matrix that does nothing (identity).
|
static int |
MAX_SMALL_COORD
Maximal ineger that is considered "small int".
|
static int |
MIN_SMALL_COORD
Minimal integer that is considered "small int".
|
Constructor and Description |
---|
GenMath() |
Modifier and Type | Method and Description |
---|---|
static java.awt.geom.Point2D |
addPoints(java.awt.geom.Point2D p,
double dx,
double dy)
Method to return the sum of two points.
|
static <T> void |
addToBag(java.util.Map<T,GenMath.MutableInteger> bag,
java.util.Map<T,GenMath.MutableInteger> otherBag)
Adds to bag another bag.
|
static <T> void |
addToBag(java.util.Map<T,GenMath.MutableInteger> bag,
T key)
Increments count to object in a bag.
|
static <T> void |
addToBag(java.util.Map<T,GenMath.MutableInteger> bag,
T key,
int c)
Adds to count of object in a bag.
|
static java.awt.geom.Rectangle2D |
arcBBox(java.awt.geom.Point2D s,
java.awt.geom.Point2D e,
java.awt.geom.Point2D c)
Method to compute the bounding box of the arc that runs clockwise from
"s" to "e" and is centered at "c".
|
static java.awt.geom.Point2D[] |
arcconnects(int ang,
java.awt.geom.Rectangle2D bounds1,
java.awt.geom.Rectangle2D bounds2)
Method to determine whether an arc at angle "ang" can connect the two ports
whose bounding boxes are "lx1<=X<=hx1" and "ly1<=Y<=hy1" for port 1 and
"lx2<=X<=hx2" and "ly2<=Y<=hy2" for port 2.
|
static int |
ceilInt(double x) |
static long |
ceilLong(double x) |
static boolean |
clipLine(java.awt.geom.Point2D from,
java.awt.geom.Point2D to,
double lX,
double hX,
double lY,
double hY)
Method to clip a line against a rectangle (in double-precision).
|
static boolean |
clipLine(java.awt.Point from,
java.awt.Point to,
int lx,
int hx,
int ly,
int hy)
Method to clip a line against a rectangle (in integer).
|
static java.awt.Point[] |
clipPoly(java.awt.Point[] points,
int lx,
int hx,
int ly,
int hy)
Method to clip a polygon against a rectangular region.
|
static java.awt.geom.Point2D |
closestPointToLine(java.awt.geom.Point2D p1,
java.awt.geom.Point2D p2,
java.awt.geom.Point2D pt)
Method to find the point on a line that is closest to a given point.
|
static java.awt.geom.Point2D |
closestPointToSegment(java.awt.geom.Point2D p1,
java.awt.geom.Point2D p2,
java.awt.geom.Point2D pt)
Method to find the point on a line segment that is closest to a given point.
|
static java.awt.geom.Point2D |
computeArcCenter(java.awt.geom.Point2D c,
java.awt.geom.Point2D p1,
java.awt.geom.Point2D p2)
Method used by "ioedifo.c" and "routmaze.c".
|
static double |
cos(int angle)
Method to compute the cosine of an integer angle (in tenth-degrees).
|
static double |
cosSmall(int angle)
Method to compute the cosine of a small integer angle (in tenth-degrees).
|
static <T> int |
countInBag(java.util.Map<T,GenMath.MutableInteger> bag,
T key)
Method to return the a value at a location in a collection.
|
static double |
distBetweenPoints(java.awt.geom.Point2D p1,
java.awt.geom.Point2D p2)
Method to calcute Euclidean distance between two points.
|
static double |
distToLine(java.awt.geom.Point2D l1,
java.awt.geom.Point2D l2,
java.awt.geom.Point2D pt)
Method to compute the distance between point (x,y) and the line that runs
from (x1,y1) to (x2,y2).
|
static boolean |
doublesClose(double a,
double b)
Method to compare two double-precision numbers within an approximate epsilon.
|
static boolean |
doublesEqual(double a,
double b)
Method to compare two double-precision numbers within an acceptable epsilon.
|
static boolean |
doublesEqual(double a,
double b,
double myEpsilon)
Method to compare two double-precision numbers within a given epsilon
|
static boolean |
doublesLessThan(double a,
double b)
Method to compare two numbers and see if one is less than the other within an acceptable epsilon.
|
static int |
figureAngle(double x,
double y)
Method to return the angle of a vector.
|
static int |
figureAngle(java.awt.geom.Point2D end1,
java.awt.geom.Point2D end2)
Method to return the angle between two points.
|
static double |
figureAngleRadians(java.awt.geom.Point2D end1,
java.awt.geom.Point2D end2)
Method to return the angle between two points.
|
static java.awt.geom.Point2D[] |
findCenters(double r,
double x01,
double y01,
double x02,
double y02,
double d)
Method to find the two possible centers for a circle whose radius is
"r" and has two points (x01,y01) and (x02,y02) on the edge.
|
static java.awt.geom.Point2D[] |
findCenters(double r,
java.awt.geom.Point2D p1,
java.awt.geom.Point2D p2)
Method to find the two possible centers for a circle given a radius and two edge points.
|
static int |
floorInt(double x) |
static long |
floorLong(double x) |
static double |
getArea(java.awt.geom.Rectangle2D rect)
Method to compute the area of a given rectangle.
|
static double |
getAreaOfPoints(java.awt.geom.Point2D[] points)
Method to compute the area of a polygon defined by an array of points.
|
static java.awt.geom.Rectangle2D |
getQTreeBox(double x,
double y,
double w,
double h,
double centerX,
double centerY,
int loc)
Calculates the bounding box of a child depending on the location.
|
static int |
getQuadrants(double centerX,
double centerY,
java.awt.geom.Rectangle2D box)
General method to obtain quadrant for a given box in a qTree based on the qTree center
|
static int |
getX(long xy)
Returns x coordinate packed in a long value by
packXY . |
static int |
getY(long xy)
Returns y coordinate packed in a long value by
packXY . |
static java.awt.geom.Point2D |
intersect(java.awt.geom.Point2D p1,
int ang1,
java.awt.geom.Point2D p2,
int ang2)
Method to determine the intersection of two lines and return that point.
|
static java.awt.geom.Point2D |
intersectRadians(java.awt.geom.Point2D p1,
double ang1,
java.awt.geom.Point2D p2,
double ang2)
Method to determine the intersection of two lines and return that point.
|
static boolean |
isNinetyDegreeRotation(int rotation)
Method to detect if rotation represents a 90 degree rotation in Electric
|
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 boolean |
isSmallInt(int v)
Returns true if specified int value is considered "small int".
|
static boolean |
isSmallInt(long v)
Returns true if specified long value is considered "small int".
|
static boolean |
objectsReallyEqual(java.lang.Object first,
java.lang.Object second)
Method to compare two objects for equality.
|
static long |
packXY(int x,
int y)
Pack a pair of integer coordinates in a long value.
|
static long |
polarToXY(int len,
int angle)
Returns Cartesian coordinates of a vector specified in polar coordinates.
|
static int |
primeSince(int x)
Method to return a prime number greater or equal than a give threshold.
|
static double |
rint(double x) |
static int |
roundInt(double x) |
static long |
roundLong(double x)
Returns the closest
long to the argument. |
static double |
sin(int angle)
Method to compute the sine of an integer angle (in tenth-degrees).
|
static double |
sinSmall(int angle)
Method to compute the sine of a small integer angle (in tenth-degrees).
|
static double |
toNearest(double a,
double nearest)
Method to round a value to the nearest increment.
|
static java.lang.String |
transformArrayIntoString(double[] s)
Method to transform an array of doubles into a string that can be stored in a preference.
|
static double[] |
transformStringIntoArray(java.lang.String vector)
Method to extract an array of doubles from a string.
|
static long |
unsignedIntValue(int n)
Method to return a long that represents the unsigned
value of an integer.
|
public static final int MIN_SMALL_COORD
public static final int MAX_SMALL_COORD
public static final java.awt.geom.AffineTransform MATID
public static int getQuadrants(double centerX, double centerY, java.awt.geom.Rectangle2D box)
centerX
- the X center of the qTree.centerY
- the Y center of the qTree.box
- the given box.public static java.awt.geom.Rectangle2D getQTreeBox(double x, double y, double w, double h, double centerX, double centerY, int loc)
x
- Parent x valuey
- Parent y valuew
- Child width (1/4 of parent if qtree)h
- Child height (1/2 of parent if qtree)centerX
- Parent center x valuecenterY
- Parent center y valueloc
- Location in qtreepublic static java.lang.String transformArrayIntoString(double[] s)
s
- the values.public static double[] transformStringIntoArray(java.lang.String vector)
vector
- the input vector in string form.public static <T> void addToBag(java.util.Map<T,GenMath.MutableInteger> bag, T key)
bag
- Map implementing Bag.key
- object to add to bag.public static <T> void addToBag(java.util.Map<T,GenMath.MutableInteger> bag, java.util.Map<T,GenMath.MutableInteger> otherBag)
bag
- bag to update.otherBag
- bag used for update.public static <T> void addToBag(java.util.Map<T,GenMath.MutableInteger> bag, T key, int c)
bag
- Map implementing Bag.key
- object in a bag.c
- count to add to bag.public static <T> int countInBag(java.util.Map<T,GenMath.MutableInteger> bag, T key)
bag
- the collection (a Map).key
- a key to an entry in the collection.public static boolean objectsReallyEqual(java.lang.Object first, java.lang.Object second)
first
- the first object to compare.second
- the second object to compare.public static boolean isNinetyDegreeRotation(int rotation)
rotation
- the rotation amount.public static int figureAngle(java.awt.geom.Point2D end1, java.awt.geom.Point2D end2)
end1
- the first point.end2
- the second point.public static int figureAngle(double x, double y)
x
- x-coordinate of a vector.y
- y-coordinate of a vector.public static double figureAngleRadians(java.awt.geom.Point2D end1, java.awt.geom.Point2D end2)
end1
- the first point.end2
- the second point.public static double getArea(java.awt.geom.Rectangle2D rect)
rect
- the rectanglepublic static double getAreaOfPoints(java.awt.geom.Point2D[] points)
points
- the array of points.public static java.awt.geom.Point2D addPoints(java.awt.geom.Point2D p, double dx, double dy)
p
- the first point.dx
- the X component of the second pointdy
- the T component of the second pointpublic static boolean isOnLine(java.awt.geom.Point2D end1, java.awt.geom.Point2D end2, java.awt.geom.Point2D pt)
NOTE: If you are comparing Electric database units, DO NOT use this method. Use the corresponding method from DBMath.
end1
- the first end of the line segment.end2
- the second end of the line segment.pt
- the point in question.public static java.awt.geom.Point2D closestPointToSegment(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2, java.awt.geom.Point2D pt)
p1
- one end of the line segment.p2
- the other end of the line segment.pt
- the point near the line segment.public static java.awt.geom.Point2D closestPointToLine(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2, java.awt.geom.Point2D pt)
p1
- one end of the line.p2
- the other end of the line.pt
- the point near the line.public static java.awt.geom.Point2D[] arcconnects(int ang, java.awt.geom.Rectangle2D bounds1, java.awt.geom.Rectangle2D bounds2)
public static double distBetweenPoints(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)
p1
- the first point.p2
- the second point.public static double distToLine(java.awt.geom.Point2D l1, java.awt.geom.Point2D l2, java.awt.geom.Point2D pt)
public static java.awt.geom.Point2D computeArcCenter(java.awt.geom.Point2D c, java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)
public static java.awt.geom.Point2D[] findCenters(double r, java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)
r
- the radius of the circle.p1
- one point on the edge of the circle.p2
- the other point on the edge of the circle.public static java.awt.geom.Point2D intersect(java.awt.geom.Point2D p1, int ang1, java.awt.geom.Point2D p2, int ang2)
p1
- a point on the first line.ang1
- the angle of the first line (in tenth degrees).p2
- a point on the second line.ang2
- the angle of the second line (in tenth degrees).public static java.awt.geom.Point2D intersectRadians(java.awt.geom.Point2D p1, double ang1, java.awt.geom.Point2D p2, double ang2)
p1
- a point on the first line.ang1
- the angle of the first line (in radians).p2
- a point on the second line.ang2
- the angle of the second line (in radians).public static java.awt.geom.Rectangle2D arcBBox(java.awt.geom.Point2D s, java.awt.geom.Point2D e, java.awt.geom.Point2D c)
public static java.awt.geom.Point2D[] findCenters(double r, double x01, double y01, double x02, double y02, double d)
public static double toNearest(double a, double nearest)
a
- the value to round.nearest
- the increment to which it should be rounded.public static boolean doublesEqual(double a, double b)
a
- the first number.b
- the second number.public static boolean doublesEqual(double a, double b, double myEpsilon)
a
- the first number.b
- the second number.myEpsilon
- the given epsilonpublic static boolean doublesLessThan(double a, double b)
a
- the first number.b
- the second number.public static boolean doublesClose(double a, double b)
NOTE: If you are comparing Electric database units, DO NOT use this method. Use the corresponding method from DBMath.
a
- the first number.b
- the second number.public static boolean clipLine(java.awt.geom.Point2D from, java.awt.geom.Point2D to, double lX, double hX, double lY, double hY)
from
- one end of the line.to
- the other end of the line.lX
- the low X bound of the clip.hX
- the high X bound of the clip.lY
- the low Y bound of the clip.hY
- the high Y bound of the clip.
The points are modified to fit inside of the clip area.public static boolean clipLine(java.awt.Point from, java.awt.Point to, int lx, int hx, int ly, int hy)
from
- one end of the line.to
- the other end of the line.lx
- the low X bound of the clip.hx
- the high X bound of the clip.ly
- the low Y bound of the clip.hy
- the high Y bound of the clip.
The points are modified to fit inside of the clip area.public static java.awt.Point[] clipPoly(java.awt.Point[] points, int lx, int hx, int ly, int hy)
points
- an array of points that define the polygon.lx
- the low X bound of the clipping region.hx
- the high X bound of the clipping region.ly
- the low Y bound of the clipping region.hy
- the high Y bound of the clipping region.public static long roundLong(double x)
long
to the argument. The result
is rounded to an integer by adding 1/2, taking the floor of the
result, and casting the result to type long
. In other
words, the result is equal to the value of the expression:
(long)Math.floor(a + 0.5d)
Special cases:
Long.MIN_VALUE
, the result is
equal to the value of Long.MIN_VALUE
.
Long.MAX_VALUE
, the result is
equal to the value of Long.MAX_VALUE
.x
- a floating-point value to be rounded to a long
.long
value.Long.MAX_VALUE
,
Long.MIN_VALUE
public static double rint(double x)
public static int roundInt(double x)
public static long floorLong(double x)
public static long ceilLong(double x)
public static int floorInt(double x)
public static int ceilInt(double x)
public static double sin(int angle)
angle
- the angle in tenth-degrees.public static double cos(int angle)
angle
- the angle in tenth-degrees.public static double sinSmall(int angle)
angle
- the angle in tenth-degrees in range 0..900.public static double cosSmall(int angle)
angle
- the angle in tenth-degrees in range [0..900].public static long polarToXY(int len, int angle)
len
- positive vector lengthangle
- the angle in tenth-degrees in range [0..3600).getX(long)
,
getY(long)
public static long packXY(int x, int y)
getX
and getY
to unpack coordiantes.x
- x-coordinatey
- y-coordinategetX(long)
,
getY(long)
public static int getX(long xy)
packXY
.packXY(int, int)
public static int getY(long xy)
packXY
.packXY(int, int)
public static long unsignedIntValue(int n)
public static boolean isSmallInt(long v)
v
- specified long value.public static boolean isSmallInt(int v)
v
- specified int value.public static int primeSince(int x)
x
- threshold