Добавлены функции модуля для версоров и кватернионо / Functions of modulus have been added for versors and quaternions

This commit is contained in:
Andrey Pokidov 2024-11-25 19:47:45 +07:00
parent bef7ab98f4
commit 03e390c1d0
12 changed files with 246 additions and 211 deletions

View file

@ -57,7 +57,7 @@ void print_versor(const BgFP32Versor* versor)
void print_vector(const BgFP32Vector3* vector) void print_vector(const BgFP32Vector3* vector)
{ {
printf("(%f, %f, %f) / %f\n", vector->x1, vector->x2, vector->x3, bg_fp32_vector3_get_module(vector)); printf("(%f, %f, %f) / %f\n", vector->x1, vector->x2, vector->x3, bg_fp32_vector3_get_modulus(vector));
} }
/* /*
int main() int main()
@ -120,7 +120,6 @@ int main()
} }
*/ */
/*
int main() int main()
{ {
const unsigned int amount = 1000000; const unsigned int amount = 1000000;
@ -130,7 +129,7 @@ int main()
now = GetTickCount64(); now = GetTickCount64();
srand((unsigned int)(now & 0xfffffff)); srand((unsigned int)(now & 0xfffffff));
#else #else
timespec now; struct timespec now;
clock_gettime(0, &now); clock_gettime(0, &now);
srand((unsigned int)(now.tv_nsec & 0xfffffff)); srand((unsigned int)(now.tv_nsec & 0xfffffff));
#endif // _WIN64 #endif // _WIN64
@ -191,14 +190,3 @@ int main()
free(versors1); free(versors1);
return 0; return 0;
} }
*/
int main() {
BgFP32Versor versor;
bg_fp32_versor_reset(&versor);
printf("Versor: (%f, %f, %f, %f)\n", versor.s0, versor.x1, versor.x2, versor.x3);
return 0;
}

View file

@ -18,20 +18,20 @@ const BgFP32Vector2 TEST_BG_FP32_VECTOR2_COMMON_2[] = {
{ 1.5f, -23.35f } { 1.5f, -23.35f }
}; };
// =============== Square module ================ // // =============== Square modulus =============== //
const float BG_FP32_VECTOR2_SQUARE_MODULE_1[] = { 25.0f, 25.0f, 500000000.0f, 100.01f, 15266.150221f }; const float BG_FP32_VECTOR2_SQUARE_MODULUS_1[] = { 25.0f, 25.0f, 500000000.0f, 100.01f, 15266.150221f };
int test_bg_fp32_vector2_square_module() int test_bg_fp32_vector2_square_modulus()
{ {
print_test_name("BgFP32Vector2 square module"); print_test_name("BgFP32Vector2 square modulus");
float square_module; float square_modulus;
for (int i = 0; i < TEST_BG_FP32_VECTOR2_AMOUNT_1; i++) { for (int i = 0; i < TEST_BG_FP32_VECTOR2_AMOUNT_1; i++) {
square_module = bg_fp32_vector2_get_square_module(&TEST_BG_FP32_VECTOR2_COMMON_1[i]); square_modulus = bg_fp32_vector2_get_square_modulus(&TEST_BG_FP32_VECTOR2_COMMON_1[i]);
if (!test_bg_fp32_are_equal(square_module, BG_FP32_VECTOR2_SQUARE_MODULE_1[i], TEST_BG_FP32_TWO_EPSYLON)) { if (!test_bg_fp32_are_equal(square_modulus, BG_FP32_VECTOR2_SQUARE_MODULUS_1[i], TEST_BG_FP32_TWO_EPSYLON)) {
print_test_failed(); print_test_failed();
return TEST_RESULT_FAILED; return TEST_RESULT_FAILED;
} }
@ -43,18 +43,18 @@ int test_bg_fp32_vector2_square_module()
// =================== Module =================== // // =================== Module =================== //
const float BG_FP32_VECTOR2_MODULE_1[] = { 5.0f, 5.0f, 22360.68f, 10.0005f, 123.55626338f }; const float BG_FP32_VECTOR2_MODULUS_1[] = { 5.0f, 5.0f, 22360.68f, 10.0005f, 123.55626338f };
int test_bg_fp32_vector2_module() int test_bg_fp32_vector2_modulus()
{ {
print_test_name("BgFP32Vector2 module"); print_test_name("BgFP32Vector2 modulus");
float square_module; float square_modulus;
for (int i = 0; i < TEST_BG_FP32_VECTOR2_AMOUNT_1; i++) { for (int i = 0; i < TEST_BG_FP32_VECTOR2_AMOUNT_1; i++) {
square_module = bg_fp32_vector2_get_module(&TEST_BG_FP32_VECTOR2_COMMON_1[i]); square_modulus = bg_fp32_vector2_get_modulus(&TEST_BG_FP32_VECTOR2_COMMON_1[i]);
if (!test_bg_fp32_are_equal(square_module, BG_FP32_VECTOR2_MODULE_1[i], TEST_BG_FP32_EPSYLON)) { if (!test_bg_fp32_are_equal(square_modulus, BG_FP32_VECTOR2_MODULUS_1[i], TEST_BG_FP32_EPSYLON)) {
print_test_failed(); print_test_failed();
return TEST_RESULT_FAILED; return TEST_RESULT_FAILED;
} }
@ -130,11 +130,11 @@ int test_bg_fp32_vector2()
{ {
print_test_section("BgFP32Vector2"); print_test_section("BgFP32Vector2");
if (test_bg_fp32_vector2_square_module() != TEST_RESULT_SUCCES) { if (test_bg_fp32_vector2_square_modulus() != TEST_RESULT_SUCCES) {
return TEST_RESULT_FAILED; return TEST_RESULT_FAILED;
} }
if (test_bg_fp32_vector2_module() != TEST_RESULT_SUCCES) { if (test_bg_fp32_vector2_modulus() != TEST_RESULT_SUCCES) {
return TEST_RESULT_FAILED; return TEST_RESULT_FAILED;
} }

View file

@ -5,9 +5,9 @@
int test_bg_fp32_vector2(); int test_bg_fp32_vector2();
int test_bg_fp32_vector2_square_module(); int test_bg_fp32_vector2_square_modulus();
int test_bg_fp32_vector2_module(); int test_bg_fp32_vector2_modulus();
int test_bg_fp32_vector2_add(); int test_bg_fp32_vector2_add();

View file

@ -9,15 +9,15 @@ void bg_fp32_quaternion_get_rotation_matrix(const BgFP32Quaternion* quaternion,
const float x2x2 = quaternion->x2 * quaternion->x2; const float x2x2 = quaternion->x2 * quaternion->x2;
const float x3x3 = quaternion->x3 * quaternion->x3; const float x3x3 = quaternion->x3 * quaternion->x3;
const float square_module = (s0s0 + x1x1) + (x2x2 + x3x3); const float square_modulus = (s0s0 + x1x1) + (x2x2 + x3x3);
if (-BG_FP32_EPSYLON <= square_module && square_module <= BG_FP32_EPSYLON) if (-BG_FP32_EPSYLON <= square_modulus && square_modulus <= BG_FP32_EPSYLON)
{ {
bg_fp32_matrix3x3_set_to_identity(matrix); bg_fp32_matrix3x3_set_to_identity(matrix);
return; return;
} }
const float corrector1 = 1.0f / square_module; const float corrector1 = 1.0f / square_modulus;
const float corrector2 = 2.0f * corrector1; const float corrector2 = 2.0f * corrector1;
const float s0x1 = quaternion->s0 * quaternion->x1; const float s0x1 = quaternion->s0 * quaternion->x1;
@ -47,15 +47,15 @@ void bg_fp64_quaternion_get_rotation_matrix(const BgFP64Quaternion* quaternion,
const double x2x2 = quaternion->x2 * quaternion->x2; const double x2x2 = quaternion->x2 * quaternion->x2;
const double x3x3 = quaternion->x3 * quaternion->x3; const double x3x3 = quaternion->x3 * quaternion->x3;
const double square_module = (s0s0 + x1x1) + (x2x2 + x3x3); const double square_modulus = (s0s0 + x1x1) + (x2x2 + x3x3);
if (-BG_FP64_EPSYLON <= square_module && square_module <= BG_FP64_EPSYLON) if (-BG_FP64_EPSYLON <= square_modulus && square_modulus <= BG_FP64_EPSYLON)
{ {
bg_fp64_matrix3x3_set_to_identity(matrix); bg_fp64_matrix3x3_set_to_identity(matrix);
return; return;
} }
const double corrector1 = 1.0f / square_module; const double corrector1 = 1.0f / square_modulus;
const double corrector2 = 2.0f * corrector1; const double corrector2 = 2.0f * corrector1;
const double s0x1 = quaternion->s0 * quaternion->x1; const double s0x1 = quaternion->s0 * quaternion->x1;
@ -87,15 +87,15 @@ void bg_fp32_quaternion_get_reverse_matrix(const BgFP32Quaternion* quaternion, B
const float x2x2 = quaternion->x2 * quaternion->x2; const float x2x2 = quaternion->x2 * quaternion->x2;
const float x3x3 = quaternion->x3 * quaternion->x3; const float x3x3 = quaternion->x3 * quaternion->x3;
const float square_module = (s0s0 + x1x1) + (x2x2 + x3x3); const float square_modulus = (s0s0 + x1x1) + (x2x2 + x3x3);
if (-BG_FP32_EPSYLON <= square_module && square_module <= BG_FP32_EPSYLON) if (-BG_FP32_EPSYLON <= square_modulus && square_modulus <= BG_FP32_EPSYLON)
{ {
bg_fp32_matrix3x3_set_to_identity(matrix); bg_fp32_matrix3x3_set_to_identity(matrix);
return; return;
} }
const float corrector1 = 1.0f / square_module; const float corrector1 = 1.0f / square_modulus;
const float corrector2 = 2.0f * corrector1; const float corrector2 = 2.0f * corrector1;
const float s0x1 = quaternion->s0 * quaternion->x1; const float s0x1 = quaternion->s0 * quaternion->x1;
@ -125,15 +125,15 @@ void bg_fp64_quaternion_get_reverse_matrix(const BgFP64Quaternion* quaternion, B
const double x2x2 = quaternion->x2 * quaternion->x2; const double x2x2 = quaternion->x2 * quaternion->x2;
const double x3x3 = quaternion->x3 * quaternion->x3; const double x3x3 = quaternion->x3 * quaternion->x3;
const double square_module = (s0s0 + x1x1) + (x2x2 + x3x3); const double square_modulus = (s0s0 + x1x1) + (x2x2 + x3x3);
if (-BG_FP64_EPSYLON <= square_module && square_module <= BG_FP64_EPSYLON) if (-BG_FP64_EPSYLON <= square_modulus && square_modulus <= BG_FP64_EPSYLON)
{ {
bg_fp64_matrix3x3_set_to_identity(matrix); bg_fp64_matrix3x3_set_to_identity(matrix);
return; return;
} }
const double corrector1 = 1.0f / square_module; const double corrector1 = 1.0f / square_modulus;
const double corrector2 = 2.0f * corrector1; const double corrector2 = 2.0f * corrector1;
const double s0x1 = quaternion->s0 * quaternion->x1; const double s0x1 = quaternion->s0 * quaternion->x1;

View file

@ -89,72 +89,96 @@ static inline void bg_fp64_quaternion_copy(const BgFP64Quaternion* from, BgFP64Q
// ============= Copy to twin type ============== // // ============= Copy to twin type ============== //
static inline void bg_fp32_quaternion_set_from_fp64(const BgFP64Quaternion* versor, BgFP32Quaternion* result) static inline void bg_fp32_quaternion_set_from_fp64(const BgFP64Quaternion* quaternion, BgFP32Quaternion* result)
{ {
result->s0 = (float) versor->s0; result->s0 = (float) quaternion->s0;
result->x1 = (float) versor->x1; result->x1 = (float) quaternion->x1;
result->x2 = (float) versor->x2; result->x2 = (float) quaternion->x2;
result->x3 = (float) versor->x3; result->x3 = (float) quaternion->x3;
} }
static inline void bg_fp64_quaternion_set_from_fp32(const BgFP32Quaternion* versor, BgFP64Quaternion* result) static inline void bg_fp64_quaternion_set_from_fp32(const BgFP32Quaternion* quaternion, BgFP64Quaternion* result)
{ {
result->s0 = versor->s0; result->s0 = quaternion->s0;
result->x1 = versor->x1; result->x1 = quaternion->x1;
result->x2 = versor->x2; result->x2 = quaternion->x2;
result->x3 = versor->x3; result->x3 = quaternion->x3;
} }
// ================= Inversion ================== // // ================= Inversion ================== //
static inline void bg_fp32_quaternion_conjugate(BgFP32Quaternion* versor) static inline void bg_fp32_quaternion_conjugate(BgFP32Quaternion* quaternion)
{ {
versor->x1 = -versor->x1; quaternion->x1 = -quaternion->x1;
versor->x2 = -versor->x2; quaternion->x2 = -quaternion->x2;
versor->x3 = -versor->x3; quaternion->x3 = -quaternion->x3;
} }
static inline void bg_fp64_quaternion_conjugate(BgFP64Quaternion* versor) static inline void bg_fp64_quaternion_conjugate(BgFP64Quaternion* quaternion)
{ {
versor->x1 = -versor->x1; quaternion->x1 = -quaternion->x1;
versor->x2 = -versor->x2; quaternion->x2 = -quaternion->x2;
versor->x3 = -versor->x3; quaternion->x3 = -quaternion->x3;
} }
// ================ Set Conjugate =============== // // ================ Set Conjugate =============== //
static inline void bg_fp32_quaternion_set_conjugate(const BgFP32Quaternion* versor, BgFP32Quaternion* result) static inline void bg_fp32_quaternion_set_conjugate(const BgFP32Quaternion* quaternion, BgFP32Quaternion* result)
{ {
result->s0 = versor->s0; result->s0 = quaternion->s0;
result->x1 = -versor->x1; result->x1 = -quaternion->x1;
result->x2 = -versor->x2; result->x2 = -quaternion->x2;
result->x3 = -versor->x3; result->x3 = -quaternion->x3;
} }
static inline void bg_fp64_quaternion_set_conjugate(const BgFP64Quaternion* versor, BgFP64Quaternion* result) static inline void bg_fp64_quaternion_set_conjugate(const BgFP64Quaternion* quaternion, BgFP64Quaternion* result)
{ {
result->s0 = versor->s0; result->s0 = quaternion->s0;
result->x1 = -versor->x1; result->x1 = -quaternion->x1;
result->x2 = -versor->x2; result->x2 = -quaternion->x2;
result->x3 = -versor->x3; result->x3 = -quaternion->x3;
} }
// ================ Get Inverted ================ // // ================ Set Conjugate =============== //
static inline void bg_fp32_quaternion_set_conjugate_fp64(const BgFP64Quaternion* versor, BgFP32Quaternion* result) static inline void bg_fp32_quaternion_set_conjugate_fp64(const BgFP64Quaternion* quaternion, BgFP32Quaternion* result)
{ {
result->s0 = (float) versor->s0; result->s0 = (float) quaternion->s0;
result->x1 = (float) -versor->x1; result->x1 = (float) -quaternion->x1;
result->x2 = (float) -versor->x2; result->x2 = (float) -quaternion->x2;
result->x3 = (float) -versor->x3; result->x3 = (float) -quaternion->x3;
} }
static inline void bg_fp64_quaternion_set_conjugate_fp32(const BgFP32Quaternion* versor, BgFP64Quaternion* result) static inline void bg_fp64_quaternion_set_conjugate_fp32(const BgFP32Quaternion* quaternion, BgFP64Quaternion* result)
{ {
result->s0 = versor->s0; result->s0 = quaternion->s0;
result->x1 = -versor->x1; result->x1 = -quaternion->x1;
result->x2 = -versor->x2; result->x2 = -quaternion->x2;
result->x3 = -versor->x3; result->x3 = -quaternion->x3;
}
// ============= Get Square Modulus ============= //
static inline float bg_fp32_quaternion_get_square_modulus(const BgFP32Quaternion* quaternion)
{
return (quaternion->s0 * quaternion->s0 + quaternion->x1 * quaternion->x1) + (quaternion->x2 * quaternion->x2 + quaternion->x3 * quaternion->x3);
}
static inline double bg_fp64_quaternion_get_square_modulus(const BgFP64Quaternion* quaternion)
{
return (quaternion->s0 * quaternion->s0 + quaternion->x1 * quaternion->x1) + (quaternion->x2 * quaternion->x2 + quaternion->x3 * quaternion->x3);
}
// ================ Get Modulus ================= //
static inline float bg_fp32_quaternion_get_modulus(const BgFP32Quaternion* quaternion)
{
return sqrtf(bg_fp32_quaternion_get_square_modulus(quaternion));
}
static inline double bg_fp64_quaternion_get_modulus(const BgFP64Quaternion* quaternion)
{
return sqrt(bg_fp64_quaternion_get_square_modulus(quaternion));
} }
// ============ Make Rotation Matrix ============ // // ============ Make Rotation Matrix ============ //

View file

@ -8,19 +8,19 @@ float bg_fp32_vector2_get_angle(const BgFP32Vector2* vector1, const BgFP32Vector
return 0.0f; return 0.0f;
} }
const float square_module1 = bg_fp32_vector2_get_square_module(vector1); const float square_modulus1 = bg_fp32_vector2_get_square_modulus(vector1);
if (square_module1 <= BG_FP32_SQUARE_EPSYLON) { if (square_modulus1 <= BG_FP32_SQUARE_EPSYLON) {
return 0.0f; return 0.0f;
} }
const float square_module2 = bg_fp32_vector2_get_square_module(vector2); const float square_modulus2 = bg_fp32_vector2_get_square_modulus(vector2);
if (square_module2 <= BG_FP32_SQUARE_EPSYLON) { if (square_modulus2 <= BG_FP32_SQUARE_EPSYLON) {
return 0.0f; return 0.0f;
} }
const float cosine = bg_fp32_vector2_dot_product(vector1, vector2) / sqrtf(square_module1 * square_module2); const float cosine = bg_fp32_vector2_dot_product(vector1, vector2) / sqrtf(square_modulus1 * square_modulus2);
if (cosine >= 1.0f - BG_FP32_EPSYLON) { if (cosine >= 1.0f - BG_FP32_EPSYLON) {
return 0.0f; return 0.0f;
@ -39,19 +39,19 @@ double bg_fp64_vector2_get_angle(const BgFP64Vector2* vector1, const BgFP64Vecto
return 0.0; return 0.0;
} }
const double square_module1 = bg_fp64_vector2_get_square_module(vector1); const double square_modulus1 = bg_fp64_vector2_get_square_modulus(vector1);
if (square_module1 <= BG_FP64_SQUARE_EPSYLON) { if (square_modulus1 <= BG_FP64_SQUARE_EPSYLON) {
return 0.0; return 0.0;
} }
const double square_module2 = bg_fp64_vector2_get_square_module(vector2); const double square_modulus2 = bg_fp64_vector2_get_square_modulus(vector2);
if (square_module2 <= BG_FP64_SQUARE_EPSYLON) { if (square_modulus2 <= BG_FP64_SQUARE_EPSYLON) {
return 0.0; return 0.0;
} }
const double cosine = bg_fp64_vector2_dot_product(vector1, vector2) / sqrt(square_module1 * square_module2); const double cosine = bg_fp64_vector2_dot_product(vector1, vector2) / sqrt(square_modulus1 * square_modulus2);
if (cosine >= 1.0 - BG_FP64_EPSYLON) { if (cosine >= 1.0 - BG_FP64_EPSYLON) {
return 0.0; return 0.0;

View file

@ -102,50 +102,50 @@ static inline void bg_fp64_vector2_set_reverse_fp32(const BgFP32Vector2* from, B
// =================== Module =================== // // =================== Module =================== //
static inline float bg_fp32_vector2_get_square_module(const BgFP32Vector2* vector) static inline float bg_fp32_vector2_get_square_modulus(const BgFP32Vector2* vector)
{ {
return vector->x1 * vector->x1 + vector->x2 * vector->x2; return vector->x1 * vector->x1 + vector->x2 * vector->x2;
} }
static inline double bg_fp64_vector2_get_square_module(const BgFP64Vector2* vector) static inline double bg_fp64_vector2_get_square_modulus(const BgFP64Vector2* vector)
{ {
return vector->x1 * vector->x1 + vector->x2 * vector->x2; return vector->x1 * vector->x1 + vector->x2 * vector->x2;
} }
static inline float bg_fp32_vector2_get_module(const BgFP32Vector2* vector) static inline float bg_fp32_vector2_get_modulus(const BgFP32Vector2* vector)
{ {
return sqrtf(bg_fp32_vector2_get_square_module(vector)); return sqrtf(bg_fp32_vector2_get_square_modulus(vector));
} }
static inline double bg_fp64_vector2_get_module(const BgFP64Vector2* vector) static inline double bg_fp64_vector2_get_modulus(const BgFP64Vector2* vector)
{ {
return sqrt(bg_fp64_vector2_get_square_module(vector)); return sqrt(bg_fp64_vector2_get_square_modulus(vector));
} }
// ================= Comparison ================= // // ================= Comparison ================= //
static inline int bg_fp32_vector2_is_zero(const BgFP32Vector2* vector) static inline int bg_fp32_vector2_is_zero(const BgFP32Vector2* vector)
{ {
return bg_fp32_vector2_get_square_module(vector) <= BG_FP32_SQUARE_EPSYLON; return bg_fp32_vector2_get_square_modulus(vector) <= BG_FP32_SQUARE_EPSYLON;
} }
static inline int bg_fp64_vector2_is_zero(const BgFP64Vector2* vector) static inline int bg_fp64_vector2_is_zero(const BgFP64Vector2* vector)
{ {
return bg_fp64_vector2_get_square_module(vector) <= BG_FP64_SQUARE_EPSYLON; return bg_fp64_vector2_get_square_modulus(vector) <= BG_FP64_SQUARE_EPSYLON;
} }
static inline int bg_fp32_vector2_is_unit(const BgFP32Vector2* vector) static inline int bg_fp32_vector2_is_unit(const BgFP32Vector2* vector)
{ {
const float square_module = bg_fp32_vector2_get_square_module(vector); const float square_modulus = bg_fp32_vector2_get_square_modulus(vector);
return 1.0f - BG_FP32_TWO_EPSYLON <= square_module && square_module <= 1.0f + BG_FP32_TWO_EPSYLON; return 1.0f - BG_FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + BG_FP32_TWO_EPSYLON;
} }
static inline int bg_fp64_vector2_is_unit(const BgFP64Vector2* vector) static inline int bg_fp64_vector2_is_unit(const BgFP64Vector2* vector)
{ {
const double square_module = bg_fp64_vector2_get_square_module(vector); const double square_modulus = bg_fp64_vector2_get_square_modulus(vector);
return 1.0f - BG_FP64_TWO_EPSYLON <= square_module && square_module <= 1.0f + BG_FP64_TWO_EPSYLON; return 1.0f - BG_FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + BG_FP64_TWO_EPSYLON;
} }
// ==================== Add ===================== // // ==================== Add ===================== //
@ -274,35 +274,35 @@ static inline double bg_fp64_vector2_cross_product(const BgFP64Vector2* vector1,
static inline int bg_fp32_vector2_normalize(BgFP32Vector2* vector) static inline int bg_fp32_vector2_normalize(BgFP32Vector2* vector)
{ {
const float square_module = bg_fp32_vector2_get_square_module(vector); const float square_modulus = bg_fp32_vector2_get_square_modulus(vector);
if (1.0f - BG_FP32_TWO_EPSYLON <= square_module && square_module <= 1.0f + BG_FP32_TWO_EPSYLON) { if (1.0f - BG_FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + BG_FP32_TWO_EPSYLON) {
return 1; return 1;
} }
if (square_module <= BG_FP32_SQUARE_EPSYLON) { if (square_modulus <= BG_FP32_SQUARE_EPSYLON) {
bg_fp32_vector2_reset(vector); bg_fp32_vector2_reset(vector);
return 0; return 0;
} }
bg_fp32_vector2_divide(vector, sqrtf(square_module), vector); bg_fp32_vector2_divide(vector, sqrtf(square_modulus), vector);
return 1; return 1;
} }
static inline int bg_fp64_vector2_normalize(BgFP64Vector2* vector) static inline int bg_fp64_vector2_normalize(BgFP64Vector2* vector)
{ {
const double square_module = bg_fp64_vector2_get_square_module(vector); const double square_modulus = bg_fp64_vector2_get_square_modulus(vector);
if (1.0 - BG_FP64_TWO_EPSYLON <= square_module && square_module <= 1.0 + BG_FP64_TWO_EPSYLON) { if (1.0 - BG_FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0 + BG_FP64_TWO_EPSYLON) {
return 1; return 1;
} }
if (square_module <= BG_FP64_SQUARE_EPSYLON) { if (square_modulus <= BG_FP64_SQUARE_EPSYLON) {
bg_fp64_vector2_reset(vector); bg_fp64_vector2_reset(vector);
return 0; return 0;
} }
bg_fp64_vector2_divide(vector, sqrt(square_module), vector); bg_fp64_vector2_divide(vector, sqrt(square_modulus), vector);
return 1; return 1;
} }
@ -360,38 +360,38 @@ static inline double bg_fp64_vector2_get_distance(const BgFP64Vector2* vector1,
static inline int bg_fp32_vector2_are_equal(const BgFP32Vector2* vector1, const BgFP32Vector2* vector2) static inline int bg_fp32_vector2_are_equal(const BgFP32Vector2* vector1, const BgFP32Vector2* vector2)
{ {
const float square_module1 = bg_fp32_vector2_get_square_module(vector1); const float square_modulus1 = bg_fp32_vector2_get_square_modulus(vector1);
const float square_module2 = bg_fp32_vector2_get_square_module(vector2); const float square_modulus2 = bg_fp32_vector2_get_square_modulus(vector2);
const float square_module3 = bg_fp32_vector2_get_square_distance(vector1, vector2); const float square_modulus3 = bg_fp32_vector2_get_square_distance(vector1, vector2);
// 2.0f means dimension amount // 2.0f means dimension amount
if (square_module1 < BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT || square_module2 < BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT) { if (square_modulus1 < BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT || square_modulus2 < BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT) {
return square_module3 < (2.0f * BG_FP32_SQUARE_EPSYLON); return square_modulus3 < (2.0f * BG_FP32_SQUARE_EPSYLON);
} }
if (square_module1 <= square_module2) { if (square_modulus1 <= square_modulus2) {
return square_module3 <= (2.0f * BG_FP32_SQUARE_EPSYLON) * square_module2; return square_modulus3 <= (2.0f * BG_FP32_SQUARE_EPSYLON) * square_modulus2;
} }
return square_module3 <= (2.0f * BG_FP32_SQUARE_EPSYLON) * square_module1; return square_modulus3 <= (2.0f * BG_FP32_SQUARE_EPSYLON) * square_modulus1;
} }
static inline int bg_fp64_vector2_are_equal(const BgFP64Vector2* vector1, const BgFP64Vector2* vector2) static inline int bg_fp64_vector2_are_equal(const BgFP64Vector2* vector1, const BgFP64Vector2* vector2)
{ {
const double square_module1 = bg_fp64_vector2_get_square_module(vector1); const double square_modulus1 = bg_fp64_vector2_get_square_modulus(vector1);
const double square_module2 = bg_fp64_vector2_get_square_module(vector2); const double square_modulus2 = bg_fp64_vector2_get_square_modulus(vector2);
const double square_module3 = bg_fp64_vector2_get_square_distance(vector1, vector2); const double square_modulus3 = bg_fp64_vector2_get_square_distance(vector1, vector2);
// 2.0 means dimension amount // 2.0 means dimension amount
if (square_module1 < BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT || square_module2 < BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT) { if (square_modulus1 < BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT || square_modulus2 < BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT) {
return square_module3 < (2.0 * BG_FP64_SQUARE_EPSYLON); return square_modulus3 < (2.0 * BG_FP64_SQUARE_EPSYLON);
} }
if (square_module1 <= square_module2) { if (square_modulus1 <= square_modulus2) {
return square_module3 <= (2.0 * BG_FP64_SQUARE_EPSYLON) * square_module2; return square_modulus3 <= (2.0 * BG_FP64_SQUARE_EPSYLON) * square_modulus2;
} }
return square_module3 <= (2.0 * BG_FP64_SQUARE_EPSYLON) * square_module1; return square_modulus3 <= (2.0 * BG_FP64_SQUARE_EPSYLON) * square_modulus1;
} }
#endif #endif

View file

@ -8,19 +8,19 @@ float bg_fp32_vector3_get_angle(const BgFP32Vector3* vector1, const BgFP32Vector
return 0.0f; return 0.0f;
} }
const float square_module1 = bg_fp32_vector3_get_square_module(vector1); const float square_modulus1 = bg_fp32_vector3_get_square_modulus(vector1);
if (square_module1 <= BG_FP32_SQUARE_EPSYLON) { if (square_modulus1 <= BG_FP32_SQUARE_EPSYLON) {
return 0.0f; return 0.0f;
} }
const float square_module2 = bg_fp32_vector3_get_square_module(vector2); const float square_modulus2 = bg_fp32_vector3_get_square_modulus(vector2);
if (square_module2 <= BG_FP32_SQUARE_EPSYLON) { if (square_modulus2 <= BG_FP32_SQUARE_EPSYLON) {
return 0.0f; return 0.0f;
} }
const float cosine = bg_fp32_vector3_dot_product(vector1, vector2) / sqrtf(square_module1 * square_module2); const float cosine = bg_fp32_vector3_dot_product(vector1, vector2) / sqrtf(square_modulus1 * square_modulus2);
if (cosine >= 1.0f - BG_FP32_EPSYLON) { if (cosine >= 1.0f - BG_FP32_EPSYLON) {
return 0.0f; return 0.0f;
@ -39,19 +39,19 @@ double bg_fp64_vector3_get_angle(const BgFP64Vector3* vector1, const BgFP64Vecto
return 0.0; return 0.0;
} }
const double square_module1 = bg_fp64_vector3_get_square_module(vector1); const double square_modulus1 = bg_fp64_vector3_get_square_modulus(vector1);
if (square_module1 <= BG_FP64_SQUARE_EPSYLON) { if (square_modulus1 <= BG_FP64_SQUARE_EPSYLON) {
return 0.0; return 0.0;
} }
const double square_module2 = bg_fp64_vector3_get_square_module(vector2); const double square_modulus2 = bg_fp64_vector3_get_square_modulus(vector2);
if (square_module2 <= BG_FP64_SQUARE_EPSYLON) { if (square_modulus2 <= BG_FP64_SQUARE_EPSYLON) {
return 0.0; return 0.0;
} }
const double cosine = bg_fp64_vector3_dot_product(vector1, vector2) / sqrt(square_module1 * square_module2); const double cosine = bg_fp64_vector3_dot_product(vector1, vector2) / sqrt(square_modulus1 * square_modulus2);
if (cosine >= 1.0 - BG_FP64_EPSYLON) { if (cosine >= 1.0 - BG_FP64_EPSYLON) {
return 0.0; return 0.0;

View file

@ -116,50 +116,50 @@ static inline void bg_fp64_vector3_set_reverse_fp32(const BgFP32Vector3* from, B
// =================== Module =================== // // =================== Module =================== //
static inline float bg_fp32_vector3_get_square_module(const BgFP32Vector3* vector) static inline float bg_fp32_vector3_get_square_modulus(const BgFP32Vector3* vector)
{ {
return vector->x1 * vector->x1 + vector->x2 * vector->x2 + vector->x3 * vector->x3; return vector->x1 * vector->x1 + vector->x2 * vector->x2 + vector->x3 * vector->x3;
} }
static inline double bg_fp64_vector3_get_square_module(const BgFP64Vector3* vector) static inline double bg_fp64_vector3_get_square_modulus(const BgFP64Vector3* vector)
{ {
return vector->x1 * vector->x1 + vector->x2 * vector->x2 + vector->x3 * vector->x3; return vector->x1 * vector->x1 + vector->x2 * vector->x2 + vector->x3 * vector->x3;
} }
static inline float bg_fp32_vector3_get_module(const BgFP32Vector3* vector) static inline float bg_fp32_vector3_get_modulus(const BgFP32Vector3* vector)
{ {
return sqrtf(bg_fp32_vector3_get_square_module(vector)); return sqrtf(bg_fp32_vector3_get_square_modulus(vector));
} }
static inline double bg_fp64_vector3_get_module(const BgFP64Vector3* vector) static inline double bg_fp64_vector3_get_modulus(const BgFP64Vector3* vector)
{ {
return sqrt(bg_fp64_vector3_get_square_module(vector)); return sqrt(bg_fp64_vector3_get_square_modulus(vector));
} }
// ================= Comparison ================= // // ================= Comparison ================= //
static inline int bg_fp32_vector3_is_zero(const BgFP32Vector3* vector) static inline int bg_fp32_vector3_is_zero(const BgFP32Vector3* vector)
{ {
return bg_fp32_vector3_get_square_module(vector) <= BG_FP32_SQUARE_EPSYLON; return bg_fp32_vector3_get_square_modulus(vector) <= BG_FP32_SQUARE_EPSYLON;
} }
static inline int bg_fp64_vector3_is_zero(const BgFP64Vector3* vector) static inline int bg_fp64_vector3_is_zero(const BgFP64Vector3* vector)
{ {
return bg_fp64_vector3_get_square_module(vector) <= BG_FP64_SQUARE_EPSYLON; return bg_fp64_vector3_get_square_modulus(vector) <= BG_FP64_SQUARE_EPSYLON;
} }
static inline int bg_fp32_vector3_is_unit(const BgFP32Vector3* vector) static inline int bg_fp32_vector3_is_unit(const BgFP32Vector3* vector)
{ {
const float square_module = bg_fp32_vector3_get_square_module(vector); const float square_modulus = bg_fp32_vector3_get_square_modulus(vector);
return 1.0f - BG_FP32_TWO_EPSYLON <= square_module && square_module <= 1.0f + BG_FP32_TWO_EPSYLON; return 1.0f - BG_FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + BG_FP32_TWO_EPSYLON;
} }
static inline int bg_fp64_vector3_is_unit(const BgFP64Vector3* vector) static inline int bg_fp64_vector3_is_unit(const BgFP64Vector3* vector)
{ {
const double square_module = bg_fp64_vector3_get_square_module(vector); const double square_modulus = bg_fp64_vector3_get_square_modulus(vector);
return 1.0f - BG_FP64_TWO_EPSYLON <= square_module && square_module <= 1.0f + BG_FP64_TWO_EPSYLON; return 1.0f - BG_FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + BG_FP64_TWO_EPSYLON;
} }
// ==================== Add ===================== // // ==================== Add ===================== //
@ -350,35 +350,35 @@ static inline void bg_fp64_vector3_double_cross(const BgFP64Vector3* vector1, co
static inline int bg_fp32_vector3_normalize(BgFP32Vector3* vector) static inline int bg_fp32_vector3_normalize(BgFP32Vector3* vector)
{ {
const float square_module = bg_fp32_vector3_get_square_module(vector); const float square_modulus = bg_fp32_vector3_get_square_modulus(vector);
if (1.0f - BG_FP32_TWO_EPSYLON <= square_module && square_module <= 1.0f + BG_FP32_TWO_EPSYLON) { if (1.0f - BG_FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + BG_FP32_TWO_EPSYLON) {
return 1; return 1;
} }
if (square_module <= BG_FP32_SQUARE_EPSYLON) { if (square_modulus <= BG_FP32_SQUARE_EPSYLON) {
bg_fp32_vector3_reset(vector); bg_fp32_vector3_reset(vector);
return 0; return 0;
} }
bg_fp32_vector3_divide(vector, sqrtf(square_module), vector); bg_fp32_vector3_divide(vector, sqrtf(square_modulus), vector);
return 1; return 1;
} }
static inline int bg_fp64_vector3_normalize(BgFP64Vector3* vector) static inline int bg_fp64_vector3_normalize(BgFP64Vector3* vector)
{ {
const double square_module = bg_fp64_vector3_get_square_module(vector); const double square_modulus = bg_fp64_vector3_get_square_modulus(vector);
if (1.0 - BG_FP64_TWO_EPSYLON <= square_module && square_module <= 1.0 + BG_FP64_TWO_EPSYLON) { if (1.0 - BG_FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0 + BG_FP64_TWO_EPSYLON) {
return 1; return 1;
} }
if (square_module <= BG_FP64_SQUARE_EPSYLON) { if (square_modulus <= BG_FP64_SQUARE_EPSYLON) {
bg_fp64_vector3_reset(vector); bg_fp64_vector3_reset(vector);
return 0; return 0;
} }
bg_fp64_vector3_divide(vector, sqrt(square_module), vector); bg_fp64_vector3_divide(vector, sqrt(square_modulus), vector);
return 1; return 1;
} }
@ -438,38 +438,38 @@ static inline double bg_fp64_vector3_get_distance(const BgFP64Vector3* vector1,
static inline int bg_fp32_vector3_are_equal(const BgFP32Vector3* vector1, const BgFP32Vector3* vector2) static inline int bg_fp32_vector3_are_equal(const BgFP32Vector3* vector1, const BgFP32Vector3* vector2)
{ {
const float square_module1 = bg_fp32_vector3_get_square_module(vector1); const float square_modulus1 = bg_fp32_vector3_get_square_modulus(vector1);
const float square_module2 = bg_fp32_vector3_get_square_module(vector2); const float square_modulus2 = bg_fp32_vector3_get_square_modulus(vector2);
const float square_module3 = bg_fp32_vector3_get_square_distance(vector1, vector2); const float square_modulus3 = bg_fp32_vector3_get_square_distance(vector1, vector2);
// 3.0f means dimension amount // 3.0f means dimension amount
if (square_module1 < BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT || square_module2 < BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT) { if (square_modulus1 < BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT || square_modulus2 < BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT) {
return square_module3 < (3.0f * BG_FP32_SQUARE_EPSYLON); return square_modulus3 < (3.0f * BG_FP32_SQUARE_EPSYLON);
} }
if (square_module1 <= square_module2) { if (square_modulus1 <= square_modulus2) {
return square_module3 <= (3.0f * BG_FP32_SQUARE_EPSYLON) * square_module2; return square_modulus3 <= (3.0f * BG_FP32_SQUARE_EPSYLON) * square_modulus2;
} }
return square_module3 <= (3.0f * BG_FP32_SQUARE_EPSYLON) * square_module1; return square_modulus3 <= (3.0f * BG_FP32_SQUARE_EPSYLON) * square_modulus1;
} }
static inline int bg_fp64_vector3_are_equal(const BgFP64Vector3* vector1, const BgFP64Vector3* vector2) static inline int bg_fp64_vector3_are_equal(const BgFP64Vector3* vector1, const BgFP64Vector3* vector2)
{ {
const double square_module1 = bg_fp64_vector3_get_square_module(vector1); const double square_modulus1 = bg_fp64_vector3_get_square_modulus(vector1);
const double square_module2 = bg_fp64_vector3_get_square_module(vector2); const double square_modulus2 = bg_fp64_vector3_get_square_modulus(vector2);
const double square_module3 = bg_fp64_vector3_get_square_distance(vector1, vector2); const double square_modulus3 = bg_fp64_vector3_get_square_distance(vector1, vector2);
// 3.0 means dimension amount // 3.0 means dimension amount
if (square_module1 < BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT || square_module2 < BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT) { if (square_modulus1 < BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT || square_modulus2 < BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT) {
return square_module3 < (3.0 * BG_FP64_SQUARE_EPSYLON); return square_modulus3 < (3.0 * BG_FP64_SQUARE_EPSYLON);
} }
if (square_module1 <= square_module2) { if (square_modulus1 <= square_modulus2) {
return square_module3 <= (3.0 * BG_FP64_SQUARE_EPSYLON) * square_module2; return square_modulus3 <= (3.0 * BG_FP64_SQUARE_EPSYLON) * square_modulus2;
} }
return square_module3 <= (3.0 * BG_FP64_SQUARE_EPSYLON) * square_module1; return square_modulus3 <= (3.0 * BG_FP64_SQUARE_EPSYLON) * square_modulus1;
} }
#endif #endif

View file

@ -7,9 +7,9 @@ const BgFP32Versor BG_FP32_IDLE_VERSOR = { 1.0f, 0.0f, 0.0f, 0.0f };
const BgFP64Versor BG_FP64_IDLE_VERSOR = { 1.0, 0.0, 0.0, 0.0 }; const BgFP64Versor BG_FP64_IDLE_VERSOR = { 1.0, 0.0, 0.0, 0.0 };
void __bg_fp32_versor_normalize(const float square_module, __BgFP32DarkTwinVersor* twin) void __bg_fp32_versor_normalize(const float square_modulus, __BgFP32DarkTwinVersor* twin)
{ {
if (square_module <= BG_FP32_SQUARE_EPSYLON || (twin->s0 * twin->s0) >= (1.0f - BG_FP32_TWO_EPSYLON) * square_module) { if (square_modulus <= BG_FP32_SQUARE_EPSYLON || (twin->s0 * twin->s0) >= (1.0f - BG_FP32_TWO_EPSYLON) * square_modulus) {
twin->s0 = 1.0f; twin->s0 = 1.0f;
twin->x1 = 0.0f; twin->x1 = 0.0f;
twin->x2 = 0.0f; twin->x2 = 0.0f;
@ -17,17 +17,17 @@ void __bg_fp32_versor_normalize(const float square_module, __BgFP32DarkTwinVerso
return; return;
} }
const float module = sqrtf(square_module); const float modulus = sqrtf(square_modulus);
twin->s0 /= module; twin->s0 /= modulus;
twin->x1 /= module; twin->x1 /= modulus;
twin->x2 /= module; twin->x2 /= modulus;
twin->x3 /= module; twin->x3 /= modulus;
} }
void __bg_fp64_versor_normalize(const double square_module, __BgFP64DarkTwinVersor* twin) void __bg_fp64_versor_normalize(const double square_modulus, __BgFP64DarkTwinVersor* twin)
{ {
if (square_module <= BG_FP64_SQUARE_EPSYLON || (twin->s0 * twin->s0) >= (1.0 - BG_FP64_TWO_EPSYLON) * square_module) { if (square_modulus <= BG_FP64_SQUARE_EPSYLON || (twin->s0 * twin->s0) >= (1.0 - BG_FP64_TWO_EPSYLON) * square_modulus) {
twin->s0 = 1.0; twin->s0 = 1.0;
twin->x1 = 0.0; twin->x1 = 0.0;
twin->x2 = 0.0; twin->x2 = 0.0;
@ -35,12 +35,12 @@ void __bg_fp64_versor_normalize(const double square_module, __BgFP64DarkTwinVers
return; return;
} }
const double module = sqrt(square_module); const double modulus = sqrt(square_modulus);
twin->s0 /= module; twin->s0 /= modulus;
twin->x1 /= module; twin->x1 /= modulus;
twin->x2 /= module; twin->x2 /= modulus;
twin->x3 /= module; twin->x3 /= modulus;
} }
// =============== Set Crude Turn =============== // // =============== Set Crude Turn =============== //
@ -108,11 +108,11 @@ void bg_fp32_versor_get_rotation(const BgFP32Versor* versor, BgFP32Rotation3* re
result->radians = 2.0f * acosf(versor->s0 / sqrtf(versor->s0 * versor->s0 + square_vector)); result->radians = 2.0f * acosf(versor->s0 / sqrtf(versor->s0 * versor->s0 + square_vector));
const float vector_module = sqrtf(square_vector); const float vector_modulus = sqrtf(square_vector);
result->axis.x1 = versor->x1 / vector_module; result->axis.x1 = versor->x1 / vector_modulus;
result->axis.x2 = versor->x2 / vector_module; result->axis.x2 = versor->x2 / vector_modulus;
result->axis.x3 = versor->x3 / vector_module; result->axis.x3 = versor->x3 / vector_modulus;
} }
void bg_fp64_versor_get_rotation(const BgFP64Versor* versor, BgFP64Rotation3* result) void bg_fp64_versor_get_rotation(const BgFP64Versor* versor, BgFP64Rotation3* result)
@ -130,9 +130,9 @@ void bg_fp64_versor_get_rotation(const BgFP64Versor* versor, BgFP64Rotation3* re
result->radians = 2.0 * acos(versor->s0 / sqrt(versor->s0 * versor->s0 + square_vector)); result->radians = 2.0 * acos(versor->s0 / sqrt(versor->s0 * versor->s0 + square_vector));
const double vector_module = sqrt(square_vector); const double vector_modulus = sqrt(square_vector);
result->axis.x1 = versor->x1 / vector_module; result->axis.x1 = versor->x1 / vector_modulus;
result->axis.x2 = versor->x2 / vector_module; result->axis.x2 = versor->x2 / vector_modulus;
result->axis.x3 = versor->x3 / vector_module; result->axis.x3 = versor->x3 / vector_modulus;
} }

View file

@ -58,9 +58,9 @@ static inline void bg_fp64_versor_reset(BgFP64Versor* versor)
// ==================== Set ===================== // // ==================== Set ===================== //
void __bg_fp32_versor_normalize(const float square_module, __BgFP32DarkTwinVersor* twin); void __bg_fp32_versor_normalize(const float square_modulus, __BgFP32DarkTwinVersor* twin);
void __bg_fp64_versor_normalize(const double square_module, __BgFP64DarkTwinVersor* twin); void __bg_fp64_versor_normalize(const double square_modulus, __BgFP64DarkTwinVersor* twin);
static inline void bg_fp32_versor_set_values(const float s0, const float x1, const float x2, const float x3, BgFP32Versor* versor) static inline void bg_fp32_versor_set_values(const float s0, const float x1, const float x2, const float x3, BgFP32Versor* versor)
{ {
@ -71,13 +71,13 @@ static inline void bg_fp32_versor_set_values(const float s0, const float x1, con
twin->x2 = x2; twin->x2 = x2;
twin->x3 = x3; twin->x3 = x3;
const float square_module = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3); const float square_modulus = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3);
if (1.0f - BG_FP32_TWO_EPSYLON <= square_module && square_module <= 1.0f + BG_FP32_TWO_EPSYLON) { if (1.0f - BG_FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + BG_FP32_TWO_EPSYLON) {
return; return;
} }
__bg_fp32_versor_normalize(square_module, (__BgFP32DarkTwinVersor*)versor); __bg_fp32_versor_normalize(square_modulus, (__BgFP32DarkTwinVersor*)versor);
} }
static inline void bg_fp64_versor_set_values(const double s0, const double x1, const double x2, const double x3, BgFP64Versor* versor) static inline void bg_fp64_versor_set_values(const double s0, const double x1, const double x2, const double x3, BgFP64Versor* versor)
@ -89,13 +89,13 @@ static inline void bg_fp64_versor_set_values(const double s0, const double x1, c
twin->x2 = x2; twin->x2 = x2;
twin->x3 = x3; twin->x3 = x3;
const double square_module = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3); const double square_modulus = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3);
if (1.0 - BG_FP64_TWO_EPSYLON <= square_module && square_module <= 1.0 + BG_FP64_TWO_EPSYLON) { if (1.0 - BG_FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0 + BG_FP64_TWO_EPSYLON) {
return; return;
} }
__bg_fp64_versor_normalize(square_module, twin); __bg_fp64_versor_normalize(square_modulus, twin);
} }
// ==================== Copy ==================== // // ==================== Copy ==================== //
@ -150,6 +150,30 @@ static inline void bg_fp64_versor_set_rotation(const BgFP64Rotation3* rotation,
bg_fp64_versor_set_crude_turn(rotation->axis.x1, rotation->axis.x2, rotation->axis.x3, rotation->radians, BG_ANGLE_UNIT_RADIANS, result); bg_fp64_versor_set_crude_turn(rotation->axis.x1, rotation->axis.x2, rotation->axis.x3, rotation->radians, BG_ANGLE_UNIT_RADIANS, result);
} }
// =============== Square modulus =============== //
static inline int bg_fp32_versor_get_square_modulus(const BgFP32Versor* versor)
{
return (versor->s0 * versor->s0 + versor->x1 * versor->x1) + (versor->x2 * versor->x2 + versor->x3 * versor->x3);
}
static inline int bg_fp64_versor_get_square_modulus(const BgFP64Versor* versor)
{
return (versor->s0 * versor->s0 + versor->x1 * versor->x1) + (versor->x2 * versor->x2 + versor->x3 * versor->x3);
}
// =================== Modulus ================== //
static inline int bg_fp32_versor_get_modulus(const BgFP32Versor* versor)
{
return sqrtf(bg_fp32_versor_get_square_modulus(versor));
}
static inline int bg_fp64_versor_get_modulus(const BgFP64Versor* versor)
{
return sqrt(bg_fp64_versor_get_square_modulus(versor));
}
// ================= Comparison ================= // // ================= Comparison ================= //
static inline int bg_fp32_versor_is_idle(const BgFP32Versor* versor) static inline int bg_fp32_versor_is_idle(const BgFP32Versor* versor)
@ -257,7 +281,7 @@ static inline void bg_fp32_versor_combine(const BgFP32Versor* second, const BgFP
const float x2 = (second->x2 * first->s0 + second->s0 * first->x2) - (second->x1 * first->x3 - second->x3 * first->x1); const float x2 = (second->x2 * first->s0 + second->s0 * first->x2) - (second->x1 * first->x3 - second->x3 * first->x1);
const float x3 = (second->x3 * first->s0 + second->s0 * first->x3) - (second->x2 * first->x1 - second->x1 * first->x2); const float x3 = (second->x3 * first->s0 + second->s0 * first->x3) - (second->x2 * first->x1 - second->x1 * first->x2);
const float square_module = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3); const float square_modulus = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3);
__BgFP32DarkTwinVersor* twin = (__BgFP32DarkTwinVersor*)result; __BgFP32DarkTwinVersor* twin = (__BgFP32DarkTwinVersor*)result;
@ -266,11 +290,11 @@ static inline void bg_fp32_versor_combine(const BgFP32Versor* second, const BgFP
twin->x2 = x2; twin->x2 = x2;
twin->x3 = x3; twin->x3 = x3;
if (1.0f - BG_FP32_TWO_EPSYLON <= square_module && square_module <= 1.0f + BG_FP32_TWO_EPSYLON) { if (1.0f - BG_FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + BG_FP32_TWO_EPSYLON) {
return; return;
} }
__bg_fp32_versor_normalize(square_module, twin); __bg_fp32_versor_normalize(square_modulus, twin);
} }
static inline void bg_fp64_versor_combine(const BgFP64Versor* second, const BgFP64Versor* first, BgFP64Versor* result) static inline void bg_fp64_versor_combine(const BgFP64Versor* second, const BgFP64Versor* first, BgFP64Versor* result)
@ -280,7 +304,7 @@ static inline void bg_fp64_versor_combine(const BgFP64Versor* second, const BgFP
const double x2 = (second->x2 * first->s0 + second->s0 * first->x2) - (second->x1 * first->x3 - second->x3 * first->x1); const double x2 = (second->x2 * first->s0 + second->s0 * first->x2) - (second->x1 * first->x3 - second->x3 * first->x1);
const double x3 = (second->x3 * first->s0 + second->s0 * first->x3) - (second->x2 * first->x1 - second->x1 * first->x2); const double x3 = (second->x3 * first->s0 + second->s0 * first->x3) - (second->x2 * first->x1 - second->x1 * first->x2);
const double square_module = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3); const double square_modulus = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3);
__BgFP64DarkTwinVersor* twin = (__BgFP64DarkTwinVersor*)result; __BgFP64DarkTwinVersor* twin = (__BgFP64DarkTwinVersor*)result;
@ -289,11 +313,11 @@ static inline void bg_fp64_versor_combine(const BgFP64Versor* second, const BgFP
twin->x2 = x2; twin->x2 = x2;
twin->x3 = x3; twin->x3 = x3;
if (1.0 - BG_FP64_TWO_EPSYLON <= square_module && square_module <= 1.0 + BG_FP64_TWO_EPSYLON) { if (1.0 - BG_FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0 + BG_FP64_TWO_EPSYLON) {
return; return;
} }
__bg_fp64_versor_normalize(square_module, twin); __bg_fp64_versor_normalize(square_modulus, twin);
} }
// ================= Rotation3 ================== // // ================= Rotation3 ================== //

View file

@ -1 +0,0 @@
,andrey,andrey-pokidov-pc,25.11.2024 16:20,file:///home/andrey/.config/libreoffice/4;