"...gitlab@mmg-gitlab.fjfi.cvut.cz:tnl/tnl-dev.git" did not exist on "fd79794bfe3241c32f7a2257a705b85610ce245f"
Newer
Older
/***************************************************************************
tnlStaticVector.h - description
-------------------
begin : Feb 10, 2014
copyright : (C) 2014 by Tomas Oberhuber
email : tomas.oberhuber@fjfi.cvut.cz
***************************************************************************/
/* See Copyright Notice in tnl/Copyright */
#include <TNL/Arrays/StaticArray.h>
template< int Size, typename Real = double >
class tnlStaticVector : public Arrays::tnlStaticArray< Size, Real >
{
public:
typedef Real RealType;
enum { size = Size };
tnlStaticVector();
tnlStaticVector( const Real v[ Size ] );
//! This sets all vector components to v
tnlStaticVector( const Real& v );
//! Copy constructor
tnlStaticVector( const tnlStaticVector< Size, Real >& v );
static String getType();
//! Adding operator
tnlStaticVector& operator += ( const tnlStaticVector& v );
//! Subtracting operator
tnlStaticVector& operator -= ( const tnlStaticVector& v );
//! Multiplication with number
tnlStaticVector& operator *= ( const Real& c );
tnlStaticVector operator + ( const tnlStaticVector& u ) const;
tnlStaticVector operator - ( const tnlStaticVector& u ) const;
//! Multiplication with number
tnlStaticVector operator * ( const Real& c ) const;
//! Scalar product
Real operator * ( const tnlStaticVector& u ) const;
bool operator < ( const tnlStaticVector& v ) const;
bool operator <= ( const tnlStaticVector& v ) const;
bool operator > ( const tnlStaticVector& v ) const;
bool operator >= ( const tnlStaticVector& v ) const;
template< typename OtherReal >
__cuda_callable__
operator tnlStaticVector< Size, OtherReal >() const;
};
template< typename Real >
class tnlStaticVector< 1, Real > : public Arrays::tnlStaticArray< 1, Real >
{
public:
typedef Real RealType;
enum { size = 1 };
tnlStaticVector();
//! This sets all vector components to v
tnlStaticVector( const Real& v );
//! Copy constructor
tnlStaticVector( const tnlStaticVector< 1, Real >& v );
static String getType();
tnlStaticVector& operator += ( const tnlStaticVector& v );
tnlStaticVector& operator -= ( const tnlStaticVector& v );
//! Multiplication with number
tnlStaticVector& operator *= ( const Real& c );
tnlStaticVector operator + ( const tnlStaticVector& u ) const;
tnlStaticVector operator - ( const tnlStaticVector& u ) const;
//! Multiplication with number
tnlStaticVector operator * ( const Real& c ) const;
//! Scalar product
Real operator * ( const tnlStaticVector& u ) const;
bool operator < ( const tnlStaticVector& v ) const;
bool operator <= ( const tnlStaticVector& v ) const;
bool operator > ( const tnlStaticVector& v ) const;
bool operator >= ( const tnlStaticVector& v ) const;
template< typename OtherReal >
__cuda_callable__
operator tnlStaticVector< 1, OtherReal >() const;
};
template< typename Real >
class tnlStaticVector< 2, Real > : public Arrays::tnlStaticArray< 2, Real >
{
public:
typedef Real RealType;
enum { size = 2 };
tnlStaticVector();
tnlStaticVector( const Real v[ 2 ] );
//! This sets all vector components to v
tnlStaticVector( const Real& v );
tnlStaticVector( const Real& v1, const Real& v2 );
//! Copy constructor
tnlStaticVector( const tnlStaticVector< 2, Real >& v );
static String getType();
//! Adding operator
tnlStaticVector& operator += ( const tnlStaticVector& v );
//! Subtracting operator
tnlStaticVector& operator -= ( const tnlStaticVector& v );
//! Multiplication with number
tnlStaticVector& operator *= ( const Real& c );
//! Adding operator
tnlStaticVector operator + ( const tnlStaticVector& u ) const;
//! Subtracting operator
tnlStaticVector operator - ( const tnlStaticVector& u ) const;
//! Multiplication with number
tnlStaticVector operator * ( const Real& c ) const;
//! Scalar product
Real operator * ( const tnlStaticVector& u ) const;
bool operator < ( const tnlStaticVector& v ) const;
bool operator <= ( const tnlStaticVector& v ) const;
bool operator > ( const tnlStaticVector& v ) const;
bool operator >= ( const tnlStaticVector& v ) const;
template< typename OtherReal >
__cuda_callable__
operator tnlStaticVector< 2, OtherReal >() const;
};
template< typename Real >
class tnlStaticVector< 3, Real > : public Arrays::tnlStaticArray< 3, Real >
{
public:
typedef Real RealType;
enum { size = 3 };
tnlStaticVector();
tnlStaticVector( const Real v[ 3 ] );
//! This sets all vector components to v
tnlStaticVector( const Real& v );
tnlStaticVector( const Real& v1, const Real& v2, const Real& v3 );
//! Copy constructor
tnlStaticVector( const tnlStaticVector< 3, Real >& v );
static String getType();
tnlStaticVector& operator += ( const tnlStaticVector& v );
tnlStaticVector& operator -= ( const tnlStaticVector& v );
//! Multiplication with number
tnlStaticVector& operator *= ( const Real& c );
tnlStaticVector operator + ( const tnlStaticVector& u ) const;
tnlStaticVector operator - ( const tnlStaticVector& u ) const;
//! Multiplication with number
tnlStaticVector operator * ( const Real& c ) const;
//! Scalar product
Real operator * ( const tnlStaticVector& u ) const;
bool operator < ( const tnlStaticVector& v ) const;
bool operator <= ( const tnlStaticVector& v ) const;
bool operator > ( const tnlStaticVector& v ) const;
bool operator >= ( const tnlStaticVector& v ) const;
template< typename OtherReal >
__cuda_callable__
operator tnlStaticVector< 3, OtherReal >() const;
};
template< int Size, typename Real >
tnlStaticVector< Size, Real > operator * ( const Real& c, const tnlStaticVector< Size, Real >& u );
tnlStaticVector< Size, Real > abs( const tnlStaticVector< Size, Real >& u ) { return u.abs(); };
} // namespace Vectors
#include <TNL/Vectors/StaticVector_impl.h>
#include <TNL/Vectors/StaticVector1D_impl.h>
#include <TNL/Vectors/StaticVector2D_impl.h>
#include <TNL/Vectors/StaticVector3D_impl.h>
namespace Vectors {
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
// TODO: move to some other source file
template< typename Real >
tnlStaticVector< 3, Real > tnlVectorProduct( const tnlStaticVector< 3, Real >& u,
const tnlStaticVector< 3, Real >& v )
{
tnlStaticVector< 3, Real > p;
p[ 0 ] = u[ 1 ] * v[ 2 ] - u[ 2 ] * v[ 1 ];
p[ 1 ] = u[ 2 ] * v[ 0 ] - u[ 0 ] * v[ 2 ];
p[ 2 ] = u[ 0 ] * v[ 1 ] - u[ 1 ] * v[ 0 ];
return p;
};
template< typename Real >
Real tnlScalarProduct( const tnlStaticVector< 2, Real >& u,
const tnlStaticVector< 2, Real >& v )
{
return u[ 0 ] * v[ 0 ] + u[ 1 ] * v[ 1 ];
};
template< typename Real >
Real tnlScalarProduct( const tnlStaticVector< 3, Real >& u,
const tnlStaticVector< 3, Real >& v )
{
return u[ 0 ] * v[ 0 ] + u[ 1 ] * v[ 1 ] + u[ 2 ] * v[ 2 ];
};
template< typename Real >
Real tnlTriangleArea( const tnlStaticVector< 2, Real >& a,
const tnlStaticVector< 2, Real >& b,
const tnlStaticVector< 2, Real >& c )
{
tnlStaticVector< 3, Real > u1, u2;
u1. x() = b. x() - a. x();
u1. y() = b. y() - a. y();
u1. z() = 0.0;
u2. x() = c. x() - a. x();
u2. y() = c. y() - a. y();
u2. z() = 0;
const tnlStaticVector< 3, Real > v = tnlVectorProduct( u1, u2 );
return 0.5 * ::sqrt( tnlScalarProduct( v, v ) );
template< typename Real >
Real tnlTriangleArea( const tnlStaticVector< 3, Real >& a,
const tnlStaticVector< 3, Real >& b,
const tnlStaticVector< 3, Real >& c )
{
tnlStaticVector< 3, Real > u1, u2;
u1. x() = b. x() - a. x();
u1. y() = b. y() - a. y();
u1. z() = 0.0;
u2. x() = c. x() - a. x();
u2. y() = c. y() - a. y();
u2. z() = 0;
const tnlStaticVector< 3, Real > v = tnlVectorProduct( u1, u2 );
return 0.5 * ::sqrt( tnlScalarProduct( v, v ) );
} // namespace Vectors