Большое переупорядочивание исходного кода
This commit is contained in:
parent
fffe2be43b
commit
43bf030295
26 changed files with 1225 additions and 1137 deletions
|
|
@ -44,6 +44,50 @@ inline void bgc_vector2_set_values_fp64(const double x1, const double x2, BgcVec
|
|||
to->x2 = x2;
|
||||
}
|
||||
|
||||
// ================== Modulus =================== //
|
||||
|
||||
inline float bgc_vector2_get_square_modulus_fp32(const BgcVector2FP32* vector)
|
||||
{
|
||||
return vector->x1 * vector->x1 + vector->x2 * vector->x2;
|
||||
}
|
||||
|
||||
inline double bgc_vector2_get_square_modulus_fp64(const BgcVector2FP64* vector)
|
||||
{
|
||||
return vector->x1 * vector->x1 + vector->x2 * vector->x2;
|
||||
}
|
||||
|
||||
inline float bgc_vector2_get_modulus_fp32(const BgcVector2FP32* vector)
|
||||
{
|
||||
return sqrtf(bgc_vector2_get_square_modulus_fp32(vector));
|
||||
}
|
||||
|
||||
inline double bgc_vector2_get_modulus_fp64(const BgcVector2FP64* vector)
|
||||
{
|
||||
return sqrt(bgc_vector2_get_square_modulus_fp64(vector));
|
||||
}
|
||||
|
||||
// ================= Comparison ================= //
|
||||
|
||||
inline int bgc_vector2_is_zero_fp32(const BgcVector2FP32* vector)
|
||||
{
|
||||
return bgc_vector2_get_square_modulus_fp32(vector) <= BGC_SQUARE_EPSYLON_FP32;
|
||||
}
|
||||
|
||||
inline int bgc_vector2_is_zero_fp64(const BgcVector2FP64* vector)
|
||||
{
|
||||
return bgc_vector2_get_square_modulus_fp64(vector) <= BGC_SQUARE_EPSYLON_FP64;
|
||||
}
|
||||
|
||||
inline int bgc_vector2_is_unit_fp32(const BgcVector2FP32* vector)
|
||||
{
|
||||
return bgc_is_sqare_unit_fp32(bgc_vector2_get_square_modulus_fp32(vector));
|
||||
}
|
||||
|
||||
inline int bgc_vector2_is_unit_fp64(const BgcVector2FP64* vector)
|
||||
{
|
||||
return bgc_is_sqare_unit_fp64(bgc_vector2_get_square_modulus_fp64(vector));
|
||||
}
|
||||
|
||||
// ==================== Copy ==================== //
|
||||
|
||||
inline void bgc_vector2_copy_fp32(const BgcVector2FP32* from, BgcVector2FP32* to)
|
||||
|
|
@ -84,7 +128,7 @@ inline void bgc_vector2_swap_fp64(BgcVector2FP64* vector1, BgcVector2FP64* vecto
|
|||
vector1->x2 = x2;
|
||||
}
|
||||
|
||||
// ============= Copy to twin type ============== //
|
||||
// ================== Convert =================== //
|
||||
|
||||
inline void bgc_vector2_convert_fp64_to_fp32(const BgcVector2FP64* from, BgcVector2FP32* to)
|
||||
{
|
||||
|
|
@ -98,76 +142,118 @@ inline void bgc_vector2_convert_fp32_to_fp64(const BgcVector2FP32* from, BgcVect
|
|||
to->x2 = from->x2;
|
||||
}
|
||||
|
||||
// =================== Reverse ================== //
|
||||
// ================== Reverse =================== //
|
||||
|
||||
inline void bgc_vector2_set_reverse_fp32(const BgcVector2FP32* from, BgcVector2FP32* to)
|
||||
inline void bgc_vector2_reverse_fp32(BgcVector2FP32* vector)
|
||||
{
|
||||
to->x1 = -from->x1;
|
||||
to->x2 = -from->x2;
|
||||
vector->x1 = -vector->x1;
|
||||
vector->x2 = -vector->x2;
|
||||
}
|
||||
|
||||
inline void bgc_vector2_set_reverse_fp64(const BgcVector2FP64* from, BgcVector2FP64* to)
|
||||
inline void bgc_vector2_reverse_fp64(BgcVector2FP64* vector)
|
||||
{
|
||||
to->x1 = -from->x1;
|
||||
to->x2 = -from->x2;
|
||||
vector->x1 = -vector->x1;
|
||||
vector->x2 = -vector->x2;
|
||||
}
|
||||
|
||||
// ============= Reverse twin type ============== //
|
||||
// ================= Normalize ================== //
|
||||
|
||||
inline void bgc_vector2_set_reverse_fp64_to_fp32(const BgcVector2FP64* from, BgcVector2FP32* to)
|
||||
inline int bgc_vector2_normalize_fp32(BgcVector2FP32* vector)
|
||||
{
|
||||
to->x1 = (float) -from->x1;
|
||||
to->x2 = (float) -from->x2;
|
||||
const float square_modulus = bgc_vector2_get_square_modulus_fp32(vector);
|
||||
|
||||
if (bgc_is_sqare_unit_fp32(square_modulus)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32 || square_modulus != square_modulus) {
|
||||
vector->x1 = 0.0f;
|
||||
vector->x2 = 0.0f;
|
||||
return 0;
|
||||
}
|
||||
|
||||
const float multiplicand = sqrtf(1.0f / square_modulus);
|
||||
|
||||
vector->x1 *= multiplicand;
|
||||
vector->x2 *= multiplicand;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||