 |
Shiokaze Framework
A research-oriented fluid solver for computer graphics
|
|
Go to the documentation of this file.
36 template <
class T,
unsigned D>
struct vec {
50 for(
unsigned dim=0; dim<D; ++dim ) this->v[dim] = T();
58 template<
class Y>
vec(
const Y *
v ) {
59 for(
unsigned dim=0; dim<D; ++dim ) this->v[dim] =
v[dim];
68 for(
unsigned dim=0; dim<D; ++dim ) this->v[dim] =
v.v[dim];
77 for(
unsigned dim=0; dim<D; ++dim ) this->v[dim] =
v;
103 v[0] = x;
v[1] = y;
v[2] = z;
134 for(
unsigned dim=0; dim<D; ++dim )
if(
v[dim] )
return false;
144 for(
unsigned dim=0; dim<D; ++dim )
if( this->v[dim] !=
v[dim])
return false;
154 return ! (*
this ==
v);
165 struct vec result(*
this);
166 for(
unsigned dim=0; dim<D; ++dim ) result[dim] +=
v[dim];
178 struct vec result(*
this);
179 for(
unsigned dim=0; dim<D; ++dim ) result[dim] -=
v[dim];
189 for(
unsigned dim=0; dim<D; ++dim ) this->v[dim] +=
v[dim];
198 for(
unsigned dim=0; dim<D; ++dim ) this->v[dim] -=
v[dim];
209 struct vec result(*
this);
210 for(
unsigned dim=0; dim<D; ++dim ) result[dim] *= s;
222 struct vec result(*
this);
223 for(
unsigned dim=0; dim<D; ++dim ) result[dim] /= s;
233 for(
unsigned dim=0; dim<D; ++dim )
v[dim] *= s;
242 for(
unsigned dim=0; dim<D; ++dim )
v[dim] /= s;
254 for(
unsigned dim=0; dim<D; ++dim ) result += this->v[dim]*
v[dim];
265 for(
unsigned dim=0; dim<D; ++dim ) result += this->v[dim]*this->v[dim];
276 for(
unsigned dim=0; dim<D; ++dim ) result = std::max(result,(
double)std::abs(this->v[dim]));
286 return sqrt(
norm2());
306 for(
unsigned dim=0; dim<D; ++dim )
v[dim] /= length;
333 return v[0]*r[1]-
v[1]*r[0];
345 return vec<T,3>(
v[1]*r[2]-
v[2]*r[1],
v[2]*r[0]-
v[0]*r[2],
v[0]*r[1]-
v[1]*r[0]);
355 for(
int dim=0; dim<D; ++dim ) result[dim] =
v[dim]+0.5;
366 for(
int dim=0; dim<D; ++dim ) result[dim] =
v[dim];
379 for(
int _dim=0; _dim<D; ++_dim ) result[_dim] =
v[_dim]+0.5*(dim!=_dim);
392 return vec<Y,3>(
v[0]+0.5*(dim==0),
v[1]+0.5*(dim==1),
v[2]+0.5*(dim==2));
395 template <
class T,
class Y>
static inline T operator^(
const vec<T,2> &l,
const vec<Y,2> &r) {
bool operator==(const vec &v) const
Get if the vector is equal to the input vector.
Definition: vec.h:143
vec< T, 3 > cross(const vec< Y, 3 > &r) const
Compute the cross product for three dimensions.
Definition: vec.h:343
T cross2(const vec< Y, 2 > &r) const
Compute the cross product for two dimensions.
Definition: vec.h:331
const T & operator[](unsigned idx) const
Get the value at a specified dimension.
Definition: vec.h:113
bool empty() const
Get if all the elements in the vector is empty.
Definition: vec.h:133
vec< T, D > operator-(const vec< Y, D > &v) const
Subtract a vector.
Definition: vec.h:177
void operator-=(const vec< Y, D > &v)
Subtract a vector.
Definition: vec.h:197
vec< Y, D > edge(int dim) const
Compute the position of the center of edge position from the index space.
Definition: vec.h:390
vec(T x, T y, T z)
Constructor for three dimensional vector.
Definition: vec.h:101
T v[D]
Vector value array.
Definition: vec.h:44
vec operator*(Y s) const
Multiply a value.
Definition: vec.h:208
vec rotate90() const
Rotate vector 90 degrees counterclockwise.
Definition: vec.h:316
double norm_inf() const
Compute L-inf norm.
Definition: vec.h:274
double len() const
Compute L1 norm.
Definition: vec.h:285
T & operator[](unsigned idx)
Get the reference to the value at a specified dimension.
Definition: vec.h:124
vec normal() const
Compute normalized vector.
Definition: vec.h:294
#define SHKZ_BEGIN_NAMESPACE
Name space beggining definition for shiokaze.
Definition: common.h:39
vec(T x, T y)
Constructor for two dimensional vector.
Definition: vec.h:87
bool normalize()
Normaliz vector.
Definition: vec.h:303
vec(T v)
Constructor.
Definition: vec.h:76
vec< Y, D > face(int dim) const
Compute the position of the center of face position from the index space.
Definition: vec.h:377
vec< Y, D > nodal() const
Compute the position of the nodal position from the index space.
Definition: vec.h:364
vec< T, D > operator+(const vec< Y, D > &v) const
Add a vector.
Definition: vec.h:164
bool operator!=(const vec &v) const
Get if the vector is not equal to the input vector.
Definition: vec.h:153
vec(const vec< Y, D > &v)
Copy constructor.
Definition: vec.h:67
vec operator/(Y s) const
Divide by a value.
Definition: vec.h:221
double norm2() const
Compute L2 norm.
Definition: vec.h:263
Fixed sized vector structure.
Definition: vec.h:38
void operator*=(Y s)
Multiply a value.
Definition: vec.h:232
#define SHKZ_END_NAMESPACE
Name space end definition for shiokaze.
Definition: common.h:44
vec()
Default constructor.
Definition: vec.h:49
void operator+=(const vec< Y, D > &v)
Add a vector.
Definition: vec.h:188
void operator/=(Y s)
Divide by a value.
Definition: vec.h:241
vec< Y, D > cell() const
Compute the position of the center of a cell from the index space.
Definition: vec.h:353
vec(const Y *v)
Copy constructor.
Definition: vec.h:58
T operator*(vec< Y, D > v) const
Compute the dot product.
Definition: vec.h:252