Dune-Fufem 2.11-git
Loading...
Searching...
No Matches
box.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright © DUNE-FUFEM Project contributors, see file AUTHORS.md
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
3
4#ifndef BOX_HH
5#define BOX_HH
6
9template<typename CoordType, int dim>
10class Box
11{
12public:
13
15 {}
16
17 Box(const CoordType& lower, const CoordType& upper) : lower_(lower), upper_(upper)
18 {
19 for (int i = 0; i < dim; ++i)
20 center_[i] = 0.5*(upper_[i]+lower_[i]);
21 }
22
23 Box(const Box& b) : lower_(b.lower_), upper_(b.upper_)
24 {
25 for (int i = 0; i < dim; ++i)
26 center_[i] = 0.5*(upper_[i]+lower_[i]);
27 }
28
29 bool contains(const CoordType& c) const
30 {
31 for (int i = 0; i < dim; ++i)
32 if (c[i] < this->lower_[i] || c[i] >= this->upper_[i])
33 return false;
34 return true;
35 }
36
37 bool intersects(const Box& b)
38 {
39 for (int i = 0; i < dim; ++i)
40 if (this->lower_[i] >= b.upper_[i] || b.lower_[i] >= this->upper_[i])
41 return false;
42 return true;
43 }
44
45 const CoordType& center() const
46 {
47 return this->center_;
48 }
49
50
51 double size(int i)
52 {
53 return upper_[i]-lower_[i];
54 }
55
56 const CoordType& lower() const
57 {
58 return lower_;
59 }
60
61 const CoordType& upper() const
62 {
63 return upper_;
64 }
65
66protected:
67 CoordType lower_;
68 CoordType upper_;
69 CoordType center_;
70};
71
72
73#endif
size_type dim() const
Simple Box class.
Definition box.hh:11
CoordType lower_
Definition box.hh:67
Box(const CoordType &lower, const CoordType &upper)
Definition box.hh:17
Box(const Box &b)
Definition box.hh:23
CoordType center_
Definition box.hh:69
~Box()
Definition box.hh:14
CoordType upper_
Definition box.hh:68
bool intersects(const Box &b)
Definition box.hh:37
const CoordType & lower() const
Definition box.hh:56
const CoordType & center() const
Definition box.hh:45
bool contains(const CoordType &c) const
Definition box.hh:29
const CoordType & upper() const
Definition box.hh:61
double size(int i)
Definition box.hh:51