Example usage for java.lang Math hypot

List of usage examples for java.lang Math hypot

Introduction

In this page you can find the example usage for java.lang Math hypot.

Prototype

public static double hypot(double x, double y) 

Source Link

Document

Returns sqrt(x2 +y2) without intermediate overflow or underflow.

Usage

From source file:io.plaidapp.ui.DesignerNewsStory.java

private void doFabExpand() {
    // translate the chrome placeholder ui so that it is centered on the FAB
    int fabCenterX = (fab.getLeft() + fab.getRight()) / 2;
    int fabCenterY = ((fab.getTop() + fab.getBottom()) / 2) - fabExpand.getTop();
    int translateX = fabCenterX - (fabExpand.getWidth() / 2);
    int translateY = fabCenterY - (fabExpand.getHeight() / 2);
    fabExpand.setTranslationX(translateX);
    fabExpand.setTranslationY(translateY);

    // then reveal the placeholder ui, starting from the center & same dimens as fab
    fabExpand.setVisibility(View.VISIBLE);
    Animator reveal = ViewAnimationUtils
            .createCircularReveal(fabExpand, fabExpand.getWidth() / 2, fabExpand.getHeight() / 2,
                    fab.getWidth() / 2, (int) Math.hypot(fabExpand.getWidth() / 2, fabExpand.getHeight() / 2))
            .setDuration(fabExpandDuration);

    // translate the placeholder ui back into position along an arc
    GravityArcMotion arcMotion = new GravityArcMotion();
    arcMotion.setMinimumVerticalAngle(70f);
    Path motionPath = arcMotion.getPath(translateX, translateY, 0, 0);
    Animator position = ObjectAnimator.ofFloat(fabExpand, View.TRANSLATION_X, View.TRANSLATION_Y, motionPath)
            .setDuration(fabExpandDuration);

    // animate from the FAB colour to the placeholder background color
    Animator background = ObjectAnimator
            .ofArgb(fabExpand, ViewUtils.BACKGROUND_COLOR, ContextCompat.getColor(this, R.color.designer_news),
                    ContextCompat.getColor(this, R.color.background_light))
            .setDuration(fabExpandDuration);

    // fade out the fab (rapidly)
    Animator fadeOutFab = ObjectAnimator.ofFloat(fab, View.ALPHA, 0f).setDuration(60);

    // play 'em all together with the material interpolator
    AnimatorSet show = new AnimatorSet();
    show.setInterpolator(getFastOutSlowInInterpolator(DesignerNewsStory.this));
    show.playTogether(reveal, background, position, fadeOutFab);
    show.start();/*from   w w w.  j  av a2 s .co m*/
}

From source file:io.plaidapp.designernews.ui.story.StoryActivity.java

private void doFabExpand() {
    // translate the chrome placeholder ui so that it is centered on the FAB
    int fabCenterX = (fab.getLeft() + fab.getRight()) / 2;
    int fabCenterY = ((fab.getTop() + fab.getBottom()) / 2) - fabExpand.getTop();
    int translateX = fabCenterX - (fabExpand.getWidth() / 2);
    int translateY = fabCenterY - (fabExpand.getHeight() / 2);
    fabExpand.setTranslationX(translateX);
    fabExpand.setTranslationY(translateY);

    // then reveal the placeholder ui, starting from the center & same dimens as fab
    fabExpand.setVisibility(View.VISIBLE);
    Animator reveal = ViewAnimationUtils
            .createCircularReveal(fabExpand, fabExpand.getWidth() / 2, fabExpand.getHeight() / 2,
                    fab.getWidth() / 2, (int) Math.hypot(fabExpand.getWidth() / 2, fabExpand.getHeight() / 2))
            .setDuration(fabExpandDuration);

    // translate the placeholder ui back into position along an arc
    GravityArcMotion arcMotion = new GravityArcMotion();
    arcMotion.setMinimumVerticalAngle(70f);
    Path motionPath = arcMotion.getPath(translateX, translateY, 0, 0);
    Animator position = ObjectAnimator.ofFloat(fabExpand, View.TRANSLATION_X, View.TRANSLATION_Y, motionPath)
            .setDuration(fabExpandDuration);

    // animate from the FAB colour to the placeholder background color
    Animator background = ObjectAnimator
            .ofArgb(fabExpand, ViewUtils.BACKGROUND_COLOR,
                    ContextCompat.getColor(this, io.plaidapp.R.color.designer_news),
                    ContextCompat.getColor(this, io.plaidapp.R.color.background_light))
            .setDuration(fabExpandDuration);

    // fade out the fab (rapidly)
    Animator fadeOutFab = ObjectAnimator.ofFloat(fab, View.ALPHA, 0f).setDuration(60);

    // play 'em all together with the material interpolator
    AnimatorSet show = new AnimatorSet();
    show.setInterpolator(getFastOutSlowInInterpolator(StoryActivity.this));
    show.playTogether(reveal, background, position, fadeOutFab);
    show.start();/* w w w.j a va  2 s .  c  o m*/
}

From source file:babbq.com.searchplace.SearchActivity.java

@OnClick(R.id.fab)
protected void save() {
    // show the save confirmation bubble
    fab.setVisibility(View.INVISIBLE);
    confirmSaveContainer.setVisibility(View.VISIBLE);
    resultsScrim.setVisibility(View.VISIBLE);

    // expand it once it's been measured and show a scrim over the search results
    confirmSaveContainer.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {

        @Override// w  w  w . jav a2  s. c  o  m
        public boolean onPreDraw() {
            // expand the confirmation
            confirmSaveContainer.getViewTreeObserver().removeOnPreDrawListener(this);
            Animator reveal = ViewAnimationUtils.createCircularReveal(confirmSaveContainer,
                    confirmSaveContainer.getWidth() / 2, confirmSaveContainer.getHeight() / 2,
                    fab.getWidth() / 2, confirmSaveContainer.getWidth() / 2);
            reveal.setDuration(250L);
            reveal.setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this,
                    android.R.interpolator.fast_out_slow_in));
            reveal.start();

            // show the scrim
            int centerX = (fab.getLeft() + fab.getRight()) / 2;
            int centerY = (fab.getTop() + fab.getBottom()) / 2;
            Animator revealScrim = ViewAnimationUtils.createCircularReveal(resultsScrim, centerX, centerY, 0,
                    (float) Math.hypot(centerX, centerY));
            revealScrim.setDuration(400L);
            revealScrim.setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this,
                    android.R.interpolator.linear_out_slow_in));
            revealScrim.start();
            ObjectAnimator fadeInScrim = ObjectAnimator.ofArgb(resultsScrim, ViewUtils.BACKGROUND_COLOR,
                    Color.TRANSPARENT, ContextCompat.getColor(SearchActivity.this, R.color.scrim));
            fadeInScrim.setDuration(800L);
            fadeInScrim.setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this,
                    android.R.interpolator.linear_out_slow_in));
            fadeInScrim.start();

            // ease in the checkboxes
            //                saveDribbble.setAlpha(0.6f);
            //                saveDribbble.setTranslationY(saveDribbble.getHeight() * 0.4f);
            //                saveDribbble.animate()
            //                        .alpha(1f)
            //                        .translationY(0f)
            //                        .setDuration(200L)
            //                        .setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this,
            //                                android.R.interpolator.linear_out_slow_in));
            //                saveDesignerNews.setAlpha(0.6f);
            //                saveDesignerNews.setTranslationY(saveDesignerNews.getHeight() * 0.5f);
            //                saveDesignerNews.animate()
            //                        .alpha(1f)
            //                        .translationY(0f)
            //                        .setDuration(200L)
            //                        .setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this,
            //                                android.R.interpolator.linear_out_slow_in));
            return false;
        }
    });
}

From source file:com.sinyuk.jianyimaterial.widgets.FloatingToolbar.java

@TargetApi(21)
private void showLollipopImpl() {
    int rootWidth = mRoot.getWidth();

    float endFabX;
    float controlX;

    if (mFabOriginalX > rootWidth / 2f) {
        endFabX = rootWidth / 2f + (mFabOriginalX - rootWidth / 2f) / 4f;
        controlX = mFabOriginalX * 0.98f;
    } else {// ww w .  j  av  a  2 s  . c  o  m
        endFabX = rootWidth / 2f - (mFabOriginalX - rootWidth / 2f) / 4f;
        controlX = mFabOriginalX * 1.02f;
    }

    /**
     * Animate FAB movement
     */
    final Path path = new Path();
    path.moveTo(mFab.getX(), mFab.getY());
    final float x2 = controlX;
    final float y2 = getY();
    path.quadTo(x2, y2, endFabX, getY());
    ObjectAnimator anim = ObjectAnimator.ofFloat(mFab, View.X, View.Y, path);
    anim.setInterpolator(new AccelerateDecelerateInterpolator());
    anim.setDuration(FAB_MORPH_DURATION);
    anim.start();

    /**
     * Fade FAB drawable
     */
    Drawable drawable = mFab.getDrawable();
    if (drawable != null) {
        anim = ObjectAnimator.ofPropertyValuesHolder(drawable, PropertyValuesHolder.ofInt("alpha", 0));
        anim.setInterpolator(new AccelerateDecelerateInterpolator());
        anim.setDuration((long) (FAB_MORPH_DURATION / 3f));
        anim.start();
    }

    /**
     * Animate FAB elevation to 8dp
     */
    anim = ObjectAnimator.ofFloat(mFab, View.TRANSLATION_Z, dpToPixels(2));
    anim.setInterpolator(new AccelerateDecelerateInterpolator());
    anim.setDuration(FAB_MORPH_DURATION);
    anim.start();

    /**
     * Create circular reveal
     */
    Animator toolbarReveal = ViewAnimationUtils.createCircularReveal(this, getWidth() / 2, getHeight() / 2,
            (float) mFab.getWidth() / 2f, (float) (Math.hypot(getWidth() / 2, getHeight() / 2)));

    toolbarReveal.setDuration(CIRCULAR_REVEAL_DURATION);
    toolbarReveal.setTarget(this);
    toolbarReveal.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            super.onAnimationStart(animation);
            mFab.setVisibility(View.INVISIBLE);
            setVisibility(View.VISIBLE);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            mMorphing = false;
        }
    });

    toolbarReveal.setInterpolator(new AccelerateInterpolator());
    toolbarReveal.setStartDelay(CIRCULAR_REVEAL_DELAY);
    toolbarReveal.start();

    /**
     * Animate FloatingToolbar elevation to 8dp
     */
    anim = ObjectAnimator.ofFloat(this, View.TRANSLATION_Z, dpToPixels(2));
    anim.setDuration(CIRCULAR_REVEAL_DURATION);
    anim.setStartDelay(CIRCULAR_REVEAL_DELAY);
    anim.start();
}

From source file:com.eugene.fithealthmaingit.UI.ChooseAddMealTabsFragment.java

private void handleSearchFavorite() {
    if (card_search_fav.getVisibility() == View.VISIBLE) {
        searchFavorite.setVisibility(View.VISIBLE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            final Animator animatorHide = ViewAnimationUtils.createCircularReveal(card_search_fav,
                    card_search_fav.getWidth() - (int) convertDpToPixel(24, getActivity()),
                    (int) convertDpToPixel(23, getActivity()),
                    (float) Math.hypot(card_search_fav.getWidth(), card_search_fav.getHeight()), 0);
            animatorHide.addListener(new Animator.AnimatorListener() {
                @Override//www .  ja v  a  2  s. c o  m
                public void onAnimationStart(Animator animation) {

                }

                @Override
                public void onAnimationEnd(Animator animation) {
                    card_search_fav.setVisibility(View.GONE);
                    ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))
                            .hideSoftInputFromWindow(searchFavorite.getWindowToken(), 0);
                }

                @Override
                public void onAnimationCancel(Animator animation) {

                }

                @Override
                public void onAnimationRepeat(Animator animation) {

                }
            });

            animatorHide.setDuration(200);
            animatorHide.start();
        } else {
            favSearch.requestFocus();
            card_search_fav.setVisibility(View.GONE);
            ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))
                    .hideSoftInputFromWindow(searchFavorite.getWindowToken(), 0);
        }
    } else {
        searchFavorite.setVisibility(View.INVISIBLE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            final Animator animator = ViewAnimationUtils.createCircularReveal(card_search_fav,
                    card_search_fav.getWidth() - (int) convertDpToPixel(24, getActivity()),
                    (int) convertDpToPixel(23, getActivity()), 0,
                    (float) Math.hypot(card_search_fav.getWidth(), card_search_fav.getHeight()));
            animator.addListener(new Animator.AnimatorListener() {
                @Override
                public void onAnimationStart(Animator animation) {
                    favSearch.requestFocus();
                }

                @Override
                public void onAnimationEnd(Animator animation) {
                    favSearch.requestFocus();
                    ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))
                            .toggleSoftInput(InputMethodManager.SHOW_FORCED,
                                    InputMethodManager.HIDE_IMPLICIT_ONLY);
                }

                @Override
                public void onAnimationCancel(Animator animation) {

                }

                @Override
                public void onAnimationRepeat(Animator animation) {

                }
            });
            card_search_fav.setVisibility(View.VISIBLE);
            if (card_search_fav.getVisibility() == View.VISIBLE) {
                animator.setDuration(300);
                animator.start();
            }
        } else {
            favSearch.requestFocus();
            card_search_fav.setVisibility(View.VISIBLE);
            ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))
                    .toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
        }
    }
}

From source file:uk.ac.diamond.scisoft.analysis.diffraction.PowderRingsUtils.java

/**
 * Find other ellipses from given ellipse and image.
 * <p>/*from   w ww. ja va 2 s  .  co  m*/
 * This is done by looking at the box profile along spokes from the
 * given centre and finding peaks. Then the distance out to those peaks is used
 * to search for more POIs and so more ellipses
 * @param image
 * @param mask (can be null)
 * @param roi initial ellipse
 * @param radialMin
 * @param radialDelta
 * @param arcLength
 * @param trimDelta
 * @param maxPoints
 * @return list of ellipses
 */
public static List<EllipticalROI> findOtherEllipses(IMonitor mon, Dataset image, BooleanDataset mask,
        EllipticalROI roi, double radialMin, double radialDelta, double arcLength, double trimDelta,
        int maxPoints) {
    if (image.getRank() != 2) {
        logger.error("Dataset must have two dimensions");
        throw new IllegalArgumentException("Dataset must have two dimensions");
    }
    if (mask != null && !image.isCompatibleWith(mask)) {
        logger.error("Mask must match image shape");
        throw new IllegalArgumentException("Mask must match image shape");
    }

    // explore all corners
    final int[] shape = image.getShape();
    final int h = shape[0];
    final int w = shape[1];
    double[] ec = roi.getPoint();
    TreeSet<Double> majors = new TreeSet<Double>();

    // TODO farm this out across several threads
    findMajorAxes(mon, majors, image, mask, roi, radialMin, radialDelta, ec, 0 - ec[0], 0 - ec[1]); // TL
    findMajorAxes(mon, majors, image, mask, roi, radialMin, radialDelta, ec, w - ec[0], 0 - ec[1]); // TR
    findMajorAxes(mon, majors, image, mask, roi, radialMin, radialDelta, ec, w - ec[0], h - ec[1]); // BR
    findMajorAxes(mon, majors, image, mask, roi, radialMin, radialDelta, ec, 0 - ec[0], h - ec[1]); // BL

    findMajorAxes(mon, majors, image, mask, roi, radialMin, radialDelta, ec, 0, h - ec[1]); // T
    findMajorAxes(mon, majors, image, mask, roi, radialMin, radialDelta, ec, w - ec[0], 0); // R
    findMajorAxes(mon, majors, image, mask, roi, radialMin, radialDelta, ec, 0, 0 - ec[1]); // B
    findMajorAxes(mon, majors, image, mask, roi, radialMin, radialDelta, ec, 0 - ec[0], 0); // L

    // and finally find POIs
    List<EllipticalROI> ells = new ArrayList<EllipticalROI>();
    double major = roi.getSemiAxis(0);
    double aspect = roi.getSemiAxis(0) / roi.getSemiAxis(1);
    double last = Double.NEGATIVE_INFINITY;
    for (double a : majors) {
        System.err.println("Current " + a + ", last " + last);
        if (a < last) {
            System.err.println("Dropped as less than last");
            continue;
        }
        if (Math.abs(a - last) < RING_SEPARATION) { // omit close rings
            last = a;
            System.err.println("Dropped as too close");
            continue;
        }
        if (Math.abs(a - major) < RING_SEPARATION) {
            last = major;
            System.err.println("Add original");
            ells.add(roi);
        } else {
            EllipticalROI er = new EllipticalROI(a, a / aspect, roi.getAngle(), ec[0], ec[1]);
            try {
                PolylineROI polyline = findPOIsNearEllipse(mon, image, mask, er, arcLength, 0.8 * radialDelta,
                        maxPoints);
                if (polyline.getNumberOfPoints() > 2) {
                    er = fitAndTrimOutliers(mon, polyline, trimDelta, roi.isCircular());
                    double emaj = er.getSemiAxis(0);
                    if (Math.abs(emaj - last) < RING_SEPARATION) { // omit close rings
                        last = a;
                        System.err.println("Dropped as fit is too close");
                        continue;
                    }
                    double[] c = er.getPointRef();
                    if (Math.hypot(c[0] - ec[0], c[1] - ec[1]) > 8 * radialDelta) {
                        last = a; // omit fits with far-off centres
                        System.err.println("Dropped as centre is far-off");
                        continue;
                    }
                    if (Math.abs(emaj - major) < RING_SEPARATION) {
                        System.err.println("Add fit that is close to original");
                    }
                    last = Math.max(a, emaj);
                    ells.add(er);
                } else {
                    logger.warn("Could not find enough points at {}", er);
                }
            } catch (IllegalArgumentException e) {
                logger.debug("Problem with {}", er, e);
                last = a;
            }
            if (mon != null)
                mon.worked(1);
        }
    }

    return ells;
}

From source file:syncleus.dann.data.matrix.SimpleRealMatrix.java

/**
 * Frobenius norm./*from  w  w  w. j a va2 s  .  c  om*/
 *
 * @return sqrt of sum of squares of all elements.
 */
public double normF() {
    double normF = 0;
    for (int i = 0; i < getRows(); i++)
        for (int j = 0; j < getCols(); j++)
            normF = Math.hypot(normF, this.matrixElements[i][j]);
    return normF;
}

From source file:edu.stanford.cfuller.imageanalysistools.clustering.ObjectClustering.java

/**
 * Applies basic clustering to an Image with objects.
 *
 * This will use the long-range gaussian filtering approach to assign clusters; objects sufficiently near to each other will be smeared into a single object and assigned to the same cluster.
 *
 * @param input             An Image mask labeled such that each object in the Image is assigned a unique nonzero greylevel value.  These should start at 1 and be consecutive.
 * @param original          The original image (not currently used... this is here to maintain the interface with a previous version that used this image)
 * @param gaussianFiltered  The mask with a long range Gaussian filter applied (as from {@link #gaussianFilterMask}).  This is an optional parameter;
 *                          input null to have this automatically generated by the method.  This parameter is
 *                          chiefly useful to save computation time when running the clutering multiple times.
 *                          This will be modified, so if planning to reuse the Gaussian filtered image, pass in a copy.
 *///from   www.j a v  a 2  s  .  co m
public static Image doBasicClustering(WritableImage input, Image original, Image gaussianFiltered) {

    RelabelFilter rlf = new RelabelFilter();
    LabelFilter lf = new LabelFilter();
    MaskFilter mf = new MaskFilter();

    mf.setReferenceImage(input);

    Histogram h_individualCentromeres = new Histogram(input);

    WritableImage origCopy = null;

    if (gaussianFiltered == null) {

        origCopy = gaussianFilterMask(input).getWritableInstance();

    } else {
        origCopy = gaussianFiltered.getWritableInstance();
    }

    lf.apply(origCopy);

    WritableImage mapped = ImageFactory.createWritable(origCopy);

    Histogram h_mapped_0 = new Histogram(origCopy);

    //first, find the centroid of each cluster

    org.apache.commons.math3.linear.RealVector centroids_x = new ArrayRealVector(h_mapped_0.getMaxValue() + 1);
    org.apache.commons.math3.linear.RealVector centroids_y = new ArrayRealVector(h_mapped_0.getMaxValue() + 1);

    org.apache.commons.math3.linear.RealVector counts = new ArrayRealVector(h_mapped_0.getMaxValue() + 1);

    centroids_x.mapMultiplyToSelf(0.0);
    centroids_y.mapMultiplyToSelf(0.0);
    counts.mapMultiplyToSelf(0.0);

    for (ImageCoordinate i : origCopy) {
        if (origCopy.getValue(i) > 0) {
            int value = (int) origCopy.getValue(i);
            centroids_x.setEntry(value, centroids_x.getEntry(value) + i.get(ImageCoordinate.X));
            centroids_y.setEntry(value, centroids_y.getEntry(value) + i.get(ImageCoordinate.Y));
            counts.setEntry(value, counts.getEntry(value) + 1);
        }
    }
    for (int i = 0; i < counts.getDimension(); i++) {
        if (counts.getEntry(i) == 0) {
            counts.setEntry(i, 1);
            centroids_x.setEntry(i, -1 * origCopy.getDimensionSizes().get(ImageCoordinate.X));
            centroids_y.setEntry(i, -1 * origCopy.getDimensionSizes().get(ImageCoordinate.Y));
        }
        centroids_x.setEntry(i, centroids_x.getEntry(i) / counts.getEntry(i));
        centroids_y.setEntry(i, centroids_y.getEntry(i) / counts.getEntry(i));

    }

    for (ImageCoordinate i : origCopy) {

        if (mapped.getValue(i) > 0 || input.getValue(i) == 0)
            continue;

        double minDistance = Double.MAX_VALUE;
        int minIndex = 0;

        for (int j = 0; j < centroids_x.getDimension(); j++) {
            double dist = Math.hypot(centroids_x.getEntry(j) - i.get(ImageCoordinate.X),
                    centroids_y.getEntry(j) - i.get(ImageCoordinate.Y));
            if (dist < minDistance) {
                minDistance = dist;
                minIndex = j;
            }
        }

        mapped.setValue(i, minIndex);

    }

    int[] centromereAssignments = new int[h_individualCentromeres.getMaxValue() + 1];
    java.util.Arrays.fill(centromereAssignments, 0);

    for (ImageCoordinate i : mapped) {

        if (input.getValue(i) > 0) {

            int value = (int) input.getValue(i);

            if (centromereAssignments[value] > 0) {
                mapped.setValue(i, centromereAssignments[value]);
            } else {
                centromereAssignments[value] = (int) mapped.getValue(i);
            }

        }
    }

    mf.apply(mapped);
    origCopy.copy(mapped);
    mf.setReferenceImage(origCopy);

    mf.apply(input);
    rlf.apply(input);
    rlf.apply(origCopy);

    return origCopy;
}

From source file:uk.ac.diamond.scisoft.analysis.diffraction.PowderRingsUtils.java

/**
 * Find major axes by looking along thick line given by relative coordinates to centre for
 * maximum intensity values/*from   w w w  .  ja  v a  2s.  c o  m*/
 * @param mon
 * @param axes
 * @param image
 * @param mask
 * @param roi
 * @param offset minimum position of peaks
 * @param width of line
 * @param centre
 * @param dx
 * @param dy
 */
private static void findMajorAxes(IMonitor mon, TreeSet<Double> axes, Dataset image, Dataset mask,
        EllipticalROI roi, double offset, double width, double[] centre, double dx, double dy) {
    RectangularROI rroi = new RectangularROI();
    rroi.setPoint(centre);
    rroi.setAngle(Math.atan2(dy, dx));
    rroi.setLengths(Math.hypot(dx, dy), width);
    rroi.translate(0, -0.5);
    rroi.setClippingCompensation(true);
    Dataset profile = ROIProfile.maxInBox(image, mask, rroi)[0];

    List<IdentifiedPeak> peaks = Generic1DFitter
            .findPeaks(DatasetFactory.createRange(profile.getSize(), Dataset.INT), profile, PEAK_SMOOTHING);
    if (mon != null)
        mon.worked(profile.getSize());

    System.err.printf("\n");
    DescriptiveStatistics stats = new DescriptiveStatistics();
    int[] pb = new int[1];
    int[] pe = new int[1];
    for (IdentifiedPeak p : peaks) {
        if (p.getPos() < offset) {
            continue;
        }
        pb[0] = (int) p.getMinXVal();
        pe[0] = (int) p.getMaxXVal();
        p.setArea((Double) profile.getSlice(pb, pe, null).sum());
        stats.addValue(p.getArea());
        System.err.printf("P %f A %f W %f H %f\n", p.getPos(), p.getArea(), p.getFWHM(), p.getHeight());
    }

    double area = stats.getMean() + 0.4 * (stats.getPercentile(75) - stats.getPercentile(25));
    logger.debug("Area: {}", stats);
    logger.debug("Minimum threshold: {}", area);

    double majorFactor = roi.getSemiAxis(0) / roi.getDistance(rroi.getAngle());
    double maxFWHM = MAX_FWHM_FACTOR * width;
    for (IdentifiedPeak p : peaks) {
        double l = p.getPos();
        if (l < offset) {
            continue;
        }
        //         System.err.println(p);
        // filter on area and FWHM
        if (p.getFWHM() > maxFWHM) {
            continue;
        }
        if (p.getArea() < area) {
            break;
        }
        axes.add(l * majorFactor);
    }
    if (mon != null)
        mon.worked(peaks.size());

}

From source file:com.sinyuk.jianyimaterial.widgets.FloatingToolbar.java

@TargetApi(21)
private void hideLollipopImpl() {
    int rootWidth = mRoot.getWidth();

    float controlX;

    if (mFabOriginalX > rootWidth / 2f) {
        controlX = mFabOriginalX * 0.98f;
    } else {//from www . j a  v a 2  s .  c o  m
        controlX = mFabOriginalX * 1.02f;
    }

    final Path path = new Path();
    path.moveTo(mFab.getX(), mFab.getY());
    final float x2 = controlX;
    final float y2 = getY();
    path.quadTo(x2, y2, mFabOriginalX, mFabOriginalY + getTranslationY());
    ObjectAnimator anim = ObjectAnimator.ofFloat(mFab, View.X, View.Y, path);
    anim.setInterpolator(new AccelerateDecelerateInterpolator());
    anim.setDuration(FAB_UNMORPH_DURATION);
    anim.setStartDelay(FAB_UNMORPH_DELAY);
    anim.start();

    /**
     * Animate FAB elevation back to 6dp
     */
    anim = ObjectAnimator.ofFloat(mFab, View.TRANSLATION_Z, 0);
    anim.setInterpolator(new AccelerateDecelerateInterpolator());
    anim.setDuration(FAB_UNMORPH_DURATION);
    anim.setStartDelay(FAB_UNMORPH_DELAY);
    anim.start();

    /**
     * Restore alpha of FAB drawable
     */
    Drawable drawable = mFab.getDrawable();
    if (drawable != null) {
        anim = ObjectAnimator.ofPropertyValuesHolder(drawable, PropertyValuesHolder.ofInt("alpha", 255));
        anim.setInterpolator(new AccelerateDecelerateInterpolator());
        anim.setDuration(FAB_UNMORPH_DURATION);
        anim.setStartDelay(FAB_UNMORPH_DELAY);
        anim.start();
    }

    Animator toolbarReveal = ViewAnimationUtils.createCircularReveal(this, getWidth() / 2, getHeight() / 2,
            (float) (Math.hypot(getWidth() / 2, getHeight() / 2)), (float) mFab.getWidth() / 2f);

    toolbarReveal.setTarget(this);
    toolbarReveal.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            setVisibility(View.INVISIBLE);
            mFab.setVisibility(View.VISIBLE);
            mMorphing = false;
        }
    });
    toolbarReveal.setDuration(CIRCULAR_UNREVEAL_DURATION);
    toolbarReveal.setInterpolator(new AccelerateInterpolator());
    toolbarReveal.setStartDelay(CIRCULAR_UNREVEAL_DELAY);
    toolbarReveal.start();

    /**
     * Animate FloatingToolbar animation back to 6dp
     */
    anim = ObjectAnimator.ofFloat(this, View.TRANSLATION_Z, 0);
    anim.setDuration(CIRCULAR_UNREVEAL_DURATION);
    anim.setStartDelay(CIRCULAR_UNREVEAL_DELAY);
    anim.start();
}