OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
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
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<double, 3>(b.width_m, b.height_m, 0.0))
41 && isInside(b.center_m + 0.5 * Vector_t<double, 3>(-b.width_m, b.height_m, 0.0))
42 && isInside(b.center_m + 0.5 * Vector_t<double, 3>(-b.width_m, -b.height_m, 0.0))
43 && isInside(b.center_m + 0.5 * Vector_t<double, 3>(b.width_m, -b.height_m, 0.0)));
44 }
45
46 void BoundingBox2D::writeGnuplot(std::ostream& out) const {
47 std::vector<Vector_t<double, 3>> pts(
48 {Vector_t<double, 3>(center_m[0] + 0.5 * width_m, center_m[1] + 0.5 * height_m, 0),
49 Vector_t<double, 3>(center_m[0] - 0.5 * width_m, center_m[1] + 0.5 * height_m, 0),
50 Vector_t<double, 3>(center_m[0] - 0.5 * width_m, center_m[1] - 0.5 * height_m, 0),
52 center_m[0] + 0.5 * width_m, center_m[1] - 0.5 * height_m, 0)});
53 unsigned int width = out.precision() + 8;
54 for (unsigned int i = 0; i < 5; ++i) {
55 Vector_t<double, 3>& pt = pts[i % 4];
56
57 out << std::setw(width) << pt[0] << std::setw(width) << pt[1] << 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 << std::setw(18)
64 << center_m[1] - 0.5 * height_m << std::setw(18) << center_m[0] + 0.5 * width_m
65 << std::setw(18) << center_m[1] + 0.5 * height_m << std::endl;
66 }
67
68 std::ostream& operator<<(std::ostream& out, const BoundingBox2D& bb) {
69 bb.print(out);
70 return out;
71 }
72} // namespace mslang
ippl::Vector< T, Dim > Vector_t
std::ostream & operator<<(std::ostream &out, const BoundingBox2D &bb)
Vector_t< double, 3 > center_m
void print(std::ostream &out) const
bool isInside(const Vector_t< double, 3 > &X) const
virtual void writeGnuplot(std::ostream &out) const
bool doesIntersect(const BoundingBox2D &bb) const