Переименование типов в соответствии со стилем POSIX, отказ от префикса bg_

This commit is contained in:
Andrey Pokidov 2025-01-13 21:31:26 +07:00
parent d2a25823a5
commit 605afabd94
25 changed files with 1109 additions and 1035 deletions

View file

@ -9,29 +9,172 @@
#include <time.h> #include <time.h>
#endif // _WINDOWS_ #endif // _WINDOWS_
BgFP32Vector3* allocate_vectors3(const unsigned int amount) typedef struct {
// fp32_versor_t versor1, versor2, result;
fp32_matrix3x3_t matrix;
fp32_vector3_t vector1, vector2;
} fp32_structure_t;
fp32_structure_t* allocate_structures(const unsigned int amount)
{ {
return calloc(amount, sizeof(BgFP32Vector3)); return calloc(amount, sizeof(fp32_structure_t));
} }
BgFP32Vector3* make_zero_vectors3(const unsigned int amount) fp32_structure_t* make_structures(const unsigned int amount)
{ {
BgFP32Vector3* list = allocate_vectors3(amount); fp32_structure_t* list = allocate_structures(amount);
if (list == 0) {
return 0;
}
const float multiplier = 2.0f / RAND_MAX;
for (unsigned int i = 0; i < amount; i++) {
/*
fp32_versor_set_values(
rand() * multiplier - 1.0f,
rand() * multiplier - 1.0f,
rand() * multiplier - 1.0f,
rand() * multiplier - 1.0f,
&list[i].versor1
);
fp32_versor_set_values(
rand() * multiplier - 1.0f,
rand() * multiplier - 1.0f,
rand() * multiplier - 1.0f,
rand() * multiplier - 1.0f,
&list[i].versor2
);
fp32_versor_reset(&list[i].result);
*/
fp32_matrix3x3_set_to_identity(&list[i].matrix);
fp32_vector3_set_values(
rand() * multiplier - 1.0f,
rand() * multiplier - 1.0f,
rand() * multiplier - 1.0f,
&list[i].vector1
);
fp32_vector3_reset(&list[i].vector2);
}
return list;
}
void print_versor(const fp32_versor_t* versor)
{
printf("Versor (%f, %f, %f, %f)\n", versor->s0, versor->x1, versor->x2, versor->x3);
}
void print_vector(const fp32_vector3_t* vector)
{
printf("(%f, %f, %f) / %f\n", vector->x1, vector->x2, vector->x3, fp32_vector3_get_modulus(vector));
}
void item_work(fp32_structure_t* item)
{
//fp32_versor_combine(&item->versor1, &item->versor1, &item->result);
//fp32_versor_make_rotation_matrix(&item->result, &item->matrix);
fp32_matrix3x3_right_product(&item->matrix, &item->vector1, &item->vector2);
}
void circle_work(const unsigned int amount, fp32_structure_t* list)
{
for (unsigned int i = 0; i < amount; i++) {
//fp32_versor_combine(&list[i].versor1, &list[i].versor1, &list[i].result);
//fp32_versor_make_rotation_matrix(&list[i].result, &list[i].matrix);
fp32_matrix3x3_right_product(&list[i].matrix, &list[i].vector1, &list[i].vector2);
//fp32_versor_turn(&list[i].result, &list[i].vector1, &list[i].vector2);
}
}
int main()
{
const unsigned int amount = 1000000;
fp32_structure_t* list;
#ifdef _WIN64
ULONGLONG now, start, end;
now = GetTickCount64();
srand((unsigned int)(now & 0xfffffff));
#else
struct timespec start, end;
clock_gettime(0, &start);
srand((unsigned int)(start.tv_nsec & 0xfffffff));
#endif // _WIN64
list = make_structures(amount);
#ifdef _WIN64
end = GetTickCount64();
printf("Setup time: %lld\n", end - now);
start = GetTickCount64();
#else
clock_gettime(CLOCK_REALTIME, &end);
printf("Time: %lf\n", (end.tv_sec - start.tv_sec) * 1000.0 + (end.tv_nsec - start.tv_nsec) * 0.000001);
clock_gettime(CLOCK_REALTIME, &start);
#endif // _WIN64
for (int j = 0; j < 1000; j++) {
//circle(amount, list);
for (unsigned int i = 0; i < amount; i++) {
//item_work(list + i);
//fp32_versor_combine(&list[i].versor1, &list[i].versor1, &list[i].result);
//fp32_versor_make_rotation_matrix(&list[i].result, &list[i].matrix);
fp32_matrix3x3_right_product(&list[i].matrix, &list[i].vector1, &list[i].vector2);
//fp32_versor_turn(&list[i].result, &list[i].vector1, &list[i].vector2);
}
}
#ifdef _WIN64
end = GetTickCount64();
printf("Time: %lld\n", end - start);
#else
clock_gettime(CLOCK_REALTIME, &end);
printf("Time: %lf\n", (end.tv_sec - start.tv_sec) * 1000.0 + (end.tv_nsec - start.tv_nsec) * 0.000001);
#endif // _WIN64
//print_versor(&list[10].versor1);
//print_versor(&list[10].versor2);
//print_versor(&list[10].result);
free(list);
return 0;
}
/*
fp32_vector3_t* allocate_vectors3(const unsigned int amount)
{
return calloc(amount, sizeof(fp32_vector3_t));
}
fp32_vector3_t* make_zero_vectors3(const unsigned int amount)
{
fp32_vector3_t* list = allocate_vectors3(amount);
if (list == 0) { if (list == 0) {
return 0; return 0;
} }
for (unsigned int i = 0; i < amount; i++) { for (unsigned int i = 0; i < amount; i++) {
bg_fp32_vector3_reset(&list[i]); fp32_vector3_reset(&list[i]);
} }
return list; return list;
} }
BgFP32Vector3* make_random_vectors3(const unsigned int amount) fp32_vector3_t* make_random_vectors3(const unsigned int amount)
{ {
BgFP32Vector3* list = allocate_vectors3(amount); fp32_vector3_t* list = allocate_vectors3(amount);
if (list == 0) { if (list == 0) {
return 0; return 0;
@ -48,29 +191,29 @@ BgFP32Vector3* make_random_vectors3(const unsigned int amount)
return list; return list;
} }
BgFP32Versor* allocate_versors(const unsigned int amount) fp32_versor_t* allocate_versors(const unsigned int amount)
{ {
return calloc(amount, sizeof(BgFP32Versor)); return calloc(amount, sizeof(fp32_versor_t));
} }
BgFP32Versor * make_zero_versors(const unsigned int amount) fp32_versor_t * make_zero_versors(const unsigned int amount)
{ {
BgFP32Versor * list = allocate_versors(amount); fp32_versor_t * list = allocate_versors(amount);
if (list == 0) { if (list == 0) {
return 0; return 0;
} }
for (unsigned int i = 0; i < amount; i++) { for (unsigned int i = 0; i < amount; i++) {
bg_fp32_versor_reset(&list[i]); fp32_versor_reset(&list[i]);
} }
return list; return list;
} }
BgFP32Versor * make_random_versors(const unsigned int amount) fp32_versor_t * make_random_versors(const unsigned int amount)
{ {
BgFP32Versor * list = allocate_versors(amount); fp32_versor_t * list = allocate_versors(amount);
if (list == 0) { if (list == 0) {
return 0; return 0;
@ -79,7 +222,7 @@ BgFP32Versor * make_random_versors(const unsigned int amount)
const float multiplier = 2.0f / RAND_MAX; const float multiplier = 2.0f / RAND_MAX;
for (unsigned int i = 0; i < amount; i++) { for (unsigned int i = 0; i < amount; i++) {
bg_fp32_versor_set_values( fp32_versor_set_values(
rand() * multiplier - 1.0f, rand() * multiplier - 1.0f,
rand() * multiplier - 1.0f, rand() * multiplier - 1.0f,
rand() * multiplier - 1.0f, rand() * multiplier - 1.0f,
@ -91,76 +234,6 @@ BgFP32Versor * make_random_versors(const unsigned int amount)
return list; return list;
} }
void print_versor(const BgFP32Versor* versor)
{
printf("Versor (%f, %f, %f, %f)\n", versor->s0, versor->x1, versor->x2, versor->x3);
}
void print_vector(const BgFP32Vector3* vector)
{
printf("(%f, %f, %f) / %f\n", vector->x1, vector->x2, vector->x3, bg_fp32_vector3_get_modulus(vector));
}
/*
int main()
{
const unsigned int amount = 1000000;
#ifdef _WIN64
ULONGLONG now;
now = GetTickCount64();
srand((unsigned int)(now & 0xfffffff));
#else
struct timespec now;
clock_gettime(CLOCK_REALTIME, &now);
srand((unsigned int)(now.tv_nsec & 0xfffffff));
#endif // _WIN64
BgFP32Versor * versors = make_random_versors(amount);
if (versors == 0) {
printf("Cannot allocate memory for versors");
return 0;
}
BgFP32Vector3 initial, result;
bg_fp32_vector3_set_values(1, 2, 3, &initial);
bg_fp32_vector3_copy(&initial, &result);
#ifdef _WIN64
ULONGLONG start, end;
start = GetTickCount64();
#else
struct timespec start, end;
clock_gettime(CLOCK_REALTIME, &start);
#endif // _WIN64
for (unsigned int i = 0; i < amount; i++) {
bg_fp32_versor_turn2(&versors[i], &result, &result);
}
for (unsigned int i = amount; i > 0; i--) {
bg_fp32_versor_turn_back2(&versors[i - 1], &result, &result);
}
#ifdef _WIN64
end = GetTickCount64();
printf("Time: %lld\n", end - start);
#else
clock_gettime(CLOCK_REALTIME, &end);
printf("Time: %lf\n", (end.tv_sec - start.tv_sec) * 1000.0 + (end.tv_nsec - start.tv_nsec) * 0.000001);
#endif // _WIN64
print_vector(&initial);
print_vector(&result);
free(versors);
return 0;
}
*/
int main() int main()
{ {
const unsigned int amount = 1000000; const unsigned int amount = 1000000;
@ -175,14 +248,14 @@ int main()
srand((unsigned int)(now.tv_nsec & 0xfffffff)); srand((unsigned int)(now.tv_nsec & 0xfffffff));
#endif // _WIN64 #endif // _WIN64
BgFP32Versor * versors1 = make_random_versors(amount); fp32_versor_t * versors1 = make_random_versors(amount);
if (versors1 == 0) { if (versors1 == 0) {
printf("Cannot allocate memory for versors1"); printf("Cannot allocate memory for versors1");
return 0; return 0;
} }
BgFP32Versor * versors2 = make_random_versors(amount); fp32_versor_t * versors2 = make_random_versors(amount);
if (versors2 == 0) { if (versors2 == 0) {
printf("Cannot allocate memory for versors2"); printf("Cannot allocate memory for versors2");
@ -190,7 +263,7 @@ int main()
return 0; return 0;
} }
BgFP32Versor * results = make_zero_versors(amount); fp32_versor_t * results = make_zero_versors(amount);
if (results == 0) { if (results == 0) {
printf("Cannot allocate memory for results"); printf("Cannot allocate memory for results");
@ -199,7 +272,7 @@ int main()
return 0; return 0;
} }
BgFP32Matrix3x3* matrixes =malloc(amount * sizeof(BgFP32Matrix3x3)); fp32_matrix3x3_t* matrixes =malloc(amount * sizeof(fp32_matrix3x3_t));
if (matrixes == 0) { if (matrixes == 0) {
printf("Cannot allocate memory for matrixes"); printf("Cannot allocate memory for matrixes");
@ -209,7 +282,7 @@ int main()
return 0; return 0;
} }
BgFP32Vector3* vectors = make_random_vectors3(amount); fp32_vector3_t* vectors = make_random_vectors3(amount);
if (results == 0) { if (results == 0) {
printf("Cannot allocate memory for result vectors"); printf("Cannot allocate memory for result vectors");
@ -233,10 +306,10 @@ int main()
#endif // _WIN64 #endif // _WIN64
for (int j = 0; j < 1000; j++) { for (int j = 0; j < 1000; j++) {
for (unsigned int i = 0; i < amount; i++) { for (unsigned int i = 0; i < amount; i++) {
bg_fp32_versor_combine(&versors1[i], &versors2[i], &results[i]); fp32_versor_combine(&versors1[i], &versors2[i], &results[i]);
bg_fp32_versor_make_rotation_matrix(&versors1[i], &matrixes[i]); fp32_versor_make_rotation_matrix(&versors1[i], &matrixes[i]);
bg_fp32_matrix3x3_right_product(&matrixes[i], &vectors[i], &vectors[i]); fp32_matrix3x3_right_product(&matrixes[i], &vectors[i], &vectors[i]);
//bg_fp32_versor_turn(&results[i], &vectors[i], &vectors[i]); //fp32_versor_turn(&results[i], &vectors[i], &vectors[i]);
} }
} }
@ -261,3 +334,4 @@ int main()
free(versors1); free(versors1);
return 0; return 0;
} }
*/

View file

@ -1,8 +1,8 @@
#include "fp32_vector2_test.h" #include "fp32_vector2_test.h"
const int TEST_BG_FP32_VECTOR2_AMOUNT_1 = 5; const int TEST_FP32_VECTOR2_AMOUNT_1 = 5;
const BgFP32Vector2 TEST_BG_FP32_VECTOR2_COMMON_1[] = { const fp32_vector2_t TEST_FP32_VECTOR2_COMMON_1[] = {
{ 3.0f, 4.0f }, { 3.0f, 4.0f },
{ -3.0f, -4.0f }, { -3.0f, -4.0f },
{ 10000.0f, -20000.0f }, { 10000.0f, -20000.0f },
@ -10,7 +10,7 @@ const BgFP32Vector2 TEST_BG_FP32_VECTOR2_COMMON_1[] = {
{ -123.5f, 3.7283f } { -123.5f, 3.7283f }
}; };
const BgFP32Vector2 TEST_BG_FP32_VECTOR2_COMMON_2[] = { const fp32_vector2_t TEST_FP32_VECTOR2_COMMON_2[] = {
{ -3.0f, -4.0f }, { -3.0f, -4.0f },
{ -3.0f, -4.0f }, { -3.0f, -4.0f },
{ 0.002f, -0.05f }, { 0.002f, -0.05f },
@ -20,18 +20,18 @@ const BgFP32Vector2 TEST_BG_FP32_VECTOR2_COMMON_2[] = {
// =============== Square modulus =============== // // =============== Square modulus =============== //
const float BG_FP32_VECTOR2_SQUARE_MODULUS_1[] = { 25.0f, 25.0f, 500000000.0f, 100.01f, 15266.150221f }; const float FP32_VECTOR2_SQUARE_MODULUS_1[] = { 25.0f, 25.0f, 500000000.0f, 100.01f, 15266.150221f };
int test_bg_fp32_vector2_square_modulus() int test_fp32_vector2_square_modulus()
{ {
print_test_name("BgFP32Vector2 square modulus"); print_test_name("fp32_vector2_t square modulus");
float square_modulus; float square_modulus;
for (int i = 0; i < TEST_BG_FP32_VECTOR2_AMOUNT_1; i++) { for (int i = 0; i < TEST_FP32_VECTOR2_AMOUNT_1; i++) {
square_modulus = bg_fp32_vector2_get_square_modulus(&TEST_BG_FP32_VECTOR2_COMMON_1[i]); square_modulus = fp32_vector2_get_square_modulus(&TEST_FP32_VECTOR2_COMMON_1[i]);
if (!test_bg_fp32_are_equal(square_modulus, BG_FP32_VECTOR2_SQUARE_MODULUS_1[i], TEST_BG_FP32_TWO_EPSYLON)) { if (!test_fp32_are_equal(square_modulus, FP32_VECTOR2_SQUARE_MODULUS_1[i], TEST_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_modulus()
// =================== Module =================== // // =================== Module =================== //
const float BG_FP32_VECTOR2_MODULUS_1[] = { 5.0f, 5.0f, 22360.68f, 10.0005f, 123.55626338f }; const float FP32_VECTOR2_MODULUS_1[] = { 5.0f, 5.0f, 22360.68f, 10.0005f, 123.55626338f };
int test_bg_fp32_vector2_modulus() int test_fp32_vector2_modulus()
{ {
print_test_name("BgFP32Vector2 modulus"); print_test_name("fp32_vector2_t modulus");
float square_modulus; float square_modulus;
for (int i = 0; i < TEST_BG_FP32_VECTOR2_AMOUNT_1; i++) { for (int i = 0; i < TEST_FP32_VECTOR2_AMOUNT_1; i++) {
square_modulus = bg_fp32_vector2_get_modulus(&TEST_BG_FP32_VECTOR2_COMMON_1[i]); square_modulus = fp32_vector2_get_modulus(&TEST_FP32_VECTOR2_COMMON_1[i]);
if (!test_bg_fp32_are_equal(square_modulus, BG_FP32_VECTOR2_MODULUS_1[i], TEST_BG_FP32_EPSYLON)) { if (!test_fp32_are_equal(square_modulus, FP32_VECTOR2_MODULUS_1[i], TEST_FP32_EPSYLON)) {
print_test_failed(); print_test_failed();
return TEST_RESULT_FAILED; return TEST_RESULT_FAILED;
} }
@ -66,7 +66,7 @@ int test_bg_fp32_vector2_modulus()
// ===================== Add ==================== // // ===================== Add ==================== //
const BgFP32Vector2 TEST_BG_FP32_VECTOR2_COMMON_1_2_SUM[] = { const fp32_vector2_t TEST_FP32_VECTOR2_COMMON_1_2_SUM[] = {
{ 0.0f, 0.0f }, { 0.0f, 0.0f },
{ -6.0f, -8.0f }, { -6.0f, -8.0f },
{ 10000.002f, -20000.05f }, { 10000.002f, -20000.05f },
@ -74,17 +74,17 @@ const BgFP32Vector2 TEST_BG_FP32_VECTOR2_COMMON_1_2_SUM[] = {
{ -122.0f, -19.6217f } { -122.0f, -19.6217f }
}; };
int test_bg_fp32_vector2_add() int test_fp32_vector2_add()
{ {
print_test_name("BgFP32Vector2 add"); print_test_name("fp32_vector2_t add");
BgFP32Vector2 vector; fp32_vector2_t vector;
for (int i = 0; i < TEST_BG_FP32_VECTOR2_AMOUNT_1; i++) { for (int i = 0; i < TEST_FP32_VECTOR2_AMOUNT_1; i++) {
bg_fp32_vector2_add(&TEST_BG_FP32_VECTOR2_COMMON_1[i], &TEST_BG_FP32_VECTOR2_COMMON_2[i], &vector); fp32_vector2_add(&TEST_FP32_VECTOR2_COMMON_1[i], &TEST_FP32_VECTOR2_COMMON_2[i], &vector);
if (!test_bg_fp32_are_equal(vector.x1, TEST_BG_FP32_VECTOR2_COMMON_1_2_SUM[i].x1, TEST_BG_FP32_EPSYLON) || if (!test_fp32_are_equal(vector.x1, TEST_FP32_VECTOR2_COMMON_1_2_SUM[i].x1, TEST_FP32_EPSYLON) ||
!test_bg_fp32_are_equal(vector.x2, TEST_BG_FP32_VECTOR2_COMMON_1_2_SUM[i].x2, TEST_BG_FP32_EPSYLON)) { !test_fp32_are_equal(vector.x2, TEST_FP32_VECTOR2_COMMON_1_2_SUM[i].x2, TEST_FP32_EPSYLON)) {
print_test_failed(); print_test_failed();
return TEST_RESULT_FAILED; return TEST_RESULT_FAILED;
} }
@ -96,7 +96,7 @@ int test_bg_fp32_vector2_add()
// ================== Subtract ================== // // ================== Subtract ================== //
const BgFP32Vector2 TEST_BG_FP32_VECTOR2_COMMON_1_2_DIFF[] = { const fp32_vector2_t TEST_FP32_VECTOR2_COMMON_1_2_DIFF[] = {
{ 6.0f, 8.0f }, { 6.0f, 8.0f },
{ 0.0f, 0.0f }, { 0.0f, 0.0f },
{ 9999.998f, -19999.95f }, { 9999.998f, -19999.95f },
@ -104,17 +104,17 @@ const BgFP32Vector2 TEST_BG_FP32_VECTOR2_COMMON_1_2_DIFF[] = {
{ -125.0f, 27.0783f } { -125.0f, 27.0783f }
}; };
int test_bg_fp32_vector2_subtract() int test_fp32_vector2_subtract()
{ {
print_test_name("BgFP32Vector2 subtract"); print_test_name("fp32_vector2_t subtract");
BgFP32Vector2 vector; fp32_vector2_t vector;
for (int i = 0; i < TEST_BG_FP32_VECTOR2_AMOUNT_1; i++) { for (int i = 0; i < TEST_FP32_VECTOR2_AMOUNT_1; i++) {
bg_fp32_vector2_subtract(&TEST_BG_FP32_VECTOR2_COMMON_1[i], &TEST_BG_FP32_VECTOR2_COMMON_2[i], &vector); fp32_vector2_subtract(&TEST_FP32_VECTOR2_COMMON_1[i], &TEST_FP32_VECTOR2_COMMON_2[i], &vector);
if (!test_bg_fp32_are_equal(vector.x1, TEST_BG_FP32_VECTOR2_COMMON_1_2_DIFF[i].x1, TEST_BG_FP32_EPSYLON) || if (!test_fp32_are_equal(vector.x1, TEST_FP32_VECTOR2_COMMON_1_2_DIFF[i].x1, TEST_FP32_EPSYLON) ||
!test_bg_fp32_are_equal(vector.x2, TEST_BG_FP32_VECTOR2_COMMON_1_2_DIFF[i].x2, TEST_BG_FP32_EPSYLON)) { !test_fp32_are_equal(vector.x2, TEST_FP32_VECTOR2_COMMON_1_2_DIFF[i].x2, TEST_FP32_EPSYLON)) {
print_test_failed(); print_test_failed();
return TEST_RESULT_FAILED; return TEST_RESULT_FAILED;
} }
@ -126,23 +126,23 @@ int test_bg_fp32_vector2_subtract()
// ==================== 1234 ==================== // // ==================== 1234 ==================== //
int test_bg_fp32_vector2() int test_fp32_vector2()
{ {
print_test_section("BgFP32Vector2"); print_test_section("fp32_vector2_t");
if (test_bg_fp32_vector2_square_modulus() != TEST_RESULT_SUCCES) { if (test_fp32_vector2_square_modulus() != TEST_RESULT_SUCCES) {
return TEST_RESULT_FAILED; return TEST_RESULT_FAILED;
} }
if (test_bg_fp32_vector2_modulus() != TEST_RESULT_SUCCES) { if (test_fp32_vector2_modulus() != TEST_RESULT_SUCCES) {
return TEST_RESULT_FAILED; return TEST_RESULT_FAILED;
} }
if (test_bg_fp32_vector2_add() != TEST_RESULT_SUCCES) { if (test_fp32_vector2_add() != TEST_RESULT_SUCCES) {
return TEST_RESULT_FAILED; return TEST_RESULT_FAILED;
} }
if (test_bg_fp32_vector2_subtract() != TEST_RESULT_SUCCES) { if (test_fp32_vector2_subtract() != TEST_RESULT_SUCCES) {
return TEST_RESULT_FAILED; return TEST_RESULT_FAILED;
} }

View file

@ -3,14 +3,14 @@
#include "geometry_test.h" #include "geometry_test.h"
int test_bg_fp32_vector2(); int test_fp32_vector2();
int test_bg_fp32_vector2_square_modulus(); int test_fp32_vector2_square_modulus();
int test_bg_fp32_vector2_modulus(); int test_fp32_vector2_modulus();
int test_bg_fp32_vector2_add(); int test_fp32_vector2_add();
int test_bg_fp32_vector2_subtract(); int test_fp32_vector2_subtract();
#endif #endif

View file

@ -6,13 +6,13 @@
#define TEST_RESULT_SUCCES 0 #define TEST_RESULT_SUCCES 0
#define TEST_RESULT_FAILED 100 #define TEST_RESULT_FAILED 100
#define TEST_BG_FP32_EPSYLON 1E-6f #define TEST_FP32_EPSYLON 1E-6f
#define TEST_BG_FP32_TWO_EPSYLON 2E-6f #define TEST_FP32_TWO_EPSYLON 2E-6f
#define TEST_BG_FP32_SQUARE_EPSYLON 1E-12f #define TEST_FP32_SQUARE_EPSYLON 1E-12f
#define TEST_BG_FP64_EPSYLON 1E-13f #define TEST_FP64_EPSYLON 1E-13f
#define TEST_BG_FP64_TWO_EPSYLON 2E-13f #define TEST_FP64_TWO_EPSYLON 2E-13f
#define TEST_BG_FP64_SQUARE_EPSYLON 1E-26f #define TEST_FP64_SQUARE_EPSYLON 1E-26f
void print_test_section(const char * name); void print_test_section(const char * name);
@ -22,7 +22,7 @@ void print_test_success();
void print_test_failed(); void print_test_failed();
inline int test_bg_fp32_are_equal(const float value1, const float value2, const float epsylon) inline int test_fp32_are_equal(const float value1, const float value2, const float epsylon)
{ {
if (-1.0f <= value1 && value1 <= 1.0f) { if (-1.0f <= value1 && value1 <= 1.0f) {
const float difference = value1 - value2; const float difference = value1 - value2;
@ -36,7 +36,7 @@ inline int test_bg_fp32_are_equal(const float value1, const float value2, const
return value1 * (1.0f + epsylon) <= value2 && value2 * (1.0f + epsylon) <= value1; return value1 * (1.0f + epsylon) <= value2 && value2 * (1.0f + epsylon) <= value1;
} }
inline int test_bg_fp64_are_equal(const double value1, const double value2, const double epsylon) inline int test_fp64_are_equal(const double value1, const double value2, const double epsylon)
{ {
if (-1.0 <= value1 && value1 <= 1.0) { if (-1.0 <= value1 && value1 <= 1.0) {
const double difference = value1 - value2; const double difference = value1 - value2;

View file

@ -9,7 +9,7 @@
int main() int main()
{ {
if (test_bg_fp32_vector2() == TEST_RESULT_FAILED) { if (test_fp32_vector2() == TEST_RESULT_FAILED) {
return PROGRAM_RESULT_FAILED; return PROGRAM_RESULT_FAILED;
} }

View file

@ -1,32 +1,32 @@
#ifndef _GEOMETRY_ANGLE_H_ #ifndef _BASIC_GEOMETRY_ANGLE_H_
#define _GEOMETRY_ANGLE_H_ #define _BASIC_GEOMETRY_ANGLE_H_
#include <math.h> #include <math.h>
#include "basis.h" #include "basis.h"
#define BG_FP32_PI 3.1415926536f #define FP32_PI 3.1415926536f
#define BG_FP32_TWO_PI 6.2831853072f #define FP32_TWO_PI 6.2831853072f
#define BG_FP32_HALF_OF_PI 1.5707963268f #define FP32_HALF_OF_PI 1.5707963268f
#define BG_FP32_THIRD_OF_PI 1.0471975512f #define FP32_THIRD_OF_PI 1.0471975512f
#define BG_FP32_FOURTH_OF_PI 0.7853981634f #define FP32_FOURTH_OF_PI 0.7853981634f
#define BG_FP32_SIXTH_OF_PI 0.5235987756f #define FP32_SIXTH_OF_PI 0.5235987756f
#define BG_FP32_DEGREES_IN_RADIAN 57.295779513f #define FP32_DEGREES_IN_RADIAN 57.295779513f
#define BG_FP32_TURNS_IN_RADIAN 0.1591549431f #define FP32_TURNS_IN_RADIAN 0.1591549431f
#define BG_FP32_RADIANS_IN_DEGREE 1.745329252E-2f #define FP32_RADIANS_IN_DEGREE 1.745329252E-2f
#define BG_FP32_TURNS_IN_DEGREE 2.7777777778E-3f #define FP32_TURNS_IN_DEGREE 2.7777777778E-3f
#define BG_FP64_PI 3.14159265358979324 #define FP64_PI 3.14159265358979324
#define BG_FP64_TWO_PI 6.28318530717958648 #define FP64_TWO_PI 6.28318530717958648
#define BG_FP64_HALF_OF_PI 1.57079632679489662 #define FP64_HALF_OF_PI 1.57079632679489662
#define BG_FP64_THIRD_OF_PI 1.04719755119659775 #define FP64_THIRD_OF_PI 1.04719755119659775
#define BG_FP64_FOURTH_OF_PI 0.78539816339744831 #define FP64_FOURTH_OF_PI 0.78539816339744831
#define BG_FP64_SIXTH_OF_PI 0.523598775598298873 #define FP64_SIXTH_OF_PI 0.523598775598298873
#define BG_FP64_DEGREES_IN_RADIAN 57.2957795130823209 #define FP64_DEGREES_IN_RADIAN 57.2957795130823209
#define BG_FP64_TURNS_IN_RADIAN 0.159154943091895336 #define FP64_TURNS_IN_RADIAN 0.159154943091895336
#define BG_FP64_RADIANS_IN_DEGREE 1.74532925199432958E-2 #define FP64_RADIANS_IN_DEGREE 1.74532925199432958E-2
#define BG_FP64_TURNS_IN_DEGREE 2.77777777777777778E-3 #define FP64_TURNS_IN_DEGREE 2.77777777777777778E-3
typedef enum { typedef enum {
BG_ANGLE_UNIT_RADIANS = 1, BG_ANGLE_UNIT_RADIANS = 1,
@ -52,51 +52,51 @@ typedef enum {
// ========= Convert radians to degrees ========= // // ========= Convert radians to degrees ========= //
static inline float bg_fp32_radians_to_degrees(const float radians) static inline float fp32_radians_to_degrees(const float radians)
{ {
return radians * BG_FP32_DEGREES_IN_RADIAN; return radians * FP32_DEGREES_IN_RADIAN;
} }
static inline double bg_fp64_radians_to_degrees(const double radians) static inline double fp64_radians_to_degrees(const double radians)
{ {
return radians * BG_FP64_DEGREES_IN_RADIAN; return radians * FP64_DEGREES_IN_RADIAN;
} }
// ========== Convert radians to turns ========== // // ========== Convert radians to turns ========== //
static inline float bg_fp32_radians_to_turns(const float radians) static inline float fp32_radians_to_turns(const float radians)
{ {
return radians * BG_FP32_TURNS_IN_RADIAN; return radians * FP32_TURNS_IN_RADIAN;
} }
static inline double bg_fp64_radians_to_turns(const double radians) static inline double fp64_radians_to_turns(const double radians)
{ {
return radians * BG_FP64_TURNS_IN_RADIAN; return radians * FP64_TURNS_IN_RADIAN;
} }
// ========= Convert radians to any unit ======== // // ========= Convert radians to any unit ======== //
static inline float bg_fp32_radians_to_units(const float radians, const angle_unit_t to_unit) static inline float fp32_radians_to_units(const float radians, const angle_unit_t to_unit)
{ {
if (to_unit == BG_ANGLE_UNIT_DEGREES) { if (to_unit == BG_ANGLE_UNIT_DEGREES) {
return radians * BG_FP32_DEGREES_IN_RADIAN; return radians * FP32_DEGREES_IN_RADIAN;
} }
if (to_unit == BG_ANGLE_UNIT_TURNS) { if (to_unit == BG_ANGLE_UNIT_TURNS) {
return radians * BG_FP32_TURNS_IN_RADIAN; return radians * FP32_TURNS_IN_RADIAN;
} }
return radians; return radians;
} }
static inline double bg_fp64_radians_to_units(const double radians, const angle_unit_t to_unit) static inline double fp64_radians_to_units(const double radians, const angle_unit_t to_unit)
{ {
if (to_unit == BG_ANGLE_UNIT_DEGREES) { if (to_unit == BG_ANGLE_UNIT_DEGREES) {
return radians * BG_FP64_DEGREES_IN_RADIAN; return radians * FP64_DEGREES_IN_RADIAN;
} }
if (to_unit == BG_ANGLE_UNIT_TURNS) { if (to_unit == BG_ANGLE_UNIT_TURNS) {
return radians * BG_FP64_TURNS_IN_RADIAN; return radians * FP64_TURNS_IN_RADIAN;
} }
return radians; return radians;
@ -104,20 +104,20 @@ static inline double bg_fp64_radians_to_units(const double radians, const angle_
// ============ Normalize radians ============= // // ============ Normalize radians ============= //
static inline float bg_fp32_radians_normalize(const float radians, const angle_range_t range) static inline float fp32_radians_normalize(const float radians, const angle_range_t range)
{ {
if (range == BG_ANGLE_RANGE_UNSIGNED) { if (range == BG_ANGLE_RANGE_UNSIGNED) {
if (0.0f <= radians && radians < BG_FP32_TWO_PI) { if (0.0f <= radians && radians < FP32_TWO_PI) {
return radians; return radians;
} }
} }
else { else {
if (-BG_FP32_PI < radians && radians <= BG_FP32_PI) { if (-FP32_PI < radians && radians <= FP32_PI) {
return radians; return radians;
} }
} }
float turns = radians * BG_FP32_TURNS_IN_RADIAN; float turns = radians * FP32_TURNS_IN_RADIAN;
turns -= floorf(turns); turns -= floorf(turns);
@ -125,23 +125,23 @@ static inline float bg_fp32_radians_normalize(const float radians, const angle_r
turns -= 1.0f; turns -= 1.0f;
} }
return turns * BG_FP32_TWO_PI; return turns * FP32_TWO_PI;
} }
static inline double bg_fp64_radians_normalize(const double radians, const angle_range_t range) static inline double fp64_radians_normalize(const double radians, const angle_range_t range)
{ {
if (range == BG_ANGLE_RANGE_UNSIGNED) { if (range == BG_ANGLE_RANGE_UNSIGNED) {
if (0.0 <= radians && radians < BG_FP64_TWO_PI) { if (0.0 <= radians && radians < FP64_TWO_PI) {
return radians; return radians;
} }
} }
else { else {
if (-BG_FP64_PI < radians && radians <= BG_FP64_PI) { if (-FP64_PI < radians && radians <= FP64_PI) {
return radians; return radians;
} }
} }
double turns = radians * BG_FP64_TURNS_IN_RADIAN; double turns = radians * FP64_TURNS_IN_RADIAN;
turns -= floor(turns); turns -= floor(turns);
@ -149,58 +149,58 @@ static inline double bg_fp64_radians_normalize(const double radians, const angle
turns -= 1.0; turns -= 1.0;
} }
return turns * BG_FP64_TWO_PI; return turns * FP64_TWO_PI;
} }
// !================= Degrees ==================! // // !================= Degrees ==================! //
// ========= Convert degrees to radians ========= // // ========= Convert degrees to radians ========= //
static inline float bg_fp32_degrees_to_radians(const float degrees) static inline float fp32_degrees_to_radians(const float degrees)
{ {
return degrees * BG_FP32_RADIANS_IN_DEGREE; return degrees * FP32_RADIANS_IN_DEGREE;
} }
static inline double bg_fp64_degrees_to_radians(const double degrees) static inline double fp64_degrees_to_radians(const double degrees)
{ {
return degrees * BG_FP64_RADIANS_IN_DEGREE; return degrees * FP64_RADIANS_IN_DEGREE;
} }
// ========== Convert degrees to turns ========== // // ========== Convert degrees to turns ========== //
static inline float bg_fp32_degrees_to_turns(const float radians) static inline float fp32_degrees_to_turns(const float radians)
{ {
return radians * BG_FP32_TURNS_IN_DEGREE; return radians * FP32_TURNS_IN_DEGREE;
} }
static inline double bg_fp64_degrees_to_turns(const double radians) static inline double fp64_degrees_to_turns(const double radians)
{ {
return radians * BG_FP64_TURNS_IN_DEGREE; return radians * FP64_TURNS_IN_DEGREE;
} }
// ========= Convert degreess to any unit ======== // // ========= Convert degreess to any unit ======== //
static inline float bg_fp32_degrees_to_units(const float degrees, const angle_unit_t to_unit) static inline float fp32_degrees_to_units(const float degrees, const angle_unit_t to_unit)
{ {
if (to_unit == BG_ANGLE_UNIT_RADIANS) { if (to_unit == BG_ANGLE_UNIT_RADIANS) {
return degrees * BG_FP32_RADIANS_IN_DEGREE; return degrees * FP32_RADIANS_IN_DEGREE;
} }
if (to_unit == BG_ANGLE_UNIT_TURNS) { if (to_unit == BG_ANGLE_UNIT_TURNS) {
return degrees * BG_FP32_TURNS_IN_DEGREE; return degrees * FP32_TURNS_IN_DEGREE;
} }
return degrees; return degrees;
} }
static inline double bg_fp64_degrees_to_units(const double degrees, const angle_unit_t to_unit) static inline double fp64_degrees_to_units(const double degrees, const angle_unit_t to_unit)
{ {
if (to_unit == BG_ANGLE_UNIT_RADIANS) { if (to_unit == BG_ANGLE_UNIT_RADIANS) {
return degrees * BG_FP64_RADIANS_IN_DEGREE; return degrees * FP64_RADIANS_IN_DEGREE;
} }
if (to_unit == BG_ANGLE_UNIT_TURNS) { if (to_unit == BG_ANGLE_UNIT_TURNS) {
return degrees * BG_FP64_TURNS_IN_DEGREE; return degrees * FP64_TURNS_IN_DEGREE;
} }
return degrees; return degrees;
@ -208,7 +208,7 @@ static inline double bg_fp64_degrees_to_units(const double degrees, const angle_
// ============ Normalize degrees ============= // // ============ Normalize degrees ============= //
static inline float bg_fp32_degrees_normalize(const float degrees, const angle_range_t range) static inline float fp32_degrees_normalize(const float degrees, const angle_range_t range)
{ {
if (range == BG_ANGLE_RANGE_UNSIGNED) { if (range == BG_ANGLE_RANGE_UNSIGNED) {
if (0.0f <= degrees && degrees < 360.0f) { if (0.0f <= degrees && degrees < 360.0f) {
@ -221,7 +221,7 @@ static inline float bg_fp32_degrees_normalize(const float degrees, const angle_r
} }
} }
float turns = degrees * BG_FP32_TURNS_IN_DEGREE; float turns = degrees * FP32_TURNS_IN_DEGREE;
turns -= floorf(turns); turns -= floorf(turns);
@ -232,7 +232,7 @@ static inline float bg_fp32_degrees_normalize(const float degrees, const angle_r
return turns * 360.0f; return turns * 360.0f;
} }
static inline double bg_fp64_degrees_normalize(const double degrees, const angle_range_t range) static inline double fp64_degrees_normalize(const double degrees, const angle_range_t range)
{ {
if (range == BG_ANGLE_RANGE_UNSIGNED) { if (range == BG_ANGLE_RANGE_UNSIGNED) {
if (0.0 <= degrees && degrees < 360.0) { if (0.0 <= degrees && degrees < 360.0) {
@ -245,7 +245,7 @@ static inline double bg_fp64_degrees_normalize(const double degrees, const angle
} }
} }
double turns = degrees * BG_FP64_TURNS_IN_DEGREE; double turns = degrees * FP64_TURNS_IN_DEGREE;
turns -= floor(turns); turns -= floor(turns);
@ -260,34 +260,34 @@ static inline double bg_fp64_degrees_normalize(const double degrees, const angle
// ========== Convert turns to radians ========== // // ========== Convert turns to radians ========== //
static inline float bg_fp32_turns_to_radians(const float turns) static inline float fp32_turns_to_radians(const float turns)
{ {
return turns * BG_FP32_TWO_PI; return turns * FP32_TWO_PI;
} }
static inline double bg_fp64_turns_to_radians(const double turns) static inline double fp64_turns_to_radians(const double turns)
{ {
return turns * BG_FP64_TWO_PI; return turns * FP64_TWO_PI;
} }
// ========== Convert turns to degrees ========== // // ========== Convert turns to degrees ========== //
static inline float bg_fp32_turns_to_degrees(const float turns) static inline float fp32_turns_to_degrees(const float turns)
{ {
return turns * 360.0f; return turns * 360.0f;
} }
static inline double bg_fp64_turns_to_degrees(const double turns) static inline double fp64_turns_to_degrees(const double turns)
{ {
return turns * 360.0; return turns * 360.0;
} }
// ========= Convert turns to any unit ======== // // ========= Convert turns to any unit ======== //
static inline float bg_fp32_turns_to_units(const float turns, const angle_unit_t to_unit) static inline float fp32_turns_to_units(const float turns, const angle_unit_t to_unit)
{ {
if (to_unit == BG_ANGLE_UNIT_RADIANS) { if (to_unit == BG_ANGLE_UNIT_RADIANS) {
return turns * BG_FP32_TWO_PI; return turns * FP32_TWO_PI;
} }
if (to_unit == BG_ANGLE_UNIT_DEGREES) { if (to_unit == BG_ANGLE_UNIT_DEGREES) {
@ -297,10 +297,10 @@ static inline float bg_fp32_turns_to_units(const float turns, const angle_unit_t
return turns; return turns;
} }
static inline double bg_fp64_turns_to_units(const double turns, const angle_unit_t to_unit) static inline double fp64_turns_to_units(const double turns, const angle_unit_t to_unit)
{ {
if (to_unit == BG_ANGLE_UNIT_RADIANS) { if (to_unit == BG_ANGLE_UNIT_RADIANS) {
return turns * BG_FP64_TWO_PI; return turns * FP64_TWO_PI;
} }
if (to_unit == BG_ANGLE_UNIT_DEGREES) { if (to_unit == BG_ANGLE_UNIT_DEGREES) {
@ -312,7 +312,7 @@ static inline double bg_fp64_turns_to_units(const double turns, const angle_unit
// ============= Normalize turns ============== // // ============= Normalize turns ============== //
static inline float bg_fp32_turns_normalize(const float turns, const angle_range_t range) static inline float fp32_turns_normalize(const float turns, const angle_range_t range)
{ {
if (range == BG_ANGLE_RANGE_UNSIGNED) { if (range == BG_ANGLE_RANGE_UNSIGNED) {
if (0.0f <= turns && turns < 1.0f) { if (0.0f <= turns && turns < 1.0f) {
@ -334,7 +334,7 @@ static inline float bg_fp32_turns_normalize(const float turns, const angle_range
return rest; return rest;
} }
static inline double bg_fp64_turns_normalize(const double turns, const angle_range_t range) static inline double fp64_turns_normalize(const double turns, const angle_range_t range)
{ {
if (range == BG_ANGLE_RANGE_UNSIGNED) { if (range == BG_ANGLE_RANGE_UNSIGNED) {
if (0.0 <= turns && turns < 1.0) { if (0.0 <= turns && turns < 1.0) {
@ -360,27 +360,27 @@ static inline double bg_fp64_turns_normalize(const double turns, const angle_ran
// ========= Convert any unit to radians ======== // // ========= Convert any unit to radians ======== //
static inline float bg_fp32_angle_to_radians(const float angle, const angle_unit_t unit) static inline float fp32_angle_to_radians(const float angle, const angle_unit_t unit)
{ {
if (unit == BG_ANGLE_UNIT_DEGREES) { if (unit == BG_ANGLE_UNIT_DEGREES) {
return angle * BG_FP32_RADIANS_IN_DEGREE; return angle * FP32_RADIANS_IN_DEGREE;
} }
if (unit == BG_ANGLE_UNIT_TURNS) { if (unit == BG_ANGLE_UNIT_TURNS) {
return angle * BG_FP32_TWO_PI; return angle * FP32_TWO_PI;
} }
return angle; return angle;
} }
static inline double bg_fp64_angle_to_radians(const double angle, const angle_unit_t unit) static inline double fp64_angle_to_radians(const double angle, const angle_unit_t unit)
{ {
if (unit == BG_ANGLE_UNIT_DEGREES) { if (unit == BG_ANGLE_UNIT_DEGREES) {
return angle * BG_FP64_RADIANS_IN_DEGREE; return angle * FP64_RADIANS_IN_DEGREE;
} }
if (unit == BG_ANGLE_UNIT_TURNS) { if (unit == BG_ANGLE_UNIT_TURNS) {
return angle * BG_FP64_TWO_PI; return angle * FP64_TWO_PI;
} }
return angle; return angle;
@ -388,10 +388,10 @@ static inline double bg_fp64_angle_to_radians(const double angle, const angle_un
// ========= Convert any unit to degreess ======== // // ========= Convert any unit to degreess ======== //
static inline float bg_fp32_angle_to_degrees(const float angle, const angle_unit_t unit) static inline float fp32_angle_to_degrees(const float angle, const angle_unit_t unit)
{ {
if (unit == BG_ANGLE_UNIT_RADIANS) { if (unit == BG_ANGLE_UNIT_RADIANS) {
return angle * BG_FP32_DEGREES_IN_RADIAN; return angle * FP32_DEGREES_IN_RADIAN;
} }
if (unit == BG_ANGLE_UNIT_TURNS) { if (unit == BG_ANGLE_UNIT_TURNS) {
@ -401,10 +401,10 @@ static inline float bg_fp32_angle_to_degrees(const float angle, const angle_unit
return angle; return angle;
} }
static inline double bg_fp64_angle_to_degrees(const double angle, const angle_unit_t unit) static inline double fp64_angle_to_degrees(const double angle, const angle_unit_t unit)
{ {
if (unit == BG_ANGLE_UNIT_RADIANS) { if (unit == BG_ANGLE_UNIT_RADIANS) {
return angle * BG_FP64_DEGREES_IN_RADIAN; return angle * FP64_DEGREES_IN_RADIAN;
} }
if (unit == BG_ANGLE_UNIT_TURNS) { if (unit == BG_ANGLE_UNIT_TURNS) {
@ -416,27 +416,27 @@ static inline double bg_fp64_angle_to_degrees(const double angle, const angle_un
// ========= Convert any unit to turns ======== // // ========= Convert any unit to turns ======== //
static inline float bg_fp32_angle_to_turns(const float angle, const angle_unit_t unit) static inline float fp32_angle_to_turns(const float angle, const angle_unit_t unit)
{ {
if (unit == BG_ANGLE_UNIT_RADIANS) { if (unit == BG_ANGLE_UNIT_RADIANS) {
return angle * BG_FP32_TURNS_IN_RADIAN; return angle * FP32_TURNS_IN_RADIAN;
} }
if (unit == BG_ANGLE_UNIT_DEGREES) { if (unit == BG_ANGLE_UNIT_DEGREES) {
return angle * BG_FP32_TURNS_IN_DEGREE; return angle * FP32_TURNS_IN_DEGREE;
} }
return angle; return angle;
} }
static inline double bg_fp64_angle_to_turns(const double angle, const angle_unit_t unit) static inline double fp64_angle_to_turns(const double angle, const angle_unit_t unit)
{ {
if (unit == BG_ANGLE_UNIT_RADIANS) { if (unit == BG_ANGLE_UNIT_RADIANS) {
return angle * BG_FP64_TURNS_IN_RADIAN; return angle * FP64_TURNS_IN_RADIAN;
} }
if (unit == BG_ANGLE_UNIT_DEGREES) { if (unit == BG_ANGLE_UNIT_DEGREES) {
return angle * BG_FP64_TURNS_IN_DEGREE; return angle * FP64_TURNS_IN_DEGREE;
} }
return angle; return angle;
@ -444,7 +444,7 @@ static inline double bg_fp64_angle_to_turns(const double angle, const angle_unit
// ============= Get Full Circle ============== // // ============= Get Full Circle ============== //
static inline float bg_fp32_angle_get_full_circle(const angle_unit_t unit) static inline float fp32_angle_get_full_circle(const angle_unit_t unit)
{ {
if (unit == BG_ANGLE_UNIT_DEGREES) { if (unit == BG_ANGLE_UNIT_DEGREES) {
return 360.0f; return 360.0f;
@ -454,10 +454,10 @@ static inline float bg_fp32_angle_get_full_circle(const angle_unit_t unit)
return 1.0f; return 1.0f;
} }
return BG_FP32_TWO_PI; return FP32_TWO_PI;
} }
static inline double bg_fp64_angle_get_full_circle(const angle_unit_t unit) static inline double fp64_angle_get_full_circle(const angle_unit_t unit)
{ {
if (unit == BG_ANGLE_UNIT_DEGREES) { if (unit == BG_ANGLE_UNIT_DEGREES) {
return 360.0; return 360.0;
@ -467,12 +467,12 @@ static inline double bg_fp64_angle_get_full_circle(const angle_unit_t unit)
return 1.0; return 1.0;
} }
return BG_FP64_TWO_PI; return FP64_TWO_PI;
} }
// ============= Get Half Circle ============== // // ============= Get Half Circle ============== //
static inline float bg_fp32_angle_get_half_circle(const angle_unit_t unit) static inline float fp32_angle_get_half_circle(const angle_unit_t unit)
{ {
if (unit == BG_ANGLE_UNIT_DEGREES) { if (unit == BG_ANGLE_UNIT_DEGREES) {
return 180.0f; return 180.0f;
@ -482,10 +482,10 @@ static inline float bg_fp32_angle_get_half_circle(const angle_unit_t unit)
return 0.5f; return 0.5f;
} }
return BG_FP32_PI; return FP32_PI;
} }
static inline double bg_fp64_angle_get_half_circle(const angle_unit_t unit) static inline double fp64_angle_get_half_circle(const angle_unit_t unit)
{ {
if (unit == BG_ANGLE_UNIT_DEGREES) { if (unit == BG_ANGLE_UNIT_DEGREES) {
return 180.0; return 180.0;
@ -495,12 +495,12 @@ static inline double bg_fp64_angle_get_half_circle(const angle_unit_t unit)
return 0.5; return 0.5;
} }
return BG_FP64_PI; return FP64_PI;
} }
// ============= Get Half Circle ============== // // ============= Get Half Circle ============== //
static inline float bg_fp32_angle_get_quater_circle(const angle_unit_t unit) static inline float fp32_angle_get_quater_circle(const angle_unit_t unit)
{ {
if (unit == BG_ANGLE_UNIT_DEGREES) { if (unit == BG_ANGLE_UNIT_DEGREES) {
return 90.0f; return 90.0f;
@ -510,10 +510,10 @@ static inline float bg_fp32_angle_get_quater_circle(const angle_unit_t unit)
return 0.25f; return 0.25f;
} }
return BG_FP32_HALF_OF_PI; return FP32_HALF_OF_PI;
} }
static inline double bg_fp64_angle_get_quater_circle(const angle_unit_t unit) static inline double fp64_angle_get_quater_circle(const angle_unit_t unit)
{ {
if (unit == BG_ANGLE_UNIT_DEGREES) { if (unit == BG_ANGLE_UNIT_DEGREES) {
return 90.0; return 90.0;
@ -523,35 +523,35 @@ static inline double bg_fp64_angle_get_quater_circle(const angle_unit_t unit)
return 0.25; return 0.25;
} }
return BG_FP64_HALF_OF_PI; return FP64_HALF_OF_PI;
} }
// ================ Normalize ================= // // ================ Normalize ================= //
static inline float bg_fp32_angle_normalize(const float angle, const angle_unit_t unit, const angle_range_t range) static inline float fp32_angle_normalize(const float angle, const angle_unit_t unit, const angle_range_t range)
{ {
if (unit == BG_ANGLE_UNIT_DEGREES) { if (unit == BG_ANGLE_UNIT_DEGREES) {
return bg_fp32_degrees_normalize(angle, range); return fp32_degrees_normalize(angle, range);
} }
if (unit == BG_ANGLE_UNIT_TURNS) { if (unit == BG_ANGLE_UNIT_TURNS) {
return bg_fp32_turns_normalize(angle, range); return fp32_turns_normalize(angle, range);
} }
return bg_fp32_radians_normalize(angle, range); return fp32_radians_normalize(angle, range);
} }
static inline double bg_fp64_angle_normalize(const double angle, const angle_unit_t unit, const angle_range_t range) static inline double fp64_angle_normalize(const double angle, const angle_unit_t unit, const angle_range_t range)
{ {
if (unit == BG_ANGLE_UNIT_DEGREES) { if (unit == BG_ANGLE_UNIT_DEGREES) {
return bg_fp64_degrees_normalize(angle, range); return fp64_degrees_normalize(angle, range);
} }
if (unit == BG_ANGLE_UNIT_TURNS) { if (unit == BG_ANGLE_UNIT_TURNS) {
return bg_fp64_turns_normalize(angle, range); return fp64_turns_normalize(angle, range);
} }
return bg_fp64_radians_normalize(angle, range); return fp64_radians_normalize(angle, range);
} }
#endif #endif

View file

@ -1,56 +1,56 @@
#ifndef __GEOMETRY__TYPES_H_ #ifndef __GEOMETRY__TYPES_H_
#define __GEOMETRY__TYPES_H_ #define __GEOMETRY__TYPES_H_
#define BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT 10.0f #define FP32_EPSYLON_EFFECTIVENESS_LIMIT 10.0f
#define BG_FP32_EPSYLON 5E-7f #define FP32_EPSYLON 5E-7f
#define BG_FP32_TWO_EPSYLON 1E-6f #define FP32_TWO_EPSYLON 1E-6f
#define BG_FP32_SQUARE_EPSYLON 2.5E-13f #define FP32_SQUARE_EPSYLON 2.5E-13f
#define BG_FP32_ONE_THIRD 0.333333333f #define FP32_ONE_THIRD 0.333333333f
#define BG_FP32_ONE_SIXTH 0.166666667f #define FP32_ONE_SIXTH 0.166666667f
#define BG_FP32_ONE_NINETH 0.111111111f #define FP32_ONE_NINETH 0.111111111f
#define BG_FP32_GOLDEN_RATIO_HIGH 1.618034f #define FP32_GOLDEN_RATIO_HIGH 1.618034f
#define BG_FP32_GOLDEN_RATIO_LOW 0.618034f #define FP32_GOLDEN_RATIO_LOW 0.618034f
#define BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT 10.0 #define FP64_EPSYLON_EFFECTIVENESS_LIMIT 10.0
#define BG_FP64_EPSYLON 5E-14 #define FP64_EPSYLON 5E-14
#define BG_FP64_TWO_EPSYLON 1E-13 #define FP64_TWO_EPSYLON 1E-13
#define BG_FP64_SQUARE_EPSYLON 2.5E-27 #define FP64_SQUARE_EPSYLON 2.5E-27
#define BG_FP64_ONE_THIRD 0.333333333333333333 #define FP64_ONE_THIRD 0.333333333333333333
#define BG_FP64_ONE_SIXTH 0.166666666666666667 #define FP64_ONE_SIXTH 0.166666666666666667
#define BG_FP64_ONE_NINETH 0.111111111111111111 #define FP64_ONE_NINETH 0.111111111111111111
#define BG_FP64_GOLDEN_RATIO_HIGH 1.61803398874989485 #define FP64_GOLDEN_RATIO_HIGH 1.61803398874989485
#define BG_FP64_GOLDEN_RATIO_LOW 0.61803398874989485 #define FP64_GOLDEN_RATIO_LOW 0.61803398874989485
static inline int bg_fp32_are_equal(const float value1, const float value2) static inline int fp32_are_equal(const float value1, const float value2)
{ {
if (-BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT < value1 && value1 < BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT) { if (-FP32_EPSYLON_EFFECTIVENESS_LIMIT < value1 && value1 < FP32_EPSYLON_EFFECTIVENESS_LIMIT) {
return -BG_FP32_EPSYLON <= (value1 - value2) && (value1 - value2) <= BG_FP32_EPSYLON; return -FP32_EPSYLON <= (value1 - value2) && (value1 - value2) <= FP32_EPSYLON;
} }
if (value1 < 0.0f) { if (value1 < 0.0f) {
return (1.0f + BG_FP32_EPSYLON) * value2 <= value1 && (1.0f + BG_FP32_EPSYLON) * value1 <= value2; return (1.0f + FP32_EPSYLON) * value2 <= value1 && (1.0f + FP32_EPSYLON) * value1 <= value2;
} }
return value2 <= value1 * (1.0f + BG_FP32_EPSYLON) && value1 <= value2 * (1.0f + BG_FP32_EPSYLON); return value2 <= value1 * (1.0f + FP32_EPSYLON) && value1 <= value2 * (1.0f + FP32_EPSYLON);
} }
static inline int bg_fp64_are_equal(const double value1, const double value2) static inline int fp64_are_equal(const double value1, const double value2)
{ {
if (-BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT < value1 && value1 < BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT) { if (-FP64_EPSYLON_EFFECTIVENESS_LIMIT < value1 && value1 < FP64_EPSYLON_EFFECTIVENESS_LIMIT) {
return -BG_FP64_EPSYLON <= (value1 - value2) && (value1 - value2) <= BG_FP64_EPSYLON; return -FP64_EPSYLON <= (value1 - value2) && (value1 - value2) <= FP64_EPSYLON;
} }
if (value1 < 0.0) { if (value1 < 0.0) {
return (1.0 + BG_FP64_EPSYLON) * value2 <= value1 && (1.0 + BG_FP64_EPSYLON) * value1 <= value2; return (1.0 + FP64_EPSYLON) * value2 <= value1 && (1.0 + FP64_EPSYLON) * value1 <= value2;
} }
return value2 <= value1 * (1.0 + BG_FP64_EPSYLON) && value1 <= value2 * (1.0 + BG_FP64_EPSYLON); return value2 <= value1 * (1.0 + FP64_EPSYLON) && value1 <= value2 * (1.0 + FP64_EPSYLON);
} }
#endif #endif

View file

Internal server error - Personal Git Server: Beyond coding. We Forge.

500

Internal server error

Forgejo version: 11.0.1+gitea-1.22.0

@ -1,5 +1,5 @@
#ifndef _GEOMETRY_MATRIX2X2_H_ #ifndef _BASIC_GEOMETRY_MATRIX2X2_H_
#define _GEOMETRY_MATRIX2X2_H_ #define _BASIC_GEOMETRY_MATRIX2X2_H_
#include "angle.h" #include "angle.h"
#include "vector2.h" #include "vector2.h"
@ -7,7 +7,7 @@
// =================== Reset ==================== // // =================== Reset ==================== //
static inline void bg_fp32_matrix2x2_reset(BgFP32Matrix2x2* matrix) static inline void fp32_matrix2x2_reset(fp32_matrix2x2_t* matrix)
{ {
matrix->r1c1 = 0.0f; matrix->r1c1 = 0.0f;
matrix->r1c2 = 0.0f; matrix->r1c2 = 0.0f;
@ -15,7 +15,7 @@ static inline void bg_fp32_matrix2x2_reset(BgFP32Matrix2x2* matrix)
matrix->r2c2 = 0.0f; matrix->r2c2 = 0.0f;
} }
static inline void bg_fp64_matrix2x2_reset(BgFP64Matrix2x2* matrix) static inline void fp64_matrix2x2_reset(fp64_matrix2x2_t* matrix)
{ {
matrix->r1c1 = 0.0; matrix->r1c1 = 0.0;
matrix->r1c2 = 0.0; matrix->r1c2 = 0.0;
@ -25,7 +25,7 @@ static inline void bg_fp64_matrix2x2_reset(BgFP64Matrix2x2* matrix)
// ================== Identity ================== // // ================== Identity ================== //
static inline void bg_fp32_matrix2x2_set_to_identity(BgFP32Matrix2x2* matrix) static inline void fp32_matrix2x2_set_to_identity(fp32_matrix2x2_t* matrix)
{ {
matrix->r1c1 = 1.0f; matrix->r1c1 = 1.0f;
matrix->r1c2 = 0.0f; matrix->r1c2 = 0.0f;
@ -33,7 +33,7 @@ static inline void bg_fp32_matrix2x2_set_to_identity(BgFP32Matrix2x2* matrix)
matrix->r2c2 = 1.0f; matrix->r2c2 = 1.0f;
} }
static inline void bg_fp64_matrix2x2_set_to_identity(BgFP64Matrix2x2* matrix) static inline void fp64_matrix2x2_set_to_identity(fp64_matrix2x2_t* matrix)
{ {
matrix->r1c1 = 1.0; matrix->r1c1 = 1.0;
matrix->r1c2 = 0.0; matrix->r1c2 = 0.0;
@ -43,7 +43,7 @@ static inline void bg_fp64_matrix2x2_set_to_identity(BgFP64Matrix2x2* matrix)
// ================ Make Diagonal =============== // // ================ Make Diagonal =============== //