Virtual Testbed
Ship dynamics simulator for extreme conditions
rectangle.hh
1 #ifndef VTESTBED_GEOMETRY_RECTANGLE_HH
2 #define VTESTBED_GEOMETRY_RECTANGLE_HH
3 
4 #include <array>
5 
6 #include <vtestbed/geometry/types.hh>
7 
8 namespace vtb {
9 
10  namespace geometry {
11 
12  template <class T, int N>
13  class Rectangle: public std::array<Vertex<T,N>,2> {
14 
15  private:
17 
18  public:
19  static constexpr const int dimensions = N;
20  using scalar_type = T;
21  using value_type = typename base_type::value_type;
22  using pointer = typename base_type::pointer;
23  using const_pointer = typename base_type::const_pointer;
24  using reference = typename base_type::reference;
25  using const_reference = typename base_type::const_reference;
26  using iterator = typename base_type::iterator;
27  using const_iterator = typename base_type::const_iterator;
28  using size_type = typename base_type::size_type;
29  using difference_type = typename base_type::difference_type;
30  using reverse_iterator = typename base_type::reverse_iterator;
31  using const_reverse_iterator = typename base_type::const_reverse_iterator;
32 
33  public:
34  using base_type::base_type;
35  using base_type::operator=;
36  using base_type::operator[];
37 
38 
39  inline explicit
40  Rectangle(const_reference p0, const_reference p1):
41  base_type{p0,p1} {}
42 
43  inline value_type
44  extent() const {
45  return this->back() - this->front();
46  }
47 
48  inline const_reference min() const { return this->front(); }
49  inline const_reference max() const { return this->back(); }
50  inline reference min() { return this->front(); }
51  inline reference max() { return this->back(); }
52  inline void clear() { this->front() = T{}, this->back() = T{}; }
53 
54  };
55 
56  template <class T, int N>
57  inline Vertex<T,N>
58  centroid(const Rectangle<T,N>& r) {
59  return (r[0]+r[1])*T{0.5};
60  }
61 
62  template <class T, int N>
63  inline Vertex<T,N>
64  area(const Rectangle<T,N>& r) {
65  return product(r[1] - r[0]);
66  }
67 
68  }
69 
70 }
71 
72 #endif // vim:filetype=cpp
Main namespace.
Definition: convert.hh:9