OverSim
BoundingBox2D.cc
Go to the documentation of this file.
1 //
2 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH)
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 //
18 
24 #include <BoundingBox2D.h>
25 
27 
29 {
30  this->tl = tl;
31  this->br = br;
32 }
33 
34 BoundingBox2D::BoundingBox2D(double tlx, double tly, double brx, double bry)
35 {
36  tl.x = tlx;
37  tl.y = tly;
38  br.x = brx;
39  br.y = bry;
40 }
41 
43 {
44  tl.x = center.x - width * 0.5;
45  tl.y = center.y + width * 0.5;
46  br.x = center.x + width * 0.5;
47  br.y = center.y - width * 0.5;
48 }
49 
51 {
52  if(tl.x > box.br.x)
53  return false;
54  if(tl.y < box.br.y)
55  return false;
56 
57  if(br.x < box.tl.x)
58  return false;
59  if(br.y > box.tl.y)
60  return false;
61 
62  return true;
63 }
64 
65 bool BoundingBox2D::collide(const Vector2D p) const
66 {
67  if(p.x > tl.x && p.x < br.x && p.y < tl.y && p.y > br.y)
68  return true;
69  else
70  return false;
71 }
72 
74 {
75  return tl.y;
76 }
77 
79 {
80  return br.y;
81 }
82 
84 {
85  return tl.x;
86 }
87 
89 {
90  return br.x;
91 }
92 
93 std::ostream& operator<<(std::ostream& Stream, const BoundingBox2D& box)
94 {
95  return Stream << box.tl << " - " << box.br;
96 }