Use FloatMath for our float math.
This commit is contained in:
@@ -19,9 +19,9 @@ public abstract class AbstractArc extends RectangularShape implements IArc
|
||||
|
||||
@Override // from interface IArc
|
||||
public Point getStartPoint (Point target) {
|
||||
float a = (float)Math.toRadians(getAngleStart());
|
||||
target.setLocation(getX() + (1f + (float)Math.cos(a)) * getWidth() / 2f,
|
||||
getY() + (1f - (float)Math.sin(a)) * getHeight() / 2f);
|
||||
float a = FloatMath.toRadians(getAngleStart());
|
||||
target.setLocation(getX() + (1f + FloatMath.cos(a)) * getWidth() / 2f,
|
||||
getY() + (1f - FloatMath.sin(a)) * getHeight() / 2f);
|
||||
return target;
|
||||
}
|
||||
|
||||
@@ -32,9 +32,9 @@ public abstract class AbstractArc extends RectangularShape implements IArc
|
||||
|
||||
@Override // from interface IArc
|
||||
public Point getEndPoint (Point target) {
|
||||
float a = (float)Math.toRadians(getAngleStart() + getAngleExtent());
|
||||
target.setLocation(getX() + (1f + (float)Math.cos(a)) * getWidth() / 2f,
|
||||
getY() + (1f - (float)Math.sin(a)) * getHeight() / 2f);
|
||||
float a = FloatMath.toRadians(getAngleStart() + getAngleExtent());
|
||||
target.setLocation(getX() + (1f + FloatMath.cos(a)) * getWidth() / 2f,
|
||||
getY() + (1f - FloatMath.sin(a)) * getHeight() / 2f);
|
||||
return target;
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ public abstract class AbstractArc extends RectangularShape implements IArc
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean containsAngle = containsAngle((float)Math.toDegrees(-Math.atan2(ny, nx)));
|
||||
boolean containsAngle = containsAngle(FloatMath.toDegrees(-FloatMath.atan2(ny, nx)));
|
||||
if (getArcType() == PIE) {
|
||||
return containsAngle;
|
||||
}
|
||||
@@ -195,7 +195,7 @@ public abstract class AbstractArc extends RectangularShape implements IArc
|
||||
|
||||
/** Returns a normalized angle (bound between 0 and 360 degrees). */
|
||||
protected float getNormAngle (float angle) {
|
||||
return angle - (float)Math.floor(angle / 360f) * 360f;
|
||||
return angle - FloatMath.floor(angle / 360f) * 360f;
|
||||
}
|
||||
|
||||
/** An iterator over an {@link IArc}. */
|
||||
@@ -264,7 +264,7 @@ public abstract class AbstractArc extends RectangularShape implements IArc
|
||||
this.height = a.getHeight() / 2f;
|
||||
this.x = a.getX() + width;
|
||||
this.y = a.getY() + height;
|
||||
this.angle = -(float)Math.toRadians(a.getAngleStart());
|
||||
this.angle = -FloatMath.toRadians(a.getAngleStart());
|
||||
this.extent = -a.getAngleExtent();
|
||||
this.type = a.getArcType();
|
||||
this.t = t;
|
||||
@@ -278,16 +278,16 @@ public abstract class AbstractArc extends RectangularShape implements IArc
|
||||
|
||||
if (Math.abs(extent) >= 360f) {
|
||||
arcCount = 4;
|
||||
k = 4f / 3f * ((float)Math.sqrt(2f) - 1f);
|
||||
step = (float)Math.PI / 2f;
|
||||
k = 4f / 3f * (FloatMath.sqrt(2f) - 1f);
|
||||
step = FloatMath.PI / 2f;
|
||||
if (extent < 0f) {
|
||||
step = -step;
|
||||
k = -k;
|
||||
}
|
||||
} else {
|
||||
arcCount = (int)Math.rint(Math.abs(extent) / 90f);
|
||||
step = (float)Math.toRadians(extent / arcCount);
|
||||
k = 4f / 3f * (1f - (float)Math.cos(step / 2f)) / (float)Math.sin(step / 2f);
|
||||
step = FloatMath.toRadians(extent / arcCount);
|
||||
k = 4f / 3f * (1f - FloatMath.cos(step / 2f)) / FloatMath.sin(step / 2f);
|
||||
}
|
||||
|
||||
lineCount = 0;
|
||||
@@ -319,8 +319,8 @@ public abstract class AbstractArc extends RectangularShape implements IArc
|
||||
if (index == 0) {
|
||||
type = SEG_MOVETO;
|
||||
count = 1;
|
||||
cos = (float)Math.cos(angle);
|
||||
sin = (float)Math.sin(angle);
|
||||
cos = FloatMath.cos(angle);
|
||||
sin = FloatMath.sin(angle);
|
||||
kx = k * width * sin;
|
||||
ky = k * height * cos;
|
||||
coords[0] = mx = x + cos * width;
|
||||
@@ -331,8 +331,8 @@ public abstract class AbstractArc extends RectangularShape implements IArc
|
||||
coords[0] = mx - kx;
|
||||
coords[1] = my + ky;
|
||||
angle += step;
|
||||
cos = (float)Math.cos(angle);
|
||||
sin = (float)Math.sin(angle);
|
||||
cos = FloatMath.cos(angle);
|
||||
sin = FloatMath.sin(angle);
|
||||
kx = k * width * sin;
|
||||
ky = k * height * cos;
|
||||
coords[4] = mx = x + cos * width;
|
||||
|
||||
@@ -117,7 +117,7 @@ public abstract class AbstractEllipse extends RectangularShape implements IEllip
|
||||
// the arc.
|
||||
|
||||
/** The coefficient to calculate control points of Bezier curves. */
|
||||
private static final float U = 2f / 3f * ((float)Math.sqrt(2) - 1f);
|
||||
private static final float U = 2f / 3f * (FloatMath.sqrt(2) - 1f);
|
||||
|
||||
/** The points coordinates calculation table. */
|
||||
private static final float[][] POINTS = {
|
||||
|
||||
@@ -141,7 +141,7 @@ public abstract class AbstractRoundRectangle extends RectangularShape implements
|
||||
};
|
||||
|
||||
/** The coefficient to calculate control points of Bezier curves. */
|
||||
protected static final float U = 0.5f - 2f / 3f * ((float)Math.sqrt(2f) - 1f);
|
||||
protected static final float U = 0.5f - 2f / 3f * (FloatMath.sqrt(2f) - 1f);
|
||||
|
||||
/** The points coordinates calculation table. */
|
||||
protected static final float[][] POINTS = {
|
||||
|
||||
@@ -313,8 +313,8 @@ public class AffineTransform implements Cloneable, Serializable
|
||||
* @param angle the angle of rotation (in radians).
|
||||
*/
|
||||
public void setToRotation (float angle) {
|
||||
float sin = (float)Math.sin(angle);
|
||||
float cos = (float)Math.cos(angle);
|
||||
float sin = FloatMath.sin(angle);
|
||||
float cos = FloatMath.cos(angle);
|
||||
if (Math.abs(cos) < ZERO) {
|
||||
cos = 0;
|
||||
sin = sin > 0 ? 1f : -1f;
|
||||
|
||||
@@ -174,16 +174,16 @@ public class Arc extends AbstractArc implements Serializable
|
||||
*/
|
||||
public void setArcByTangent (IPoint p1, IPoint p2, IPoint p3, float radius) {
|
||||
// use simple geometric calculations of arc center, radius and angles by tangents
|
||||
float a1 = -(float)Math.atan2(p1.getY() - p2.getY(), p1.getX() - p2.getX());
|
||||
float a2 = -(float)Math.atan2(p3.getY() - p2.getY(), p3.getX() - p2.getX());
|
||||
float a1 = -FloatMath.atan2(p1.getY() - p2.getY(), p1.getX() - p2.getX());
|
||||
float a2 = -FloatMath.atan2(p3.getY() - p2.getY(), p3.getX() - p2.getX());
|
||||
float am = (a1 + a2) / 2f;
|
||||
float ah = a1 - am;
|
||||
float d = radius / Math.abs((float)Math.sin(ah));
|
||||
float x = p2.getX() + d * (float)Math.cos(am);
|
||||
float y = p2.getY() - d * (float)Math.sin(am);
|
||||
ah = ah >= 0f ? (float)Math.PI * 1.5f - ah : (float)Math.PI * 0.5f - ah;
|
||||
a1 = getNormAngle((float)Math.toDegrees(am - ah));
|
||||
a2 = getNormAngle((float)Math.toDegrees(am + ah));
|
||||
float d = radius / Math.abs(FloatMath.sin(ah));
|
||||
float x = p2.getX() + d * FloatMath.cos(am);
|
||||
float y = p2.getY() - d * FloatMath.sin(am);
|
||||
ah = ah >= 0f ? FloatMath.PI * 1.5f - ah : FloatMath.PI * 0.5f - ah;
|
||||
a1 = getNormAngle(FloatMath.toDegrees(am - ah));
|
||||
a2 = getNormAngle(FloatMath.toDegrees(am + ah));
|
||||
float delta = a2 - a1;
|
||||
if (delta <= 0f) {
|
||||
delta += 360f;
|
||||
@@ -196,8 +196,8 @@ public class Arc extends AbstractArc implements Serializable
|
||||
* the center of this arc.
|
||||
*/
|
||||
public void setAngleStart (IPoint point) {
|
||||
float angle = (float)Math.atan2(point.getY() - getCenterY(), point.getX() - getCenterX());
|
||||
setAngleStart(getNormAngle(-(float)Math.toDegrees(angle)));
|
||||
float angle = FloatMath.atan2(point.getY() - getCenterY(), point.getX() - getCenterX());
|
||||
setAngleStart(getNormAngle(-FloatMath.toDegrees(angle)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -210,8 +210,8 @@ public class Arc extends AbstractArc implements Serializable
|
||||
public void setAngles (float x1, float y1, float x2, float y2) {
|
||||
float cx = getCenterX();
|
||||
float cy = getCenterY();
|
||||
float a1 = getNormAngle(-(float)Math.toDegrees(Math.atan2(y1 - cy, x1 - cx)));
|
||||
float a2 = getNormAngle(-(float)Math.toDegrees(Math.atan2(y2 - cy, x2 - cx)));
|
||||
float a1 = getNormAngle(-FloatMath.toDegrees(FloatMath.atan2(y1 - cy, x1 - cx)));
|
||||
float a2 = getNormAngle(-FloatMath.toDegrees(FloatMath.atan2(y2 - cy, x2 - cx)));
|
||||
a2 -= a1;
|
||||
if (a2 <= 0f) {
|
||||
a2 += 360f;
|
||||
|
||||
@@ -38,7 +38,7 @@ class Crossing
|
||||
if (d < 0f) {
|
||||
return 0;
|
||||
}
|
||||
d = (float)Math.sqrt(d);
|
||||
d = FloatMath.sqrt(d);
|
||||
res[rc++] = (-b + d) / (a * 2f);
|
||||
// d != 0f
|
||||
if (d != 0f) {
|
||||
@@ -72,15 +72,15 @@ class Crossing
|
||||
float n = -a / 3f;
|
||||
|
||||
if (R2 < Q3) {
|
||||
float t = (float)Math.acos(R / Math.sqrt(Q3)) / 3f;
|
||||
float p = 2f * (float)Math.PI / 3f;
|
||||
float m = -2f * (float)Math.sqrt(Q);
|
||||
res[rc++] = m * (float)Math.cos(t) + n;
|
||||
res[rc++] = m * (float)Math.cos(t + p) + n;
|
||||
res[rc++] = m * (float)Math.cos(t - p) + n;
|
||||
float t = FloatMath.acos(R / FloatMath.sqrt(Q3)) / 3f;
|
||||
float p = 2f * FloatMath.PI / 3f;
|
||||
float m = -2f * FloatMath.sqrt(Q);
|
||||
res[rc++] = m * FloatMath.cos(t) + n;
|
||||
res[rc++] = m * FloatMath.cos(t + p) + n;
|
||||
res[rc++] = m * FloatMath.cos(t - p) + n;
|
||||
} else {
|
||||
// Debug.println("R2 >= Q3 (" + R2 + "/" + Q3 + ")");
|
||||
float A = (float)Math.pow(Math.abs(R) + Math.sqrt(R2 - Q3), 1f / 3f);
|
||||
float A = FloatMath.pow(Math.abs(R) + FloatMath.sqrt(R2 - Q3), 1f / 3f);
|
||||
if (R > 0f) {
|
||||
A = -A;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public class CubicCurves
|
||||
|
||||
public static float getFlatness (float x1, float y1, float ctrlx1, float ctrly1,
|
||||
float ctrlx2, float ctrly2, float x2, float y2) {
|
||||
return (float)Math.sqrt(getFlatnessSq(x1, y1, ctrlx1, ctrly1, ctrlx2, ctrly2, x2, y2));
|
||||
return FloatMath.sqrt(getFlatnessSq(x1, y1, ctrlx1, ctrly1, ctrlx2, ctrly2, x2, y2));
|
||||
}
|
||||
|
||||
public static float getFlatness (float[] coords, int offset) {
|
||||
|
||||
@@ -9,7 +9,7 @@ package pythagoras.f;
|
||||
*/
|
||||
public class GeometryUtil
|
||||
{
|
||||
public static final float EPSILON = (float)Math.pow(10, -14);
|
||||
public static final float EPSILON = FloatMath.pow(10, -14);
|
||||
|
||||
public static int intersectLinesWithParams (float x1, float y1, float x2, float y2,
|
||||
float x3, float y3, float x4, float y4,
|
||||
|
||||
@@ -81,7 +81,7 @@ public class Lines
|
||||
* Returns the distance from the specified point to the specified line.
|
||||
*/
|
||||
public static float pointLineDist (float px, float py, float x1, float y1, float x2, float y2) {
|
||||
return (float)Math.sqrt(pointLineDistSq(px, py, x1, y1, x2, y2));
|
||||
return FloatMath.sqrt(pointLineDistSq(px, py, x1, y1, x2, y2));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,7 +119,7 @@ public class Lines
|
||||
* Returns the distance between the specified point and the specified line segment.
|
||||
*/
|
||||
public static float pointSegDist (float px, float py, float x1, float y1, float x2, float y2) {
|
||||
return (float)Math.sqrt(pointSegDistSq(px, py, x1, y1, x2, y2));
|
||||
return FloatMath.sqrt(pointSegDistSq(px, py, x1, y1, x2, y2));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user