OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
BoundingBox2D.cpp
Go to the documentation of this file.
1//
2// Class BoundingBox2D
3//
4// This class provides functionality to compute bounding boxes, to compute if a position
5// is inside the box.
6//
7// Copyright (c) 2018 - 2021, Christof Metzger-Kraus
8//
9// All rights reserved
10//
11// This file is part of OPAL.
12//
13// OPAL is free software: you can redistribute it and/or modify
14// it under the terms of the GNU General Public License as published by
15// the Free Software Foundation, either version 3 of the License, or
16// (at your option) any later version.
17//
18// You should have received a copy of the GNU General Public License
19// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
20//
22
23namespace mslang {
25 return ((center_m[0] - 0.5 * width_m <= bb.center_m[0] + 0.5 * bb.width_m) &&
26 (center_m[0] + 0.5 * width_m >= bb.center_m[0] - 0.5 * bb.width_m) &&
27 (center_m[1] - 0.5 * height_m <= bb.center_m[1] + 0.5 * bb.height_m) &&
28 (center_m[1] + 0.5 * height_m >= bb.center_m[1] - 0.5 * bb.height_m));
29 }
30
31 bool BoundingBox2D::isInside(const Vector_t &X) const {
32 if (2 * std::abs(X[0] - center_m[0]) <= width_m &&
33 2 * std::abs(X[1] - center_m[1]) <= height_m)
34 return true;
35
36 return false;
37 }
38
40 return (isInside(b.center_m + 0.5 * Vector_t( b.width_m, b.height_m, 0.0)) &&
41 isInside(b.center_m + 0.5 * Vector_t(-b.width_m, b.height_m, 0.0)) &&
42 isInside(b.center_m + 0.5 * Vector_t(-b.width_m, -b.height_m, 0.0)) &&
43 isInside(b.center_m + 0.5 * Vector_t( b.width_m, -b.height_m, 0.0)));
44 }
45
46 void BoundingBox2D::writeGnuplot(std::ostream &out) const {
47 std::vector<Vector_t> pts({Vector_t(center_m[0] + 0.5 * width_m, center_m[1] + 0.5 * height_m, 0),
48 Vector_t(center_m[0] - 0.5 * width_m, center_m[1] + 0.5 * height_m, 0),
49 Vector_t(center_m[0] - 0.5 * width_m, center_m[1] - 0.5 * height_m, 0),
50 Vector_t(center_m[0] + 0.5 * width_m, center_m[1] - 0.5 * height_m, 0)});
51 unsigned int width = out.precision() + 8;
52 for (unsigned int i = 0; i < 5; ++ i) {
53 Vector_t & pt = pts[i % 4];
54
55 out << std::setw(width) << pt[0]
56 << std::setw(width) << pt[1]
57 << std::endl;
58 }
59 out << std::endl;
60 }
61
62 void BoundingBox2D::print(std::ostream &out) const {
63 out << std::setw(18) << center_m[0] - 0.5 * width_m
64 << std::setw(18) << center_m[1] - 0.5 * height_m
65 << std::setw(18) << center_m[0] + 0.5 * width_m
66 << std::setw(18) << center_m[1] + 0.5 * height_m
67 << std::endl;
68 }
69
70 std::ostream & operator<< (std::ostream &out, const BoundingBox2D &bb) {
71 bb.print(out);
72 return out;
73 }
74}
#define X(arg)
Definition: fftpack.cpp:112
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
std::ostream & operator<<(std::ostream &out, const BoundingBox2D &bb)
void print(std::ostream &out) const
bool isInside(const Vector_t &X) const
virtual void writeGnuplot(std::ostream &out) const
bool doesIntersect(const BoundingBox2D &bb) const
Vektor< double, 3 > Vector_t
Definition: Vektor.h:6