/*--------------------------------*/
/* Conversion of numericals types */
/*--------------------------------*/
/* Version 1.0                    */
/* Author : S Leroy               */
/* Date : 5/03/98                 */
/* Modification : 9/03/98         */
/*--------------------------------*/
/* PC Version by M Trabucato      */
/*--------------------------------*/
/* Conversion : OK (avec version 27.04.98 11:35 (22582) */
/*--------------------------------*/
 
#ifndef _3DCONV_H_
#define _3DCONV_H_
 
#include "MTH\Specif\VEC\sl12_3D.h"
#include "MTH\Specif\VEC\sl_3D.h"
#include "MTH\Specif\VEC\sw12_3D.h"
#include "MTH\Specif\VEC\sw_3D.h"
#include "MTH\Specif\SCA\converse.h"
 
/*--------------------------------------*/
/* 2D Vector Outer Product              */
/*--------------------------------------*/
__inline SCA_td_sl sl_fn_2DOuterProduct(
                                        SCA_td_sl x0,
                                        SCA_td_sl y0,
                                        SCA_td_sl x1,
                                        SCA_td_sl y1,
                                        SCA_td_sl x2,
                                        SCA_td_sl y2
                                       )
{
 return MTH_M_xAdd3( MTH_M_xMul( x0 , MTH_M_xSub( y1 , y2 ) ) ,
                     MTH_M_xMul( x1 , MTH_M_xSub( y2 , y0 ) ) ,
                     MTH_M_xMul( x2 , MTH_M_xSub( y0 , y1 ) ) );
}
 
/*--------------------------------------------*/
/*            Vector Conversion               */
/*--------------------------------------------*/
/* Vector Normalisation */
__inline sw12_3D_tdstVector * VEC_p_sw12_3DNormalise_sl3D(
                                                          sw12_3D_tdstVector   * _p_stsw12_3D_Dest,
                                                          sw12_3D_tdstVector * _p_stsl3_DSrc
                                                         )
{
  MTH3D_M_vNormalizeVector(_p_stsw12_3D_Dest,_p_stsl3_DSrc);
  return _p_stsw12_3D_Dest;
}
 
/*------------------------------*/
/* sw12_3D <- Normalise (sl_3D) */
/*------------------------------*/
__inline sw12_3D_tdstVector * VEC_p_sw12_3DNormalize_sw3D(
                                                          sw12_3D_tdstVector   * _p_stsw12_3D_Dest,
                                                          sw_3D_tdstVector * _p_stsw_3DSrc
                                                         )
{
 MTH3D_M_vNormalizeVector(_p_stsw12_3D_Dest,_p_stsw_3DSrc);
 return _p_stsw12_3D_Dest;
}
 
 
/*--------------------------------*/
/* sw12_3D <- Normalise (sl12_3D) */
/*--------------------------------*/
__inline sw12_3D_tdstVector * VEC_p_sw12_3DNormalize_sl123D(
                                                            sw12_3D_tdstVector * _p_stsw12_3D_Dest,
                                                            sl12_3D_tdstVector * _p_stsl12_3DSrc
                                                           )
{
 MTH3D_M_vNormalizeVector(_p_stsw12_3D_Dest,_p_stsl12_3DSrc);
 return _p_stsw12_3D_Dest;
}
 
 
/*--------------------------------*/
/* Vector Normalisation functions */
/*--------------------------------*/
#define sw12_3D_vNormalizeVector_Dsw12_Ssl(VectDest, VectA) VEC_p_sw12_3DNormalize_sl3D(VectDest, VectA)
#define sw12_3D_vNormalizeVector_Dsw12_Ssl12(VectDest, VectA) VEC_p_sw12_3DNormalize_sl123D(VectDest, VectA)
#define sw12_3D_vNormalizeVector_Dsw12_Ssw(VectDest, VectA) VEC_p_sw12_3DNormalize_sw3D(VectDest, VectA)
#define sw12_3D_vNormalizeVector_Dsw12_Ssw12(VectDest, VectA) VEC_p_sw12_3DNormalize_sw3D(VectDest, VectA)
 
 
/*--------------------------------------------*/
/*            Vector Conversion               */
/*--------------------------------------------*/
/* Conversion sw3D in sl3D */
__inline sl_3D_tdstVector * VEC_p_sw3DConverse_sw3DTosl3D(
                                      sl_3D_tdstVector * _p_stsl3DDest,
                                      sw_3D_tdstVector * _p_stsw3DSrc
                                     )
{
  MTH3D_M_vCopyVector(_p_stsl3DDest,_p_stsw3DSrc);
  return _p_stsl3DDest;
}
 
/* Conversion sl3D in sw3D */
__inline sw_3D_tdstVector * VEC_p_sw3DConverse_sl3DTosw3D(
                                      sw_3D_tdstVector * _p_stsw3DDest,
                                      sl_3D_tdstVector * _p_stsl3DSrc
                                     )
{
  MTH3D_M_vCopyVector(_p_stsw3DDest,_p_stsl3DSrc);
  return _p_stsw3DDest;
}
 
/*--------------------------------------------*/
/*     Vector/Matrix    Multiplication        */
/*--------------------------------------------*/
/* Specific functions */
/* PC OK */
__inline void sw12_3D_fn_vMulMatrixVector_Dsl_SswWithoutBuffer(
                                                               sl_3D_tdstVector * p_VectDest,
                                                               sw12_3D_tdstMatrix * p_MatA,
                                                               sw_3D_tdstVector * p_VectA)
{
  MTH3D_M_vMulMatrixVectorWithoutBuffer(p_VectDest,p_MatA,p_VectA);
}
 
/* Explicit name */
/* To be optimzed of course */
/* PC OK */
__inline void sw12_3D_fn_vMulMatrixSw12Vector_Dsl_Ssl(
                                                sl_3D_tdstVector * p_VectDest,
                                                sw12_3D_tdstMatrix * p_MatA,
                                                sl_3D_tdstVector * p_VectA)
 
{
  MTH3D_M_vMulMatrixVectorWithoutBuffer(p_VectDest,p_MatA,p_VectA);
}
 
/*-------------------------------------------------------------------------------------------*/
/*                    Mul Add Vector                                                         */
/*-------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------*/
/* sw_3D_M_vMulAddVector( sw_3D, sl12, sw_3D, sw_3D)   sw_3D = sl12*sw_3D + sw_3D */
/*--------------------------------------------------------------------------------*/
/* PC OK */
__inline void sw_3D_fn_vMulAddVector_sw3D_sl12_sw3D_sw_3D(
									sw_3D_tdstVector * _p_stswVectorResult,
									td_sl12 _sl12_scalar,
									sw_3D_tdstVector * _p_stswVectorA,
									sw_3D_tdstVector * _p_stswVectorB
                                   )
{
 MTH3D_M_vMulScalarVector( _p_stswVectorResult, _sl12_scalar, _p_stswVectorA);
 MTH3D_M_vAddVector( _p_stswVectorResult, _p_stswVectorResult, _p_stswVectorB);
}
 
/*----------------------------------------------------------------------------------*/
/* sl_3D_M_vMulAddVector : sl_3D <- sw * sw12_3D + sl_3D                            */
/*----------------------------------------------------------------------------------*/
__inline void sl_3D_fn_vMulAddVector_sl3D_sw_sw123D_sl3D(
									sl_3D_tdstVector * _p_stslVectorResult,
									td_sw _sw_scalar,
									sw12_3D_tdstVector * _p_stsw12VectorA,
									sl_3D_tdstVector * _p_stslVectorB
                                   )
{
 MTH3D_M_vMulScalarVector( _p_stslVectorResult, _sw_scalar, _p_stsw12VectorA);
 MTH3D_M_vAddVector( _p_stslVectorResult, _p_stslVectorResult, _p_stslVectorB);
}
/*----------------------------------------------------------------------------------*/
/* sl_3D_M_vMulAddVector : sl_3D <- sw12 * sw_3D + sl_3D                            */
/*----------------------------------------------------------------------------------*/
#define sl_3D_M_vMulAddVector_sl3D_sw12_sw3D_sl3D( _p_sl_3DResult, _sw12, _p_sw_3D, _p_sl_3D) \
{                                                                           \
 MTH3D_M_vMulScalarVector( _p_sl_3DResult, _sw12, _p_sw_3D);				\
 MTH3D_M_vAddVector( _p_sl_3DResult, _p_sl_3DResult, _p_sl_3D);				\
}
/*----------------------------------------------------------------------------------*/
/* sl_3D_M_vMulAddVector : sw_3D <- sw * sw12_3D + sw_3D                            */
/*----------------------------------------------------------------------------------*/
#define sw_3D_M_vMulAddVector_sw3D_sw_sw123D_sw3D( _p_sw_3DResult, _sw, _p_sw12_3D, _p_sw_3D) \
{																	\
 MTH3D_M_vMulScalarVector( _p_sw_3DResult, _sw, _p_sw12_3D);		\
 MTH3D_M_vAddVector( _p_sw_3DResult, _p_sw_3DResult, _p_sw_3D);		\
}
 
#define sl_3D_M_vMulAddVector_sl3D_sw_sw123D_sl3D( sl_3DResult, sw, sw12_3D, sl_3D) sl_3D_fn_vMulAddVector_sl3D_sw_sw123D_sl3D( sl_3DResult, sw, sw12_3D, sl_3D)
#define sw_3D_M_vMulAddVector_sw3D_sl12_sw3D_sw3D( sw_3DResult, sl12, sw_3D_1, sw_3D_2) sw_3D_fn_vMulAddVector_sw3D_sl12_sw3D_sw3D( sw_3DResult, sl12, sw_3D_1, sw_3D_2)
/*-------------------------------------------------------------------------------------------*/
/*            Dot Products                                                                   */
/*-------------------------------------------------------------------------------------------*/
/*----------------------------------------------*/
/* sw_3D_M_xDotProductVector ( sw_3D, sw12_3D ) */
/*----------------------------------------------*/
/* PC OK */
__inline td_sl VEC_3D_fn_sl_DotProductVector_sw_sw(
												sw_3D_tdstVector * _p_stswVectorA,
												sw_3D_tdstVector * _p_stswVectorB
                                               )
{
 return MTH3D_M_xDotProductVector(_p_stswVectorA,_p_stswVectorB);
}
 
/*--------------------------------------------------------*/
/* sw_3D_M_sw_DotProductVector_sw_sw12 ( sw_3D, sw12_3D ) */
/*--------------------------------------------------------*/
__inline td_sw VEC_3D_fn_sw_DotProductVector_sw_sw12(
												sw_3D_tdstVector * _p_stswVector,
												sw12_3D_tdstVector * _p_stsw12Vector
                                               )
{
 return MTH3D_M_xDotProductVector(_p_stswVector,_p_stsw12Vector);
}
 
/*--------------------------------------------------------*/
/* sw_3D_M_sl_DotProductVector_sl_sw12 ( sl_3D, sw12_3D ) */
/*--------------------------------------------------------*/
__inline td_sl VEC_3D_fn_sl_DotProductVector_sl_sw12(
												sl_3D_tdstVector * _p_stslVector,
												sw12_3D_tdstVector * _p_stsw12Vector
                                               )
{
 return MTH3D_M_xDotProductVector(_p_stslVector,_p_stsw12Vector);
}
 
#define VEC_3D_M_sl_DotProductVector_sw_sw( sw_3D_1, sw_3D_2 ) VEC_3D_fn_sl_DotProductVector_sw_sw( sw_3D_1, sw_3D_2 )
#define VEC_3D_M_sw_DotProductVector_sw_sw12( sw_3D, sw12_3D ) VEC_3D_fn_sw_DotProductVector_sw_sw12( sw_3D, sw12_3D )
#define VEC_3D_M_sl_DotProductVector_sl_sw12( sl_3D, sw12_3D ) VEC_3D_fn_sl_DotProductVector_sl_sw12( sl_3D, sw12_3D )
 
/*------------------------------------------------------------------------------------------------------------------------*/
/*                               Mul Scalar Vector                                                                        */
/*------------------------------------------------------------------------------------------------------------------------*/
 
/*----------------------------------------------*/
/* MulScalar sw_3D <- sl12 * sw_3D              */
/*----------------------------------------------*/
/* PC OK */
__inline sw_3D_tdstVector * sw_3D_fn_MulScalarVector_sl12_Sw3D
                                               (
                                                sw_3D_tdstVector * _p_stswVectorResult,
												td_sl12 _p_s12Scalar,
												sw_3D_tdstVector * _p_stswVector
                                               )
{
 MTH3D_M_vMulScalarVector( _p_stswVectorResult, _p_s12Scalar, _p_stswVector);
 
 return _p_stswVectorResult;
}
 
/*----------------------------------------------*/
/* MulScalar sw_3D <- sw * sw12_3D              */
/*----------------------------------------------*/
__inline sw_3D_tdstVector * sw_3D_fn_MulScalarVector_sw_sw123D
                                               (
                                                sw_3D_tdstVector * _p_stswVectorResult,
												td_sw swScalar,
												sw12_3D_tdstVector * _p_stsw12Vector
                                               )
{
 MTH3D_M_vMulScalarVector( _p_stswVectorResult, swScalar, _p_stsw12Vector);
 
 return _p_stswVectorResult;
}
 
#define sw_3D_M_MulScalarVector_sw_sw123D(Vectd,a,VectA) sw_3D_fn_MulScalarVector_sw_sw123D(Vectd,a,VectA)
#define sw_3D_M_MulScalarVector_sl12_sw3D(Vectd,a,VectA) sw_3D_fn_MulScalarVector_sl12_sw3D(Vectd,a,VectA)
/*------------------------------------------------------------------------------------------------------------------------*/
/*                               Div Vector Scalar                                                                        */
/*------------------------------------------------------------------------------------------------------------------------*/
/*-----------------------*/
/* sw12_3D <- sw_3D / sw */
/*-----------------------*/
__inline sw12_3D_tdstVector * sw12_3D_fn_VectorDivScalar_sw3D_sw
                                               (
                                                sw12_3D_tdstVector * _p_stsw12VectorResult,
												sw_3D_tdstVector * _p_stswVector,
												td_sw swScalar
                                               )
{
 MTH3D_M_vDivScalarVector( _p_stsw12VectorResult, _p_stswVector, swScalar);
 
 return _p_stsw12VectorResult;
}
#define sw12_3D_M_VectorDivScalar_sw3D_sw(Vectd,Vecta,a) sw12_3D_fn_VectorDivScalar_sw3D_sw(Vectd,Vecta,a)
/*------------------------------------------------------------*/
/* Square norm of a vector                                    */
/*------------------------------------------------------------*/
__inline td_sl sw_3D_fn_sl_SqrVector(
									sw_3D_tdstVector * _p_stswVectorA
                                   )
{
 return MTH3D_M_xSqrVector(_p_stswVectorA);
}
#define sw_3D_M_sl_SqrVector_sw(VectA) sw_3D_fn_sl_SqrVector(VectA)
/*--------------------------------*/
/* Vector Normalisation functions */
/*--------------------------------*/
#define sw12_3D_vNormalizeVector_Dsw12_Ssl(VectDest, VectA)   VEC_p_sw12_3DNormalize_sl3D(VectDest, VectA)
#define sw12_3D_vNormalizeVector_Dsw12_Ssl12(VectDest, VectA) VEC_p_sw12_3DNormalize_sl123D(VectDest, VectA)
#define sw12_3D_vNormalizeVector_Dsw12_Ssw(VectDest, VectA)   VEC_p_sw12_3DNormalize_sw3D(VectDest, VectA)
#define sw12_3D_vNormalizeVector_Dsw12_Ssw12(VectDest, VectA) VEC_p_sw12_3DNormalize_sw3D(VectDest, VectA)
/*---------------------------------------------*/
/* sl <- sl_3D_M_slVectorGapSqr (sw_3D, sw_3D) */
/*---------------------------------------------*/
#define sl_3D_M_slVectorGapSqr_sw3D_sw3D(VectA, VectB)          MTH3D_M_xVectorGapSqr(VectA, VectB)
 
/*-----------------------------------------------------*/
/* ul <- VEC_M_ulVectorGapSqr_sl3D_sl3D (sl_3D, sl_3D) */
/*-----------------------------------------------------*/
__inline unsigned long VEC_fn_ulVectorGapSqr_sl3D_sl3D(
                                                       sl_3D_tdstVector *_p_stsl3D_A,
                                                       sl_3D_tdstVector *_p_stsl3D_B
                                                      )
{
 return MTH_M_xRealToLong(MTH3D_M_xVectorGapSqr(_p_stsl3D_A, _p_stsl3D_B));
}
 
#define VEC_M_ulVectorGapSqr_sl3D_sl3D(sl_3D_1, sl_3D_2) VEC_fn_ulVectorGapSqr_sl3D_sl3D(sl_3D_1, sl_3D_2)
 
/* Macro definitions */
#define sw12_3D_M_vMulMatrixSw12Vector_Dsw_Ssl( VectDest, MatA, VectA) sw12_3D_fn_vMulMatrixSw12Vector_Dsl_Ssl( VectDest, MatA, VectA)
#define sw12_3D_M_vMulMatrixVector_Dsl_SswWithoutBuffer( VectDest, MatA, VectA) sw12_3D_fn_vMulMatrixVector_Dsl_SswWithoutBuffer( VectDest, MatA, VectA)
#define Conv_sl3DTosw3D(_p_stsl3D,_p_stsw3D) VEC_p_sw3DConverse_sl3DTosw3D(_p_stsl3D,_p_stsw3D)
#define Conv_sw3DTosl3D(_p_stsw3D,_p_stsl3D) VEC_p_sw3DConverse_sw3DTosl3D(_p_stsw3D,_p_stsl3D)
 
#endif
