]> Dogcows Code - chaz/yoink/blob - src/Moof/Rectangle.hh
e41b879cc2e85ba3cd4d71057495c2c0c376d42e
[chaz/yoink] / src / Moof / Rectangle.hh
1
2 /*] Copyright (c) 2009-2010, Charles McGarvey [**************************
3 **] All rights reserved.
4 *
5 * vi:ts=4 sw=4 tw=75
6 *
7 * Distributable under the terms and conditions of the 2-clause BSD license;
8 * see the file COPYING for a complete text of the license.
9 *
10 **************************************************************************/
11
12 #ifndef _MOOF_RECTANGLE_HH_
13 #define _MOOF_RECTANGLE_HH_
14
15 #include <Moof/Math.hh>
16
17
18 namespace Mf {
19
20
21 /**
22 * Axis-aligned Bounding Box
23 */
24
25 struct Rectangle
26 {
27 Vector2 min;
28 Vector2 max;
29
30
31 Rectangle() {}
32
33 Rectangle(const Vector2& a, const Vector2& b)
34 {
35 init(a, b);
36 }
37
38 Rectangle(Scalar ax, Scalar ay, Scalar bx, Scalar by)
39 {
40 Vector2 a(ax, ay);
41 Vector2 b(bx, by);
42
43 init(a, b);
44 }
45
46 void init(const Vector2& a, const Vector2& b)
47 {
48 if (a[0] < b[0])
49 {
50 min[0] = a[0];
51 max[0] = b[0];
52 }
53 else
54 {
55 min[0] = b[0];
56 max[0] = a[0];
57 }
58 if (a[1] < b[1])
59 {
60 min[1] = a[1];
61 max[1] = b[1];
62 }
63 else
64 {
65 min[1] = b[1];
66 max[1] = a[1];
67 }
68 }
69
70 Vector2 getCenter() const
71 {
72 return Vector2((min[0] + max[0]) / 2.0,
73 (min[1] + max[1]) / 2.0);
74 }
75
76 void getCorners(Vector2 corners[4]) const;
77 };
78
79
80 } // namespace Mf
81
82 #endif // _MOOF_RECTANGLE_HH_
83
This page took 0.031549 seconds and 3 git commands to generate.