41 #ifndef __H__COMMON__MATH_VECTOR__
42 #define __H__COMMON__MATH_VECTOR__
47 #include "../../ug_config.h"
48 #include "../../types.h"
65 template <std::
size_t N,
typename T = number>
class MathVector;
71 template <std::
size_t fromN, std::
size_t toN,
typename T>
75 static const size_t minN = std::min(toN, fromN);
76 static const size_t maxN = std::max(toN, fromN);
77 for(
size_t i = 0; i < minN; ++i)
79 for(
size_t i = minN; i < maxN; ++i)
84 template <std::
size_t N,
typename T>
95 template <std::
size_t N,
typename T>
101 static const std::size_t
Size = N;
108 template <std::
size_t fromN>
111 return MathVectorFrom<fromN, N, T>(v);
139 inline std::size_t
size()
const {
return N;}
161 template <
typename T>
167 static const std::size_t
Size = 1;
182 template <std::
size_t fromN>
185 return MathVectorFrom<0, fromN, T>(v);
206 inline std::size_t
size()
const {
return 1;}
228 template <
typename T>
234 static const std::size_t
Size = 1;
246 template <std::
size_t fromN>
249 return MathVectorFrom<1, fromN, T>(v);
270 inline std::size_t
size()
const {
return 1;}
292 template <
typename T>
298 static const std::size_t
Size = 2;
315 template <std::
size_t fromN>
318 return MathVectorFrom<2, fromN, T>(v);
339 inline std::size_t
size()
const {
return 2;}
364 template <
typename T>
370 static const std::size_t
Size = 3;
388 template <std::
size_t fromN>
391 return MathVectorFrom<3, fromN, T>(v);
412 inline std::size_t
size()
const {
return 3;}
442 template <
typename T>
448 static const std::size_t
Size = 4;
467 template <std::
size_t fromN>
470 return MathVectorFrom<4, fromN, T>(v);
491 inline std::size_t
size()
const {
return 4;}
522 template <std::
size_t N,
typename T>
525 for(std::size_t i = 0; i < N; ++i)
527 if(v[i] != w[i])
return false;
532 template <
typename T>
540 template <std::
size_t N,
typename T>
543 for(std::size_t i = 0; i < N; ++i)
545 if(v[i] < w[i] -
SMALL)
return true;
546 else if(v[i] > w[i] +
SMALL)
return false;
551 template <std::
size_t N,
typename T>
557 template <std::
size_t N,
typename T>
560 for(std::size_t i = 0; i < N; ++i)
561 outStream <<
"[" << i <<
"]: " << v.
coord(i) << std::endl;
565 template <
typename T>
568 outStream <<
"(empty)";
572 template <
typename T>
575 outStream <<
"(" << v[0] <<
")";
578 template <
typename T>
581 outStream <<
"("<<v[0]<<
", "<<v[1]<<
")";
584 template <
typename T>
587 outStream <<
"("<<v[0]<<
", "<<v[1]<<
", "<<v[2]<<
")";
590 template <
typename T>
593 outStream <<
"("<<v[0]<<
", "<<v[1]<<
", "<<v[2]<<
", "<<v[3]<<
")";
612 template <
class TStream, std::
size_t N,
class T>
615 out.write((
char*)val.
m_data,
sizeof(T) * N);
618 template <
class TStream, std::
size_t N,
class T>
621 out.read((
char*)valOut.
m_data,
sizeof(T) * N);
Definition: math_vector.h:163
const value_type & x() const
Definition: math_vector.h:217
static MathVector from(const MathVector< 4, T > &v)
Definition: math_vector.h:181
MathVector(const MathVector< 0, T > &v)
Definition: math_vector.h:175
value_type & operator[](std::size_t index)
Definition: math_vector.h:211
static MathVector from(const MathVector< 3, T > &v)
Definition: math_vector.h:180
std::size_t size_type
Definition: math_vector.h:165
std::size_t size() const
Definition: math_vector.h:206
value_type & coord(std::size_t index)
Definition: math_vector.h:208
MathVector(value_type x)
Definition: math_vector.h:171
value_type coord(std::size_t index) const
Definition: math_vector.h:209
MathVector()
Definition: math_vector.h:170
static MathVector from(const MathVector< fromN, T > &v)
Definition: math_vector.h:183
static MathVector from(const MathVector< 1, T > &v)
Definition: math_vector.h:178
T value_type
Definition: math_vector.h:166
void assign(const MathVector< 0, T > &v)
Definition: math_vector.h:221
const value_type & operator[](std::size_t index) const
Definition: math_vector.h:212
static MathVector from(const MathVector< 0, T > &v)
Definition: math_vector.h:177
static MathVector from(const MathVector< 2, T > &v)
Definition: math_vector.h:179
value_type & x()
Definition: math_vector.h:216
value_type m_data[1]
Definition: math_vector.h:219
void set_coord(std::size_t index, value_type v)
Definition: math_vector.h:214
Definition: math_vector.h:230
static MathVector from(const MathVector< 4, T > &v)
Definition: math_vector.h:245
static MathVector from(const MathVector< 1, T > &v)
Definition: math_vector.h:242
void set_coord(std::size_t index, value_type v)
Definition: math_vector.h:278
std::size_t size_type
Definition: math_vector.h:232
value_type & operator[](std::size_t index)
Definition: math_vector.h:275
MathVector(value_type x)
Definition: math_vector.h:238
void assign(const MathVector< 1, T > &v)
Definition: math_vector.h:285
value_type & coord(std::size_t index)
Definition: math_vector.h:272
const value_type & x() const
Definition: math_vector.h:281
value_type coord(std::size_t index) const
Definition: math_vector.h:273
static MathVector from(const MathVector< 2, T > &v)
Definition: math_vector.h:243
static MathVector from(const MathVector< 3, T > &v)
Definition: math_vector.h:244
static MathVector from(const MathVector< 0, T > &v)
Definition: math_vector.h:241
T value_type
Definition: math_vector.h:233
value_type & x()
Definition: math_vector.h:280
MathVector(const MathVector< 1, T > &v)
Definition: math_vector.h:239
const value_type & operator[](std::size_t index) const
Definition: math_vector.h:276
MathVector()
Definition: math_vector.h:237
std::size_t size() const
Definition: math_vector.h:270
static MathVector from(const MathVector< fromN, T > &v)
Definition: math_vector.h:247
value_type m_data[1]
Definition: math_vector.h:283
Definition: math_vector.h:294
value_type & operator[](std::size_t index)
Definition: math_vector.h:344
std::size_t size_type
Definition: math_vector.h:296
T value_type
Definition: math_vector.h:297
static MathVector from(const MathVector< 1, T > &v)
Definition: math_vector.h:311
value_type & x()
Definition: math_vector.h:349
static MathVector from(const MathVector< 0, T > &v)
Definition: math_vector.h:310
void assign(const MathVector< 2, T > &v)
Definition: math_vector.h:357
MathVector()
Definition: math_vector.h:301
static MathVector from(const MathVector< 2, T > &v)
Definition: math_vector.h:312
static MathVector from(const MathVector< 4, T > &v)
Definition: math_vector.h:314
MathVector(value_type x, value_type y)
Definition: math_vector.h:303
value_type & y()
Definition: math_vector.h:352
value_type m_data[2]
Definition: math_vector.h:355
const value_type & operator[](std::size_t index) const
Definition: math_vector.h:345
MathVector(const value_type &val)
Definition: math_vector.h:302
static MathVector from(const MathVector< fromN, T > &v)
Definition: math_vector.h:316
std::size_t size() const
Definition: math_vector.h:339
static MathVector from(const MathVector< 3, T > &v)
Definition: math_vector.h:313
value_type coord(std::size_t index) const
Definition: math_vector.h:342
const value_type & y() const
Definition: math_vector.h:353
void set_coord(std::size_t index, value_type v)
Definition: math_vector.h:347
MathVector(const MathVector< 2, T > &v)
Definition: math_vector.h:308
const value_type & x() const
Definition: math_vector.h:350
value_type & coord(std::size_t index)
Definition: math_vector.h:341
Definition: math_vector.h:366
value_type m_data[3]
Definition: math_vector.h:431
MathVector(value_type x, value_type y, value_type z)
Definition: math_vector.h:375
static MathVector from(const MathVector< fromN, T > &v)
Definition: math_vector.h:389
const value_type & z() const
Definition: math_vector.h:429
static MathVector from(const MathVector< 3, T > &v)
Definition: math_vector.h:386
void set_coord(std::size_t index, value_type v)
Definition: math_vector.h:420
const value_type & operator[](std::size_t index) const
Definition: math_vector.h:418
value_type & coord(std::size_t index)
Definition: math_vector.h:414
const value_type & x() const
Definition: math_vector.h:423
static MathVector from(const MathVector< 1, T > &v)
Definition: math_vector.h:384
T value_type
Definition: math_vector.h:369
MathVector(const MathVector< 3, T > &v)
Definition: math_vector.h:381
value_type & operator[](std::size_t index)
Definition: math_vector.h:417
void assign(const MathVector< 3, T > &v)
Definition: math_vector.h:433
MathVector()
Definition: math_vector.h:373
static MathVector from(const MathVector< 2, T > &v)
Definition: math_vector.h:385
value_type & y()
Definition: math_vector.h:425
value_type & z()
Definition: math_vector.h:428
const value_type & y() const
Definition: math_vector.h:426
static MathVector from(const MathVector< 0, T > &v)
Definition: math_vector.h:383
MathVector(const value_type &val)
Definition: math_vector.h:374
std::size_t size() const
Definition: math_vector.h:412
static MathVector from(const MathVector< 4, T > &v)
Definition: math_vector.h:387
value_type & x()
Definition: math_vector.h:422
std::size_t size_type
Definition: math_vector.h:368
value_type coord(std::size_t index) const
Definition: math_vector.h:415
Definition: math_vector.h:444
MathVector(value_type x, value_type y, value_type z, value_type w)
Definition: math_vector.h:453
value_type coord(std::size_t index) const
Definition: math_vector.h:494
value_type & x()
Definition: math_vector.h:501
void set_coord(std::size_t index, value_type v)
Definition: math_vector.h:499
T value_type
Definition: math_vector.h:447
value_type & z()
Definition: math_vector.h:507
MathVector(const value_type &val)
Definition: math_vector.h:452
static MathVector from(const MathVector< 4, T > &v)
Definition: math_vector.h:466
static MathVector from(const MathVector< 2, T > &v)
Definition: math_vector.h:464
static MathVector from(const MathVector< 0, T > &v)
Definition: math_vector.h:462
const value_type & y() const
Definition: math_vector.h:505
MathVector()
Definition: math_vector.h:451
static MathVector from(const MathVector< fromN, T > &v)
Definition: math_vector.h:468
const value_type & x() const
Definition: math_vector.h:502
const value_type & operator[](std::size_t index) const
Definition: math_vector.h:497
value_type m_data[4]
Definition: math_vector.h:513
MathVector(const MathVector< 4, T > &v)
Definition: math_vector.h:460
static MathVector from(const MathVector< 1, T > &v)
Definition: math_vector.h:463
const value_type & z() const
Definition: math_vector.h:508
std::size_t size() const
Definition: math_vector.h:491
value_type & w()
Definition: math_vector.h:510
std::size_t size_type
Definition: math_vector.h:446
value_type & coord(std::size_t index)
Definition: math_vector.h:493
value_type & operator[](std::size_t index)
Definition: math_vector.h:496
const value_type & w() const
Definition: math_vector.h:511
static MathVector from(const MathVector< 3, T > &v)
Definition: math_vector.h:465
void assign(const MathVector< 4, T > &v)
Definition: math_vector.h:515
value_type & y()
Definition: math_vector.h:504
a mathematical Vector with N entries.
Definition: math_vector.h:97
MathVector(const MathVector &v)
Definition: math_vector.h:106
MathVector(const value_type &val)
Definition: math_vector.h:105
MathVector & operator*=(const value_type &val)
Definition: math_vector.h:130
value_type m_data[N]
Definition: math_vector.h:150
MathVector()
Definition: math_vector.h:104
MathVector & operator=(const MathVector &v)
Definition: math_vector.h:115
MathVector & operator-=(const MathVector &v)
Definition: math_vector.h:124
void set_coord(std::size_t index, value_type v)
Definition: math_vector.h:147
MathVector & operator+=(const MathVector &v)
Definition: math_vector.h:123
value_type operator*(const MathVector &v) const
Definition: math_vector.h:137
T value_type
Definition: math_vector.h:99
value_type coord(size_t index) const
Definition: math_vector.h:142
static MathVector from(const MathVector< fromN, T > &v)
Definition: math_vector.h:109
value_type & coord(size_t index)
Definition: math_vector.h:141
value_type & operator[](size_t index)
Definition: math_vector.h:144
MathVector operator-() const
Definition: math_vector.h:134
void assign(const MathVector< N > &v)
Definition: math_vector.h:153
const value_type & operator[](size_t index) const
Definition: math_vector.h:145
MathVector & operator/=(const value_type &val)
Definition: math_vector.h:131
std::size_t size_type
Definition: math_vector.h:100
static const std::size_t Size
Definition: math_vector.h:101
std::size_t size() const
Definition: math_vector.h:139
std::ostream & operator<<(std::ostream &outStream, const ug::MathMatrix< 2, 2 > &m)
Definition: math_matrix.cpp:38
#define UG_API
Definition: ug_config.h:65
std::ostream & write_plain_txt(std::ostream &outStream, const ug::MathVector< 1 > &v)
plain text output of MathVector objects: space-separated coordinates
Definition: math_vector.cpp:67
MathVector< toN, T > MathVectorFrom(const MathVector< fromN, T > &v)
helper method which creates a vector from another vector of different dimensionality
Definition: math_vector.h:72
bool operator==(const MathVector< N, T > &v, const MathVector< N, T > &w)
Definition: math_vector.h:523
std::istream & read_plain_txt(std::istream &inStream, ug::MathVector< 1 > &v)
plain text input of MathVectors: read space-separated coordinates
Definition: math_vector.cpp:95
bool operator<(const MathVector< N, T > &v, const MathVector< N, T > &w)
Definition: math_vector.h:541
bool operator!=(const MathVector< N, T > &v, const MathVector< N, T > &w)
Definition: math_vector.h:552
const number SMALL
Definition: math_constants.h:41
void Deserialize(TIStream &buf, ParallelVector< T > &v)
Deerialize for ParallelVector<T>
Definition: restart_bridge.cpp:112
void Serialize(TOStream &buf, const ParallelVector< T > &v)
Serialize for ParallelVector<T>
Definition: restart_bridge.cpp:103