Commit 8f518b3c authored by Sebastian Eibl's avatar Sebastian Eibl
Browse files

make GenericAABB, Vector2, Vector3, Matrix3 and Quaternion trivially copyable

parent 8d9e0999
Pipeline #11396 passed with stages
in 352 minutes and 46 seconds
......@@ -216,6 +216,7 @@ private:
vector_type minCorner_; /// minimal values
vector_type maxCorner_; /// maximal values
};
static_assert( std::is_trivially_copyable<GenericAABB<real_t>>::value, "GenericAABB<real_t> has to be trivially copyable!");
......
......@@ -95,7 +95,7 @@ private:
public:
//**Constructors*****************************************************************************************************
explicit inline Matrix3();
explicit inline Matrix3() = default;
explicit inline Matrix3( Type init );
explicit inline Matrix3( const Vector3<Type>& a, const Vector3<Type>& b, const Vector3<Type>& c );
explicit inline Matrix3( Type xx, Type xy, Type xz, Type yx, Type yy, Type yz, Type zx, Type zy, Type zz );
......@@ -104,7 +104,7 @@ public:
template< typename Axis, typename Angle >
explicit Matrix3( Vector3<Axis> axis, Angle angle );
inline Matrix3( const Matrix3& m );
inline Matrix3( const Matrix3& m ) = default;
template< typename Other >
inline Matrix3( const Matrix3<Other>& m );
......@@ -122,7 +122,7 @@ public:
/*!\name Operators */
//@{
inline Matrix3& operator= ( Type set );
inline Matrix3& operator= ( const Matrix3& set );
inline Matrix3& operator= ( const Matrix3& set ) = default;
template< typename Other > inline Matrix3& operator= ( const Matrix3<Other>& set );
template< typename Other > inline bool operator==( const Matrix3<Other>& rhs ) const;
template< typename Other > inline bool operator!=( const Matrix3<Other>& rhs ) const;
......@@ -236,17 +236,23 @@ private:
//**Member variables****************************************************************************
/*!\name Member variables */
//@{
Type v_[9]; //!< The nine statically allocated matrix elements.
/*!< Access to the matrix elements is gained via the subscript or function call
operator. The order of the elements is
\f[\left(\begin{array}{*{3}{c}}
0 & 1 & 2 \\
3 & 4 & 5 \\
6 & 7 & 8 \\
\end{array}\right)\f] */
/**
* The nine statically allocated matrix elements.
* Access to the matrix elements is gained via the subscript or function call
* operator. The order of the elements is
* \f[\left(\begin{array}{*{3}{c}}
* 0 & 1 & 2 \\
* 3 & 4 & 5 \\
* 6 & 7 & 8 \\
* \end{array}\right)\f]
**/
Type v_[9] = {Type(1), Type(0), Type(0),
Type(0), Type(1), Type(0),
Type(0), Type(0), Type(1)};
//@}
//*******************************************************************************************************************
};
static_assert( std::is_trivially_copyable<Matrix3<real_t>>::value, "Matrix3<real_t> has to be trivially copyable!");
//**********************************************************************************************************************
......@@ -258,21 +264,6 @@ private:
//
//======================================================================================================================
//**********************************************************************************************************************
/*!\fn Matrix3<Type>::Matrix3()
// \brief The default constructor for Matrix3.
//
// The diagonal matrix elements are initialized with 1, all other elements are initialized
// with 0.
*/
template< typename Type >
inline Matrix3<Type>::Matrix3()
{
v_[0] = v_[4] = v_[8] = Type(1);
v_[1] = v_[2] = v_[3] = v_[5] = v_[6] = v_[7] = Type(0);
}
//**********************************************************************************************************************
//**********************************************************************************************************************
/*!\fn Matrix3<Type>::Matrix3( Type init )
......@@ -392,30 +383,6 @@ Matrix3<Type>::Matrix3( Vector3<Axis> axis, Angle angle )
//**********************************************************************************************************************
//**********************************************************************************************************************
/*!\fn Matrix3<Type>::Matrix3( const Matrix3& m )
// \brief The copy constructor for Matrix3.
//
// \param m Matrix to be copied.
//
// The copy constructor is explicitly defined in order to enable/facilitate NRV optimization.
*/
template< typename Type >
inline Matrix3<Type>::Matrix3( const Matrix3& m )
{
v_[0] = m.v_[0];
v_[1] = m.v_[1];
v_[2] = m.v_[2];
v_[3] = m.v_[3];
v_[4] = m.v_[4];
v_[5] = m.v_[5];
v_[6] = m.v_[6];
v_[7] = m.v_[7];
v_[8] = m.v_[8];
}
//**********************************************************************************************************************
//**********************************************************************************************************************
/*!\fn Matrix3<Type>::Matrix3( const Matrix3<Other>& m )
// \brief Conversion constructor from different Matrix3 instances.
......@@ -514,36 +481,6 @@ inline Matrix3<Type>& Matrix3<Type>::operator=( Type set )
//**********************************************************************************************************************
//**********************************************************************************************************************
/*!\fn Matrix3<Type>& Matrix3<Type>::operator=( const Matrix3& set )
// \brief Copy assignment operator for Matrix3.
//
// \param set Matrix to be copied.
// \return Reference to the assigned matrix.
//
// Explicit definition of a copy assignment operator for performance reasons.
*/
template< typename Type >
inline Matrix3<Type>& Matrix3<Type>::operator=( const Matrix3& set )
{
// This implementation is faster than the synthesized default copy assignment operator and
// faster than an implementation with the C library function 'memcpy' in combination with a
// protection against self-assignment. Additionally, this version goes without a protection
// against self-assignment.
v_[0] = set.v_[0];
v_[1] = set.v_[1];
v_[2] = set.v_[2];
v_[3] = set.v_[3];
v_[4] = set.v_[4];
v_[5] = set.v_[5];
v_[6] = set.v_[6];
v_[7] = set.v_[7];
v_[8] = set.v_[8];
return *this;
}
//**********************************************************************************************************************
//**********************************************************************************************************************
/*!\fn Matrix3<Type>& Matrix3<Type>::operator=( const Matrix3<Other>& set )
// \brief Assignment operator for different Matrix3 instances.
......
......@@ -115,7 +115,7 @@ public:
//**Constructors********************************************************************************
/*!\name Constructors */
//@{
explicit inline Quaternion();
explicit inline Quaternion() = default;
explicit inline Quaternion( Type r, Type i, Type j, Type k );
......@@ -127,7 +127,7 @@ public:
template< typename Other >
explicit inline Quaternion( const Vector3<Other>& euler );
inline Quaternion( const Quaternion& q );
inline Quaternion( const Quaternion& q ) = default;
template< typename Other >
inline Quaternion( const Quaternion<Other>& q );
......@@ -141,7 +141,7 @@ public:
//**Operators***********************************************************************************
/*!\name Operators */
//@{
inline Quaternion& operator= ( const Quaternion& rhs );
inline Quaternion& operator= ( const Quaternion& rhs ) = default;
template< typename Other > inline Quaternion& operator= ( const Quaternion<Other>& rhs );
inline Type operator[]( size_t index ) const;
//@}
......@@ -195,15 +195,20 @@ private:
//**Member variables****************************************************************************
/*!\name Member variables */
//@{
Type v_[4]; //!< The four statically allocated quaternion elements.
/*!< Access to the quaternion values is gained via the subscript operator.
The order of the elements is
\f[\left(\begin{array}{*{4}{c}}
0 & 1 & 2 & 3 \\
\end{array}\right)\f] */
/**
* The four statically allocated quaternion elements.
*
* Access to the quaternion values is gained via the subscript operator.
* The order of the elements is
* \f[\left(\begin{array}{*{4}{c}}
* 0 & 1 & 2 & 3 \\
* \end{array}\right)\f]
**/
Type v_[4] = {Type(1), Type(0), Type(0), Type(0)};
//@}
//**********************************************************************************************
};
static_assert( std::is_trivially_copyable<Quaternion<real_t>>::value, "Quaternion<real_t> has to be trivially copyable!");
//*************************************************************************************************
......@@ -215,21 +220,6 @@ private:
//
//=================================================================================================
//*************************************************************************************************
/*!\brief The default constructor for Quaternion.
*
* The real part of the quaternion is initialized with 1, whereas the imaginary parts are
* initialized with 0:
\f[ \left(\begin{array}{c} 1 \\ 0 \\ 0 \\ 0 \end{array}\right) \f]
*/
template< typename Type > // Data type of the quaternion
inline Quaternion<Type>::Quaternion()
{
reset();
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Constructor for a direct initialization of all quaternion elements.
......@@ -331,24 +321,6 @@ inline Quaternion<Type>::Quaternion( const Vector3<Other>& euler )
//*************************************************************************************************
//*************************************************************************************************
/*!\brief The copy constructor for Quaternion.
*
* \param q Quaternion to be copied.
*
* The copy constructor is explicitly defined in order to enable/facilitate NRV optimization.
*/
template< typename Type > // Data type of the quaternion
inline Quaternion<Type>::Quaternion( const Quaternion& q )
{
v_[0] = q.v_[0];
v_[1] = q.v_[1];
v_[2] = q.v_[2];
v_[3] = q.v_[3];
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Conversion constructor from different Quaternion instances.
*
......@@ -374,29 +346,6 @@ inline Quaternion<Type>::Quaternion( const Quaternion<Other>& q )
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Copy assignment operator for Quaternion.
*
* \param rhs Quaternion to be copied.
* \return Reference to the assigned quaternion.
*
* Explicit definition of a copy assignment operator for performance reasons.
*/
template< typename Type > // Data type of the quaternion
inline Quaternion<Type>& Quaternion<Type>::operator=( const Quaternion<Type>& rhs )
{
// This implementation is faster than the synthesized default copy assignment operator and
// faster than an implementation with the C library function 'memcpy' in combination with a
// protection against self-assignment. Additionally, this version goes without a protection
// against self-assignment.
v_[0] = rhs.v_[0];
v_[1] = rhs.v_[1];
v_[2] = rhs.v_[2];
v_[3] = rhs.v_[3];
return *this;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Assignment operator for different Quaternion instances.
......
......@@ -107,12 +107,12 @@ public:
//*******************************************************************************************************************
//**Constructors*****************************************************************************************************
explicit inline Vector2();
explicit inline Vector2() = default;
explicit inline Vector2( Type init );
template< typename Other > explicit inline Vector2( Other init );
explicit inline Vector2( Type x, Type y );
explicit inline Vector2( const Type* init );
inline Vector2( const Vector2& v );
inline Vector2( const Vector2& v ) = default;
template< typename Other >
inline Vector2( const Vector2<Other>& v );
......@@ -125,7 +125,7 @@ public:
//**Operators********************************************************************************************************
/*!\name Operators */
//@{
inline Vector2& operator= ( const Vector2& v );
inline Vector2& operator= ( const Vector2& v ) = default;
template< typename Other > inline Vector2& operator= ( const Vector2<Other>& v );
template< typename Other > inline bool operator==( Other rhs ) const;
template< typename Other > inline bool operator==( const Vector2<Other>& rhs ) const;
......@@ -172,15 +172,20 @@ public:
//**Member variables****************************************************************************
/*!\name Member variables */
//@{
Type v_[2]; //!< The two statically allocated vector elements.
/*!< Access to the vector values is gained via the subscript operator.
The order of the elements is
\f[\left(\begin{array}{*{2}{c}}
0 & 1 \\
\end{array}\right)\f] */
/**
* The two statically allocated vector elements.
*
* Access to the vector values is gained via the subscript operator.
* The order of the elements is
* \f[\left(\begin{array}{*{2}{c}}
* 0 & 1 \\
* \end{array}\right)\f]
**/
Type v_[2] = {Type(), Type()};
//@}
//*******************************************************************************************************************
};
static_assert( std::is_trivially_copyable<Vector2<real_t>>::value, "Vector2<real_t> has to be trivially copyable!");
//**********************************************************************************************************************
template<typename T>
......@@ -193,19 +198,6 @@ Vector2<T> & normalize( Vector2<T> & v );
//
//======================================================================================================================
//**********************************************************************************************************************
/*!\fn Vector2<Type>::Vector2()
// \brief The default constructor for Vector2.
//
// All vector elements are initialized to the default value (i.e. 0 for integral data types).
*/
template< typename Type >
inline Vector2<Type>::Vector2()
{
v_[0] = v_[1] = Type();
}
//**********************************************************************************************************************
//**********************************************************************************************************************
/*!\fn Vector2<Type>::Vector2( Type init )
......@@ -271,23 +263,6 @@ inline Vector2<Type>::Vector2( const Type* init )
//**********************************************************************************************************************
//**********************************************************************************************************************
/*!\fn Vector2<Type>::Vector2( const Vector2& v )
// \brief The copy constructor for Vector2.
//
// \param v Vector to be copied.
//
// The copy constructor is explicitly defined in order to enable/facilitate NRV optimization.
*/
template< typename Type >
inline Vector2<Type>::Vector2( const Vector2& v )
{
v_[0] = v.v_[0];
v_[1] = v.v_[1];
}
//**********************************************************************************************************************
//**********************************************************************************************************************
/*!\fn Vector2<Type>::Vector2( const Vector2<Other>& v )
// \brief Conversion constructor from different Vector2 instances.
......@@ -312,28 +287,6 @@ inline Vector2<Type>::Vector2( const Vector2<Other>& v )
//
//======================================================================================================================
//**********************************************************************************************************************
/*!\fn Vector2<Type>& Vector2<Type>::operator=( const Vector2& v )
// \brief Copy assignment operator for Vector2.
//
// \param v Vector to be copied.
// \return Reference to the assigned vector.
//
// Explicit definition of a copy assignment operator for performance reasons.
*/
template< typename Type >
inline Vector2<Type>& Vector2<Type>::operator=( const Vector2& v )
{
// This implementation is faster than the synthesized default copy assignment operator and
// faster than an implementation with the C library function 'memcpy' in combination with a
// protection against self-assignment. Additionally, this version goes without a protection
// against self-assignment.
v_[0] = v.v_[0];
v_[1] = v.v_[1];
return *this;
}
//**********************************************************************************************************************
//**********************************************************************************************************************
/*!\fn Vector2<Type>& Vector2<Type>::operator=( const Vector2<Other>& v )
......
......@@ -108,12 +108,12 @@ public:
//*******************************************************************************************************************
//**Constructors*****************************************************************************************************
explicit inline Vector3();
explicit inline Vector3() = default;
explicit inline Vector3( Type init );
template< typename Other > explicit inline Vector3( Other init );
explicit inline Vector3( Type x, Type y, Type z );
explicit inline Vector3( const Type* init );
inline Vector3( const Vector3& v );
inline Vector3( const Vector3& v ) = default;
template< typename Other >
inline Vector3( const Vector3<Other>& v );
......@@ -126,7 +126,7 @@ public:
//**Operators********************************************************************************************************
/*!\name Operators */
//@{
inline Vector3& operator= ( const Vector3& v );
inline Vector3& operator= ( const Vector3& v ) = default;
template< typename Other > inline Vector3& operator= ( const Vector3<Other>& v );
template< typename Other > inline bool operator==( Other rhs ) const;
template< typename Other > inline bool operator==( const Vector3<Other>& rhs ) const;
......@@ -179,15 +179,20 @@ public:
//**Member variables****************************************************************************
/*!\name Member variables */
//@{
Type v_[3]; //!< The three statically allocated vector elements.
/*!< Access to the vector values is gained via the subscript operator.
The order of the elements is
\f[\left(\begin{array}{*{3}{c}}
0 & 1 & 2 \\
\end{array}\right)\f] */
/**
* The three statically allocated vector elements.
*
* Access to the vector values is gained via the subscript operator.
* The order of the elements is
* \f[\left(\begin{array}{*{3}{c}}
* 0 & 1 & 2 \\
* \end{array}\right)\f]
**/
Type v_[3] = {Type(), Type(), Type()};
//@}
//*******************************************************************************************************************
};
static_assert( std::is_trivially_copyable<Vector3<real_t>>::value, "Vector3<real_t> has to be trivially copyable!");
//**********************************************************************************************************************
template<typename T>
......@@ -200,19 +205,6 @@ Vector3<T> & normalize( Vector3<T> & v );
//
//======================================================================================================================
//**********************************************************************************************************************
/*!\fn Vector3<Type>::Vector3()
// \brief The default constructor for Vector3.
//
// All vector elements are initialized to the default value (i.e. 0 for integral data types).
*/
template< typename Type >
inline Vector3<Type>::Vector3()
{
v_[0] = v_[1] = v_[2] = Type();
}
//**********************************************************************************************************************
//**********************************************************************************************************************
/*!\fn Vector3<Type>::Vector3( Type init )
......@@ -281,24 +273,6 @@ inline Vector3<Type>::Vector3( const Type* init )
//**********************************************************************************************************************
//**********************************************************************************************************************
/*!\fn Vector3<Type>::Vector3( const Vector3& v )
// \brief The copy constructor for Vector3.
//
// \param v Vector to be copied.
//
// The copy constructor is explicitly defined in order to enable/facilitate NRV optimization.
*/
template< typename Type >
inline Vector3<Type>::Vector3( const Vector3& v )
{
v_[0] = v.v_[0];
v_[1] = v.v_[1];
v_[2] = v.v_[2];
}
//**********************************************************************************************************************
//**********************************************************************************************************************
/*!\fn Vector3<Type>::Vector3( const Vector3<Other>& v )
// \brief Conversion constructor from different Vector3 instances.
......@@ -324,29 +298,6 @@ inline Vector3<Type>::Vector3( const Vector3<Other>& v )
//
//======================================================================================================================
//**********************************************************************************************************************
/*!\fn Vector3<Type>& Vector3<Type>::operator=( const Vector3& v )
// \brief Copy assignment operator for Vector3.
//
// \param v Vector to be copied.
// \return Reference to the assigned vector.
//
// Explicit definition of a copy assignment operator for performance reasons.
*/
template< typename Type >
inline Vector3<Type>& Vector3<Type>::operator=( const Vector3& v )
{
// This implementation is faster than the synthesized default copy assignment operator and
// faster than an implementation with the C library function 'memcpy' in combination with a
// protection against self-assignment. Additionally, this version goes without a protection
// against self-assignment.
v_[0] = v.v_[0];
v_[1] = v.v_[1];
v_[2] = v.v_[2];
return *this;
}
//**********************************************************************************************************************
//**********************************************************************************************************************
/*!\fn Vector3<Type>& Vector3<Type>::operator=( const Vector3<Other>& v )
......
......@@ -818,7 +818,9 @@ bool collide( BoxID b1, BoxID b2, Container& container )
for( unsigned int i=0; i<3; ++i ) {
sign[i] = ( sign[i]>0 ) ? ( hl1[i] ) : ( -hl1[i] );
}
#ifdef WALBERLA_LOGLEVEL_DETAIL
const Vec3 tmp1( sign );
#endif
pB1 += R1 * sign;
Vec3 pB2 = b2->getPosition();
......@@ -826,7 +828,9 @@ bool collide( BoxID b1, BoxID b2, Container& container )
for( size_t i=0; i<3; ++i ) {
sign[i] = ( sign[i]>0 ) ? ( -hl2[i] ) : ( hl2[i] );
}
#ifdef WALBERLA_LOGLEVEL_DETAIL
const Vec3 tmp2( sign );
#endif
pB2 += R2 * sign;
Vec3 ua, ub;
......
......@@ -115,7 +115,7 @@ int main(int argc, char * argv[])
for( real_t x(-10); x < real_t(11); x += real_t(0.25) )
{
static const Vector3<real_t> ZERO_VECTOR;
static const Vector3<real_t> ZERO_VECTOR {};
Plane pShifted( p );
pShifted.shift( x );
WALBERLA_CHECK_FLOAT_EQUAL( pShifted.signedDistance( ZERO_VECTOR ), -x );
......
......@@ -199,8 +199,8 @@ public:
void val( real_t& _val, cell_idx_t x, cell_idx_t, cell_idx_t ) const override { _val = real_c( cos( period_*( real_c(x) + real_c(0.5) ) ) ); }
private:
const real_t period_;
const vec3_t vel_;
const real_t period_ {};
const vec3_t vel_ {};
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment