Gets a float array of the 2D coordinates representing a rectangles corners. - Android Graphics

Android examples for Graphics:Rectangle

Description

Gets a float array of the 2D coordinates representing a rectangles corners.

Demo Code


//package com.java2s;
import android.graphics.RectF;

public class Main {
    /**//  w  w  w.j a  v  a  2s  . co  m
     * Gets a float array of the 2D coordinates representing a rectangles
     * corners.
     * The order of the corners in the float array is:
     * 0------->1
     * ^        |
     * |        |
     * |        v
     * 3<-------2
     *
     * @param r the rectangle to get the corners of
     * @return the float array of corners (8 floats)
     */
    public static float[] getCornersFromRect(RectF r) {
        return new float[] { r.left, r.top, r.right, r.top, r.right,
                r.bottom, r.left, r.bottom };
    }
}

Related Tutorials