bgc-c/basic-geometry/dual-versor.h

147 lines
3.8 KiB
C

#ifndef _BGC_DUAL_VERSOR_H_
#define _BGC_DUAL_VERSOR_H_
// =================== Types ==================== //
typedef struct {
struct {
float s0, x1, x2, x3;
} _real, _dual;
} BGC_FP32_DualVersor;
typedef struct {
struct {
double s0, x1, x2, x3;
} _real, _dual;
} BGC_FP64_DualVersor;
// =================== Reset ==================== //
inline void bgc_fp32_dual_versor_reset(BGC_FP32_DualVersor* number)
{
number->_real.s0 = 1.0f;
number->_real.x1 = 0.0f;
number->_real.x2 = 0.0f;
number->_real.x3 = 0.0f;
number->_dual.s0 = 0.0f;
number->_dual.x1 = 0.0f;
number->_dual.x2 = 0.0f;
number->_dual.x3 = 0.0f;
}
inline void bgc_fp64_dual_versor_reset(BGC_FP64_DualVersor* number)
{
number->_real.s0 = 1.0f;
number->_real.x1 = 0.0f;
number->_real.x2 = 0.0f;
number->_real.x3 = 0.0f;
number->_dual.s0 = 0.0f;
number->_dual.x1 = 0.0f;
number->_dual.x2 = 0.0f;
number->_dual.x3 = 0.0f;
}
// ==================== Copy ==================== //
inline void bgc_fp32_dual_versor_copy(BGC_FP32_DualVersor* destination, const BGC_FP32_DualVersor* source)
{
destination->_real.s0 = source->_real.s0;
destination->_real.x1 = source->_real.x1;
destination->_real.x2 = source->_real.x2;
destination->_real.x3 = source->_real.x3;
destination->_dual.s0 = source->_dual.s0;
destination->_dual.x1 = source->_dual.x1;
destination->_dual.x2 = source->_dual.x2;
destination->_dual.x3 = source->_dual.x3;
}
inline void bgc_fp64_dual_versor_copy(BGC_FP64_DualVersor* destination, const BGC_FP64_DualVersor* source)
{
destination->_real.s0 = source->_real.s0;
destination->_real.x1 = source->_real.x1;
destination->_real.x2 = source->_real.x2;
destination->_real.x3 = source->_real.x3;
destination->_dual.s0 = source->_dual.s0;
destination->_dual.x1 = source->_dual.x1;
destination->_dual.x2 = source->_dual.x2;
destination->_dual.x3 = source->_dual.x3;
}
// ==================== Swap ==================== //
inline void bgc_fp32_dual_versor_swap(BGC_FP32_DualVersor* first, BGC_FP32_DualVersor* second)
{
// Real
float s0 = second->_real.s0;
float x1 = second->_real.x1;
float x2 = second->_real.x2;
float x3 = second->_real.x3;
second->_real.s0 = first->_real.s0;
second->_real.x1 = first->_real.x1;
second->_real.x2 = first->_real.x2;
second->_real.x3 = first->_real.x3;
first->_real.s0 = s0;
first->_real.x1 = x1;
first->_real.x2 = x2;
first->_real.x3 = x3;
// Dual
s0 = second->_dual.s0;
x1 = second->_dual.x1;
x2 = second->_dual.x2;
x3 = second->_dual.x3;
second->_dual.s0 = first->_dual.s0;
second->_dual.x1 = first->_dual.x1;
second->_dual.x2 = first->_dual.x2;
second->_dual.x3 = first->_dual.x3;
first->_dual.s0 = s0;
first->_dual.x1 = x1;
first->_dual.x2 = x2;
first->_dual.x3 = x3;
}
inline void bgc_fp64_dual_versor_swap(BGC_FP64_DualVersor* first, BGC_FP64_DualVersor* second)
{
// Real
double s0 = second->_real.s0;
double x1 = second->_real.x1;
double x2 = second->_real.x2;
double x3 = second->_real.x3;
second->_real.s0 = first->_real.s0;
second->_real.x1 = first->_real.x1;
second->_real.x2 = first->_real.x2;
second->_real.x3 = first->_real.x3;
first->_real.s0 = s0;
first->_real.x1 = x1;
first->_real.x2 = x2;
first->_real.x3 = x3;
// Dual
s0 = second->_dual.s0;
x1 = second->_dual.x1;
x2 = second->_dual.x2;
x3 = second->_dual.x3;
second->_dual.s0 = first->_dual.s0;
second->_dual.x1 = first->_dual.x1;
second->_dual.x2 = first->_dual.x2;
second->_dual.x3 = first->_dual.x3;
first->_dual.s0 = s0;
first->_dual.x1 = x1;
first->_dual.x2 = x2;
first->_dual.x3 = x3;
}
#endif