stator
A math, geometry, and utility library
box.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2017 Marcus N Campbell Bannerman <[email protected]>
3 
4  This file is part of stator.
5 
6  stator is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  stator is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with stator. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 
22 // stator
23 #include "stator/constants.hpp"
24 #include "stator/config.hpp"
25 
26 namespace stator {
27  namespace geometry {
35  template<typename Scalar, size_t D>
36  class AABox {
37  public:
39  max_(max), min_(min)
40  {}
41 
42  const Vector<Scalar, D>& max() const { return max_; }
43  const Vector<Scalar, D>& min() const { return min_; }
44 
45  Vector<Scalar, D> dimensions() const { return max_ - min_; }
46 
47  protected:
50  };
51 
53  template<typename Scalar, size_t D>
54  Scalar volume(const AABox<Scalar, D>& bb) {
55  auto extent = bb.dimensions();
56  Scalar measure = extent[0];
57  for (size_t i(1); i < D; ++i)
58  measure *= extent[i];
59  return measure;
60  }
61 
63  template<typename Scalar, size_t D>
64  Scalar area(const AABox<Scalar, D>& bb) {
65  auto extent = bb.dimensions();
66  Scalar measure = 0;
67  for (size_t i(0); i < D; ++i)
68  for (size_t j(i+1); j < D; ++j)
69  measure += extent[i] * extent[j];
70  return 2 * measure;
71  }
72  } // namespace geometry
73 } //namespace stator
auto area(const Obj &)
Compute a Hausdorf measure of the boundary/boundaries of an object.
const Vector< Scalar, D > & min() const
Definition: box.hpp:43
auto volume(const Obj &)
Compute a Hausdorf measure of the interior of an object.
Vector< Scalar, D > dimensions() const
Definition: box.hpp:45
Vector< Scalar, D > min_
Definition: box.hpp:49
const Vector< Scalar, D > & max() const
Definition: box.hpp:42
Fundamental typedef&#39;s and macros for stator.
AABox(const Vector< Scalar, D > &max, const Vector< Scalar, D > &min)
Definition: box.hpp:38
An axis-aligned box/block (including its interior volume).
Definition: box.hpp:36
Vector< Scalar, D > max_
Definition: box.hpp:48
The stator library namespace.
Definition: frontpage.dox:243
Matrix< Scalar, D, 1 > Vector
A convenience typedef for a non-aligned Eigen Vector.
Definition: config.hpp:58