/** * Calculates the distance between the two given points. * * @param x1 * @param y1 * @param x2 * @param y2 * @return */ protected float getDistance(float x1, float y1, float x2, float y2) { //return Math.abs(y1 - y2); //return Math.abs(x1 - x2); return (float) Math.hypot(x1 - x2, y1 - y2); }
/** * Returns the absolute value of this complex number. * This quantity is also known as the <em>modulus</em> or <em>magnitude</em>. * * @return the absolute value of this complex number */ public double abs() { return Math.hypot(re, im); }
private static double distance(float x1, float y1, float x2, float y2) { double x = x2 - x1; double y = y2 - y1; return Math.hypot(x, y); } }
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.hypot(x, y); }
/** * @return distance from a (0, 0) point. */ public int distance() { // a simplified distance formula because the other coord is (0, 0) return (int) Math.hypot(x, y); }
public static float mag(float a, float b) { return (float) Math.hypot(a, b); }
public static float getScale(Matrix matrix) { points[0] = 0; points[1] = 0; // Use sqrt(2) so that the hypotenuse is of length 1. points[2] = SQRT_2; points[3] = SQRT_2; matrix.mapPoints(points); float dx = points[2] - points[0]; float dy = points[3] - points[1]; // TODO: figure out why the result needs to be divided by 2. return (float) Math.hypot(dx, dy) / 2f; }
/** * Returns a bitmap that lights up red subpixels at the bottom, green subpixels on the right, and * blue subpixels in bottom-right. */ Bitmap generateGradient() { int[][] pixels = new int[1080][1920]; for (int y = 0; y < 1080; y++) { for (int x = 0; x < 1920; x++) { int r = (int) (y / 1080f * 255); int g = (int) (x / 1920f * 255); int b = (int) ((Math.hypot(x, y) / Math.hypot(1080, 1920)) * 255); pixels[y][x] = r << 16 | g << 8 | b; } } return new Bitmap(pixels); }
@Override protected ExprEval eval(double x, double y) { return ExprEval.of(Math.hypot(x, y)); } }
private static double calculateMaxDistance(View sceneRoot, int focalX, int focalY) { int maxX = Math.max(focalX, sceneRoot.getWidth() - focalX); int maxY = Math.max(focalY, sceneRoot.getHeight() - focalY); return Math.hypot(maxX, maxY); }
@Override @NonNull public Path getPath(float startX, float startY, float endX, float endY) { double dx = endX - startX; double dy = endY - startY; float length = (float) Math.hypot(dx, dy); double angle = Math.atan2(dy, dx); mTempMatrix.setScale(length, length); mTempMatrix.postRotate((float) Math.toDegrees(angle)); mTempMatrix.postTranslate(startX, startY); Path path = new Path(); mPatternPath.transform(mTempMatrix, path); return path; }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void prepareCircularReveal(View startView, View targetView) { int centerX = (startView.getLeft() + startView.getRight()) / 2; int centerY = (startView.getTop() + startView.getBottom()) / 2; float finalRadius = (float) Math.hypot((double) centerX, (double) centerY); mCircularReveal = ViewAnimationUtils.createCircularReveal( targetView, centerX, centerY, 0, finalRadius); mCircularReveal.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mCircularReveal.removeListener(this); } }); } }
/** * Calculate the duration for the transition depending upon how far the text has to move. */ private long calculateDuration(@NonNull Rect startPosition, @NonNull Rect endPosition) { float distance = (float) Math.hypot( startPosition.exactCenterX() - endPosition.exactCenterX(), startPosition.exactCenterY() - endPosition.exactCenterY()); long duration = (long) (1000 * (distance / velocity)); return Math.max(minDuration, Math.min(maxDuration, duration)); }
@Override @NonNull protected Animator getAnimator(@NonNull ViewGroup container, View from, View to, boolean isPush, boolean toAddedToContainer) { final float radius = (float) Math.hypot(cx, cy); Animator animator = null; if (isPush && to != null) { animator = ViewAnimationUtils.createCircularReveal(to, cx, cy, 0, radius); } else if (!isPush && from != null) { animator = ViewAnimationUtils.createCircularReveal(from, cx, cy, radius, 0); } return animator; }
private boolean createCircularReveal() { if (mColorBg == null) { return false; } int w = mColorBg.getWidth(); int h = mColorBg.getHeight(); if (ViewCompat.isAttachedToWindow(mColorBg) && w != 0 && h != 0) { ViewAnimationUtils.createCircularReveal(mColorBg, w / 2, h / 2, 0, (float) Math.hypot(w / 2, h / 2)).setDuration(300).start(); return true; } else { return false; } }
private RadialGradient getRadialGradient() { int gradientHash = getGradientHash(); RadialGradient gradient = radialGradientCache.get(gradientHash); if (gradient != null) { return gradient; } PointF startPoint = startPointAnimation.getValue(); PointF endPoint = endPointAnimation.getValue(); GradientColor gradientColor = colorAnimation.getValue(); int[] colors = gradientColor.getColors(); float[] positions = gradientColor.getPositions(); int x0 = (int) (boundsRect.left + boundsRect.width() / 2 + startPoint.x); int y0 = (int) (boundsRect.top + boundsRect.height() / 2 + startPoint.y); int x1 = (int) (boundsRect.left + boundsRect.width() / 2 + endPoint.x); int y1 = (int) (boundsRect.top + boundsRect.height() / 2 + endPoint.y); float r = (float) Math.hypot(x1 - x0, y1 - y0); gradient = new RadialGradient(x0, y0, r, colors, positions, Shader.TileMode.CLAMP); radialGradientCache.put(gradientHash, gradient); return gradient; }
/** * Gets the distance between this point and another. * * @param other other point * @return the distance */ public int distanceTo(LocalPoint other) { return (int) Math.hypot(getX() - other.getX(), getY() - other.getY()); }
/** * Gets the distance between this point and another. * * @param other other point * @return the distance */ public int distanceTo(Point other) { return (int) Math.hypot(getX() - other.getX(), getY() - other.getY()); }
private RadialGradient getRadialGradient() { int gradientHash = getGradientHash(); RadialGradient gradient = radialGradientCache.get(gradientHash); if (gradient != null) { return gradient; } PointF startPoint = startPointAnimation.getValue(); PointF endPoint = endPointAnimation.getValue(); GradientColor gradientColor = colorAnimation.getValue(); int[] colors = gradientColor.getColors(); float[] positions = gradientColor.getPositions(); float x0 = startPoint.x; float y0 = startPoint.y; float x1 = endPoint.x; float y1 = endPoint.y; float r = (float) Math.hypot(x1 - x0, y1 - y0); if (r <= 0) { r = 0.001f; } gradient = new RadialGradient(x0, y0, r, colors, positions, Shader.TileMode.CLAMP); radialGradientCache.put(gradientHash, gradient); return gradient; }