/**
  * Takes an array of 2D coordinates representing corners and returns the smallest rectangle
  * containing those coordinates.
  *
  * @param array array of 2D coordinates
  * @return smallest rectangle containing coordinates
  */
 public static RectF trapToRect(float[] array) {
   RectF r =
       new RectF(
           Float.POSITIVE_INFINITY,
           Float.POSITIVE_INFINITY,
           Float.NEGATIVE_INFINITY,
           Float.NEGATIVE_INFINITY);
   for (int i = 1; i < array.length; i += 2) {
     float x = array[i - 1];
     float y = array[i];
     r.left = (x < r.left) ? x : r.left;
     r.top = (y < r.top) ? y : r.top;
     r.right = (x > r.right) ? x : r.right;
     r.bottom = (y > r.bottom) ? y : r.bottom;
   }
   r.sort();
   return r;
 }