41#ifndef __H__COMMON__MATH_VECTOR__
42#define __H__COMMON__MATH_VECTOR__
47#include "../../ug_config.h"
48#include "../../types.h"
65template <std::
size_t N,
typename T = number>
class MathVector;
71template <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)
84template <std::
size_t N,
typename T>
95template <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;}
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;}
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;}
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;}
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;}
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;}
522template <std::
size_t N,
typename T>
525 for(std::size_t i = 0; i < N; ++i)
527 if(v[i] != w[i])
return false;
540template <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;
551template <std::
size_t N,
typename T>
557template <std::
size_t N,
typename T>
560 for(std::size_t i = 0; i < N; ++i)
561 outStream <<
"[" << i <<
"]: " << v.
coord(i) << std::endl;
568 outStream <<
"(empty)";
575 outStream <<
"(" << v[0] <<
")";
581 outStream <<
"("<<v[0]<<
", "<<v[1]<<
")";
587 outStream <<
"("<<v[0]<<
", "<<v[1]<<
", "<<v[2]<<
")";
593 outStream <<
"("<<v[0]<<
", "<<v[1]<<
", "<<v[2]<<
", "<<v[3]<<
")";
612template <
class TStream, std::
size_t N,
class T>
615 out.write((
char*)val.
m_data,
sizeof(T) * N);
618template <
class TStream, std::
size_t N,
class T>
621 out.read((
char*)valOut.
m_data,
sizeof(T) * N);
static MathVector from(const MathVector< 4, T > &v)
Definition math_vector.h:181
value_type & coord(std::size_t index)
Definition math_vector.h:208
MathVector(const MathVector< 0, T > &v)
Definition math_vector.h:175
const value_type & operator[](std::size_t index) const
Definition math_vector.h:212
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
const value_type & x() const
Definition math_vector.h:217
std::size_t size() const
Definition math_vector.h:206
value_type & x()
Definition math_vector.h:216
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
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
void set_coord(std::size_t index, value_type v)
Definition math_vector.h:214
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
const value_type & operator[](std::size_t index) const
Definition math_vector.h:276
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
value_type & x()
Definition math_vector.h:280
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
const value_type & x() const
Definition math_vector.h:281
MathVector(const MathVector< 1, T > &v)
Definition math_vector.h:239
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
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
value_type & y()
Definition math_vector.h:352
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
const value_type & x() const
Definition math_vector.h:350
const value_type & y() const
Definition math_vector.h:353
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
value_type & coord(std::size_t index)
Definition math_vector.h:341
static MathVector from(const MathVector< 3, T > &v)
Definition math_vector.h:313
const value_type & operator[](std::size_t index) const
Definition math_vector.h:345
value_type coord(std::size_t index) const
Definition math_vector.h:342
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
value_type & operator[](std::size_t index)
Definition math_vector.h:344
value_type & x()
Definition math_vector.h:422
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
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 & z() const
Definition math_vector.h:429
value_type & operator[](std::size_t index)
Definition math_vector.h:417
value_type & z()
Definition math_vector.h:428
static MathVector from(const MathVector< 1, T > &v)
Definition math_vector.h:384
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 & y() const
Definition math_vector.h:426
T value_type
Definition math_vector.h:369
MathVector(const MathVector< 3, T > &v)
Definition math_vector.h:381
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
static MathVector from(const MathVector< 0, T > &v)
Definition math_vector.h:383
MathVector(const value_type &val)
Definition math_vector.h:374
value_type & y()
Definition math_vector.h:425
std::size_t size() const
Definition math_vector.h:412
static MathVector from(const MathVector< 4, T > &v)
Definition math_vector.h:387
std::size_t size_type
Definition math_vector.h:368
value_type coord(std::size_t index) const
Definition math_vector.h:415
const value_type & x() const
Definition math_vector.h:423
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
void set_coord(std::size_t index, value_type v)
Definition math_vector.h:499
const value_type & x() const
Definition math_vector.h:502
T value_type
Definition math_vector.h:447
value_type & y()
Definition math_vector.h:504
value_type & operator[](std::size_t index)
Definition math_vector.h:496
MathVector(const value_type &val)
Definition math_vector.h:452
const value_type & operator[](std::size_t index) const
Definition math_vector.h:497
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 & w() const
Definition math_vector.h:511
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
value_type & w()
Definition math_vector.h:510
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
std::size_t size_type
Definition math_vector.h:446
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 & z()
Definition math_vector.h:507
value_type & coord(std::size_t index)
Definition math_vector.h:493
value_type & x()
Definition math_vector.h:501
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
value_type m_data[N]
Definition math_vector.h:150
MathVector()
Definition math_vector.h:104
void set_coord(std::size_t index, value_type v)
Definition math_vector.h:147
value_type operator*(const MathVector &v) const
Definition math_vector.h:137
MathVector & operator-=(const MathVector &v)
Definition math_vector.h:124
MathVector & operator/=(const value_type &val)
Definition math_vector.h:131
const value_type & operator[](size_t index) const
Definition math_vector.h:145
T value_type
Definition math_vector.h:99
value_type & operator[](size_t index)
Definition math_vector.h:144
MathVector & operator*=(const value_type &val)
Definition math_vector.h:130
value_type coord(size_t index) const
Definition math_vector.h:142
value_type & coord(size_t index)
Definition math_vector.h:141
MathVector & operator+=(const MathVector &v)
Definition math_vector.h:123
static MathVector from(const MathVector< fromN, T > &v)
Definition math_vector.h:109
MathVector & operator=(const MathVector &v)
Definition math_vector.h:115
MathVector operator-() const
Definition math_vector.h:134
void assign(const MathVector< N > &v)
Definition math_vector.h:153
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