OSVR-Core
Rect.h
Go to the documentation of this file.
1 
11 // Copyright 2015 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 #ifndef INCLUDED_Rect_h_GUID_A81C8929_371D_4EBC_C6BB_A7264EF642E6
26 #define INCLUDED_Rect_h_GUID_A81C8929_371D_4EBC_C6BB_A7264EF642E6
27 
28 // Internal Includes
29 // - none
30 
31 // Library/third-party includes
32 // - none
33 
34 // Standard includes
35 #include <array>
36 
37 namespace osvr {
38 namespace util {
39  template <typename Scalar = double> class Rect {
40  public:
41  typedef Rect type;
42  typedef Scalar value_type;
43  enum Side { LEFT = 0, RIGHT = 1, TOP = 2, BOTTOM = 3 };
44 
46  value_type &operator[](Side s) {
47  return m_data[static_cast<index_type>(s)];
48  }
49  value_type operator[](Side s) const {
50  return m_data[static_cast<index_type>(s)];
51  }
52 
54  type &operator()(Side s, value_type v) {
55  (*this)[s] = v;
56  return *this;
57  }
58 
60  type &operator*=(Scalar v) {
61  for (auto &e : m_data) {
62  e *= v;
63  }
64  return *this;
65  }
66 
67  private:
68  typedef std::array<Scalar, 4> storage_type;
69  typedef std::size_t index_type;
70  storage_type m_data;
71  };
72  typedef Rect<> Rectd;
73 
74  template <typename StreamType, typename Scalar>
75  StreamType &operator<<(StreamType &os, Rect<Scalar> const &rect) {
76  typedef Rect<Scalar> R;
77  os << "L: " << rect[R::LEFT];
78  os << " R: " << rect[R::RIGHT];
79  os << " T: " << rect[R::TOP];
80  os << " B: " << rect[R::BOTTOM];
81  return os;
82  }
83 } // namespace util
84 } // namespace osvr
85 
86 #endif // INCLUDED_Rect_h_GUID_A81C8929_371D_4EBC_C6BB_A7264EF642E6
Definition: RunLoopManager.h:42
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
type & operator()(Side s, value_type v)
Chained function call operator for setting sides.
Definition: Rect.h:54
Definition: Rect.h:39
type & operator*=(Scalar v)
Componentwise multiplication by scalar.
Definition: Rect.h:60
value_type & operator[](Side s)
Access by side.
Definition: Rect.h:46