Небольшие исправления, а также добавление гомогенного трёхмерного вектора
This commit is contained in:
parent
03627f4401
commit
043cc72c81
25 changed files with 1686 additions and 1644 deletions
190
basic-geometry/hg-vector3.h
Normal file
190
basic-geometry/hg-vector3.h
Normal file
|
|
@ -0,0 +1,190 @@
|
|||
#ifndef _BGC_HG_VECTOR3_H_INCLUDED_
|
||||
#define _BGC_HG_VECTOR3_H_INCLUDED_
|
||||
|
||||
#include "./vector3.h"
|
||||
|
||||
// ================== Vector3 =================== //
|
||||
|
||||
// Homogeneous 3D Vector
|
||||
typedef struct
|
||||
{
|
||||
float x1, x2, x3, ratio;
|
||||
} BGC_FP32_HgVector3;
|
||||
|
||||
// Homogeneous 3D Vector
|
||||
typedef struct
|
||||
{
|
||||
double x1, x2, x3, ratio;
|
||||
} BGC_FP64_HgVector3;
|
||||
|
||||
// ================ Reset Point ================= //
|
||||
|
||||
inline void bgc_fp32_hg_vector3_reset_point(BGC_FP32_HgVector3* homogeneous_vector)
|
||||
{
|
||||
homogeneous_vector->x1 = 0.0f;
|
||||
homogeneous_vector->x2 = 0.0f;
|
||||
homogeneous_vector->x3 = 0.0f;
|
||||
homogeneous_vector->ratio = 1.0f;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_hg_vector3_reset_point(BGC_FP64_HgVector3* homogeneous_vector)
|
||||
{
|
||||
homogeneous_vector->x1 = 0.0;
|
||||
homogeneous_vector->x2 = 0.0;
|
||||
homogeneous_vector->x3 = 0.0;
|
||||
homogeneous_vector->ratio = 1.0;
|
||||
}
|
||||
|
||||
// ================ Reset Point ================= //
|
||||
|
||||
inline void bgc_fp32_hg_vector3_reset_vector(BGC_FP32_HgVector3* homogeneous_vector)
|
||||
{
|
||||
homogeneous_vector->x1 = 0.0f;
|
||||
homogeneous_vector->x2 = 0.0f;
|
||||
homogeneous_vector->x3 = 0.0f;
|
||||
homogeneous_vector->ratio = 0.0f;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_hg_vector3_reset_vector(BGC_FP64_HgVector3* homogeneous_vector)
|
||||
{
|
||||
homogeneous_vector->x1 = 0.0;
|
||||
homogeneous_vector->x2 = 0.0;
|
||||
homogeneous_vector->x3 = 0.0;
|
||||
homogeneous_vector->ratio = 0.0;
|
||||
}
|
||||
|
||||
// ==================== Make ==================== //
|
||||
|
||||
inline void bgc_fp32_hg_vector3_make(BGC_FP32_HgVector3* homogeneous_vector, const float x1, const float x2, const float x3, const float ratio)
|
||||
{
|
||||
homogeneous_vector->x1 = x1;
|
||||
homogeneous_vector->x2 = x2;
|
||||
homogeneous_vector->x3 = x3;
|
||||
homogeneous_vector->ratio = ratio;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_hg_vector3_make(BGC_FP64_HgVector3* homogeneous_vector, const double x1, const double x2, const double x3, const double ratio)
|
||||
{
|
||||
homogeneous_vector->x1 = x1;
|
||||
homogeneous_vector->x2 = x2;
|
||||
homogeneous_vector->x3 = x3;
|
||||
homogeneous_vector->ratio = ratio;
|
||||
}
|
||||
|
||||
// ================= Make Point ================= //
|
||||
|
||||
inline void bgc_fp32_hg_vector3_make_point(BGC_FP32_HgVector3* homogeneous_vector, const BGC_FP32_Vector3* regular_vector)
|
||||
{
|
||||
homogeneous_vector->x1 = regular_vector->x1;
|
||||
homogeneous_vector->x2 = regular_vector->x2;
|
||||
homogeneous_vector->x3 = regular_vector->x3;
|
||||
homogeneous_vector->ratio = 1.0f;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_hg_vector3_make_point(BGC_FP64_HgVector3* homogeneous_vector, const BGC_FP64_Vector3* regular_vector)
|
||||
{
|
||||
homogeneous_vector->x1 = regular_vector->x1;
|
||||
homogeneous_vector->x2 = regular_vector->x2;
|
||||
homogeneous_vector->x3 = regular_vector->x3;
|
||||
homogeneous_vector->ratio = 1.0;
|
||||
}
|
||||
|
||||
// ================ Make Vector ================= //
|
||||
|
||||
inline void bgc_fp32_hg_vector3_make_vector(BGC_FP32_HgVector3* homogeneous_vector, const BGC_FP32_Vector3* regular_vector)
|
||||
{
|
||||
homogeneous_vector->x1 = regular_vector->x1;
|
||||
homogeneous_vector->x2 = regular_vector->x2;
|
||||
homogeneous_vector->x3 = regular_vector->x3;
|
||||
homogeneous_vector->ratio = 0.0f;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_hg_vector3_make_vector(BGC_FP64_HgVector3* homogeneous_vector, const BGC_FP64_Vector3* regular_vector)
|
||||
{
|
||||
homogeneous_vector->x1 = regular_vector->x1;
|
||||
homogeneous_vector->x2 = regular_vector->x2;
|
||||
homogeneous_vector->x3 = regular_vector->x3;
|
||||
homogeneous_vector->ratio = 0.0;
|
||||
}
|
||||
|
||||
// ================== Is Point ================== //
|
||||
|
||||
inline int bgc_fp32_hg_vector3_is_point(const BGC_FP32_HgVector3* homogeneous_vector)
|
||||
{
|
||||
return !bgc_fp32_is_zero(homogeneous_vector->ratio);
|
||||
}
|
||||
|
||||
inline int bgc_fp64_hg_vector3_is_point(const BGC_FP64_HgVector3* homogeneous_vector)
|
||||
{
|
||||
return !bgc_fp64_is_zero(homogeneous_vector->ratio);
|
||||
}
|
||||
|
||||
// ================= Is Vector ================== //
|
||||
|
||||
inline int bgc_fp32_hg_vector3_is_vector(const BGC_FP32_HgVector3* homogeneous_vector)
|
||||
{
|
||||
return bgc_fp32_is_zero(homogeneous_vector->ratio);
|
||||
}
|
||||
|
||||
inline int bgc_fp64_hg_vector3_is_vector(const BGC_FP64_HgVector3* homogeneous_vector)
|
||||
{
|
||||
return bgc_fp64_is_zero(homogeneous_vector->ratio);
|
||||
}
|
||||
|
||||
// ==================== Copy ==================== //
|
||||
|
||||
inline void bgc_fp32_hg_vector3_copy(BGC_FP32_HgVector3* destination, const BGC_FP32_HgVector3* source)
|
||||
{
|
||||
destination->x1 = source->x1;
|
||||
destination->x2 = source->x2;
|
||||
destination->x3 = source->x3;
|
||||
destination->ratio = source->ratio;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_hg_vector3_copy(BGC_FP64_HgVector3* destination, const BGC_FP64_HgVector3* source)
|
||||
{
|
||||
destination->x1 = source->x1;
|
||||
destination->x2 = source->x2;
|
||||
destination->x3 = source->x3;
|
||||
destination->ratio = source->ratio;
|
||||
}
|
||||
|
||||
// ==================== Swap ==================== //
|
||||
|
||||
inline void bgc_fp32_hg_vector3_swap(BGC_FP32_HgVector3* first, BGC_FP32_HgVector3* second)
|
||||
{
|
||||
const float x1 = first->x1;
|
||||
const float x2 = first->x2;
|
||||
const float x3 = first->x3;
|
||||
const float ratio = first->ratio;
|
||||
|
||||
first->x1 = second->x1;
|
||||
first->x2 = second->x2;
|
||||
first->x3 = second->x3;
|
||||
first->ratio = second->ratio;
|
||||
|
||||
second->x1 = x1;
|
||||
second->x2 = x2;
|
||||
second->x3 = x3;
|
||||
second->ratio = ratio;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_hg_vector3_swap(BGC_FP64_HgVector3* first, BGC_FP64_HgVector3* second)
|
||||
{
|
||||
const double x1 = first->x1;
|
||||
const double x2 = first->x2;
|
||||
const double x3 = first->x3;
|
||||
const double ratio = first->ratio;
|
||||
|
||||
first->x1 = second->x1;
|
||||
first->x2 = second->x2;
|
||||
first->x3 = second->x3;
|
||||
first->ratio = second->ratio;
|
||||
|
||||
second->x1 = x1;
|
||||
second->x2 = x2;
|
||||
second->x3 = x3;
|
||||
second->ratio = ratio;
|
||||
}
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue