public class GenMath
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static FixpTransform |
MATID
A transformation matrix that does nothing (identity).
|
static int |
MAX_SMALL_COORD
Maximal integer 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 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 AbstractFixpPoint |
closestPointToLine(AbstractFixpPoint p1,
AbstractFixpPoint p2,
AbstractFixpPoint pt)
Method to find the point on a line that is closest to a given point.
|
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 AbstractFixpPoint |
closestPointToSegment(AbstractFixpPoint p1,
AbstractFixpPoint p2,
AbstractFixpPoint pt)
Method to find the point on a line segment 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 boolean |
containedInRectangle(AbstractFixpRectangle bb,
AbstractFixpPoint pi)
Method to determine if a point is inside a rectangle.
|
static boolean |
containedInRectangle(java.awt.geom.Rectangle2D bb,
java.awt.geom.Point2D pi)
Method to determine if a point is inside a rectangle.
|
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 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 FixpRectangle |
getQTreeBox(AbstractFixpRectangle box,
int loc)
Calculates the bounding box of a child depending on the location.
|
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 |
isMultiple(long x,
long divisor)
Returns true if the first argument is the multiple of divisor.
|
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 double |
meanEqualDistribution(double[] values)
Calculate the mean of a given, equal distributed array of doubles.
|
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 long |
roundToMultiple(long x,
long divisor) |
static long |
roundToMultiple(long x,
long divisor,
java.math.RoundingMode roundingMode)
Rounds long number to multiple of
divisor in specified rounding direction. |
static long |
roundToMultiple0(long x,
long divisor) |
static long |
roundToMultipleCeiling(long x,
long divisor) |
static long |
roundToMultipleFloor(long x,
long divisor) |
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 |
standardDeviation(double[] values)
Calculate the standard deviation of a given, equal distributed array of doubles.
|
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.
|
static double |
varianceEqualDistribution(double[] values)
Calculate the variance of a given, equal distributed array of doubles.
|
static double |
varianceEqualDistribution(double[] values,
double mean)
Calculate the variance of a given, equal distributed array of doubles.
|
public static final int MIN_SMALL_COORD
public static final int MAX_SMALL_COORD
public static final FixpTransform 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 FixpRectangle getQTreeBox(AbstractFixpRectangle box, int loc)
box
- the large boxloc
- 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 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 AbstractFixpPoint closestPointToSegment(AbstractFixpPoint p1, AbstractFixpPoint p2, AbstractFixpPoint 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 boolean containedInRectangle(AbstractFixpRectangle bb, AbstractFixpPoint pi)
bb
- the rectangle defined as AbstractFixpRectanglepi
- the point in test defined as AbstractFixpPointpublic static boolean containedInRectangle(java.awt.geom.Rectangle2D bb, java.awt.geom.Point2D pi)
bb
- the rectangle defined as Rectangle2Dpi
- the point in test defined as Point2Dpublic 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 AbstractFixpPoint closestPointToLine(AbstractFixpPoint p1, AbstractFixpPoint p2, AbstractFixpPoint 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 boolean isMultiple(long x, long divisor)
x
- the first argumentdivisor
- the divisorx
is the multiple of divisor
public static long roundToMultiple(long x, long divisor, java.math.RoundingMode roundingMode)
divisor
in specified rounding direction.
This method accepts any arguments but it may be slower that specialized roundToMultiple methods.x
- long number to rounddivisor
- divisorroundingMode
- rounding directionjava.lang.ArithmeticException
- if rounded result doesn't fit in longjava.lang.ArithmeticException
- if roundingMode is UNNECESSARY
and x
is not multiple of divisor
public static long roundToMultipleFloor(long x, long divisor)
public static long roundToMultipleCeiling(long x, long divisor)
public static long roundToMultiple(long x, long divisor)
public static long roundToMultiple0(long x, long divisor)
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
- thresholdpublic static double varianceEqualDistribution(double[] values, double mean)
values
- mean
- public static double varianceEqualDistribution(double[] values)
values
- public static double meanEqualDistribution(double[] values)
values
- public static double standardDeviation(double[] values)
values
-