OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
BoundingBox.cpp
Go to the documentation of this file.
2 
3 namespace mslang {
4  bool BoundingBox::doesIntersect(const BoundingBox &bb) const {
5  return ((center_m[0] - 0.5 * width_m <= bb.center_m[0] + 0.5 * bb.width_m) &&
6  (center_m[0] + 0.5 * width_m >= bb.center_m[0] - 0.5 * bb.width_m) &&
7  (center_m[1] - 0.5 * height_m <= bb.center_m[1] + 0.5 * bb.height_m) &&
8  (center_m[1] + 0.5 * height_m >= bb.center_m[1] - 0.5 * bb.height_m));
9  }
10 
11  bool BoundingBox::isInside(const Vector_t &X) const {
12  if (2 * std::abs(X[0] - center_m[0]) <= width_m &&
13  2 * std::abs(X[1] - center_m[1]) <= height_m)
14  return true;
15 
16  return false;
17  }
18 
19  bool BoundingBox::isInside(const BoundingBox &b) const {
20  return (isInside(b.center_m + 0.5 * Vector_t( b.width_m, b.height_m, 0.0)) &&
21  isInside(b.center_m + 0.5 * Vector_t(-b.width_m, b.height_m, 0.0)) &&
22  isInside(b.center_m + 0.5 * Vector_t(-b.width_m, -b.height_m, 0.0)) &&
23  isInside(b.center_m + 0.5 * Vector_t( b.width_m, -b.height_m, 0.0)));
24  }
25 
26  void BoundingBox::writeGnuplot(std::ostream &out) const {
27  std::vector<Vector_t> pts({Vector_t(center_m[0] + 0.5 * width_m, center_m[1] + 0.5 * height_m, 0),
28  Vector_t(center_m[0] - 0.5 * width_m, center_m[1] + 0.5 * height_m, 0),
29  Vector_t(center_m[0] - 0.5 * width_m, center_m[1] - 0.5 * height_m, 0),
30  Vector_t(center_m[0] + 0.5 * width_m, center_m[1] - 0.5 * height_m, 0)});
31  unsigned int width = out.precision() + 8;
32  for (unsigned int i = 0; i < 5; ++ i) {
33  Vector_t & pt = pts[i % 4];
34 
35  out << std::setw(width) << pt[0]
36  << std::setw(width) << pt[1]
37  << std::endl;
38  }
39  out << std::endl;
40  }
41 
42  void BoundingBox::print(std::ostream &out) const {
43  out << std::setw(18) << center_m[0] - 0.5 * width_m
44  << std::setw(18) << center_m[1] - 0.5 * height_m
45  << std::setw(18) << center_m[0] + 0.5 * width_m
46  << std::setw(18) << center_m[1] + 0.5 * height_m
47  << std::endl;
48  }
49 
50  std::ostream & operator<< (std::ostream &out, const BoundingBox &bb) {
51  bb.print(out);
52  return out;
53  }
54 }
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
void print(std::ostream &out) const
Definition: BoundingBox.cpp:42
Definition: rbendmap.h:8
bool isInside(const Vector_t &X) const
Definition: BoundingBox.cpp:11
virtual void writeGnuplot(std::ostream &out) const
Definition: BoundingBox.cpp:26
Vektor< double, 3 > Vector_t
Definition: Vektor.h:6
std::ostream & operator<<(std::ostream &out, const BoundingBox &bb)
Definition: BoundingBox.cpp:50
bool doesIntersect(const BoundingBox &bb) const
Definition: BoundingBox.cpp:4
Inform & endl(Inform &inf)
Definition: Inform.cpp:42