Remove dependencies on FloatMath

See frameworks/base commit 33253a4baa6279f81a73425b49dfb6abe5f5416e
for details.

Bug: https://code.google.com/p/android/issues/detail?id=36199
Change-Id: I928b0bee35467acb2f06f774b8d0e49fc2336795
This commit is contained in:
Neil Fuller
2014-10-02 16:48:11 +01:00
parent 3a9f3a7806
commit ac04ec9f1a
8 changed files with 15 additions and 24 deletions
@@ -23,7 +23,6 @@ import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.os.Build;
import android.util.FloatMath;
import android.util.Log;
import java.io.ByteArrayOutputStream;
@@ -72,7 +71,7 @@ public class BitmapUtils {
&& minSideLength == UNCONSTRAINED) return 1;
int lowerBound = (maxNumOfPixels == UNCONSTRAINED) ? 1 :
(int) FloatMath.ceil(FloatMath.sqrt((float) (w * h) / maxNumOfPixels));
(int) Math.ceil(Math.sqrt((double) (w * h) / maxNumOfPixels));
if (minSideLength == UNCONSTRAINED) {
return lowerBound;
@@ -96,7 +95,7 @@ public class BitmapUtils {
// Find the min x that 1 / x >= scale
public static int computeSampleSizeLarger(float scale) {
int initialSize = (int) FloatMath.floor(1f / scale);
int initialSize = (int) Math.floor(1 / scale);
if (initialSize <= 1) return 1;
return initialSize <= 8
@@ -107,7 +106,7 @@ public class BitmapUtils {
// Find the max x that 1 / x <= scale.
public static int computeSampleSize(float scale) {
Utils.assertTrue(scale > 0);
int initialSize = Math.max(1, (int) FloatMath.ceil(1 / scale));
int initialSize = Math.max(1, (int) Math.ceil(1 / scale));
return initialSize <= 8
? Utils.nextPowerOf2(initialSize)
: (initialSize + 7) / 8 * 8;
@@ -21,7 +21,6 @@ import android.graphics.Matrix;
import android.graphics.Point;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.util.FloatMath;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.ScaleGestureDetector.OnScaleGestureListener;
@@ -300,12 +299,12 @@ public class CropView extends TiledImageView implements OnScaleGestureListener {
adjustment[0] = (edges.right - getWidth()) / scale;
}
if (edges.top > 0) {
adjustment[1] = FloatMath.ceil(edges.top / scale);
adjustment[1] = (float) Math.ceil(edges.top / scale);
} else if (edges.bottom < getHeight()) {
adjustment[1] = (edges.bottom - getHeight()) / scale;
}
for (int dim = 0; dim <= 1; dim++) {
if (coef[dim] > 0) adjustment[dim] = FloatMath.ceil(adjustment[dim]);
if (coef[dim] > 0) adjustment[dim] = (float) Math.ceil(adjustment[dim]);
}
mInverseRotateMatrix.mapPoints(adjustment);
+3 -6
View File
@@ -891,8 +891,7 @@ public class CellLayout extends ViewGroup {
public float getDistanceFromCell(float x, float y, int[] cell) {
cellToCenterPoint(cell[0], cell[1], mTmpPoint);
float distance = (float) Math.sqrt( Math.pow(x - mTmpPoint[0], 2) +
Math.pow(y - mTmpPoint[1], 2));
float distance = (float) Math.hypot(x - mTmpPoint[0], y - mTmpPoint[1]);
return distance;
}
@@ -1454,8 +1453,7 @@ public class CellLayout extends ViewGroup {
}
}
validRegions.push(currentRect);
double distance = Math.sqrt(Math.pow(cellXY[0] - pixelX, 2)
+ Math.pow(cellXY[1] - pixelY, 2));
double distance = Math.hypot(cellXY[0] - pixelX, cellXY[1] - pixelY);
if ((distance <= bestDistance && !contained) ||
currentRect.contains(bestRect)) {
@@ -1525,8 +1523,7 @@ public class CellLayout extends ViewGroup {
}
}
float distance = (float)
Math.sqrt((x - cellX) * (x - cellX) + (y - cellY) * (y - cellY));
float distance = (float) Math.hypot(x - cellX, y - cellY);
int[] curDirection = mTmpPoint;
computeDirectionVector(x - cellX, y - cellY, curDirection);
// The direction score is just the dot product of the two candidate direction
+1 -2
View File
@@ -385,8 +385,7 @@ public class DeviceProfile {
}
private float dist(PointF p0, PointF p1) {
return (float) Math.sqrt((p1.x - p0.x)*(p1.x-p0.x) +
(p1.y-p0.y)*(p1.y-p0.y));
return (float) Math.hypot(p1.x - p0.x, p1.y-p0.y);
}
private float weight(PointF a, PointF b,
@@ -488,8 +488,7 @@ public class DragController {
checkTouchMove(dropTarget);
// Check if we are hovering over the scroll areas
mDistanceSinceScroll +=
Math.sqrt(Math.pow(mLastTouch[0] - x, 2) + Math.pow(mLastTouch[1] - y, 2));
mDistanceSinceScroll += Math.hypot(mLastTouch[0] - x, mLastTouch[1] - y);
mLastTouch[0] = x;
mLastTouch[1] = y;
checkScrollState(x, y);
+1 -2
View File
@@ -612,8 +612,7 @@ public class DragLayer extends FrameLayout implements ViewGroup.OnHierarchyChang
final Runnable onCompleteRunnable, final int animationEndStyle, View anchorView) {
// Calculate the duration of the animation based on the object's distance
final float dist = (float) Math.sqrt(Math.pow(to.left - from.left, 2) +
Math.pow(to.top - from.top, 2));
final float dist = (float) Math.hypot(to.left - from.left, to.top - from.top);
final Resources res = getResources();
final float maxDist = (float) res.getInteger(R.integer.config_dropAnimMaxDist);
+2 -2
View File
@@ -637,8 +637,8 @@ public class FocusHelper {
boolean satisfiesRow = (lineDelta < 0) ? (tmpLp.cellY < row) : (tmpLp.cellY > row);
if (satisfiesRow &&
(newV instanceof BubbleTextView || newV instanceof FolderIcon)) {
float tmpDistance = (float) Math.sqrt(Math.pow(tmpLp.cellX - lp.cellX, 2) +
Math.pow(tmpLp.cellY - lp.cellY, 2));
float tmpDistance = (float) Math.hypot(
tmpLp.cellX - lp.cellX, tmpLp.cellY - lp.cellY);
if (tmpDistance < closestDistance) {
closestIndex = index;
closestDistance = tmpDistance;
@@ -20,7 +20,6 @@ import android.animation.TimeInterpolator;
import android.content.Context;
import android.hardware.SensorManager;
import android.os.Build;
import android.util.FloatMath;
import android.view.ViewConfiguration;
import android.view.animation.AnimationUtils;
import android.view.animation.Interpolator;
@@ -409,7 +408,7 @@ public class LauncherScroller {
float dx = (float) (mFinalX - mStartX);
float dy = (float) (mFinalY - mStartY);
float hyp = FloatMath.sqrt(dx * dx + dy * dy);
float hyp = (float) Math.hypot(dx, dy);
float ndx = dx / hyp;
float ndy = dy / hyp;
@@ -426,7 +425,7 @@ public class LauncherScroller {
mMode = FLING_MODE;
mFinished = false;
float velocity = FloatMath.sqrt(velocityX * velocityX + velocityY * velocityY);
float velocity = (float) Math.hypot(velocityX, velocityY);
mVelocity = velocity;
mDuration = getSplineFlingDuration(velocity);