blob: f1335ee122322918576cadc17d3e43a3cff38612 [file] [log] [blame]
Yang Li35aa84b2009-05-18 18:29:05 -07001/*
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
Romain Guydb567c32009-05-21 16:23:21 -070017package android.gesture;
Yang Li35aa84b2009-05-18 18:29:05 -070018
19import android.graphics.Matrix;
20import android.graphics.Path;
21
22/**
23 * An oriented bounding box
24 */
25public class OrientedBoundingBox {
Yang Li35aa84b2009-05-18 18:29:05 -070026 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
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
Romain Guydb567c32009-05-21 16:23:21 -070050 /**
51 * Currently used for debugging purpose only.
52 *
53 * @hide
54 */
Yang Li35aa84b2009-05-18 18:29:05 -070055 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}