am 0c1faf43: Merge "Switch from FloatMath -> Math and Math.hypot where possible"

* commit '0c1faf43aecadc37b78c4ad6cb669eb351d21385':
  Switch from FloatMath -> Math and Math.hypot where possible
This commit is contained in:
Neil Fuller
2014-10-02 10:18:29 +00:00
committed by Android Git Automerger
36 changed files with 77 additions and 251 deletions

View File

@ -635,7 +635,7 @@ public class GestureOverlayView extends FrameLayout {
mStrokeBuffer.add(new GesturePoint(x, y, event.getEventTime()));
if (mHandleGestureActions && !mIsGesturing) {
mTotalLength += (float) Math.sqrt(dx * dx + dy * dy);
mTotalLength += (float) Math.hypot(dx, dy);
if (mTotalLength > mGestureStrokeLengthThreshold) {
final OrientedBoundingBox box =

View File

@ -69,8 +69,7 @@ public class GestureStroke {
bx.bottom = p.y;
len = 0;
} else {
len += Math.sqrt(Math.pow(p.x - tmpPoints[(i - 1) * 2], 2)
+ Math.pow(p.y - tmpPoints[(i -1 ) * 2 + 1], 2));
len += Math.hypot(p.x - tmpPoints[(i - 1) * 2], p.y - tmpPoints[(i -1 ) * 2 + 1]);
bx.union(p.x, p.y);
}
index++;

View File

@ -293,7 +293,7 @@ public final class GestureUtils {
}
float deltaX = currentPointX - lstPointX;
float deltaY = currentPointY - lstPointY;
float distance = (float) Math.sqrt(deltaX * deltaX + deltaY * deltaY);
float distance = (float) Math.hypot(deltaX, deltaY);
if (distanceSoFar + distance >= increment) {
float ratio = (increment - distanceSoFar) / distance;
float nx = lstPointX + ratio * deltaX;
@ -379,7 +379,7 @@ public final class GestureUtils {
for (int i = 0; i < count; i += 2) {
float dx = points[i + 2] - points[i];
float dy = points[i + 3] - points[i + 1];
sum += Math.sqrt(dx * dx + dy * dy);
sum += Math.hypot(dx, dy);
}
return sum;
}
@ -388,13 +388,13 @@ public final class GestureUtils {
float totalLen = computeTotalLength(points);
float dx = points[2] - points[0];
float dy = points[3] - points[1];
return (float) Math.sqrt(dx * dx + dy * dy) / totalLen;
return (float) Math.hypot(dx, dy) / totalLen;
}
static float computeStraightness(float[] points, float totalLen) {
float dx = points[2] - points[0];
float dy = points[3] - points[1];
return (float) Math.sqrt(dx * dx + dy * dy) / totalLen;
return (float) Math.hypot(dx, dy) / totalLen;
}
/**

View File

@ -281,7 +281,7 @@ public class GeomagneticField {
* @return Horizontal component of the field strength in nonoteslas.
*/
public float getHorizontalStrength() {
return (float) Math.sqrt(mX * mX + mY * mY);
return (float) Math.hypot(mX, mY);
}
/**

View File

@ -20,7 +20,6 @@ import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.text.style.ParagraphStyle;
import android.util.FloatMath;
/**
* A BoringLayout is a very simple Layout implementation for text that
@ -211,7 +210,7 @@ public class BoringLayout extends Layout implements TextUtils.EllipsizeCallback
TextLine line = TextLine.obtain();
line.set(paint, source, 0, source.length(), Layout.DIR_LEFT_TO_RIGHT,
Layout.DIRS_ALL_LEFT_TO_RIGHT, false, null);
mMax = (int) FloatMath.ceil(line.metrics(null));
mMax = (int) Math.ceil(line.metrics(null));
TextLine.recycle(line);
}
@ -305,7 +304,7 @@ public class BoringLayout extends Layout implements TextUtils.EllipsizeCallback
TextLine line = TextLine.obtain();
line.set(paint, text, 0, length, Layout.DIR_LEFT_TO_RIGHT,
Layout.DIRS_ALL_LEFT_TO_RIGHT, false, null);
fm.width = (int) FloatMath.ceil(line.metrics(fm));
fm.width = (int) Math.ceil(line.metrics(fm));
TextLine.recycle(line);
return fm;

View File

@ -94,7 +94,7 @@ public final class MathUtils {
public static float dist(float x1, float y1, float x2, float y2) {
final float x = (x2 - x1);
final float y = (y2 - y1);
return (float) Math.sqrt(x * x + y * y);
return (float) Math.hypot(x, y);
}
public static float dist(float x1, float y1, float z1, float x2, float y2, float z2) {
@ -105,7 +105,7 @@ public final class MathUtils {
}
public static float mag(float a, float b) {
return (float) Math.sqrt(a * a + b * b);
return (float) Math.hypot(a, b);
}
public static float mag(float a, float b, float c) {

View File

@ -88,7 +88,7 @@ public final class Spline {
throw new IllegalArgumentException("The control points must have "
+ "monotonic Y values.");
}
float h = FloatMath.hypot(a, b);
float h = (float) Math.hypot(a, b);
if (h > 9f) {
float t = 3f / h;
m[i] = t * a * d[i];

View File

@ -21,7 +21,6 @@ import android.content.res.Resources;
import android.os.Build;
import android.os.Handler;
import android.os.SystemClock;
import android.util.FloatMath;
/**
* Detects scaling transformation gestures using the supplied {@link MotionEvent}s.
@ -394,7 +393,7 @@ public class ScaleGestureDetector {
if (inDoubleTapMode()) {
span = spanY;
} else {
span = FloatMath.sqrt(spanX * spanX + spanY * spanY);
span = (float) Math.hypot(spanX, spanY);
}
// Dispatch begin/end events as needed.

View File

@ -18,7 +18,6 @@ package android.widget;
import android.content.Context;
import android.hardware.SensorManager;
import android.util.FloatMath;
import android.util.Log;
import android.view.ViewConfiguration;
import android.view.animation.AnimationUtils;
@ -173,9 +172,7 @@ public class OverScroller {
* @return The original velocity less the deceleration, norm of the X and Y velocity vector.
*/
public float getCurrVelocity() {
float squaredNorm = mScrollerX.mCurrVelocity * mScrollerX.mCurrVelocity;
squaredNorm += mScrollerY.mCurrVelocity * mScrollerY.mCurrVelocity;
return FloatMath.sqrt(squaredNorm);
return (float) Math.hypot(mScrollerX.mCurrVelocity, mScrollerY.mCurrVelocity);
}
/**

View File

@ -19,7 +19,6 @@ package android.widget;
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;
@ -436,7 +435,7 @@ public class Scroller {
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;
@ -453,7 +452,7 @@ public class Scroller {
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);

View File

@ -1043,10 +1043,8 @@ public class StackView extends AdapterViewAnimator {
if (mView != null) {
final LayoutParams viewLp = (LayoutParams) mView.getLayoutParams();
float d = (float) Math.sqrt(Math.pow(viewLp.horizontalOffset, 2) +
Math.pow(viewLp.verticalOffset, 2));
float maxd = (float) Math.sqrt(Math.pow(mSlideAmount, 2) +
Math.pow(0.4f * mSlideAmount, 2));
float d = (float) Math.hypot(viewLp.horizontalOffset, viewLp.verticalOffset);
float maxd = (float) Math.hypot(mSlideAmount, 0.4f * mSlideAmount);
if (velocity == 0) {
return (invert ? (1 - d / maxd) : d / maxd) * DEFAULT_ANIMATION_DURATION;

View File

@ -92,7 +92,6 @@ import android.text.style.URLSpan;
import android.text.style.UpdateAppearance;
import android.text.util.Linkify;
import android.util.AttributeSet;
import android.util.FloatMath;
import android.util.Log;
import android.util.TypedValue;
import android.view.AccessibilityIterators.TextSegmentIterator;
@ -4556,7 +4555,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
* make sure the entire cursor gets invalidated instead of
* sometimes missing half a pixel.
*/
float thick = FloatMath.ceil(mTextPaint.getStrokeWidth());
float thick = (float) Math.ceil(mTextPaint.getStrokeWidth());
if (thick < 1.0f) {
thick = 1.0f;
}
@ -4566,10 +4565,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
// mHighlightPath is guaranteed to be non null at that point.
mHighlightPath.computeBounds(TEMP_RECTF, false);
invalidate((int) FloatMath.floor(horizontalPadding + TEMP_RECTF.left - thick),
(int) FloatMath.floor(verticalPadding + TEMP_RECTF.top - thick),
(int) FloatMath.ceil(horizontalPadding + TEMP_RECTF.right + thick),
(int) FloatMath.ceil(verticalPadding + TEMP_RECTF.bottom + thick));
invalidate((int) Math.floor(horizontalPadding + TEMP_RECTF.left - thick),
(int) Math.floor(verticalPadding + TEMP_RECTF.top - thick),
(int) Math.ceil(horizontalPadding + TEMP_RECTF.right + thick),
(int) Math.ceil(verticalPadding + TEMP_RECTF.bottom + thick));
}
} else {
for (int i = 0; i < mEditor.mCursorCount; i++) {
@ -6236,7 +6235,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
max = Math.max(max, layout.getLineWidth(i));
}
return (int) FloatMath.ceil(max);
return (int) Math.ceil(max);
}
/**
@ -6313,7 +6312,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
if (boring == null || boring == UNKNOWN_BORING) {
if (des < 0) {
des = (int) FloatMath.ceil(Layout.getDesiredWidth(mTransformed, mTextPaint));
des = (int) Math.ceil(Layout.getDesiredWidth(mTransformed, mTextPaint));
}
width = des;
} else {
@ -6343,7 +6342,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
if (hintBoring == null || hintBoring == UNKNOWN_BORING) {
if (hintDes < 0) {
hintDes = (int) FloatMath.ceil(Layout.getDesiredWidth(mHint, mTextPaint));
hintDes = (int) Math.ceil(Layout.getDesiredWidth(mHint, mTextPaint));
}
hintWidth = hintDes;
} else {
@ -6649,8 +6648,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
* keep leading edge in view.
*/
int left = (int) FloatMath.floor(layout.getLineLeft(line));
int right = (int) FloatMath.ceil(layout.getLineRight(line));
int left = (int) Math.floor(layout.getLineLeft(line));
int right = (int) Math.ceil(layout.getLineRight(line));
if (right - left < hspace) {
scrollx = (right + left) / 2 - hspace / 2;
@ -6662,10 +6661,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
}
} else if (a == Layout.Alignment.ALIGN_RIGHT) {
int right = (int) FloatMath.ceil(layout.getLineRight(line));
int right = (int) Math.ceil(layout.getLineRight(line));
scrollx = right - hspace;
} else { // a == Layout.Alignment.ALIGN_LEFT (will also be the default)
scrollx = (int) FloatMath.floor(layout.getLineLeft(line));
scrollx = (int) Math.floor(layout.getLineLeft(line));
}
if (ht < vspace) {
@ -6740,8 +6739,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
final int top = layout.getLineTop(line);
final int bottom = layout.getLineTop(line + 1);
int left = (int) FloatMath.floor(layout.getLineLeft(line));
int right = (int) FloatMath.ceil(layout.getLineRight(line));
int left = (int) Math.floor(layout.getLineLeft(line));
int right = (int) Math.ceil(layout.getLineRight(line));
int ht = layout.getHeight();
int hspace = mRight - mLeft - getCompoundPaddingLeft() - getCompoundPaddingRight();

View File

@ -857,7 +857,7 @@ public class GlowPadView extends View {
// tx and ty are relative to wave center
float tx = eventX - mWaveCenterX;
float ty = eventY - mWaveCenterY;
float touchRadius = (float) Math.sqrt(dist2(tx, ty));
float touchRadius = (float) Math.hypot(tx, ty);
final float scale = touchRadius > mOuterRadius ? mOuterRadius / touchRadius : 1.0f;
float limitX = tx * scale;
float limitY = ty * scale;

View File

@ -832,7 +832,7 @@ public class MultiWaveView extends View {
// tx and ty are relative to wave center
float tx = eventX - mWaveCenterX;
float ty = eventY - mWaveCenterY;
float touchRadius = (float) Math.sqrt(dist2(tx, ty));
float touchRadius = (float) Math.hypot(tx, ty);
final float scale = touchRadius > mOuterRadius ? mOuterRadius / touchRadius : 1.0f;
float limitX = tx * scale;
float limitY = ty * scale;

View File

@ -22,7 +22,6 @@ import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.util.FloatMath;
import android.util.Log;
public class PointCloud {
@ -151,8 +150,8 @@ public class PointCloud {
float eta = PI/2.0f;
float dEta = 2.0f * PI / pointsInBand;
for (int i = 0; i < pointsInBand; i++) {
float x = r * FloatMath.cos(eta);
float y = r * FloatMath.sin(eta);
float x = r * (float) Math.cos(eta);
float y = r * (float) Math.sin(eta);
eta += dEta;
mPointCloud.add(new Point(x, y, r));
}
@ -167,32 +166,24 @@ public class PointCloud {
return mScale;
}
private static float hypot(float x, float y) {
return FloatMath.sqrt(x*x + y*y);
}
private static float max(float a, float b) {
return a > b ? a : b;
}
public int getAlphaForPoint(Point point) {
// Contribution from positional glow
float glowDistance = hypot(glowManager.x - point.x, glowManager.y - point.y);
float glowDistance = (float) Math.hypot(glowManager.x - point.x, glowManager.y - point.y);
float glowAlpha = 0.0f;
if (glowDistance < glowManager.radius) {
float cosf = FloatMath.cos(PI * 0.25f * glowDistance / glowManager.radius);
glowAlpha = glowManager.alpha * max(0.0f, (float) Math.pow(cosf, 10.0f));
float cosf = (float) Math.cos(PI * 0.25f * glowDistance / glowManager.radius);
glowAlpha = glowManager.alpha * Math.max(0.0f, (float) Math.pow(cosf, 10.0f));
}
// Compute contribution from Wave
float radius = hypot(point.x, point.y);
float radius = (float) Math.hypot(point.x, point.y);
float waveAlpha = 0.0f;
if (radius < waveManager.radius * 2) {
float distanceToWaveRing = (radius - waveManager.radius);
float cosf = FloatMath.cos(PI * 0.5f * distanceToWaveRing / waveManager.radius);
waveAlpha = waveManager.alpha * max(0.0f, (float) Math.pow(cosf, 6.0f));
float cosf = (float) Math.cos(PI * 0.5f * distanceToWaveRing / waveManager.radius);
waveAlpha = waveManager.alpha * Math.max(0.0f, (float) Math.pow(cosf, 6.0f));
}
return (int) (max(glowAlpha, waveAlpha) * 255);
return (int) (Math.max(glowAlpha, waveAlpha) * 255);
}
private float interp(float min, float max, float f) {

View File

@ -16,8 +16,6 @@
package android.graphics;
import android.util.FloatMath;
/**
* 4x5 matrix for transforming the color+alpha components of a Bitmap.
* The matrix is stored in a single array, and its treated as follows:
@ -118,9 +116,9 @@ public class ColorMatrix {
*/
public void setRotate(int axis, float degrees) {
reset();
float radians = degrees * (float)Math.PI / 180;
float cosine = FloatMath.cos(radians);
float sine = FloatMath.sin(radians);
double radians = degrees * Math.PI / 180d;
float cosine = (float) Math.cos(radians);
float sine = (float) Math.sin(radians);
switch (axis) {
// Rotation around the red color
case 0:

View File

@ -18,7 +18,6 @@ package android.graphics;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.FloatMath;
/**
@ -109,7 +108,7 @@ public class PointF implements Parcelable {
* Returns the euclidian distance from (0,0) to (x,y)
*/
public static float length(float x, float y) {
return FloatMath.sqrt(x * x + y * y);
return (float) Math.hypot(x, y);
}
/**

View File

@ -20,7 +20,6 @@ import java.io.PrintWriter;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.FloatMath;
import com.android.internal.util.FastMath;
/**
@ -450,8 +449,8 @@ public class RectF implements Parcelable {
* floor of top and left, and the ceiling of right and bottom.
*/
public void roundOut(Rect dst) {
dst.set((int) FloatMath.floor(left), (int) FloatMath.floor(top),
(int) FloatMath.ceil(right), (int) FloatMath.ceil(bottom));
dst.set((int) Math.floor(left), (int) Math.floor(top),
(int) Math.ceil(right), (int) Math.ceil(bottom));
}
/**

View File

@ -70,7 +70,7 @@ public class Point {
}
public float length() {
return (float)Math.sqrt(x*x + y*y);
return (float)Math.hypot(x, y);
}
public float distanceTo(Point p) {

View File

@ -37,7 +37,6 @@ import android.os.Handler;
import android.os.Looper;
import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.LargeTest;
import android.util.FloatMath;
import android.util.Log;
import android.view.SurfaceHolder;
import com.android.mediaframeworktest.CameraStressTestRunner;

View File

@ -24,7 +24,6 @@ import android.os.Handler;
import android.os.Looper;
import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.LargeTest;
import android.util.FloatMath;
import android.util.Log;
import android.view.SurfaceHolder;

View File

@ -23,7 +23,6 @@ import android.database.DataSetObserver;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.FloatMath;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
@ -351,7 +350,7 @@ public class RecentsHorizontalScrollView extends HorizontalScrollView
View child = mAdapter.createView(mLinearLayout);
child.measure(childWidthMeasureSpec, childheightMeasureSpec);
mNumItemsInOneScreenful =
(int) FloatMath.ceil(dm.widthPixels / (float) child.getMeasuredWidth());
(int) Math.ceil(dm.widthPixels / (double) child.getMeasuredWidth());
addToRecycledViews(child);
for (int i = 0; i < mNumItemsInOneScreenful - 1; i++) {

View File

@ -23,7 +23,6 @@ import android.database.DataSetObserver;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.FloatMath;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
@ -361,7 +360,7 @@ public class RecentsVerticalScrollView extends ScrollView
View child = mAdapter.createView(mLinearLayout);
child.measure(childWidthMeasureSpec, childheightMeasureSpec);
mNumItemsInOneScreenful =
(int) FloatMath.ceil(dm.heightPixels / (float) child.getMeasuredHeight());
(int) Math.ceil(dm.heightPixels / (double) child.getMeasuredHeight());
addToRecycledViews(child);
for (int i = 0; i < mNumItemsInOneScreenful - 1; i++) {

View File

@ -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);

View File

@ -23,7 +23,6 @@ import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Handler;
import android.os.SystemProperties;
import android.util.FloatMath;
import android.util.Log;
import android.util.Slog;
@ -401,7 +400,7 @@ public abstract class WindowOrientationListener {
if (LOG) {
Slog.v(TAG, "Raw acceleration vector: "
+ "x=" + x + ", y=" + y + ", z=" + z
+ ", magnitude=" + FloatMath.sqrt(x * x + y * y + z * z));
+ ", magnitude=" + Math.sqrt(x * x + y * y + z * z));
}
// Apply a low-pass filter to the acceleration up vector in cartesian space.
@ -428,7 +427,7 @@ public abstract class WindowOrientationListener {
if (LOG) {
Slog.v(TAG, "Filtered acceleration vector: "
+ "x=" + x + ", y=" + y + ", z=" + z
+ ", magnitude=" + FloatMath.sqrt(x * x + y * y + z * z));
+ ", magnitude=" + Math.sqrt(x * x + y * y + z * z));
}
skipSample = false;
}
@ -442,7 +441,7 @@ public abstract class WindowOrientationListener {
boolean isSwinging = false;
if (!skipSample) {
// Calculate the magnitude of the acceleration vector.
final float magnitude = FloatMath.sqrt(x * x + y * y + z * z);
final float magnitude = (float) Math.sqrt(x * x + y * y + z * z);
if (magnitude < NEAR_ZERO_MAGNITUDE) {
if (LOG) {
Slog.v(TAG, "Ignoring sensor data, magnitude too close to zero.");

View File

@ -17,7 +17,6 @@
package com.android.server;
import android.text.format.DateUtils;
import android.util.FloatMath;
/** @hide */
public class TwilightCalculator {
@ -75,24 +74,24 @@ public class TwilightCalculator {
final float meanAnomaly = 6.240059968f + daysSince2000 * 0.01720197f;
// true anomaly
final float trueAnomaly = meanAnomaly + C1 * FloatMath.sin(meanAnomaly) + C2
* FloatMath.sin(2 * meanAnomaly) + C3 * FloatMath.sin(3 * meanAnomaly);
final double trueAnomaly = meanAnomaly + C1 * Math.sin(meanAnomaly) + C2
* Math.sin(2 * meanAnomaly) + C3 * Math.sin(3 * meanAnomaly);
// ecliptic longitude
final float solarLng = trueAnomaly + 1.796593063f + (float) Math.PI;
final double solarLng = trueAnomaly + 1.796593063d + Math.PI;
// solar transit in days since 2000
final double arcLongitude = -longitude / 360;
float n = Math.round(daysSince2000 - J0 - arcLongitude);
double solarTransitJ2000 = n + J0 + arcLongitude + 0.0053f * FloatMath.sin(meanAnomaly)
+ -0.0069f * FloatMath.sin(2 * solarLng);
double solarTransitJ2000 = n + J0 + arcLongitude + 0.0053d * Math.sin(meanAnomaly)
+ -0.0069d * Math.sin(2 * solarLng);
// declination of sun
double solarDec = Math.asin(FloatMath.sin(solarLng) * FloatMath.sin(OBLIQUITY));
double solarDec = Math.asin(Math.sin(solarLng) * Math.sin(OBLIQUITY));
final double latRad = latiude * DEGREES_TO_RADIANS;
double cosHourAngle = (FloatMath.sin(ALTIDUTE_CORRECTION_CIVIL_TWILIGHT) - Math.sin(latRad)
double cosHourAngle = (Math.sin(ALTIDUTE_CORRECTION_CIVIL_TWILIGHT) - Math.sin(latRad)
* Math.sin(solarDec)) / (Math.cos(latRad) * Math.cos(solarDec));
// The day or night never ends for the given date and location, if this value is out of
// range.

View File

@ -69,8 +69,7 @@ final class GestureUtils {
return true;
}
final float firstMagnitude =
(float) Math.sqrt(firstDeltaX * firstDeltaX + firstDeltaY * firstDeltaY);
final float firstMagnitude = (float) Math.hypot(firstDeltaX, firstDeltaY);
final float firstXNormalized =
(firstMagnitude > 0) ? firstDeltaX / firstMagnitude : firstDeltaX;
final float firstYNormalized =
@ -83,8 +82,7 @@ final class GestureUtils {
return true;
}
final float secondMagnitude =
(float) Math.sqrt(secondDeltaX * secondDeltaX + secondDeltaY * secondDeltaY);
final float secondMagnitude = (float) Math.hypot(secondDeltaX, secondDeltaY);
final float secondXNormalized =
(secondMagnitude > 0) ? secondDeltaX / secondMagnitude : secondDeltaX;
final float secondYNormalized =

View File

@ -35,7 +35,6 @@ import android.os.Message;
import android.os.PowerManager;
import android.os.SystemClock;
import android.text.format.DateUtils;
import android.util.FloatMath;
import android.util.Slog;
import android.util.Spline;
import android.util.TimeUtils;
@ -1092,7 +1091,7 @@ final class DisplayPowerController {
if (USE_SCREEN_AUTO_BRIGHTNESS_ADJUSTMENT
&& mPowerRequest.screenAutoBrightnessAdjustment != 0.0f) {
final float adjGamma = FloatMath.pow(SCREEN_AUTO_BRIGHTNESS_ADJUSTMENT_MAX_GAMMA,
final float adjGamma = (float) Math.pow(SCREEN_AUTO_BRIGHTNESS_ADJUSTMENT_MAX_GAMMA,
Math.min(1.0f, Math.max(-1.0f,
-mPowerRequest.screenAutoBrightnessAdjustment)));
gamma *= adjGamma;
@ -1119,7 +1118,7 @@ final class DisplayPowerController {
if (gamma != 1.0f) {
final float in = value;
value = FloatMath.pow(value, gamma);
value = (float) Math.pow(value, gamma);
if (DEBUG) {
Slog.d(TAG, "updateAutoBrightness: gamma=" + gamma
+ ", in=" + in + ", out=" + value);

View File

@ -31,7 +31,6 @@ import android.opengl.EGLSurface;
import android.opengl.GLES10;
import android.opengl.GLES11Ext;
import android.os.Looper;
import android.util.FloatMath;
import android.util.Slog;
import android.view.Display;
import android.view.DisplayInfo;
@ -636,7 +635,7 @@ final class ElectronBeam {
}
private static float sigmoid(float x, float s) {
return 1.0f / (1.0f + FloatMath.exp(-x * s));
return 1.0f / (1.0f + (float) Math.exp(-x * s));
}
private static FloatBuffer createNativeFloatBuffer(int size) {

View File

@ -91,7 +91,6 @@ import android.os.WorkSource;
import android.provider.Settings;
import android.util.DisplayMetrics;
import android.util.EventLog;
import android.util.FloatMath;
import android.util.Log;
import android.util.SparseArray;
import android.util.Pair;
@ -5724,7 +5723,7 @@ public class WindowManagerService extends IWindowManager.Stub
Matrix matrix = new Matrix();
ScreenRotationAnimation.createRotationMatrix(rot, dw, dh, matrix);
// TODO: Test for RTL vs. LTR and use frame.right-width instead of -frame.left
matrix.postTranslate(-FloatMath.ceil(frame.left), -FloatMath.ceil(frame.top));
matrix.postTranslate((float) -Math.ceil(frame.left), (float) -Math.ceil(frame.top));
Canvas canvas = new Canvas(bm);
canvas.drawColor(0xFF000000);
canvas.drawBitmap(rawss, matrix, null);

View File

@ -576,7 +576,7 @@ public class TouchUtils {
final int fromX = xy[0];
final int fromY = xy[1];
int distance = (int) Math.sqrt(deltaX * deltaX + deltaY * deltaY);
int distance = (int) Math.hypot(deltaX, deltaY);
drag(test, fromX, fromX + deltaX, fromY, fromY + deltaY, distance);
@ -629,7 +629,7 @@ public class TouchUtils {
int deltaX = fromX - toX;
int deltaY = fromY - toY;
int distance = (int)Math.sqrt(deltaX * deltaX + deltaY * deltaY);
int distance = (int)Math.hypot(deltaX, deltaY);
drag(test, fromX, toX, fromY, toY, distance);
return distance;

View File

@ -20,7 +20,6 @@ import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.util.FloatMath;
import androidx.media.filterfw.Filter;
import androidx.media.filterfw.FrameImage2D;
@ -90,8 +89,8 @@ public class CropFilter extends Filter {
// Pull input frame
FrameImage2D inputImage = getConnectedInputPort("image").pullFrame().asFrameImage2D();
int[] inDims = inputImage.getDimensions();
int[] croppedDims = { (int)FloatMath.ceil(mCropRect.xEdge().length() * inDims[0]),
(int)FloatMath.ceil(mCropRect.yEdge().length() * inDims[1]) };
int[] croppedDims = { (int)Math.ceil(mCropRect.xEdge().length() * inDims[0]),
(int)Math.ceil(mCropRect.yEdge().length() * inDims[1]) };
int[] outDims = { getOutputWidth(croppedDims[0], croppedDims[1]),
getOutputHeight(croppedDims[0], croppedDims[1]) };
FrameImage2D outputImage = outPort.fetchAvailableFrame(outDims).asFrameImage2D();

View File

@ -716,9 +716,8 @@ public final class Matrix_Delegate {
float[] src = new float[] { radius, 0.f, 0.f, radius };
d.mapVectors(src, 0, src, 0, 2);
float l1 = getPointLength(src, 0);
float l2 = getPointLength(src, 2);
float l1 = (float) Math.hypot(src[0], src[1]);
float l2 = (float) Math.hypot(src[2], src[3]);
return (float) Math.sqrt(l1 * l2);
}
@ -973,10 +972,6 @@ public final class Matrix_Delegate {
}
}
private static float getPointLength(float[] src, int index) {
return (float) Math.sqrt(src[index] * src[index] + src[index + 1] * src[index + 1]);
}
/**
* multiply two matrices and store them in a 3rd.
* <p/>This in effect does dest = a*b

View File

@ -198,7 +198,7 @@ public class RadialGradient_Delegate extends Gradient_Delegate {
float _x = pt2[0];
float _y = pt2[1];
float distance = (float) Math.sqrt(_x * _x + _y * _y);
float distance = (float) Math.hypot(_x, _y);
data[index++] = getGradientColor(distance / mRadius);
}

View File

@ -1,132 +0,0 @@
/*
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.util;
import com.android.layoutlib.bridge.impl.DelegateManager;
import com.android.tools.layoutlib.annotations.LayoutlibDelegate;
/**
* Delegate implementing the native methods of android.util.FloatMath
*
* Through the layoutlib_create tool, the original native methods of FloatMath have been replaced
* by calls to methods of the same name in this delegate class.
*
* Because it's a stateless class to start with, there's no need to keep a {@link DelegateManager}
* around to map int to instance of the delegate.
*
*/
/*package*/ final class FloatMath_Delegate {
/** Prevents instantiation. */
private FloatMath_Delegate() {}
/**
* Returns the float conversion of the most positive (i.e. closest to
* positive infinity) integer value which is less than the argument.
*
* @param value to be converted
* @return the floor of value
*/
@LayoutlibDelegate
/*package*/ static float floor(float value) {
return (float)Math.floor(value);
}
/**
* Returns the float conversion of the most negative (i.e. closest to
* negative infinity) integer value which is greater than the argument.
*
* @param value to be converted
* @return the ceiling of value
*/
@LayoutlibDelegate
/*package*/ static float ceil(float value) {
return (float)Math.ceil(value);
}
/**
* Returns the closest float approximation of the sine of the argument.
*
* @param angle to compute the cosine of, in radians
* @return the sine of angle
*/
@LayoutlibDelegate
/*package*/ static float sin(float angle) {
return (float)Math.sin(angle);
}
/**
* Returns the closest float approximation of the cosine of the argument.
*
* @param angle to compute the cosine of, in radians
* @return the cosine of angle
*/
@LayoutlibDelegate
/*package*/ static float cos(float angle) {
return (float)Math.cos(angle);
}
/**
* Returns the closest float approximation of the square root of the
* argument.
*
* @param value to compute sqrt of
* @return the square root of value
*/
@LayoutlibDelegate
/*package*/ static float sqrt(float value) {
return (float)Math.sqrt(value);
}
/**
* Returns the closest float approximation of the raising "e" to the power
* of the argument.
*
* @param value to compute the exponential of
* @return the exponential of value
*/
@LayoutlibDelegate
/*package*/ static float exp(float value) {
return (float)Math.exp(value);
}
/**
* Returns the closest float approximation of the result of raising {@code
* x} to the power of {@code y}.
*
* @param x the base of the operation.
* @param y the exponent of the operation.
* @return {@code x} to the power of {@code y}.
*/
@LayoutlibDelegate
/*package*/ static float pow(float x, float y) {
return (float)Math.pow(x, y);
}
/**
* Returns {@code sqrt(}<i>{@code x}</i><sup>{@code 2}</sup>{@code +} <i>
* {@code y}</i><sup>{@code 2}</sup>{@code )}.
*
* @param x a float number
* @param y a float number
* @return the hypotenuse
*/
@LayoutlibDelegate
/*package*/ static float hypot(float x, float y) {
return (float)Math.sqrt(x*x + y*y);
}
}

View File

@ -188,7 +188,6 @@ public final class CreateInfo implements ICreateInfo {
"android.os.SystemClock",
"android.text.AndroidBidi",
"android.text.format.Time",
"android.util.FloatMath",
"android.view.Display",
"libcore.icu.DateIntervalFormat",
"libcore.icu.ICU",