1 /* 2 * Copyright (C) 2008-2009 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.gesture; 18 19 import android.graphics.Matrix; 20 import android.graphics.Path; 21 22 /** 23 * An oriented bounding box 24 */ 25 public class OrientedBoundingBox { 26 public final float squareness; 27 28 public final float width; 29 public final float height; 30 31 public final float orientation; 32 33 public final float centerX; 34 public final float centerY; 35 OrientedBoundingBox(float angle, float cx, float cy, float w, float h)36 OrientedBoundingBox(float angle, float cx, float cy, float w, float h) { 37 orientation = angle; 38 width = w; 39 height = h; 40 centerX = cx; 41 centerY = cy; 42 float ratio = w / h; 43 if (ratio > 1) { 44 squareness = 1 / ratio; 45 } else { 46 squareness = ratio; 47 } 48 } 49 50 /** 51 * Currently used for debugging purpose only. 52 * 53 * @hide 54 */ toPath()55 public Path toPath() { 56 Path path = new Path(); 57 float[] point = new float[2]; 58 point[0] = -width / 2; 59 point[1] = height / 2; 60 Matrix matrix = new Matrix(); 61 matrix.setRotate(orientation); 62 matrix.postTranslate(centerX, centerY); 63 matrix.mapPoints(point); 64 path.moveTo(point[0], point[1]); 65 66 point[0] = -width / 2; 67 point[1] = -height / 2; 68 matrix.mapPoints(point); 69 path.lineTo(point[0], point[1]); 70 71 point[0] = width / 2; 72 point[1] = -height / 2; 73 matrix.mapPoints(point); 74 path.lineTo(point[0], point[1]); 75 76 point[0] = width / 2; 77 point[1] = height / 2; 78 matrix.mapPoints(point); 79 path.lineTo(point[0], point[1]); 80 81 path.close(); 82 83 return path; 84 } 85 } 86