LBIBCell
 All Classes Functions Variables Friends Pages
Field.hpp
1 /* Copyright (c) 2013 David Sichau <mail"at"sichau"dot"eu>
2  * 2013-2015 Simon Tanaka <tanakas"at"gmx"dot"ch>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  * THE SOFTWARE.
21  */
22 #ifndef FIELD_HPP
23 #define FIELD_HPP
24 
25 namespace LbmLib {
29 template <typename T>
30 struct Field {
34  explicit Field() : x(0), y(0) {}
35 
42  explicit Field(
43  T xC,
44  T yC) : x(xC),
45  y(yC) {}
46 
50  T x;
54  T y;
55 
62  Field<T>& operator+=(const Field<T>& rhs) {
63  this->x += rhs.x;
64  this->y += rhs.y;
65  return *this;
66  }
67 
74  Field<T>& operator-=(const Field<T>& rhs) {
75  this->x -= rhs.x;
76  this->y -= rhs.y;
77  return *this;
78  }
79 
86  Field<T>& operator*=(const Field<T>& rhs) {
87  this->x *= rhs.x;
88  this->y *= rhs.y;
89  return *this;
90  }
91 
98  Field<T>& operator*=(double rhs) {
99  this->x *= rhs;
100  this->y *= rhs;
101  return *this;
102  }
103 
110  Field<T>& operator/=(double rhs) {
111  this->x /= rhs;
112  this->y /= rhs;
113  return *this;
114  }
115 };
116 
126 template <typename T>
127 inline Field<T> operator+(
128  Field<T> lhs,
129  const Field<T>& rhs) {
130  lhs += rhs;
131  return lhs;
132 }
133 
143 template <typename T>
144 inline Field<T> operator-(
145  Field<T> lhs,
146  const Field<T>& rhs) {
147  lhs -= rhs;
148  return lhs;
149 }
150 
160 template <typename T>
161 inline Field<T> operator*(
162  Field<T> lhs,
163  const Field<T>& rhs) {
164  lhs *= rhs;
165  return lhs;
166 }
167 
177 template <typename T>
178 inline Field<T> operator*(
179  Field<T> lhs,
180  double rhs) {
181  lhs *= rhs;
182  return lhs;
183 }
184 
194 template <typename T>
195 inline Field<T> operator*(
196  double lhs,
197  Field<T> rhs) {
198  rhs *= lhs;
199  return rhs;
200 }
201 
211 template <typename T>
212 inline Field<T> operator/(
213  Field<T> lhs,
214  double rhs) {
215  lhs /= rhs;
216  return lhs;
217 }
218 
228 template <typename T>
229 inline Field<T> operator/(
230  double lhs,
231  Field<T> rhs) {
232  rhs /= lhs;
233  return rhs;
234 }
235 } // end namespace
236 
237 #endif // FIELD_HPP
Field()
Constructor.
Definition: Field.hpp:34
The Field struct Storage of values in x and y direction.
Definition: Field.hpp:30
T x
x the value in x direction
Definition: Field.hpp:50
Field< T > & operator*=(double rhs)
The *= operator.
Definition: Field.hpp:98
Field< T > & operator-=(const Field< T > &rhs)
The -= operator.
Definition: Field.hpp:74
Field< T > & operator+=(const Field< T > &rhs)
The += operator.
Definition: Field.hpp:62
Field< T > & operator*=(const Field< T > &rhs)
The *= operator.
Definition: Field.hpp:86
T y
y the value in y direction
Definition: Field.hpp:54
Field(T xC, T yC)
Construtor.
Definition: Field.hpp:42
Field< T > & operator/=(double rhs)
The /= operator.
Definition: Field.hpp:110