Переименование типов в соответствии со стилем POSIX, отказ от префикса bg_
This commit is contained in:
parent
d2a25823a5
commit
605afabd94
25 changed files with 1109 additions and 1035 deletions
|
@ -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;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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 =============== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix2x2_set_to_diagonal(const float d1, const float d2, BgFP32Matrix2x2* matrix)
|
static inline void fp32_matrix2x2_set_to_diagonal(const float d1, const float d2, fp32_matrix2x2_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c1 = d1;
|
matrix->r1c1 = d1;
|
||||||
matrix->r1c2 = 0.0f;
|
matrix->r1c2 = 0.0f;
|
||||||
|
@ -51,7 +51,7 @@ static inline void bg_fp32_matrix2x2_set_to_diagonal(const float d1, const float
|
||||||
matrix->r2c2 = d2;
|
matrix->r2c2 = d2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix2x2_set_to_diagonal(const double d1, const double d2, BgFP64Matrix2x2* matrix)
|
static inline void fp64_matrix2x2_set_to_diagonal(const double d1, const double d2, fp64_matrix2x2_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c1 = d1;
|
matrix->r1c1 = d1;
|
||||||
matrix->r1c2 = 0.0;
|
matrix->r1c2 = 0.0;
|
||||||
|
@ -61,9 +61,9 @@ static inline void bg_fp64_matrix2x2_set_to_diagonal(const double d1, const doub
|
||||||
|
|
||||||
// ============== Rotation Matrix =============== //
|
// ============== Rotation Matrix =============== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix2x2_make_turn(const float angle, const angle_unit_t unit, BgFP32Matrix2x2* matrix)
|
static inline void fp32_matrix2x2_make_turn(const float angle, const angle_unit_t unit, fp32_matrix2x2_t* matrix)
|
||||||
{
|
{
|
||||||
const float radians = bg_fp32_angle_to_radians(angle, unit);
|
const float radians = fp32_angle_to_radians(angle, unit);
|
||||||
const float cosine = cosf(radians);
|
const float cosine = cosf(radians);
|
||||||
const float sine = sinf(radians);
|
const float sine = sinf(radians);
|
||||||
|
|
||||||
|
@ -73,9 +73,9 @@ static inline void bg_fp32_matrix2x2_make_turn(const float angle, const angle_un
|
||||||
matrix->r2c2 = cosine;
|
matrix->r2c2 = cosine;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix2x2_make_turn(const double angle, const angle_unit_t unit, BgFP64Matrix2x2* matrix)
|
static inline void fp64_matrix2x2_make_turn(const double angle, const angle_unit_t unit, fp64_matrix2x2_t* matrix)
|
||||||
{
|
{
|
||||||
const double radians = bg_fp64_angle_to_radians(angle, unit);
|
const double radians = fp64_angle_to_radians(angle, unit);
|
||||||
const double cosine = cos(radians);
|
const double cosine = cos(radians);
|
||||||
const double sine = sin(radians);
|
const double sine = sin(radians);
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ static inline void bg_fp64_matrix2x2_make_turn(const double angle, const angle_u
|
||||||
|
|
||||||
// ==================== Copy ==================== //
|
// ==================== Copy ==================== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix2x2_copy(const BgFP32Matrix2x2* from, BgFP32Matrix2x2* to)
|
static inline void fp32_matrix2x2_copy(const fp32_matrix2x2_t* from, fp32_matrix2x2_t* to)
|
||||||
{
|
{
|
||||||
to->r1c1 = from->r1c1;
|
to->r1c1 = from->r1c1;
|
||||||
to->r1c2 = from->r1c2;
|
to->r1c2 = from->r1c2;
|
||||||
|
@ -96,7 +96,7 @@ static inline void bg_fp32_matrix2x2_copy(const BgFP32Matrix2x2* from, BgFP32Mat
|
||||||
to->r2c2 = from->r2c2;
|
to->r2c2 = from->r2c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix2x2_copy(const BgFP64Matrix2x2* from, BgFP64Matrix2x2* to)
|
static inline void fp64_matrix2x2_copy(const fp64_matrix2x2_t* from, fp64_matrix2x2_t* to)
|
||||||
{
|
{
|
||||||
to->r1c1 = from->r1c1;
|
to->r1c1 = from->r1c1;
|
||||||
to->r1c2 = from->r1c2;
|
to->r1c2 = from->r1c2;
|
||||||
|
@ -107,7 +107,7 @@ static inline void bg_fp64_matrix2x2_copy(const BgFP64Matrix2x2* from, BgFP64Mat
|
||||||
|
|
||||||
// ==================== Swap ==================== //
|
// ==================== Swap ==================== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix2x2_swap(BgFP32Matrix2x2* matrix1, BgFP32Matrix2x2* matrix2)
|
static inline void fp32_matrix2x2_swap(fp32_matrix2x2_t* matrix1, fp32_matrix2x2_t* matrix2)
|
||||||
{
|
{
|
||||||
const float r1c1 = matrix2->r1c1;
|
const float r1c1 = matrix2->r1c1;
|
||||||
const float r1c2 = matrix2->r1c2;
|
const float r1c2 = matrix2->r1c2;
|
||||||
|
@ -128,7 +128,7 @@ static inline void bg_fp32_matrix2x2_swap(BgFP32Matrix2x2* matrix1, BgFP32Matrix
|
||||||
matrix1->r2c2 = r2c2;
|
matrix1->r2c2 = r2c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix2x2_swap(BgFP64Matrix2x2* matrix1, BgFP64Matrix2x2* matrix2)
|
static inline void fp64_matrix2x2_swap(fp64_matrix2x2_t* matrix1, fp64_matrix2x2_t* matrix2)
|
||||||
{
|
{
|
||||||
const double r1c1 = matrix2->r1c1;
|
const double r1c1 = matrix2->r1c1;
|
||||||
const double r1c2 = matrix2->r1c2;
|
const double r1c2 = matrix2->r1c2;
|
||||||
|
@ -151,7 +151,7 @@ static inline void bg_fp64_matrix2x2_swap(BgFP64Matrix2x2* matrix1, BgFP64Matrix
|
||||||
|
|
||||||
// ============= Copy to twin type ============== //
|
// ============= Copy to twin type ============== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix2x2_set_from_fp64(const BgFP64Matrix2x2* from, BgFP32Matrix2x2* to)
|
static inline void fp32_matrix2x2_set_from_fp64(const fp64_matrix2x2_t* from, fp32_matrix2x2_t* to)
|
||||||
{
|
{
|
||||||
to->r1c1 = (float)from->r1c1;
|
to->r1c1 = (float)from->r1c1;
|
||||||
to->r1c2 = (float)from->r1c2;
|
to->r1c2 = (float)from->r1c2;
|
||||||
|
@ -160,7 +160,7 @@ static inline void bg_fp32_matrix2x2_set_from_fp64(const BgFP64Matrix2x2* from,
|
||||||
to->r2c2 = (float)from->r2c2;
|
to->r2c2 = (float)from->r2c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix2x2_set_from_fp32(const BgFP32Matrix2x2* from, BgFP64Matrix2x2* to)
|
static inline void fp64_matrix2x2_set_from_fp32(const fp32_matrix2x2_t* from, fp64_matrix2x2_t* to)
|
||||||
{
|
{
|
||||||
to->r1c1 = from->r1c1;
|
to->r1c1 = from->r1c1;
|
||||||
to->r1c2 = from->r1c2;
|
to->r1c2 = from->r1c2;
|
||||||
|
@ -171,42 +171,42 @@ static inline void bg_fp64_matrix2x2_set_from_fp32(const BgFP32Matrix2x2* from,
|
||||||
|
|
||||||
// ================ Determinant ================= //
|
// ================ Determinant ================= //
|
||||||
|
|
||||||
static inline float bg_fp32_matrix2x2_get_determinant(const BgFP32Matrix2x2* matrix)
|
static inline float fp32_matrix2x2_get_determinant(const fp32_matrix2x2_t* matrix)
|
||||||
{
|
{
|
||||||
return matrix->r1c1 * matrix->r2c2 - matrix->r1c2 * matrix->r2c1;
|
return matrix->r1c1 * matrix->r2c2 - matrix->r1c2 * matrix->r2c1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline double bg_fp64_matrix2x2_get_determinant(const BgFP64Matrix2x2* matrix)
|
static inline double fp64_matrix2x2_get_determinant(const fp64_matrix2x2_t* matrix)
|
||||||
{
|
{
|
||||||
return matrix->r1c1 * matrix->r2c2 - matrix->r1c2 * matrix->r2c1;
|
return matrix->r1c1 * matrix->r2c2 - matrix->r1c2 * matrix->r2c1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================== Singular ================== //
|
// ================== Singular ================== //
|
||||||
|
|
||||||
static inline int bg_fp32_matrix2x2_is_singular(const BgFP32Matrix2x2* matrix)
|
static inline int fp32_matrix2x2_is_singular(const fp32_matrix2x2_t* matrix)
|
||||||
{
|
{
|
||||||
const float determinant = bg_fp32_matrix2x2_get_determinant(matrix);
|
const float determinant = fp32_matrix2x2_get_determinant(matrix);
|
||||||
|
|
||||||
return -BG_FP32_EPSYLON <= determinant && determinant <= BG_FP32_EPSYLON;
|
return -FP32_EPSYLON <= determinant && determinant <= FP32_EPSYLON;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int bg_fp64_matrix2x2_is_singular(const BgFP64Matrix2x2* matrix)
|
static inline int fp64_matrix2x2_is_singular(const fp64_matrix2x2_t* matrix)
|
||||||
{
|
{
|
||||||
const double determinant = bg_fp64_matrix2x2_get_determinant(matrix);
|
const double determinant = fp64_matrix2x2_get_determinant(matrix);
|
||||||
|
|
||||||
return -BG_FP64_EPSYLON <= determinant && determinant <= BG_FP64_EPSYLON;
|
return -FP64_EPSYLON <= determinant && determinant <= FP64_EPSYLON;
|
||||||
}
|
}
|
||||||
|
|
||||||
// =============== Transposition ================ //
|
// =============== Transposition ================ //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix2x2_transpose(BgFP32Matrix2x2* matrix)
|
static inline void fp32_matrix2x2_transpose(fp32_matrix2x2_t* matrix)
|
||||||
{
|
{
|
||||||
const float tmp = matrix->r1c2;
|
const float tmp = matrix->r1c2;
|
||||||
matrix->r1c2 = matrix->r2c1;
|
matrix->r1c2 = matrix->r2c1;
|
||||||
matrix->r2c1 = tmp;
|
matrix->r2c1 = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix2x2_transpose(BgFP64Matrix2x2* matrix)
|
static inline void fp64_matrix2x2_transpose(fp64_matrix2x2_t* matrix)
|
||||||
{
|
{
|
||||||
const double tmp = matrix->r1c2;
|
const double tmp = matrix->r1c2;
|
||||||
matrix->r1c2 = matrix->r2c1;
|
matrix->r1c2 = matrix->r2c1;
|
||||||
|
@ -215,11 +215,11 @@ static inline void bg_fp64_matrix2x2_transpose(BgFP64Matrix2x2* matrix)
|
||||||
|
|
||||||
// ================= Inversion ================== //
|
// ================= Inversion ================== //
|
||||||
|
|
||||||
static inline int bg_fp32_matrix2x2_invert(BgFP32Matrix2x2* matrix)
|
static inline int fp32_matrix2x2_invert(fp32_matrix2x2_t* matrix)
|
||||||
{
|
{
|
||||||
const float determinant = bg_fp32_matrix2x2_get_determinant(matrix);
|
const float determinant = fp32_matrix2x2_get_determinant(matrix);
|
||||||
|
|
||||||
if (-BG_FP32_EPSYLON <= determinant && determinant <= BG_FP32_EPSYLON) {
|
if (-FP32_EPSYLON <= determinant && determinant <= FP32_EPSYLON) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,11 +240,11 @@ static inline int bg_fp32_matrix2x2_invert(BgFP32Matrix2x2* matrix)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int bg_fp64_matrix2x2_invert(BgFP64Matrix2x2* matrix)
|
static inline int fp64_matrix2x2_invert(fp64_matrix2x2_t* matrix)
|
||||||
{
|
{
|
||||||
const double determinant = bg_fp64_matrix2x2_get_determinant(matrix);
|
const double determinant = fp64_matrix2x2_get_determinant(matrix);
|
||||||
|
|
||||||
if (-BG_FP64_EPSYLON <= determinant && determinant <= BG_FP64_EPSYLON) {
|
if (-FP64_EPSYLON <= determinant && determinant <= FP64_EPSYLON) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,7 +267,7 @@ static inline int bg_fp64_matrix2x2_invert(BgFP64Matrix2x2* matrix)
|
||||||
|
|
||||||
// =============== Set Transposed =============== //
|
// =============== Set Transposed =============== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix2x2_set_transposed(const BgFP32Matrix2x2* from, BgFP32Matrix2x2* to)
|
static inline void fp32_matrix2x2_set_transposed(const fp32_matrix2x2_t* from, fp32_matrix2x2_t* to)
|
||||||
{
|
{
|
||||||
float tmp = from->r1c2;
|
float tmp = from->r1c2;
|
||||||
|
|
||||||
|
@ -278,7 +278,7 @@ static inline void bg_fp32_matrix2x2_set_transposed(const BgFP32Matrix2x2* from,
|
||||||
to->r2c2 = from->r2c2;
|
to->r2c2 = from->r2c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix2x2_set_transposed(const BgFP64Matrix2x2* from, BgFP64Matrix2x2* to)
|
static inline void fp64_matrix2x2_set_transposed(const fp64_matrix2x2_t* from, fp64_matrix2x2_t* to)
|
||||||
{
|
{
|
||||||
double tmp = from->r1c2;
|
double tmp = from->r1c2;
|
||||||
|
|
||||||
|
@ -291,11 +291,11 @@ static inline void bg_fp64_matrix2x2_set_transposed(const BgFP64Matrix2x2* from,
|
||||||
|
|
||||||
// ================ Set Inverted ================ //
|
// ================ Set Inverted ================ //
|
||||||
|
|
||||||
static inline int bg_fp32_matrix2x2_set_inverted(const BgFP32Matrix2x2* from, BgFP32Matrix2x2* to)
|
static inline int fp32_matrix2x2_set_inverted(const fp32_matrix2x2_t* from, fp32_matrix2x2_t* to)
|
||||||
{
|
{
|
||||||
const float determinant = bg_fp32_matrix2x2_get_determinant(from);
|
const float determinant = fp32_matrix2x2_get_determinant(from);
|
||||||
|
|
||||||
if (-BG_FP32_EPSYLON <= determinant && determinant <= BG_FP32_EPSYLON) {
|
if (-FP32_EPSYLON <= determinant && determinant <= FP32_EPSYLON) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,11 +316,11 @@ static inline int bg_fp32_matrix2x2_set_inverted(const BgFP32Matrix2x2* from, Bg
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int bg_fp64_matrix2x2_set_inverted(const BgFP64Matrix2x2* from, BgFP64Matrix2x2* to)
|
static inline int fp64_matrix2x2_set_inverted(const fp64_matrix2x2_t* from, fp64_matrix2x2_t* to)
|
||||||
{
|
{
|
||||||
const double determinant = bg_fp64_matrix2x2_get_determinant(from);
|
const double determinant = fp64_matrix2x2_get_determinant(from);
|
||||||
|
|
||||||
if (-BG_FP64_EPSYLON <= determinant && determinant <= BG_FP64_EPSYLON) {
|
if (-FP64_EPSYLON <= determinant && determinant <= FP64_EPSYLON) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -343,13 +343,13 @@ static inline int bg_fp64_matrix2x2_set_inverted(const BgFP64Matrix2x2* from, Bg
|
||||||
|
|
||||||
// ================= Set Row 1 ================== //
|
// ================= Set Row 1 ================== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix2x2_set_row1(const float c1, const float c2, BgFP32Matrix2x2* matrix)
|
static inline void fp32_matrix2x2_set_row1(const float c1, const float c2, fp32_matrix2x2_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c1 = c1;
|
matrix->r1c1 = c1;
|
||||||
matrix->r1c2 = c2;
|
matrix->r1c2 = c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix2x2_set_row1(const double c1, const double c2, BgFP64Matrix2x2* matrix)
|
static inline void fp64_matrix2x2_set_row1(const double c1, const double c2, fp64_matrix2x2_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c1 = c1;
|
matrix->r1c1 = c1;
|
||||||
matrix->r1c2 = c2;
|
matrix->r1c2 = c2;
|
||||||
|
@ -357,13 +357,13 @@ static inline void bg_fp64_matrix2x2_set_row1(const double c1, const double c2,
|
||||||
|
|
||||||
// ================= Set Row 2 ================== //
|
// ================= Set Row 2 ================== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix2x2_set_row2(const float c1, const float c2, BgFP32Matrix2x2* matrix)
|
static inline void fp32_matrix2x2_set_row2(const float c1, const float c2, fp32_matrix2x2_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r2c1 = c1;
|
matrix->r2c1 = c1;
|
||||||
matrix->r2c2 = c2;
|
matrix->r2c2 = c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix2x2_set_row2(const double c1, const double c2, BgFP64Matrix2x2* matrix)
|
static inline void fp64_matrix2x2_set_row2(const double c1, const double c2, fp64_matrix2x2_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r2c1 = c1;
|
matrix->r2c1 = c1;
|
||||||
matrix->r2c2 = c2;
|
matrix->r2c2 = c2;
|
||||||
|
@ -371,13 +371,13 @@ static inline void bg_fp64_matrix2x2_set_row2(const double c1, const double c2,
|
||||||
|
|
||||||
// ================ Set Column 1 ================ //
|
// ================ Set Column 1 ================ //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix2x2_set_column1(const float r1, const float r2, BgFP32Matrix2x2* matrix)
|
static inline void fp32_matrix2x2_set_column1(const float r1, const float r2, fp32_matrix2x2_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c1 = r1;
|
matrix->r1c1 = r1;
|
||||||
matrix->r2c1 = r2;
|
matrix->r2c1 = r2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix2x2_set_column1(const double r1, const double r2, BgFP64Matrix2x2* matrix)
|
static inline void fp64_matrix2x2_set_column1(const double r1, const double r2, fp64_matrix2x2_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c1 = r1;
|
matrix->r1c1 = r1;
|
||||||
matrix->r2c1 = r2;
|
matrix->r2c1 = r2;
|
||||||
|
@ -385,13 +385,13 @@ static inline void bg_fp64_matrix2x2_set_column1(const double r1, const double r
|
||||||
|
|
||||||
// ================ Set Column 2 ================ //
|
// ================ Set Column 2 ================ //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix2x2_set_column2(const float r1, const float r2, BgFP32Matrix2x2* matrix)
|
static inline void fp32_matrix2x2_set_column2(const float r1, const float r2, fp32_matrix2x2_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c2 = r1;
|
matrix->r1c2 = r1;
|
||||||
matrix->r2c2 = r2;
|
matrix->r2c2 = r2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix2x2_set_column2(const double r1, const double r2, BgFP64Matrix2x2* matrix)
|
static inline void fp64_matrix2x2_set_column2(const double r1, const double r2, fp64_matrix2x2_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c2 = r1;
|
matrix->r1c2 = r1;
|
||||||
matrix->r2c2 = r2;
|
matrix->r2c2 = r2;
|
||||||
|
@ -399,7 +399,7 @@ static inline void bg_fp64_matrix2x2_set_column2(const double r1, const double r
|
||||||
|
|
||||||
// ================ Append scaled =============== //
|
// ================ Append scaled =============== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix2x2_append_scaled(BgFP32Matrix2x2* basic_vector, const BgFP32Matrix2x2* scalable_vector, const float scale)
|
static inline void fp32_matrix2x2_append_scaled(fp32_matrix2x2_t* basic_vector, const fp32_matrix2x2_t* scalable_vector, const float scale)
|
||||||
{
|
{
|
||||||
basic_vector->r1c1 += scalable_vector->r1c1 * scale;
|
basic_vector->r1c1 += scalable_vector->r1c1 * scale;
|
||||||
basic_vector->r1c2 += scalable_vector->r1c2 * scale;
|
basic_vector->r1c2 += scalable_vector->r1c2 * scale;
|
||||||
|
@ -408,7 +408,7 @@ static inline void bg_fp32_matrix2x2_append_scaled(BgFP32Matrix2x2* basic_vector
|
||||||
basic_vector->r2c2 += scalable_vector->r2c2 * scale;
|
basic_vector->r2c2 += scalable_vector->r2c2 * scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix2x2_append_scaled(BgFP64Matrix2x2* basic_vector, const BgFP64Matrix2x2* scalable_vector, const double scale)
|
static inline void fp64_matrix2x2_append_scaled(fp64_matrix2x2_t* basic_vector, const fp64_matrix2x2_t* scalable_vector, const double scale)
|
||||||
{
|
{
|
||||||
basic_vector->r1c1 += scalable_vector->r1c1 * scale;
|
basic_vector->r1c1 += scalable_vector->r1c1 * scale;
|
||||||
basic_vector->r1c2 += scalable_vector->r1c2 * scale;
|
basic_vector->r1c2 += scalable_vector->r1c2 * scale;
|
||||||
|
@ -419,7 +419,7 @@ static inline void bg_fp64_matrix2x2_append_scaled(BgFP64Matrix2x2* basic_vector
|
||||||
|
|
||||||
// ================== Addition ================== //
|
// ================== Addition ================== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix2x2_add(const BgFP32Matrix2x2* matrix1, const BgFP32Matrix2x2* matrix2, BgFP32Matrix2x2* sum)
|
static inline void fp32_matrix2x2_add(const fp32_matrix2x2_t* matrix1, const fp32_matrix2x2_t* matrix2, fp32_matrix2x2_t* sum)
|
||||||
{
|
{
|
||||||
sum->r1c1 = matrix1->r1c1 + matrix2->r1c1;
|
sum->r1c1 = matrix1->r1c1 + matrix2->r1c1;
|
||||||
sum->r1c2 = matrix1->r1c2 + matrix2->r1c2;
|
sum->r1c2 = matrix1->r1c2 + matrix2->r1c2;
|
||||||
|
@ -428,7 +428,7 @@ static inline void bg_fp32_matrix2x2_add(const BgFP32Matrix2x2* matrix1, const B
|
||||||
sum->r2c2 = matrix1->r2c2 + matrix2->r2c2;
|
sum->r2c2 = matrix1->r2c2 + matrix2->r2c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix2x2_add(const BgFP64Matrix2x2* matrix1, const BgFP64Matrix2x2* matrix2, BgFP64Matrix2x2* sum)
|
static inline void fp64_matrix2x2_add(const fp64_matrix2x2_t* matrix1, const fp64_matrix2x2_t* matrix2, fp64_matrix2x2_t* sum)
|
||||||
{
|
{
|
||||||
sum->r1c1 = matrix1->r1c1 + matrix2->r1c1;
|
sum->r1c1 = matrix1->r1c1 + matrix2->r1c1;
|
||||||
sum->r1c2 = matrix1->r1c2 + matrix2->r1c2;
|
sum->r1c2 = matrix1->r1c2 + matrix2->r1c2;
|
||||||
|
@ -439,7 +439,7 @@ static inline void bg_fp64_matrix2x2_add(const BgFP64Matrix2x2* matrix1, const B
|
||||||
|
|
||||||
// ================ Subtraction ================= //
|
// ================ Subtraction ================= //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix2x2_subtract(const BgFP32Matrix2x2* minuend, const BgFP32Matrix2x2* subtrahend, BgFP32Matrix2x2* difference)
|
static inline void fp32_matrix2x2_subtract(const fp32_matrix2x2_t* minuend, const fp32_matrix2x2_t* subtrahend, fp32_matrix2x2_t* difference)
|
||||||
{
|
{
|
||||||
difference->r1c1 = minuend->r1c1 - subtrahend->r1c1;
|
difference->r1c1 = minuend->r1c1 - subtrahend->r1c1;
|
||||||
difference->r1c2 = minuend->r1c2 - subtrahend->r1c2;
|
difference->r1c2 = minuend->r1c2 - subtrahend->r1c2;
|
||||||
|
@ -448,7 +448,7 @@ static inline void bg_fp32_matrix2x2_subtract(const BgFP32Matrix2x2* minuend, co
|
||||||
difference->r2c2 = minuend->r2c2 - subtrahend->r2c2;
|
difference->r2c2 = minuend->r2c2 - subtrahend->r2c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix2x2_subtract(const BgFP64Matrix2x2* minuend, const BgFP64Matrix2x2* subtrahend, BgFP64Matrix2x2* difference)
|
static inline void fp64_matrix2x2_subtract(const fp64_matrix2x2_t* minuend, const fp64_matrix2x2_t* subtrahend, fp64_matrix2x2_t* difference)
|
||||||
{
|
{
|
||||||
difference->r1c1 = minuend->r1c1 - subtrahend->r1c1;
|
difference->r1c1 = minuend->r1c1 - subtrahend->r1c1;
|
||||||
difference->r1c2 = minuend->r1c2 - subtrahend->r1c2;
|
difference->r1c2 = minuend->r1c2 - subtrahend->r1c2;
|
||||||
|
@ -459,7 +459,7 @@ static inline void bg_fp64_matrix2x2_subtract(const BgFP64Matrix2x2* minuend, co
|
||||||
|
|
||||||
// =============== Multiplication =============== //
|
// =============== Multiplication =============== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix2x2_multiply(const BgFP32Matrix2x2* multiplicand, const float multiplier, BgFP32Matrix2x2* product)
|
static inline void fp32_matrix2x2_multiply(const fp32_matrix2x2_t* multiplicand, const float multiplier, fp32_matrix2x2_t* product)
|
||||||
{
|
{
|
||||||
product->r1c1 = multiplicand->r1c1 * multiplier;
|
product->r1c1 = multiplicand->r1c1 * multiplier;
|
||||||
product->r1c2 = multiplicand->r1c2 * multiplier;
|
product->r1c2 = multiplicand->r1c2 * multiplier;
|
||||||
|
@ -468,7 +468,7 @@ static inline void bg_fp32_matrix2x2_multiply(const BgFP32Matrix2x2* multiplican
|
||||||
product->r2c2 = multiplicand->r2c2 * multiplier;
|
product->r2c2 = multiplicand->r2c2 * multiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix2x2_multiply(const BgFP64Matrix2x2* multiplicand, const double multiplier, BgFP64Matrix2x2* product)
|
static inline void fp64_matrix2x2_multiply(const fp64_matrix2x2_t* multiplicand, const double multiplier, fp64_matrix2x2_t* product)
|
||||||
{
|
{
|
||||||
product->r1c1 = multiplicand->r1c1 * multiplier;
|
product->r1c1 = multiplicand->r1c1 * multiplier;
|
||||||
product->r1c2 = multiplicand->r1c2 * multiplier;
|
product->r1c2 = multiplicand->r1c2 * multiplier;
|
||||||
|
@ -479,19 +479,19 @@ static inline void bg_fp64_matrix2x2_multiply(const BgFP64Matrix2x2* multiplican
|
||||||
|
|
||||||
// ================== Division ================== //
|
// ================== Division ================== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix2x2_divide(const BgFP32Matrix2x2* dividend, const float divisor, BgFP32Matrix2x2* quotient)
|
static inline void fp32_matrix2x2_divide(const fp32_matrix2x2_t* dividend, const float divisor, fp32_matrix2x2_t* quotient)
|
||||||
{
|
{
|
||||||
bg_fp32_matrix2x2_multiply(dividend, 1.0f / divisor, quotient);
|
fp32_matrix2x2_multiply(dividend, 1.0f / divisor, quotient);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix2x2_divide(const BgFP64Matrix2x2* dividend, const double divisor, BgFP64Matrix2x2* quotient)
|
static inline void fp64_matrix2x2_divide(const fp64_matrix2x2_t* dividend, const double divisor, fp64_matrix2x2_t* quotient)
|
||||||
{
|
{
|
||||||
bg_fp64_matrix2x2_multiply(dividend, 1.0 / divisor, quotient);
|
fp64_matrix2x2_multiply(dividend, 1.0 / divisor, quotient);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============ Left Vector Product ============= //
|
// ============ Left Vector Product ============= //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix2x2_left_product(const BgFP32Vector2* vector, const BgFP32Matrix2x2* matrix, BgFP32Vector2* result)
|
static inline void fp32_matrix2x2_left_product(const fp32_vector2_t* vector, const fp32_matrix2x2_t* matrix, fp32_vector2_t* result)
|
||||||
{
|
{
|
||||||
const float x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1;
|
const float x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1;
|
||||||
const float x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2;
|
const float x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2;
|
||||||
|
@ -500,7 +500,7 @@ static inline void bg_fp32_matrix2x2_left_product(const BgFP32Vector2* vector, c
|
||||||
result->x2 = x2;
|
result->x2 = x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix2x2_left_product(const BgFP64Vector2* vector, const BgFP64Matrix2x2* matrix, BgFP64Vector2* result)
|
static inline void fp64_matrix2x2_left_product(const fp64_vector2_t* vector, const fp64_matrix2x2_t* matrix, fp64_vector2_t* result)
|
||||||
{
|
{
|
||||||
const double x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1;
|
const double x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1;
|
||||||
const double x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2;
|
const double x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2;
|
||||||
|
@ -511,7 +511,7 @@ static inline void bg_fp64_matrix2x2_left_product(const BgFP64Vector2* vector, c
|
||||||
|
|
||||||
// ============ Right Vector Product ============ //
|
// ============ Right Vector Product ============ //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix2x2_right_product(const BgFP32Matrix2x2* matrix, const BgFP32Vector2* vector, BgFP32Vector2* result)
|
static inline void fp32_matrix2x2_right_product(const fp32_matrix2x2_t* matrix, const fp32_vector2_t* vector, fp32_vector2_t* result)
|
||||||
{
|
{
|
||||||
const float x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2;
|
const float x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2;
|
||||||
const float x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2;
|
const float x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2;
|
||||||
|
@ -520,7 +520,7 @@ static inline void bg_fp32_matrix2x2_right_product(const BgFP32Matrix2x2* matrix
|
||||||
result->x2 = x2;
|
result->x2 = x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix2x2_right_product(const BgFP64Matrix2x2* matrix, const BgFP64Vector2* vector, BgFP64Vector2* result)
|
static inline void fp64_matrix2x2_right_product(const fp64_matrix2x2_t* matrix, const fp64_vector2_t* vector, fp64_vector2_t* result)
|
||||||
{
|
{
|
||||||
const double x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2;
|
const double x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2;
|
||||||
const double x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2;
|
const double x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#ifndef _GEOMETRY_MATRIX2X3_H_
|
#ifndef _BASIC_GEOMETRY_MATRIX2X3_H_
|
||||||
#define _GEOMETRY_MATRIX2X3_H_
|
#define _BASIC_GEOMETRY_MATRIX2X3_H_
|
||||||
|
|
||||||
#include "vector2.h"
|
#include "vector2.h"
|
||||||
#include "vector3.h"
|
#include "vector3.h"
|
||||||
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
// =================== Reset ==================== //
|
// =================== Reset ==================== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix2x3_reset(BgFP32Matrix2x3* matrix)
|
static inline void fp32_matrix2x3_reset(fp32_matrix2x3_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c1 = 0.0f;
|
matrix->r1c1 = 0.0f;
|
||||||
matrix->r1c2 = 0.0f;
|
matrix->r1c2 = 0.0f;
|
||||||
|
@ -19,7 +19,7 @@ static inline void bg_fp32_matrix2x3_reset(BgFP32Matrix2x3* matrix)
|
||||||
matrix->r3c2 = 0.0f;
|
matrix->r3c2 = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix2x3_reset(BgFP64Matrix2x3* matrix)
|
static inline void fp64_matrix2x3_reset(fp64_matrix2x3_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c1 = 0.0;
|
matrix->r1c1 = 0.0;
|
||||||
matrix->r1c2 = 0.0;
|
matrix->r1c2 = 0.0;
|
||||||
|
@ -33,7 +33,7 @@ static inline void bg_fp64_matrix2x3_reset(BgFP64Matrix2x3* matrix)
|
||||||
|
|
||||||
// ==================== Copy ==================== //
|
// ==================== Copy ==================== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix2x3_copy(const BgFP32Matrix2x3* from, BgFP32Matrix2x3* to)
|
static inline void fp32_matrix2x3_copy(const fp32_matrix2x3_t* from, fp32_matrix2x3_t* to)
|
||||||
{
|
{
|
||||||
to->r1c1 = from->r1c1;
|
to->r1c1 = from->r1c1;
|
||||||
to->r1c2 = from->r1c2;
|
to->r1c2 = from->r1c2;
|
||||||
|
@ -45,7 +45,7 @@ static inline void bg_fp32_matrix2x3_copy(const BgFP32Matrix2x3* from, BgFP32Mat
|
||||||
to->r3c2 = from->r3c2;
|
to->r3c2 = from->r3c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix2x3_copy(const BgFP64Matrix2x3* from, BgFP64Matrix2x3* to)
|
static inline void fp64_matrix2x3_copy(const fp64_matrix2x3_t* from, fp64_matrix2x3_t* to)
|
||||||
{
|
{
|
||||||
to->r1c1 = from->r1c1;
|
to->r1c1 = from->r1c1;
|
||||||
to->r1c2 = from->r1c2;
|
to->r1c2 = from->r1c2;
|
||||||
|
@ -59,7 +59,7 @@ static inline void bg_fp64_matrix2x3_copy(const BgFP64Matrix2x3* from, BgFP64Mat
|
||||||
|
|
||||||
// ==================== Swap ==================== //
|
// ==================== Swap ==================== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix2x3_swap(BgFP32Matrix2x3* matrix1, BgFP32Matrix2x3* matrix2)
|
static inline void fp32_matrix2x3_swap(fp32_matrix2x3_t* matrix1, fp32_matrix2x3_t* matrix2)
|
||||||
{
|
{
|
||||||
const float r1c1 = matrix2->r1c1;
|
const float r1c1 = matrix2->r1c1;
|
||||||
const float r1c2 = matrix2->r1c2;
|
const float r1c2 = matrix2->r1c2;
|
||||||
|
@ -89,7 +89,7 @@ static inline void bg_fp32_matrix2x3_swap(BgFP32Matrix2x3* matrix1, BgFP32Matrix
|
||||||
matrix1->r3c2 = r3c2;
|
matrix1->r3c2 = r3c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix2x3_swap(BgFP64Matrix2x3* matrix1, BgFP64Matrix2x3* matrix2)
|
static inline void fp64_matrix2x3_swap(fp64_matrix2x3_t* matrix1, fp64_matrix2x3_t* matrix2)
|
||||||
{
|
{
|
||||||
const double r1c1 = matrix2->r1c1;
|
const double r1c1 = matrix2->r1c1;
|
||||||
const double r1c2 = matrix2->r1c2;
|
const double r1c2 = matrix2->r1c2;
|
||||||
|
@ -121,7 +121,7 @@ static inline void bg_fp64_matrix2x3_swap(BgFP64Matrix2x3* matrix1, BgFP64Matrix
|
||||||
|
|
||||||
// ============= Copy to twin type ============== //
|
// ============= Copy to twin type ============== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix2x3_set_from_fp64(const BgFP64Matrix2x3* from, BgFP32Matrix2x3* to)
|
static inline void fp32_matrix2x3_set_from_fp64(const fp64_matrix2x3_t* from, fp32_matrix2x3_t* to)
|
||||||
{
|
{
|
||||||
to->r1c1 = (float) from->r1c1;
|
to->r1c1 = (float) from->r1c1;
|
||||||
to->r1c2 = (float) from->r1c2;
|
to->r1c2 = (float) from->r1c2;
|
||||||
|
@ -133,7 +133,7 @@ static inline void bg_fp32_matrix2x3_set_from_fp64(const BgFP64Matrix2x3* from,
|
||||||
to->r3c2 = (float) from->r3c2;
|
to->r3c2 = (float) from->r3c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix2x3_set_from_fp32(const BgFP32Matrix2x3* from, BgFP64Matrix2x3* to)
|
static inline void fp64_matrix2x3_set_from_fp32(const fp32_matrix2x3_t* from, fp64_matrix2x3_t* to)
|
||||||
{
|
{
|
||||||
to->r1c1 = from->r1c1;
|
to->r1c1 = from->r1c1;
|
||||||
to->r1c2 = from->r1c2;
|
to->r1c2 = from->r1c2;
|
||||||
|
@ -147,7 +147,7 @@ static inline void bg_fp64_matrix2x3_set_from_fp32(const BgFP32Matrix2x3* from,
|
||||||
|
|
||||||
// =============== Set transposed =============== //
|
// =============== Set transposed =============== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix2x3_set_transposed(const BgFP32Matrix3x2* from, BgFP32Matrix2x3* to)
|
static inline void fp32_matrix2x3_set_transposed(const fp32_matrix3x2_t* from, fp32_matrix2x3_t* to)
|
||||||
{
|
{
|
||||||
to->r1c1 = from->r1c1;
|
to->r1c1 = from->r1c1;
|
||||||
to->r1c2 = from->r2c1;
|
to->r1c2 = from->r2c1;
|
||||||
|
@ -159,7 +159,7 @@ static inline void bg_fp32_matrix2x3_set_transposed(const BgFP32Matrix3x2* from,
|
||||||
to->r3c2 = from->r2c3;
|
to->r3c2 = from->r2c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix2x3_set_transposed(const BgFP64Matrix3x2* from, BgFP64Matrix2x3* to)
|
static inline void fp64_matrix2x3_set_transposed(const fp64_matrix3x2_t* from, fp64_matrix2x3_t* to)
|
||||||
{
|
{
|
||||||
to->r1c1 = from->r1c1;
|
to->r1c1 = from->r1c1;
|
||||||
to->r1c2 = from->r2c1;
|
to->r1c2 = from->r2c1;
|
||||||
|
@ -173,7 +173,7 @@ static inline void bg_fp64_matrix2x3_set_transposed(const BgFP64Matrix3x2* from,
|
||||||
|
|
||||||
// =============== Set transposed =============== //
|
// =============== Set transposed =============== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix2x3_set_transposed_fp64(const BgFP64Matrix3x2* from, BgFP32Matrix2x3* to)
|
static inline void fp32_matrix2x3_set_transposed_fp64(const fp64_matrix3x2_t* from, fp32_matrix2x3_t* to)
|
||||||
{
|
{
|
||||||
to->r1c1 = (float) from->r1c1;
|
to->r1c1 = (float) from->r1c1;
|
||||||
to->r1c2 = (float) from->r2c1;
|
to->r1c2 = (float) from->r2c1;
|
||||||
|
@ -185,7 +185,7 @@ static inline void bg_fp32_matrix2x3_set_transposed_fp64(const BgFP64Matrix3x2*
|
||||||
to->r3c2 = (float) from->r2c3;
|
to->r3c2 = (float) from->r2c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix2x3_set_transposed_fp32(const BgFP32Matrix3x2* from, BgFP64Matrix2x3* to)
|
static inline void fp64_matrix2x3_set_transposed_fp32(const fp32_matrix3x2_t* from, fp64_matrix2x3_t* to)
|
||||||
{
|
{
|
||||||
to->r1c1 = from->r1c1;
|
to->r1c1 = from->r1c1;
|
||||||
to->r1c2 = from->r2c1;
|
to->r1c2 = from->r2c1;
|
||||||
|
@ -199,13 +199,13 @@ static inline void bg_fp64_matrix2x3_set_transposed_fp32(const BgFP32Matrix3x2*
|
||||||
|
|
||||||
// ================= Set Row 1 ================== //
|
// ================= Set Row 1 ================== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix2x3_set_row1(const float c1, const float c2, BgFP32Matrix2x3* matrix)
|
static inline void fp32_matrix2x3_set_row1(const float c1, const float c2, fp32_matrix2x3_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c1 = c1;
|
matrix->r1c1 = c1;
|
||||||
matrix->r1c2 = c2;
|
matrix->r1c2 = c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix2x3_set_row1(const double c1, const double c2, BgFP64Matrix2x3* matrix)
|
static inline void fp64_matrix2x3_set_row1(const double c1, const double c2, fp64_matrix2x3_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c1 = c1;
|
matrix->r1c1 = c1;
|
||||||
matrix->r1c2 = c2;
|
matrix->r1c2 = c2;
|
||||||
|
@ -213,13 +213,13 @@ static inline void bg_fp64_matrix2x3_set_row1(const double c1, const double c2,
|
||||||
|
|
||||||
// ================= Set Row 2 ================== //
|
// ================= Set Row 2 ================== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix2x3_set_row2(const float c1, const float c2, BgFP32Matrix2x3* matrix)
|
static inline void fp32_matrix2x3_set_row2(const float c1, const float c2, fp32_matrix2x3_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r2c1 = c1;
|
matrix->r2c1 = c1;
|
||||||
matrix->r2c2 = c2;
|
matrix->r2c2 = c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix2x3_set_row2(const double c1, const double c2, BgFP64Matrix2x3* matrix)
|
static inline void fp64_matrix2x3_set_row2(const double c1, const double c2, fp64_matrix2x3_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r2c1 = c1;
|
matrix->r2c1 = c1;
|
||||||
matrix->r2c2 = c2;
|
matrix->r2c2 = c2;
|
||||||
|
@ -227,13 +227,13 @@ static inline void bg_fp64_matrix2x3_set_row2(const double c1, const double c2,
|
||||||
|
|
||||||
// ================= Set Row 3 ================== //
|
// ================= Set Row 3 ================== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix2x3_set_row3(const float c1, const float c2, BgFP32Matrix2x3* matrix)
|
static inline void fp32_matrix2x3_set_row3(const float c1, const float c2, fp32_matrix2x3_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r3c1 = c1;
|
matrix->r3c1 = c1;
|
||||||
matrix->r3c2 = c2;
|
matrix->r3c2 = c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix2x3_set_row3(const double c1, const double c2, BgFP64Matrix2x3* matrix)
|
static inline void fp64_matrix2x3_set_row3(const double c1, const double c2, fp64_matrix2x3_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r3c1 = c1;
|
matrix->r3c1 = c1;
|
||||||
matrix->r3c2 = c2;
|
matrix->r3c2 = c2;
|
||||||
|
@ -241,14 +241,14 @@ static inline void bg_fp64_matrix2x3_set_row3(const double c1, const double c2,
|
||||||
|
|
||||||
// ================ Set Column 1 ================ //
|
// ================ Set Column 1 ================ //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix2x3_set_column1(const float r1, const float r2, const float r3, BgFP32Matrix2x3* matrix)
|
static inline void fp32_matrix2x3_set_column1(const float r1, const float r2, const float r3, fp32_matrix2x3_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c1 = r1;
|
matrix->r1c1 = r1;
|
||||||
matrix->r2c1 = r2;
|
matrix->r2c1 = r2;
|
||||||
matrix->r3c1 = r3;
|
matrix->r3c1 = r3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix2x3_set_column1(const double r1, const double r2, const double r3, BgFP64Matrix2x3* matrix)
|
static inline void fp64_matrix2x3_set_column1(const double r1, const double r2, const double r3, fp64_matrix2x3_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c1 = r1;
|
matrix->r1c1 = r1;
|
||||||
matrix->r2c1 = r2;
|
matrix->r2c1 = r2;
|
||||||
|
@ -257,14 +257,14 @@ static inline void bg_fp64_matrix2x3_set_column1(const double r1, const double r
|
||||||
|
|
||||||
// ================ Set Column 2 ================ //
|
// ================ Set Column 2 ================ //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix2x3_set_column2(const float r1, const float r2, const float r3, BgFP32Matrix2x3* matrix)
|
static inline void fp32_matrix2x3_set_column2(const float r1, const float r2, const float r3, fp32_matrix2x3_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c2 = r1;
|
matrix->r1c2 = r1;
|
||||||
matrix->r2c2 = r2;
|
matrix->r2c2 = r2;
|
||||||
matrix->r3c2 = r3;
|
matrix->r3c2 = r3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix2x3_set_column2(const double r1, const double r2, const double r3, BgFP64Matrix2x3* matrix)
|
static inline void fp64_matrix2x3_set_column2(const double r1, const double r2, const double r3, fp64_matrix2x3_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c2 = r1;
|
matrix->r1c2 = r1;
|
||||||
matrix->r2c2 = r2;
|
matrix->r2c2 = r2;
|
||||||
|
@ -273,7 +273,7 @@ static inline void bg_fp64_matrix2x3_set_column2(const double r1, const double r
|
||||||
|
|
||||||
// ================ Append scaled =============== //
|
// ================ Append scaled =============== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix2x3_append_scaled(BgFP32Matrix2x3* basic_vector, const BgFP32Matrix2x3* scalable_vector, const float scale)
|
static inline void fp32_matrix2x3_append_scaled(fp32_matrix2x3_t* basic_vector, const fp32_matrix2x3_t* scalable_vector, const float scale)
|
||||||
{
|
{
|
||||||
basic_vector->r1c1 += scalable_vector->r1c1 * scale;
|
basic_vector->r1c1 += scalable_vector->r1c1 * scale;
|
||||||
basic_vector->r1c2 += scalable_vector->r1c2 * scale;
|
basic_vector->r1c2 += scalable_vector->r1c2 * scale;
|
||||||
|
@ -285,7 +285,7 @@ static inline void bg_fp32_matrix2x3_append_scaled(BgFP32Matrix2x3* basic_vector
|
||||||
basic_vector->r3c2 += scalable_vector->r3c2 * scale;
|
basic_vector->r3c2 += scalable_vector->r3c2 * scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix2x3_append_scaled(BgFP64Matrix2x3* basic_vector, const BgFP64Matrix2x3* scalable_vector, const double scale)
|
static inline void fp64_matrix2x3_append_scaled(fp64_matrix2x3_t* basic_vector, const fp64_matrix2x3_t* scalable_vector, const double scale)
|
||||||
{
|
{
|
||||||
basic_vector->r1c1 += scalable_vector->r1c1 * scale;
|
basic_vector->r1c1 += scalable_vector->r1c1 * scale;
|
||||||
basic_vector->r1c2 += scalable_vector->r1c2 * scale;
|
basic_vector->r1c2 += scalable_vector->r1c2 * scale;
|
||||||
|
@ -299,7 +299,7 @@ static inline void bg_fp64_matrix2x3_append_scaled(BgFP64Matrix2x3* basic_vector
|
||||||
|
|
||||||
// ================== Addition ================== //
|
// ================== Addition ================== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix2x3_add(const BgFP32Matrix2x3* matrix1, const BgFP32Matrix2x3* matrix2, BgFP32Matrix2x3* sum)
|
static inline void fp32_matrix2x3_add(const fp32_matrix2x3_t* matrix1, const fp32_matrix2x3_t* matrix2, fp32_matrix2x3_t* sum)
|
||||||
{
|
{
|
||||||
sum->r1c1 = matrix1->r1c1 + matrix2->r1c1;
|
sum->r1c1 = matrix1->r1c1 + matrix2->r1c1;
|
||||||
sum->r1c2 = matrix1->r1c2 + matrix2->r1c2;
|
sum->r1c2 = matrix1->r1c2 + matrix2->r1c2;
|
||||||
|
@ -311,7 +311,7 @@ static inline void bg_fp32_matrix2x3_add(const BgFP32Matrix2x3* matrix1, const B
|
||||||
sum->r3c2 = matrix1->r3c2 + matrix2->r3c2;
|
sum->r3c2 = matrix1->r3c2 + matrix2->r3c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix2x3_add(const BgFP64Matrix2x3* matrix1, const BgFP64Matrix2x3* matrix2, BgFP64Matrix2x3* sum)
|
static inline void fp64_matrix2x3_add(const fp64_matrix2x3_t* matrix1, const fp64_matrix2x3_t* matrix2, fp64_matrix2x3_t* sum)
|
||||||
{
|
{
|
||||||
sum->r1c1 = matrix1->r1c1 + matrix2->r1c1;
|
sum->r1c1 = matrix1->r1c1 + matrix2->r1c1;
|
||||||
sum->r1c2 = matrix1->r1c2 + matrix2->r1c2;
|
sum->r1c2 = matrix1->r1c2 + matrix2->r1c2;
|
||||||
|
@ -325,7 +325,7 @@ static inline void bg_fp64_matrix2x3_add(const BgFP64Matrix2x3* matrix1, const B
|
||||||
|
|
||||||
// ================ Subtraction ================= //
|
// ================ Subtraction ================= //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix2x3_subtract(const BgFP32Matrix2x3* minuend, const BgFP32Matrix2x3* subtrahend, BgFP32Matrix2x3* difference)
|
static inline void fp32_matrix2x3_subtract(const fp32_matrix2x3_t* minuend, const fp32_matrix2x3_t* subtrahend, fp32_matrix2x3_t* difference)
|
||||||
{
|
{
|
||||||
difference->r1c1 = minuend->r1c1 - subtrahend->r1c1;
|
difference->r1c1 = minuend->r1c1 - subtrahend->r1c1;
|
||||||
difference->r1c2 = minuend->r1c2 - subtrahend->r1c2;
|
difference->r1c2 = minuend->r1c2 - subtrahend->r1c2;
|
||||||
|
@ -337,7 +337,7 @@ static inline void bg_fp32_matrix2x3_subtract(const BgFP32Matrix2x3* minuend, co
|
||||||
difference->r3c2 = minuend->r3c2 - subtrahend->r3c2;
|
difference->r3c2 = minuend->r3c2 - subtrahend->r3c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix2x3_subtract(const BgFP64Matrix2x3* minuend, const BgFP64Matrix2x3* subtrahend, BgFP64Matrix2x3* difference)
|
static inline void fp64_matrix2x3_subtract(const fp64_matrix2x3_t* minuend, const fp64_matrix2x3_t* subtrahend, fp64_matrix2x3_t* difference)
|
||||||
{
|
{
|
||||||
difference->r1c1 = minuend->r1c1 - subtrahend->r1c1;
|
difference->r1c1 = minuend->r1c1 - subtrahend->r1c1;
|
||||||
difference->r1c2 = minuend->r1c2 - subtrahend->r1c2;
|
difference->r1c2 = minuend->r1c2 - subtrahend->r1c2;
|
||||||
|
@ -351,7 +351,7 @@ static inline void bg_fp64_matrix2x3_subtract(const BgFP64Matrix2x3* minuend, co
|
||||||
|
|
||||||
// =============== Multiplication =============== //
|
// =============== Multiplication =============== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix2x3_multiply(const BgFP32Matrix2x3* multiplicand, const float multiplier, BgFP32Matrix2x3* product)
|
static inline void fp32_matrix2x3_multiply(const fp32_matrix2x3_t* multiplicand, const float multiplier, fp32_matrix2x3_t* product)
|
||||||
{
|
{
|
||||||
product->r1c1 = multiplicand->r1c1 * multiplier;
|
product->r1c1 = multiplicand->r1c1 * multiplier;
|
||||||
product->r1c2 = multiplicand->r1c2 * multiplier;
|
product->r1c2 = multiplicand->r1c2 * multiplier;
|
||||||
|
@ -363,7 +363,7 @@ static inline void bg_fp32_matrix2x3_multiply(const BgFP32Matrix2x3* multiplican
|
||||||
product->r3c2 = multiplicand->r3c2 * multiplier;
|
product->r3c2 = multiplicand->r3c2 * multiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix2x3_multiply(const BgFP64Matrix2x3* multiplicand, const double multiplier, BgFP64Matrix2x3* product)
|
static inline void fp64_matrix2x3_multiply(const fp64_matrix2x3_t* multiplicand, const double multiplier, fp64_matrix2x3_t* product)
|
||||||
{
|
{
|
||||||
product->r1c1 = multiplicand->r1c1 * multiplier;
|
product->r1c1 = multiplicand->r1c1 * multiplier;
|
||||||
product->r1c2 = multiplicand->r1c2 * multiplier;
|
product->r1c2 = multiplicand->r1c2 * multiplier;
|
||||||
|
@ -377,25 +377,25 @@ static inline void bg_fp64_matrix2x3_multiply(const BgFP64Matrix2x3* multiplican
|
||||||
|
|
||||||
// ================== Division ================== //
|
// ================== Division ================== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix2x3_divide(const BgFP32Matrix2x3* dividend, const float divisor, BgFP32Matrix2x3* quotient)
|
static inline void fp32_matrix2x3_divide(const fp32_matrix2x3_t* dividend, const float divisor, fp32_matrix2x3_t* quotient)
|
||||||
{
|
{
|
||||||
bg_fp32_matrix2x3_multiply(dividend, 1.0f / divisor, quotient);
|
fp32_matrix2x3_multiply(dividend, 1.0f / divisor, quotient);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix2x3_divide(const BgFP64Matrix2x3* dividend, const double divisor, BgFP64Matrix2x3* quotient)
|
static inline void fp64_matrix2x3_divide(const fp64_matrix2x3_t* dividend, const double divisor, fp64_matrix2x3_t* quotient)
|
||||||
{
|
{
|
||||||
bg_fp64_matrix2x3_multiply(dividend, 1.0 / divisor, quotient);
|
fp64_matrix2x3_multiply(dividend, 1.0 / divisor, quotient);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============ Left Vector Product ============= //
|
// ============ Left Vector Product ============= //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix2x3_left_product(const BgFP32Vector3* vector, const BgFP32Matrix2x3* matrix, BgFP32Vector2* result)
|
static inline void fp32_matrix2x3_left_product(const fp32_vector3_t* vector, const fp32_matrix2x3_t* matrix, fp32_vector2_t* result)
|
||||||
{
|
{
|
||||||
result->x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1 + vector->x3 * matrix->r3c1;
|
result->x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1 + vector->x3 * matrix->r3c1;
|
||||||
result->x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2 + vector->x3 * matrix->r3c2;
|
result->x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2 + vector->x3 * matrix->r3c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix2x3_left_product(const BgFP64Vector3* vector, const BgFP64Matrix2x3* matrix, BgFP64Vector2* result)
|
static inline void fp64_matrix2x3_left_product(const fp64_vector3_t* vector, const fp64_matrix2x3_t* matrix, fp64_vector2_t* result)
|
||||||
{
|
{
|
||||||
result->x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1 + vector->x3 * matrix->r3c1;
|
result->x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1 + vector->x3 * matrix->r3c1;
|
||||||
result->x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2 + vector->x3 * matrix->r3c2;
|
result->x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2 + vector->x3 * matrix->r3c2;
|
||||||
|
@ -403,14 +403,14 @@ static inline void bg_fp64_matrix2x3_left_product(const BgFP64Vector3* vector, c
|
||||||
|
|
||||||
// ============ Right Vector Product ============ //
|
// ============ Right Vector Product ============ //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix2x3_right_product(const BgFP32Matrix2x3* matrix, const BgFP32Vector2* vector, BgFP32Vector3* result)
|
static inline void fp32_matrix2x3_right_product(const fp32_matrix2x3_t* matrix, const fp32_vector2_t* vector, fp32_vector3_t* result)
|
||||||
{
|
{
|
||||||
result->x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2;
|
result->x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2;
|
||||||
result->x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2;
|
result->x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2;
|
||||||
result->x3 = matrix->r3c1 * vector->x1 + matrix->r3c2 * vector->x2;
|
result->x3 = matrix->r3c1 * vector->x1 + matrix->r3c2 * vector->x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix2x3_right_product(const BgFP64Matrix2x3* matrix, const BgFP64Vector2* vector, BgFP64Vector3* result)
|
static inline void fp64_matrix2x3_right_product(const fp64_matrix2x3_t* matrix, const fp64_vector2_t* vector, fp64_vector3_t* result)
|
||||||
{
|
{
|
||||||
result->x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2;
|
result->x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2;
|
||||||
result->x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2;
|
result->x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#ifndef _GEOMETRY_MATRIX3X2_H_
|
#ifndef _BASIC_GEOMETRY_MATRIX3X2_H_
|
||||||
#define _GEOMETRY_MATRIX3X2_H_
|
#define _BASIC_GEOMETRY_MATRIX3X2_H_
|
||||||
|
|
||||||
#include "vector2.h"
|
#include "vector2.h"
|
||||||
#include "vector3.h"
|
#include "vector3.h"
|
||||||
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
// =================== Reset ==================== //
|
// =================== Reset ==================== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix3x2_reset(BgFP32Matrix3x2* matrix)
|
static inline void fp32_matrix3x2_reset(fp32_matrix3x2_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c1 = 0.0f;
|
matrix->r1c1 = 0.0f;
|
||||||
matrix->r1c2 = 0.0f;
|
matrix->r1c2 = 0.0f;
|
||||||
|
@ -18,7 +18,7 @@ static inline void bg_fp32_matrix3x2_reset(BgFP32Matrix3x2* matrix)
|
||||||
matrix->r2c3 = 0.0f;
|
matrix->r2c3 = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix3x2_reset(BgFP64Matrix3x2* matrix)
|
static inline void fp64_matrix3x2_reset(fp64_matrix3x2_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c1 = 0.0;
|
matrix->r1c1 = 0.0;
|
||||||
matrix->r1c2 = 0.0;
|
matrix->r1c2 = 0.0;
|
||||||
|
@ -31,7 +31,7 @@ static inline void bg_fp64_matrix3x2_reset(BgFP64Matrix3x2* matrix)
|
||||||
|
|
||||||
// ==================== Copy ==================== //
|
// ==================== Copy ==================== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix3x2_copy(const BgFP32Matrix3x2* from, BgFP32Matrix3x2* to)
|
static inline void fp32_matrix3x2_copy(const fp32_matrix3x2_t* from, fp32_matrix3x2_t* to)
|
||||||
{
|
{
|
||||||
to->r1c1 = from->r1c1;
|
to->r1c1 = from->r1c1;
|
||||||
to->r1c2 = from->r1c2;
|
to->r1c2 = from->r1c2;
|
||||||
|
@ -42,7 +42,7 @@ static inline void bg_fp32_matrix3x2_copy(const BgFP32Matrix3x2* from, BgFP32Mat
|
||||||
to->r2c3 = from->r2c3;
|
to->r2c3 = from->r2c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix3x2_copy(const BgFP64Matrix3x2* from, BgFP64Matrix3x2* to)
|
static inline void fp64_matrix3x2_copy(const fp64_matrix3x2_t* from, fp64_matrix3x2_t* to)
|
||||||
{
|
{
|
||||||
to->r1c1 = from->r1c1;
|
to->r1c1 = from->r1c1;
|
||||||
to->r1c2 = from->r1c2;
|
to->r1c2 = from->r1c2;
|
||||||
|
@ -55,7 +55,7 @@ static inline void bg_fp64_matrix3x2_copy(const BgFP64Matrix3x2* from, BgFP64Mat
|
||||||
|
|
||||||
// ==================== Swap ==================== //
|
// ==================== Swap ==================== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix3x2_swap(BgFP32Matrix3x2* matrix1, BgFP32Matrix3x2* matrix2)
|
static inline void fp32_matrix3x2_swap(fp32_matrix3x2_t* matrix1, fp32_matrix3x2_t* matrix2)
|
||||||
{
|
{
|
||||||
const float r1c1 = matrix2->r1c1;
|
const float r1c1 = matrix2->r1c1;
|
||||||
const float r1c2 = matrix2->r1c2;
|
const float r1c2 = matrix2->r1c2;
|
||||||
|
@ -82,7 +82,7 @@ static inline void bg_fp32_matrix3x2_swap(BgFP32Matrix3x2* matrix1, BgFP32Matrix
|
||||||
matrix1->r2c3 = r2c3;
|
matrix1->r2c3 = r2c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix3x2_swap(BgFP64Matrix3x2* matrix1, BgFP64Matrix3x2* matrix2)
|
static inline void fp64_matrix3x2_swap(fp64_matrix3x2_t* matrix1, fp64_matrix3x2_t* matrix2)
|
||||||
{
|
{
|
||||||
const double r1c1 = matrix2->r1c1;
|
const double r1c1 = matrix2->r1c1;
|
||||||
const double r1c2 = matrix2->r1c2;
|
const double r1c2 = matrix2->r1c2;
|
||||||
|
@ -111,7 +111,7 @@ static inline void bg_fp64_matrix3x2_swap(BgFP64Matrix3x2* matrix1, BgFP64Matrix
|
||||||
|
|
||||||
// ============= Set from twin type ============= //
|
// ============= Set from twin type ============= //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix3x2_set_from_fp64(const BgFP64Matrix3x2* from, BgFP32Matrix3x2* to)
|
static inline void fp32_matrix3x2_set_from_fp64(const fp64_matrix3x2_t* from, fp32_matrix3x2_t* to)
|
||||||
{
|
{
|
||||||
to->r1c1 = (float) from->r1c1;
|
to->r1c1 = (float) from->r1c1;
|
||||||
to->r1c2 = (float) from->r1c2;
|
to->r1c2 = (float) from->r1c2;
|
||||||
|
@ -122,7 +122,7 @@ static inline void bg_fp32_matrix3x2_set_from_fp64(const BgFP64Matrix3x2* from,
|
||||||
to->r2c3 = (float) from->r2c3;
|
to->r2c3 = (float) from->r2c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix3x2_set_from_fp32(const BgFP32Matrix3x2* from, BgFP64Matrix3x2* to)
|
static inline void fp64_matrix3x2_set_from_fp32(const fp32_matrix3x2_t* from, fp64_matrix3x2_t* to)
|
||||||
{
|
{
|
||||||
to->r1c1 = from->r1c1;
|
to->r1c1 = from->r1c1;
|
||||||
to->r1c2 = from->r1c2;
|
to->r1c2 = from->r1c2;
|
||||||
|
@ -135,7 +135,7 @@ static inline void bg_fp64_matrix3x2_set_from_fp32(const BgFP32Matrix3x2* from,
|
||||||
|
|
||||||
// =============== Set transposed =============== //
|
// =============== Set transposed =============== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix3x2_set_transposed(const BgFP32Matrix2x3* from, BgFP32Matrix3x2* to)
|
static inline void fp32_matrix3x2_set_transposed(const fp32_matrix2x3_t* from, fp32_matrix3x2_t* to)
|
||||||
{
|
{
|
||||||
to->r1c1 = from->r1c1;
|
to->r1c1 = from->r1c1;
|
||||||
to->r1c2 = from->r2c1;
|
to->r1c2 = from->r2c1;
|
||||||
|
@ -146,7 +146,7 @@ static inline void bg_fp32_matrix3x2_set_transposed(const BgFP32Matrix2x3* from,
|
||||||
to->r2c3 = from->r3c2;
|
to->r2c3 = from->r3c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix3x2_set_transposed(const BgFP64Matrix2x3* from, BgFP64Matrix3x2* to)
|
static inline void fp64_matrix3x2_set_transposed(const fp64_matrix2x3_t* from, fp64_matrix3x2_t* to)
|
||||||
{
|
{
|
||||||
to->r1c1 = from->r1c1;
|
to->r1c1 = from->r1c1;
|
||||||
to->r1c2 = from->r2c1;
|
to->r1c2 = from->r2c1;
|
||||||
|
@ -159,7 +159,7 @@ static inline void bg_fp64_matrix3x2_set_transposed(const BgFP64Matrix2x3* from,
|
||||||
|
|
||||||
// =============== Set transposed =============== //
|
// =============== Set transposed =============== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix3x2_set_transposed_fp64(const BgFP64Matrix2x3* from, BgFP32Matrix3x2* to)
|
static inline void fp32_matrix3x2_set_transposed_fp64(const fp64_matrix2x3_t* from, fp32_matrix3x2_t* to)
|
||||||
{
|
{
|
||||||
to->r1c1 = (float) from->r1c1;
|
to->r1c1 = (float) from->r1c1;
|
||||||
to->r1c2 = (float) from->r2c1;
|
to->r1c2 = (float) from->r2c1;
|
||||||
|
@ -170,7 +170,7 @@ static inline void bg_fp32_matrix3x2_set_transposed_fp64(const BgFP64Matrix2x3*
|
||||||
to->r2c3 = (float) from->r3c2;
|
to->r2c3 = (float) from->r3c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix3x2_set_transposed_fp32(const BgFP32Matrix2x3* from, BgFP64Matrix3x2* to)
|
static inline void fp64_matrix3x2_set_transposed_fp32(const fp32_matrix2x3_t* from, fp64_matrix3x2_t* to)
|
||||||
{
|
{
|
||||||
to->r1c1 = from->r1c1;
|
to->r1c1 = from->r1c1;
|
||||||
to->r1c2 = from->r2c1;
|
to->r1c2 = from->r2c1;
|
||||||
|
@ -183,14 +183,14 @@ static inline void bg_fp64_matrix3x2_set_transposed_fp32(const BgFP32Matrix2x3*
|
||||||
|
|
||||||
// ================= Set Row 1 ================== //
|
// ================= Set Row 1 ================== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix3x2_set_row1(const float c1, const float c2, const float c3, BgFP32Matrix3x2* matrix)
|
static inline void fp32_matrix3x2_set_row1(const float c1, const float c2, const float c3, fp32_matrix3x2_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c1 = c1;
|
matrix->r1c1 = c1;
|
||||||
matrix->r1c2 = c2;
|
matrix->r1c2 = c2;
|
||||||
matrix->r1c3 = c3;
|
matrix->r1c3 = c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix3x2_set_row1(const double c1, const double c2, const double c3, BgFP64Matrix3x2* matrix)
|
static inline void fp64_matrix3x2_set_row1(const double c1, const double c2, const double c3, fp64_matrix3x2_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c1 = c1;
|
matrix->r1c1 = c1;
|
||||||
matrix->r1c2 = c2;
|
matrix->r1c2 = c2;
|
||||||
|
@ -199,14 +199,14 @@ static inline void bg_fp64_matrix3x2_set_row1(const double c1, const double c2,
|
||||||
|
|
||||||
// ================= Set Row 2 ================== //
|
// ================= Set Row 2 ================== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix3x2_set_row2(const float c1, const float c2, const float c3, BgFP32Matrix3x2* matrix)
|
static inline void fp32_matrix3x2_set_row2(const float c1, const float c2, const float c3, fp32_matrix3x2_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r2c1 = c1;
|
matrix->r2c1 = c1;
|
||||||
matrix->r2c2 = c2;
|
matrix->r2c2 = c2;
|
||||||
matrix->r2c3 = c3;
|
matrix->r2c3 = c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix3x2_set_row2(const double c1, const double c2, const double c3, BgFP64Matrix3x2* matrix)
|
static inline void fp64_matrix3x2_set_row2(const double c1, const double c2, const double c3, fp64_matrix3x2_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r2c1 = c1;
|
matrix->r2c1 = c1;
|
||||||
matrix->r2c2 = c2;
|
matrix->r2c2 = c2;
|
||||||
|
@ -215,13 +215,13 @@ static inline void bg_fp64_matrix3x2_set_row2(const double c1, const double c2,
|
||||||
|
|
||||||
// ================ Set Column 1 ================ //
|
// ================ Set Column 1 ================ //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix3x2_set_column1(const float r1, const float r2, BgFP32Matrix3x2* matrix)
|
static inline void fp32_matrix3x2_set_column1(const float r1, const float r2, fp32_matrix3x2_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c1 = r1;
|
matrix->r1c1 = r1;
|
||||||
matrix->r2c1 = r2;
|
matrix->r2c1 = r2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix3x2_set_column1(const double r1, const double r2, BgFP64Matrix3x2* matrix)
|
static inline void fp64_matrix3x2_set_column1(const double r1, const double r2, fp64_matrix3x2_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c1 = r1;
|
matrix->r1c1 = r1;
|
||||||
matrix->r2c1 = r2;
|
matrix->r2c1 = r2;
|
||||||
|
@ -229,13 +229,13 @@ static inline void bg_fp64_matrix3x2_set_column1(const double r1, const double r
|
||||||
|
|
||||||
// ================ Set Column 2 ================ //
|
// ================ Set Column 2 ================ //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix3x2_set_column2(const float r1, const float r2, BgFP32Matrix3x2* matrix)
|
static inline void fp32_matrix3x2_set_column2(const float r1, const float r2, fp32_matrix3x2_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c2 = r1;
|
matrix->r1c2 = r1;
|
||||||
matrix->r2c2 = r2;
|
matrix->r2c2 = r2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix3x2_set_column2(const double r1, const double r2, BgFP64Matrix3x2* matrix)
|
static inline void fp64_matrix3x2_set_column2(const double r1, const double r2, fp64_matrix3x2_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c2 = r1;
|
matrix->r1c2 = r1;
|
||||||
matrix->r2c2 = r2;
|
matrix->r2c2 = r2;
|
||||||
|
@ -243,13 +243,13 @@ static inline void bg_fp64_matrix3x2_set_column2(const double r1, const double r
|
||||||
|
|
||||||
// ================ Set Column 3 ================ //
|
// ================ Set Column 3 ================ //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix3x2_set_column3(const float r1, const float r2, BgFP32Matrix3x2* matrix)
|
static inline void fp32_matrix3x2_set_column3(const float r1, const float r2, fp32_matrix3x2_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c3 = r1;
|
matrix->r1c3 = r1;
|
||||||
matrix->r2c3 = r2;
|
matrix->r2c3 = r2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix3x2_set_column3(const double r1, const double r2, BgFP64Matrix3x2* matrix)
|
static inline void fp64_matrix3x2_set_column3(const double r1, const double r2, fp64_matrix3x2_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c3 = r1;
|
matrix->r1c3 = r1;
|
||||||
matrix->r2c3 = r2;
|
matrix->r2c3 = r2;
|
||||||
|
@ -257,7 +257,7 @@ static inline void bg_fp64_matrix3x2_set_column3(const double r1, const double r
|
||||||
|
|
||||||
// ================ Append scaled =============== //
|
// ================ Append scaled =============== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix3x2_append_scaled(BgFP32Matrix3x2* basic_vector, const BgFP32Matrix3x2* scalable_vector, const float scale)
|
static inline void fp32_matrix3x2_append_scaled(fp32_matrix3x2_t* basic_vector, const fp32_matrix3x2_t* scalable_vector, const float scale)
|
||||||
{
|
{
|
||||||
basic_vector->r1c1 += scalable_vector->r1c1 * scale;
|
basic_vector->r1c1 += scalable_vector->r1c1 * scale;
|
||||||
basic_vector->r1c2 += scalable_vector->r1c2 * scale;
|
basic_vector->r1c2 += scalable_vector->r1c2 * scale;
|
||||||
|
@ -268,7 +268,7 @@ static inline void bg_fp32_matrix3x2_append_scaled(BgFP32Matrix3x2* basic_vector
|
||||||
basic_vector->r2c3 += scalable_vector->r2c3 * scale;
|
basic_vector->r2c3 += scalable_vector->r2c3 * scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix3x2_append_scaled(BgFP64Matrix3x2* basic_vector, const BgFP64Matrix3x2* scalable_vector, const double scale)
|
static inline void fp64_matrix3x2_append_scaled(fp64_matrix3x2_t* basic_vector, const fp64_matrix3x2_t* scalable_vector, const double scale)
|
||||||
{
|
{
|
||||||
basic_vector->r1c1 += scalable_vector->r1c1 * scale;
|
basic_vector->r1c1 += scalable_vector->r1c1 * scale;
|
||||||
basic_vector->r1c2 += scalable_vector->r1c2 * scale;
|
basic_vector->r1c2 += scalable_vector->r1c2 * scale;
|
||||||
|
@ -281,7 +281,7 @@ static inline void bg_fp64_matrix3x2_append_scaled(BgFP64Matrix3x2* basic_vector
|
||||||
|
|
||||||
// ================== Addition ================== //
|
// ================== Addition ================== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix3x2_add(const BgFP32Matrix3x2* matrix1, const BgFP32Matrix3x2* matrix2, BgFP32Matrix3x2* sum)
|
static inline void fp32_matrix3x2_add(const fp32_matrix3x2_t* matrix1, const fp32_matrix3x2_t* matrix2, fp32_matrix3x2_t* sum)
|
||||||
{
|
{
|
||||||
sum->r1c1 = matrix1->r1c1 + matrix2->r1c1;
|
sum->r1c1 = matrix1->r1c1 + matrix2->r1c1;
|
||||||
sum->r1c2 = matrix1->r1c2 + matrix2->r1c2;
|
sum->r1c2 = matrix1->r1c2 + matrix2->r1c2;
|
||||||
|
@ -292,7 +292,7 @@ static inline void bg_fp32_matrix3x2_add(const BgFP32Matrix3x2* matrix1, const B
|
||||||
sum->r2c3 = matrix1->r2c3 + matrix2->r2c3;
|
sum->r2c3 = matrix1->r2c3 + matrix2->r2c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix3x2_add(const BgFP64Matrix3x2* matrix1, const BgFP64Matrix3x2* matrix2, BgFP64Matrix3x2* sum)
|
static inline void fp64_matrix3x2_add(const fp64_matrix3x2_t* matrix1, const fp64_matrix3x2_t* matrix2, fp64_matrix3x2_t* sum)
|
||||||
{
|
{
|
||||||
sum->r1c1 = matrix1->r1c1 + matrix2->r1c1;
|
sum->r1c1 = matrix1->r1c1 + matrix2->r1c1;
|
||||||
sum->r1c2 = matrix1->r1c2 + matrix2->r1c2;
|
sum->r1c2 = matrix1->r1c2 + matrix2->r1c2;
|
||||||
|
@ -305,7 +305,7 @@ static inline void bg_fp64_matrix3x2_add(const BgFP64Matrix3x2* matrix1, const B
|
||||||
|
|
||||||
// ================ Subtraction ================= //
|
// ================ Subtraction ================= //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix3x2_subtract(const BgFP32Matrix3x2* minuend, const BgFP32Matrix3x2* subtrahend, BgFP32Matrix3x2* difference)
|
static inline void fp32_matrix3x2_subtract(const fp32_matrix3x2_t* minuend, const fp32_matrix3x2_t* subtrahend, fp32_matrix3x2_t* difference)
|
||||||
{
|
{
|
||||||
difference->r1c1 = minuend->r1c1 - subtrahend->r1c1;
|
difference->r1c1 = minuend->r1c1 - subtrahend->r1c1;
|
||||||
difference->r1c2 = minuend->r1c2 - subtrahend->r1c2;
|
difference->r1c2 = minuend->r1c2 - subtrahend->r1c2;
|
||||||
|
@ -316,7 +316,7 @@ static inline void bg_fp32_matrix3x2_subtract(const BgFP32Matrix3x2* minuend, co
|
||||||
difference->r2c3 = minuend->r2c3 - subtrahend->r2c3;
|
difference->r2c3 = minuend->r2c3 - subtrahend->r2c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix3x2_subtract(const BgFP64Matrix3x2* minuend, const BgFP64Matrix3x2* subtrahend, BgFP64Matrix3x2* difference)
|
static inline void fp64_matrix3x2_subtract(const fp64_matrix3x2_t* minuend, const fp64_matrix3x2_t* subtrahend, fp64_matrix3x2_t* difference)
|
||||||
{
|
{
|
||||||
difference->r1c1 = minuend->r1c1 - subtrahend->r1c1;
|
difference->r1c1 = minuend->r1c1 - subtrahend->r1c1;
|
||||||
difference->r1c2 = minuend->r1c2 - subtrahend->r1c2;
|
difference->r1c2 = minuend->r1c2 - subtrahend->r1c2;
|
||||||
|
@ -329,7 +329,7 @@ static inline void bg_fp64_matrix3x2_subtract(const BgFP64Matrix3x2* minuend, co
|
||||||
|
|
||||||
// =============== Multiplication =============== //
|
// =============== Multiplication =============== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix3x2_multiply(const BgFP32Matrix3x2* multiplicand, const float multiplier, BgFP32Matrix3x2* product)
|
static inline void fp32_matrix3x2_multiply(const fp32_matrix3x2_t* multiplicand, const float multiplier, fp32_matrix3x2_t* product)
|
||||||
{
|
{
|
||||||
product->r1c1 = multiplicand->r1c1 * multiplier;
|
product->r1c1 = multiplicand->r1c1 * multiplier;
|
||||||
product->r1c2 = multiplicand->r1c2 * multiplier;
|
product->r1c2 = multiplicand->r1c2 * multiplier;
|
||||||
|
@ -340,7 +340,7 @@ static inline void bg_fp32_matrix3x2_multiply(const BgFP32Matrix3x2* multiplican
|
||||||
product->r2c3 = multiplicand->r2c3 * multiplier;
|
product->r2c3 = multiplicand->r2c3 * multiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix3x2_multiply(const BgFP64Matrix3x2* multiplicand, const double multiplier, BgFP64Matrix3x2* product)
|
static inline void fp64_matrix3x2_multiply(const fp64_matrix3x2_t* multiplicand, const double multiplier, fp64_matrix3x2_t* product)
|
||||||
{
|
{
|
||||||
product->r1c1 = multiplicand->r1c1 * multiplier;
|
product->r1c1 = multiplicand->r1c1 * multiplier;
|
||||||
product->r1c2 = multiplicand->r1c2 * multiplier;
|
product->r1c2 = multiplicand->r1c2 * multiplier;
|
||||||
|
@ -353,26 +353,26 @@ static inline void bg_fp64_matrix3x2_multiply(const BgFP64Matrix3x2* multiplican
|
||||||
|
|
||||||
// ================== Division ================== //
|
// ================== Division ================== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix3x2_divide(const BgFP32Matrix3x2* dividend, const float divisor, BgFP32Matrix3x2* quotient)
|
static inline void fp32_matrix3x2_divide(const fp32_matrix3x2_t* dividend, const float divisor, fp32_matrix3x2_t* quotient)
|
||||||
{
|
{
|
||||||
bg_fp32_matrix3x2_multiply(dividend, 1.0f / divisor, quotient);
|
fp32_matrix3x2_multiply(dividend, 1.0f / divisor, quotient);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix3x2_divide(const BgFP64Matrix3x2* dividend, const double divisor, BgFP64Matrix3x2* quotient)
|
static inline void fp64_matrix3x2_divide(const fp64_matrix3x2_t* dividend, const double divisor, fp64_matrix3x2_t* quotient)
|
||||||
{
|
{
|
||||||
bg_fp64_matrix3x2_multiply(dividend, 1.0 / divisor, quotient);
|
fp64_matrix3x2_multiply(dividend, 1.0 / divisor, quotient);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============ Left Vector Product ============= //
|
// ============ Left Vector Product ============= //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix3x2_left_product(const BgFP32Vector2* vector, const BgFP32Matrix3x2* matrix, BgFP32Vector3* result)
|
static inline void fp32_matrix3x2_left_product(const fp32_vector2_t* vector, const fp32_matrix3x2_t* matrix, fp32_vector3_t* result)
|
||||||
{
|
{
|
||||||
result->x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1;
|
result->x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1;
|
||||||
result->x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2;
|
result->x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2;
|
||||||
result->x3 = vector->x1 * matrix->r1c3 + vector->x2 * matrix->r2c3;
|
result->x3 = vector->x1 * matrix->r1c3 + vector->x2 * matrix->r2c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix3x2_left_product(const BgFP64Vector2* vector, const BgFP64Matrix3x2* matrix, BgFP64Vector3* result)
|
static inline void fp64_matrix3x2_left_product(const fp64_vector2_t* vector, const fp64_matrix3x2_t* matrix, fp64_vector3_t* result)
|
||||||
{
|
{
|
||||||
result->x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1;
|
result->x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1;
|
||||||
result->x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2;
|
result->x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2;
|
||||||
|
@ -381,13 +381,13 @@ static inline void bg_fp64_matrix3x2_left_product(const BgFP64Vector2* vector, c
|
||||||
|
|
||||||
// ============ Right Vector Product ============ //
|
// ============ Right Vector Product ============ //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix3x2_right_product(const BgFP32Matrix3x2* matrix, const BgFP32Vector3* vector, BgFP32Vector2* result)
|
static inline void fp32_matrix3x2_right_product(const fp32_matrix3x2_t* matrix, const fp32_vector3_t* vector, fp32_vector2_t* result)
|
||||||
{
|
{
|
||||||
result->x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2 + matrix->r1c3 * vector->x3;
|
result->x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2 + matrix->r1c3 * vector->x3;
|
||||||
result->x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2 + matrix->r2c3 * vector->x3;
|
result->x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2 + matrix->r2c3 * vector->x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix3x2_right_product(const BgFP64Matrix3x2* matrix, const BgFP64Vector3* vector, BgFP64Vector2* result)
|
static inline void fp64_matrix3x2_right_product(const fp64_matrix3x2_t* matrix, const fp64_vector3_t* vector, fp64_vector2_t* result)
|
||||||
{
|
{
|
||||||
result->x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2 + matrix->r1c3 * vector->x3;
|
result->x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2 + matrix->r1c3 * vector->x3;
|
||||||
result->x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2 + matrix->r2c3 * vector->x3;
|
result->x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2 + matrix->r2c3 * vector->x3;
|
||||||
|
|
|
@ -2,11 +2,11 @@
|
||||||
|
|
||||||
// ================= Inversion ================== //
|
// ================= Inversion ================== //
|
||||||
|
|
||||||
int bg_fp32_matrix3x3_invert(BgFP32Matrix3x3* matrix)
|
int fp32_matrix3x3_invert(fp32_matrix3x3_t* matrix)
|
||||||
{
|
{
|
||||||
const float determinant = bg_fp32_matrix3x3_get_determinant(matrix);
|
const float determinant = fp32_matrix3x3_get_determinant(matrix);
|
||||||
|
|
||||||
if (-BG_FP32_EPSYLON <= determinant && determinant <= BG_FP32_EPSYLON) {
|
if (-FP32_EPSYLON <= determinant && determinant <= FP32_EPSYLON) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,11 +39,11 @@ int bg_fp32_matrix3x3_invert(BgFP32Matrix3x3* matrix)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int bg_fp64_matrix3x3_invert(BgFP64Matrix3x3* matrix)
|
int fp64_matrix3x3_invert(fp64_matrix3x3_t* matrix)
|
||||||
{
|
{
|
||||||
const double determinant = bg_fp64_matrix3x3_get_determinant(matrix);
|
const double determinant = fp64_matrix3x3_get_determinant(matrix);
|
||||||
|
|
||||||
if (-BG_FP64_EPSYLON <= determinant && determinant <= BG_FP64_EPSYLON) {
|
if (-FP64_EPSYLON <= determinant && determinant <= FP64_EPSYLON) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,11 +78,11 @@ int bg_fp64_matrix3x3_invert(BgFP64Matrix3x3* matrix)
|
||||||
|
|
||||||
// ================ Make Inverted =============== //
|
// ================ Make Inverted =============== //
|
||||||
|
|
||||||
int bg_fp32_matrix3x3_set_inverted(const BgFP32Matrix3x3* matrix, BgFP32Matrix3x3* result)
|
int fp32_matrix3x3_set_inverted(const fp32_matrix3x3_t* matrix, fp32_matrix3x3_t* result)
|
||||||
{
|
{
|
||||||
const float determinant = bg_fp32_matrix3x3_get_determinant(matrix);
|
const float determinant = fp32_matrix3x3_get_determinant(matrix);
|
||||||
|
|
||||||
if (-BG_FP32_EPSYLON <= determinant && determinant <= BG_FP32_EPSYLON) {
|
if (-FP32_EPSYLON <= determinant && determinant <= FP32_EPSYLON) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,11 +115,11 @@ int bg_fp32_matrix3x3_set_inverted(const BgFP32Matrix3x3* matrix, BgFP32Matrix3x
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int bg_fp64_matrix3x3_set_inverted(const BgFP64Matrix3x3* matrix, BgFP64Matrix3x3* result)
|
int fp64_matrix3x3_set_inverted(const fp64_matrix3x3_t* matrix, fp64_matrix3x3_t* result)
|
||||||
{
|
{
|
||||||
const double determinant = bg_fp64_matrix3x3_get_determinant(matrix);
|
const double determinant = fp64_matrix3x3_get_determinant(matrix);
|
||||||
|
|
||||||
if (-BG_FP64_EPSYLON <= determinant && determinant <= BG_FP64_EPSYLON) {
|
if (-FP64_EPSYLON <= determinant && determinant <= FP64_EPSYLON) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
#ifndef _GEOMETRY_MATRIX3X3_H_
|
#ifndef _BASIC_GEOMETRY_MATRIX3X3_H_
|
||||||
#define _GEOMETRY_MATRIX3X3_H_
|
#define _BASIC_GEOMETRY_MATRIX3X3_H_
|
||||||
|
|
||||||
#include "vector3.h"
|
#include "vector3.h"
|
||||||
#include "matrixes.h"
|
#include "matrixes.h"
|
||||||
|
|
||||||
// =================== Reset ==================== //
|
// =================== Reset ==================== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix3x3_reset(BgFP32Matrix3x3* matrix)
|
static inline void fp32_matrix3x3_reset(fp32_matrix3x3_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c1 = 0.0f;
|
matrix->r1c1 = 0.0f;
|
||||||
matrix->r1c2 = 0.0f;
|
matrix->r1c2 = 0.0f;
|
||||||
|
@ -21,7 +21,7 @@ static inline void bg_fp32_matrix3x3_reset(BgFP32Matrix3x3* matrix)
|
||||||
matrix->r3c3 = 0.0f;
|
matrix->r3c3 = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix3x3_reset(BgFP64Matrix3x3* matrix)
|
static inline void fp64_matrix3x3_reset(fp64_matrix3x3_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c1 = 0.0;
|
matrix->r1c1 = 0.0;
|
||||||
matrix->r1c2 = 0.0;
|
matrix->r1c2 = 0.0;
|
||||||
|
@ -38,7 +38,7 @@ static inline void bg_fp64_matrix3x3_reset(BgFP64Matrix3x3* matrix)
|
||||||
|
|
||||||
// ================== Identity ================== //
|
// ================== Identity ================== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix3x3_set_to_identity(BgFP32Matrix3x3* matrix)
|
static inline void fp32_matrix3x3_set_to_identity(fp32_matrix3x3_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c1 = 1.0f;
|
matrix->r1c1 = 1.0f;
|
||||||
matrix->r1c2 = 0.0f;
|
matrix->r1c2 = 0.0f;
|
||||||
|
@ -53,7 +53,7 @@ static inline void bg_fp32_matrix3x3_set_to_identity(BgFP32Matrix3x3* matrix)
|
||||||
matrix->r3c3 = 1.0f;
|
matrix->r3c3 = 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix3x3_set_to_identity(BgFP64Matrix3x3* matrix)
|
static inline void fp64_matrix3x3_set_to_identity(fp64_matrix3x3_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c1 = 1.0;
|
matrix->r1c1 = 1.0;
|
||||||
matrix->r1c2 = 0.0;
|
matrix->r1c2 = 0.0;
|
||||||
|
@ -70,7 +70,7 @@ static inline void bg_fp64_matrix3x3_set_to_identity(BgFP64Matrix3x3* matrix)
|
||||||
|
|
||||||
// ================ Make Diagonal =============== //
|
// ================ Make Diagonal =============== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix3x3_set_to_diagonal(const float d1, const float d2, const float d3, BgFP32Matrix3x3* matrix)
|
static inline void fp32_matrix3x3_set_to_diagonal(const float d1, const float d2, const float d3, fp32_matrix3x3_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c1 = d1;
|
matrix->r1c1 = d1;
|
||||||
matrix->r1c2 = 0.0f;
|
matrix->r1c2 = 0.0f;
|
||||||
|
@ -85,7 +85,7 @@ static inline void bg_fp32_matrix3x3_set_to_diagonal(const float d1, const float
|
||||||
matrix->r3c3 = d2;
|
matrix->r3c3 = d2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix3x3_set_to_diagonal(const double d1, const double d2, const double d3, BgFP64Matrix3x3* matrix)
|
static inline void fp64_matrix3x3_set_to_diagonal(const double d1, const double d2, const double d3, fp64_matrix3x3_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c1 = d1;
|
matrix->r1c1 = d1;
|
||||||
matrix->r1c2 = 0.0;
|
matrix->r1c2 = 0.0;
|
||||||
|
@ -102,7 +102,7 @@ static inline void bg_fp64_matrix3x3_set_to_diagonal(const double d1, const doub
|
||||||
|
|
||||||
// ==================== Copy ==================== //
|
// ==================== Copy ==================== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix3x3_copy(const BgFP32Matrix3x3* from, BgFP32Matrix3x3* to)
|
static inline void fp32_matrix3x3_copy(const fp32_matrix3x3_t* from, fp32_matrix3x3_t* to)
|
||||||
{
|
{
|
||||||
to->r1c1 = from->r1c1;
|
to->r1c1 = from->r1c1;
|
||||||
to->r1c2 = from->r1c2;
|
to->r1c2 = from->r1c2;
|
||||||
|
@ -117,7 +117,7 @@ static inline void bg_fp32_matrix3x3_copy(const BgFP32Matrix3x3* from, BgFP32Mat
|
||||||
to->r3c3 = from->r3c3;
|
to->r3c3 = from->r3c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix3x3_copy(const BgFP64Matrix3x3* from, BgFP64Matrix3x3* to)
|
static inline void fp64_matrix3x3_copy(const fp64_matrix3x3_t* from, fp64_matrix3x3_t* to)
|
||||||
{
|
{
|
||||||
to->r1c1 = from->r1c1;
|
to->r1c1 = from->r1c1;
|
||||||
to->r1c2 = from->r1c2;
|
to->r1c2 = from->r1c2;
|
||||||
|
@ -134,7 +134,7 @@ static inline void bg_fp64_matrix3x3_copy(const BgFP64Matrix3x3* from, BgFP64Mat
|
||||||
|
|
||||||
// ==================== Swap ==================== //
|
// ==================== Swap ==================== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix3x3_swap(BgFP32Matrix3x3* matrix1, BgFP32Matrix3x3* matrix2)
|
static inline void fp32_matrix3x3_swap(fp32_matrix3x3_t* matrix1, fp32_matrix3x3_t* matrix2)
|
||||||
{
|
{
|
||||||
const float r1c1 = matrix2->r1c1;
|
const float r1c1 = matrix2->r1c1;
|
||||||
const float r1c2 = matrix2->r1c2;
|
const float r1c2 = matrix2->r1c2;
|
||||||
|
@ -173,7 +173,7 @@ static inline void bg_fp32_matrix3x3_swap(BgFP32Matrix3x3* matrix1, BgFP32Matrix
|
||||||
matrix1->r3c3 = r3c3;
|
matrix1->r3c3 = r3c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix3x3_swap(BgFP64Matrix3x3* matrix1, BgFP64Matrix3x3* matrix2)
|
static inline void fp64_matrix3x3_swap(fp64_matrix3x3_t* matrix1, fp64_matrix3x3_t* matrix2)
|
||||||
{
|
{
|
||||||
const double r1c1 = matrix2->r1c1;
|
const double r1c1 = matrix2->r1c1;
|
||||||
const double r1c2 = matrix2->r1c2;
|
const double r1c2 = matrix2->r1c2;
|
||||||
|
@ -214,7 +214,7 @@ static inline void bg_fp64_matrix3x3_swap(BgFP64Matrix3x3* matrix1, BgFP64Matrix
|
||||||
|
|
||||||
// ============= Set from twin type ============= //
|
// ============= Set from twin type ============= //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix3x3_set_from_fp64(const BgFP64Matrix3x3* from, BgFP32Matrix3x3* to)
|
static inline void fp32_matrix3x3_set_from_fp64(const fp64_matrix3x3_t* from, fp32_matrix3x3_t* to)
|
||||||
{
|
{
|
||||||
to->r1c1 = (float) from->r1c1;
|
to->r1c1 = (float) from->r1c1;
|
||||||
to->r1c2 = (float) from->r1c2;
|
to->r1c2 = (float) from->r1c2;
|
||||||
|
@ -229,7 +229,7 @@ static inline void bg_fp32_matrix3x3_set_from_fp64(const BgFP64Matrix3x3* from,
|
||||||
to->r3c3 = (float) from->r3c3;
|
to->r3c3 = (float) from->r3c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix3x3_set_from_fp32(const BgFP32Matrix3x3* from, BgFP64Matrix3x3* to)
|
static inline void fp64_matrix3x3_set_from_fp32(const fp32_matrix3x3_t* from, fp64_matrix3x3_t* to)
|
||||||
{
|
{
|
||||||
to->r1c1 = from->r1c1;
|
to->r1c1 = from->r1c1;
|
||||||
to->r1c2 = from->r1c2;
|
to->r1c2 = from->r1c2;
|
||||||
|
@ -246,14 +246,14 @@ static inline void bg_fp64_matrix3x3_set_from_fp32(const BgFP32Matrix3x3* from,
|
||||||
|
|
||||||
// ================ Determinant ================= //
|
// ================ Determinant ================= //
|
||||||
|
|
||||||
static inline float bg_fp32_matrix3x3_get_determinant(const BgFP32Matrix3x3* matrix)
|
static inline float fp32_matrix3x3_get_determinant(const fp32_matrix3x3_t* matrix)
|
||||||
{
|
{
|
||||||
return matrix->r1c1 * (matrix->r2c2 * matrix->r3c3 - matrix->r2c3 * matrix->r3c2)
|
return matrix->r1c1 * (matrix->r2c2 * matrix->r3c3 - matrix->r2c3 * matrix->r3c2)
|
||||||
+ matrix->r1c2 * (matrix->r2c3 * matrix->r3c1 - matrix->r2c1 * matrix->r3c3)
|
+ matrix->r1c2 * (matrix->r2c3 * matrix->r3c1 - matrix->r2c1 * matrix->r3c3)
|
||||||
+ matrix->r1c3 * (matrix->r2c1 * matrix->r3c2 - matrix->r2c2 * matrix->r3c1);
|
+ matrix->r1c3 * (matrix->r2c1 * matrix->r3c2 - matrix->r2c2 * matrix->r3c1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline double bg_fp64_matrix3x3_get_determinant(const BgFP64Matrix3x3* matrix)
|
static inline double fp64_matrix3x3_get_determinant(const fp64_matrix3x3_t* matrix)
|
||||||
{
|
{
|
||||||
return matrix->r1c1 * (matrix->r2c2 * matrix->r3c3 - matrix->r2c3 * matrix->r3c2)
|
return matrix->r1c1 * (matrix->r2c2 * matrix->r3c3 - matrix->r2c3 * matrix->r3c2)
|
||||||
+ matrix->r1c2 * (matrix->r2c3 * matrix->r3c1 - matrix->r2c1 * matrix->r3c3)
|
+ matrix->r1c2 * (matrix->r2c3 * matrix->r3c1 - matrix->r2c1 * matrix->r3c3)
|
||||||
|
@ -262,29 +262,29 @@ static inline double bg_fp64_matrix3x3_get_determinant(const BgFP64Matrix3x3* ma
|
||||||
|
|
||||||
// ================== Singular ================== //
|
// ================== Singular ================== //
|
||||||
|
|
||||||
static inline int bg_fp32_matrix3x3_is_singular(const BgFP32Matrix3x3* matrix)
|
static inline int fp32_matrix3x3_is_singular(const fp32_matrix3x3_t* matrix)
|
||||||
{
|
{
|
||||||
const float determinant = bg_fp32_matrix3x3_get_determinant(matrix);
|
const float determinant = fp32_matrix3x3_get_determinant(matrix);
|
||||||
|
|
||||||
return -BG_FP32_EPSYLON <= determinant && determinant <= BG_FP32_EPSYLON;
|
return -FP32_EPSYLON <= determinant && determinant <= FP32_EPSYLON;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int bg_fp64_matrix3x3_is_singular(const BgFP64Matrix3x3* matrix)
|
static inline int fp64_matrix3x3_is_singular(const fp64_matrix3x3_t* matrix)
|
||||||
{
|
{
|
||||||
const double determinant = bg_fp64_matrix3x3_get_determinant(matrix);
|
const double determinant = fp64_matrix3x3_get_determinant(matrix);
|
||||||
|
|
||||||
return -BG_FP64_EPSYLON <= determinant && determinant <= BG_FP64_EPSYLON;
|
return -FP64_EPSYLON <= determinant && determinant <= FP64_EPSYLON;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================= Inversion ================== //
|
// ================= Inversion ================== //
|
||||||
|
|
||||||
int bg_fp32_matrix3x3_invert(BgFP32Matrix3x3* matrix);
|
int fp32_matrix3x3_invert(fp32_matrix3x3_t* matrix);
|
||||||
|
|
||||||
int bg_fp64_matrix3x3_invert(BgFP64Matrix3x3* matrix);
|
int fp64_matrix3x3_invert(fp64_matrix3x3_t* matrix);
|
||||||
|
|
||||||
// =============== Transposition ================ //
|
// =============== Transposition ================ //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix3x3_transpose(BgFP32Matrix3x3* matrix)
|
static inline void fp32_matrix3x3_transpose(fp32_matrix3x3_t* matrix)
|
||||||
{
|
{
|
||||||
float tmp = matrix->r1c2;
|
float tmp = matrix->r1c2;
|
||||||
matrix->r1c2 = matrix->r2c1;
|
matrix->r1c2 = matrix->r2c1;
|
||||||
|
@ -299,7 +299,7 @@ static inline void bg_fp32_matrix3x3_transpose(BgFP32Matrix3x3* matrix)
|
||||||
matrix->r3c2 = tmp;
|
matrix->r3c2 = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix3x3_transpose(BgFP64Matrix3x3* matrix)
|
static inline void fp64_matrix3x3_transpose(fp64_matrix3x3_t* matrix)
|
||||||
{
|
{
|
||||||
double tmp = matrix->r1c2;
|
double tmp = matrix->r1c2;
|
||||||
matrix->r1c2 = matrix->r2c1;
|
matrix->r1c2 = matrix->r2c1;
|
||||||
|
@ -316,16 +316,16 @@ static inline void bg_fp64_matrix3x3_transpose(BgFP64Matrix3x3* matrix)
|
||||||
|
|
||||||
// ================ Make Inverted =============== //
|
// ================ Make Inverted =============== //
|
||||||
|
|
||||||
int bg_fp32_matrix3x3_set_inverted(const BgFP32Matrix3x3* matrix, BgFP32Matrix3x3* result);
|
int fp32_matrix3x3_set_inverted(const fp32_matrix3x3_t* matrix, fp32_matrix3x3_t* result);
|
||||||
|
|
||||||
int bg_fp64_matrix3x3_set_inverted(const BgFP64Matrix3x3* matrix, BgFP64Matrix3x3* result);
|
int fp64_matrix3x3_set_inverted(const fp64_matrix3x3_t* matrix, fp64_matrix3x3_t* result);
|
||||||
|
|
||||||
// =============== Make Transposed ============== //
|
// =============== Make Transposed ============== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix3x3_set_transposed(const BgFP32Matrix3x3* matrix, BgFP32Matrix3x3* result)
|
static inline void fp32_matrix3x3_set_transposed(const fp32_matrix3x3_t* matrix, fp32_matrix3x3_t* result)
|
||||||
{
|
{
|
||||||
if (matrix == result) {
|
if (matrix == result) {
|
||||||
bg_fp32_matrix3x3_transpose(result);
|
fp32_matrix3x3_transpose(result);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -342,10 +342,10 @@ static inline void bg_fp32_matrix3x3_set_transposed(const BgFP32Matrix3x3* matri
|
||||||
result->r3c3 = matrix->r3c3;
|
result->r3c3 = matrix->r3c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix3x3_set_transposed(const BgFP64Matrix3x3* matrix, BgFP64Matrix3x3* result)
|
static inline void fp64_matrix3x3_set_transposed(const fp64_matrix3x3_t* matrix, fp64_matrix3x3_t* result)
|
||||||
{
|
{
|
||||||
if (matrix == result) {
|
if (matrix == result) {
|
||||||
bg_fp64_matrix3x3_transpose(result);
|
fp64_matrix3x3_transpose(result);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -364,14 +364,14 @@ static inline void bg_fp64_matrix3x3_set_transposed(const BgFP64Matrix3x3* matri
|
||||||
|
|
||||||
// ================= Set Row 1 ================== //
|
// ================= Set Row 1 ================== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix3x3_set_row1(const float c1, const float c2, const float c3, BgFP32Matrix3x3* matrix)
|
static inline void fp32_matrix3x3_set_row1(const float c1, const float c2, const float c3, fp32_matrix3x3_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c1 = c1;
|
matrix->r1c1 = c1;
|
||||||
matrix->r1c2 = c2;
|
matrix->r1c2 = c2;
|
||||||
matrix->r1c3 = c3;
|
matrix->r1c3 = c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix3x3_set_row1(const double c1, const double c2, const double c3, BgFP64Matrix3x3* matrix)
|
static inline void fp64_matrix3x3_set_row1(const double c1, const double c2, const double c3, fp64_matrix3x3_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c1 = c1;
|
matrix->r1c1 = c1;
|
||||||
matrix->r1c2 = c2;
|
matrix->r1c2 = c2;
|
||||||
|
@ -380,14 +380,14 @@ static inline void bg_fp64_matrix3x3_set_row1(const double c1, const double c2,
|
||||||
|
|
||||||
// ================= Set Row 2 ================== //
|
// ================= Set Row 2 ================== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix3x3_set_row2(const float c1, const float c2, const float c3, BgFP32Matrix3x3* matrix)
|
static inline void fp32_matrix3x3_set_row2(const float c1, const float c2, const float c3, fp32_matrix3x3_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r2c1 = c1;
|
matrix->r2c1 = c1;
|
||||||
matrix->r2c2 = c2;
|
matrix->r2c2 = c2;
|
||||||
matrix->r2c3 = c3;
|
matrix->r2c3 = c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix3x3_set_row2(const double c1, const double c2, const double c3, BgFP64Matrix3x3* matrix)
|
static inline void fp64_matrix3x3_set_row2(const double c1, const double c2, const double c3, fp64_matrix3x3_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r2c1 = c1;
|
matrix->r2c1 = c1;
|
||||||
matrix->r2c2 = c2;
|
matrix->r2c2 = c2;
|
||||||
|
@ -396,14 +396,14 @@ static inline void bg_fp64_matrix3x3_set_row2(const double c1, const double c2,
|
||||||
|
|
||||||
// ================= Set Row 3 ================== //
|
// ================= Set Row 3 ================== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix3x3_set_row3(const float c1, const float c2, const float c3, BgFP32Matrix3x3* matrix)
|
static inline void fp32_matrix3x3_set_row3(const float c1, const float c2, const float c3, fp32_matrix3x3_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r3c1 = c1;
|
matrix->r3c1 = c1;
|
||||||
matrix->r3c2 = c2;
|
matrix->r3c2 = c2;
|
||||||
matrix->r3c3 = c3;
|
matrix->r3c3 = c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix3x3_set_row3(const double c1, const double c2, const double c3, BgFP64Matrix3x3* matrix)
|
static inline void fp64_matrix3x3_set_row3(const double c1, const double c2, const double c3, fp64_matrix3x3_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r3c1 = c1;
|
matrix->r3c1 = c1;
|
||||||
matrix->r3c2 = c2;
|
matrix->r3c2 = c2;
|
||||||
|
@ -412,14 +412,14 @@ static inline void bg_fp64_matrix3x3_set_row3(const double c1, const double c2,
|
||||||
|
|
||||||
// ================ Set Column 1 ================ //
|
// ================ Set Column 1 ================ //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix3x3_set_column1(const float r1, const float r2, const float r3, BgFP32Matrix3x3* matrix)
|
static inline void fp32_matrix3x3_set_column1(const float r1, const float r2, const float r3, fp32_matrix3x3_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c1 = r1;
|
matrix->r1c1 = r1;
|
||||||
matrix->r2c1 = r2;
|
matrix->r2c1 = r2;
|
||||||
matrix->r3c1 = r3;
|
matrix->r3c1 = r3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix3x3_set_column1(const double r1, const double r2, const double r3, BgFP64Matrix3x3* matrix)
|
static inline void fp64_matrix3x3_set_column1(const double r1, const double r2, const double r3, fp64_matrix3x3_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c1 = r1;
|
matrix->r1c1 = r1;
|
||||||
matrix->r2c1 = r2;
|
matrix->r2c1 = r2;
|
||||||
|
@ -428,14 +428,14 @@ static inline void bg_fp64_matrix3x3_set_column1(const double r1, const double r
|
||||||
|
|
||||||
// ================ Set Column 2 ================ //
|
// ================ Set Column 2 ================ //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix3x3_set_column2(const float r1, const float r2, const float r3, BgFP32Matrix3x3* matrix)
|
static inline void fp32_matrix3x3_set_column2(const float r1, const float r2, const float r3, fp32_matrix3x3_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c2 = r1;
|
matrix->r1c2 = r1;
|
||||||
matrix->r2c2 = r2;
|
matrix->r2c2 = r2;
|
||||||
matrix->r3c2 = r3;
|
matrix->r3c2 = r3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix3x3_set_column2(const double r1, const double r2, const double r3, BgFP64Matrix3x3* matrix)
|
static inline void fp64_matrix3x3_set_column2(const double r1, const double r2, const double r3, fp64_matrix3x3_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c2 = r1;
|
matrix->r1c2 = r1;
|
||||||
matrix->r2c2 = r2;
|
matrix->r2c2 = r2;
|
||||||
|
@ -444,14 +444,14 @@ static inline void bg_fp64_matrix3x3_set_column2(const double r1, const double r
|
||||||
|
|
||||||
// ================ Set Column 3 ================ //
|
// ================ Set Column 3 ================ //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix3x3_set_column3(const float r1, const float r2, const float r3, BgFP32Matrix3x3* matrix)
|
static inline void fp32_matrix3x3_set_column3(const float r1, const float r2, const float r3, fp32_matrix3x3_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c3 = r1;
|
matrix->r1c3 = r1;
|
||||||
matrix->r2c3 = r2;
|
matrix->r2c3 = r2;
|
||||||
matrix->r3c3 = r3;
|
matrix->r3c3 = r3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix3x3_set_column3(const double r1, const double r2, const double r3, BgFP64Matrix3x3* matrix)
|
static inline void fp64_matrix3x3_set_column3(const double r1, const double r2, const double r3, fp64_matrix3x3_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c3 = r1;
|
matrix->r1c3 = r1;
|
||||||
matrix->r2c3 = r2;
|
matrix->r2c3 = r2;
|
||||||
|
@ -460,7 +460,7 @@ static inline void bg_fp64_matrix3x3_set_column3(const double r1, const double r
|
||||||
|
|
||||||
// ================ Append scaled =============== //
|
// ================ Append scaled =============== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix3x3_append_scaled(BgFP32Matrix3x3* basic_vector, const BgFP32Matrix3x3* scalable_vector, const float scale)
|
static inline void fp32_matrix3x3_append_scaled(fp32_matrix3x3_t* basic_vector, const fp32_matrix3x3_t* scalable_vector, const float scale)
|
||||||
{
|
{
|
||||||
basic_vector->r1c1 += scalable_vector->r1c1 * scale;
|
basic_vector->r1c1 += scalable_vector->r1c1 * scale;
|
||||||
basic_vector->r1c2 += scalable_vector->r1c2 * scale;
|
basic_vector->r1c2 += scalable_vector->r1c2 * scale;
|
||||||
|
@ -475,7 +475,7 @@ static inline void bg_fp32_matrix3x3_append_scaled(BgFP32Matrix3x3* basic_vector
|
||||||
basic_vector->r3c3 += scalable_vector->r3c3 * scale;
|
basic_vector->r3c3 += scalable_vector->r3c3 * scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix3x3_append_scaled(BgFP64Matrix3x3* basic_vector, const BgFP64Matrix3x3* scalable_vector, const double scale)
|
static inline void fp64_matrix3x3_append_scaled(fp64_matrix3x3_t* basic_vector, const fp64_matrix3x3_t* scalable_vector, const double scale)
|
||||||
{
|
{
|
||||||
basic_vector->r1c1 += scalable_vector->r1c1 * scale;
|
basic_vector->r1c1 += scalable_vector->r1c1 * scale;
|
||||||
basic_vector->r1c2 += scalable_vector->r1c2 * scale;
|
basic_vector->r1c2 += scalable_vector->r1c2 * scale;
|
||||||
|
@ -492,7 +492,7 @@ static inline void bg_fp64_matrix3x3_append_scaled(BgFP64Matrix3x3* basic_vector
|
||||||
|
|
||||||
// ================== Addition ================== //
|
// ================== Addition ================== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix3x3_add(const BgFP32Matrix3x3* matrix1, const BgFP32Matrix3x3* matrix2, BgFP32Matrix3x3* sum)
|
static inline void fp32_matrix3x3_add(const fp32_matrix3x3_t* matrix1, const fp32_matrix3x3_t* matrix2, fp32_matrix3x3_t* sum)
|
||||||
{
|
{
|
||||||
sum->r1c1 = matrix1->r1c1 + matrix2->r1c1;
|
sum->r1c1 = matrix1->r1c1 + matrix2->r1c1;
|
||||||
sum->r1c2 = matrix1->r1c2 + matrix2->r1c2;
|
sum->r1c2 = matrix1->r1c2 + matrix2->r1c2;
|
||||||
|
@ -507,7 +507,7 @@ static inline void bg_fp32_matrix3x3_add(const BgFP32Matrix3x3* matrix1, const B
|
||||||
sum->r3c3 = matrix1->r3c3 + matrix2->r3c3;
|
sum->r3c3 = matrix1->r3c3 + matrix2->r3c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix3x3_add(const BgFP64Matrix3x3* matrix1, const BgFP64Matrix3x3* matrix2, BgFP64Matrix3x3* sum)
|
static inline void fp64_matrix3x3_add(const fp64_matrix3x3_t* matrix1, const fp64_matrix3x3_t* matrix2, fp64_matrix3x3_t* sum)
|
||||||
{
|
{
|
||||||
sum->r1c1 = matrix1->r1c1 + matrix2->r1c1;
|
sum->r1c1 = matrix1->r1c1 + matrix2->r1c1;
|
||||||
sum->r1c2 = matrix1->r1c2 + matrix2->r1c2;
|
sum->r1c2 = matrix1->r1c2 + matrix2->r1c2;
|
||||||
|
@ -524,7 +524,7 @@ static inline void bg_fp64_matrix3x3_add(const BgFP64Matrix3x3* matrix1, const B
|
||||||
|
|
||||||
// ================ Subtraction ================= //
|
// ================ Subtraction ================= //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix3x3_subtract(const BgFP32Matrix3x3* minuend, const BgFP32Matrix3x3* subtrahend, BgFP32Matrix3x3* difference)
|
static inline void fp32_matrix3x3_subtract(const fp32_matrix3x3_t* minuend, const fp32_matrix3x3_t* subtrahend, fp32_matrix3x3_t* difference)
|
||||||
{
|
{
|
||||||
difference->r1c1 = minuend->r1c1 - subtrahend->r1c1;
|
difference->r1c1 = minuend->r1c1 - subtrahend->r1c1;
|
||||||
difference->r1c2 = minuend->r1c2 - subtrahend->r1c2;
|
difference->r1c2 = minuend->r1c2 - subtrahend->r1c2;
|
||||||
|
@ -539,7 +539,7 @@ static inline void bg_fp32_matrix3x3_subtract(const BgFP32Matrix3x3* minuend, co
|
||||||
difference->r3c3 = minuend->r3c3 - subtrahend->r3c3;
|
difference->r3c3 = minuend->r3c3 - subtrahend->r3c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix3x3_subtract(const BgFP64Matrix3x3* minuend, const BgFP64Matrix3x3* subtrahend, BgFP64Matrix3x3* difference)
|
static inline void fp64_matrix3x3_subtract(const fp64_matrix3x3_t* minuend, const fp64_matrix3x3_t* subtrahend, fp64_matrix3x3_t* difference)
|
||||||
{
|
{
|
||||||
difference->r1c1 = minuend->r1c1 - subtrahend->r1c1;
|
difference->r1c1 = minuend->r1c1 - subtrahend->r1c1;
|
||||||
difference->r1c2 = minuend->r1c2 - subtrahend->r1c2;
|
difference->r1c2 = minuend->r1c2 - subtrahend->r1c2;
|
||||||
|
@ -556,7 +556,7 @@ static inline void bg_fp64_matrix3x3_subtract(const BgFP64Matrix3x3* minuend, co
|
||||||
|
|
||||||
// =============== Multiplication =============== //
|
// =============== Multiplication =============== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix3x3_multiply(const BgFP32Matrix3x3* multiplicand, const float multiplier, BgFP32Matrix3x3* product)
|
static inline void fp32_matrix3x3_multiply(const fp32_matrix3x3_t* multiplicand, const float multiplier, fp32_matrix3x3_t* product)
|
||||||
{
|
{
|
||||||
product->r1c1 = multiplicand->r1c1 * multiplier;
|
product->r1c1 = multiplicand->r1c1 * multiplier;
|
||||||
product->r1c2 = multiplicand->r1c2 * multiplier;
|
product->r1c2 = multiplicand->r1c2 * multiplier;
|
||||||
|
@ -571,7 +571,7 @@ static inline void bg_fp32_matrix3x3_multiply(const BgFP32Matrix3x3* multiplican
|
||||||
product->r3c3 = multiplicand->r3c3 * multiplier;
|
product->r3c3 = multiplicand->r3c3 * multiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix3x3_multiply(const BgFP64Matrix3x3* multiplicand, const double multiplier, BgFP64Matrix3x3* product)
|
static inline void fp64_matrix3x3_multiply(const fp64_matrix3x3_t* multiplicand, const double multiplier, fp64_matrix3x3_t* product)
|
||||||
{
|
{
|
||||||
product->r1c1 = multiplicand->r1c1 * multiplier;
|
product->r1c1 = multiplicand->r1c1 * multiplier;
|
||||||
product->r1c2 = multiplicand->r1c2 * multiplier;
|
product->r1c2 = multiplicand->r1c2 * multiplier;
|
||||||
|
@ -588,19 +588,19 @@ static inline void bg_fp64_matrix3x3_multiply(const BgFP64Matrix3x3* multiplican
|
||||||
|
|
||||||
// ================== Division ================== //
|
// ================== Division ================== //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix3x3_divide(const BgFP32Matrix3x3* dividend, const float divisor, BgFP32Matrix3x3* quotient)
|
static inline void fp32_matrix3x3_divide(const fp32_matrix3x3_t* dividend, const float divisor, fp32_matrix3x3_t* quotient)
|
||||||
{
|
{
|
||||||
bg_fp32_matrix3x3_multiply(dividend, 1.0f / divisor, quotient);
|
fp32_matrix3x3_multiply(dividend, 1.0f / divisor, quotient);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix3x3_divide(const BgFP64Matrix3x3* dividend, const double divisor, BgFP64Matrix3x3* quotient)
|
static inline void fp64_matrix3x3_divide(const fp64_matrix3x3_t* dividend, const double divisor, fp64_matrix3x3_t* quotient)
|
||||||
{
|
{
|
||||||
bg_fp64_matrix3x3_multiply(dividend, 1.0 / divisor, quotient);
|
fp64_matrix3x3_multiply(dividend, 1.0 / divisor, quotient);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============ Left Vector Product ============= //
|
// ============ Left Vector Product ============= //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix3x3_left_product(const BgFP32Vector3* vector, const BgFP32Matrix3x3* matrix, BgFP32Vector3* result)
|
static inline void fp32_matrix3x3_left_product(const fp32_vector3_t* vector, const fp32_matrix3x3_t* matrix, fp32_vector3_t* result)
|
||||||
{
|
{
|
||||||
const float x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1 + vector->x3 * matrix->r3c1;
|
const float x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1 + vector->x3 * matrix->r3c1;
|
||||||
const float x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2 + vector->x3 * matrix->r3c2;
|
const float x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2 + vector->x3 * matrix->r3c2;
|
||||||
|
@ -611,7 +611,7 @@ static inline void bg_fp32_matrix3x3_left_product(const BgFP32Vector3* vector, c
|
||||||
result->x3 = x3;
|
result->x3 = x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix3x3_left_product(const BgFP64Vector3* vector, const BgFP64Matrix3x3* matrix, BgFP64Vector3* result)
|
static inline void fp64_matrix3x3_left_product(const fp64_vector3_t* vector, const fp64_matrix3x3_t* matrix, fp64_vector3_t* result)
|
||||||
{
|
{
|
||||||
const double x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1 + vector->x3 * matrix->r3c1;
|
const double x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1 + vector->x3 * matrix->r3c1;
|
||||||
const double x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2 + vector->x3 * matrix->r3c2;
|
const double x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2 + vector->x3 * matrix->r3c2;
|
||||||
|
@ -624,7 +624,7 @@ static inline void bg_fp64_matrix3x3_left_product(const BgFP64Vector3* vector, c
|
||||||
|
|
||||||
// ============ Right Vector Product ============ //
|
// ============ Right Vector Product ============ //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix3x3_right_product(const BgFP32Matrix3x3* matrix, const BgFP32Vector3* vector, BgFP32Vector3* result)
|
static inline void fp32_matrix3x3_right_product(const fp32_matrix3x3_t* matrix, const fp32_vector3_t* vector, fp32_vector3_t* result)
|
||||||
{
|
{
|
||||||
const float x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2 + matrix->r1c3 * vector->x3;
|
const float x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2 + matrix->r1c3 * vector->x3;
|
||||||
const float x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2 + matrix->r2c3 * vector->x3;
|
const float x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2 + matrix->r2c3 * vector->x3;
|
||||||
|
@ -635,7 +635,7 @@ static inline void bg_fp32_matrix3x3_right_product(const BgFP32Matrix3x3* matrix
|
||||||
result->x3 = x3;
|
result->x3 = x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix3x3_right_product(const BgFP64Matrix3x3* matrix, const BgFP64Vector3* vector, BgFP64Vector3* result)
|
static inline void fp64_matrix3x3_right_product(const fp64_matrix3x3_t* matrix, const fp64_vector3_t* vector, fp64_vector3_t* result)
|
||||||
{
|
{
|
||||||
const double x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2 + matrix->r1c3 * vector->x3;
|
const double x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2 + matrix->r1c3 * vector->x3;
|
||||||
const double x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2 + matrix->r2c3 * vector->x3;
|
const double x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2 + matrix->r2c3 * vector->x3;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
// ========== Matrix Product 2x2 at 3x2 ========= //
|
// ========== Matrix Product 2x2 at 3x2 ========= //
|
||||||
|
|
||||||
void bg_fp32_matrix_product_2x2_at_3x2(const BgFP32Matrix2x2* matrix1, const BgFP32Matrix3x2* matrix2, BgFP32Matrix3x2* result)
|
void fp32_matrix_product_2x2_at_3x2(const fp32_matrix2x2_t* matrix1, const fp32_matrix3x2_t* matrix2, fp32_matrix3x2_t* result)
|
||||||
{
|
{
|
||||||
const float r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1;
|
const float r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1;
|
||||||
const float r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2;
|
const float r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2;
|
||||||
|
@ -21,7 +21,7 @@ void bg_fp32_matrix_product_2x2_at_3x2(const BgFP32Matrix2x2* matrix1, const BgF
|
||||||
result->r2c3 = r2c3;
|
result->r2c3 = r2c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bg_fp64_matrix_product_2x2_at_3x2(const BgFP64Matrix2x2* matrix1, const BgFP64Matrix3x2* matrix2, BgFP64Matrix3x2* result)
|
void fp64_matrix_product_2x2_at_3x2(const fp64_matrix2x2_t* matrix1, const fp64_matrix3x2_t* matrix2, fp64_matrix3x2_t* result)
|
||||||
{
|
{
|
||||||
const double r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1;
|
const double r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1;
|
||||||
const double r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2;
|
const double r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2;
|
||||||
|
@ -42,7 +42,7 @@ void bg_fp64_matrix_product_2x2_at_3x2(const BgFP64Matrix2x2* matrix1, const BgF
|
||||||
|
|
||||||
// ========== Matrix Product 2x3 at 2x2 ========= //
|
// ========== Matrix Product 2x3 at 2x2 ========= //
|
||||||
|
|
||||||
void bg_fp32_matrix_product_2x3_at_2x2(const BgFP32Matrix2x3* matrix1, const BgFP32Matrix2x2* matrix2, BgFP32Matrix2x3* result)
|
void fp32_matrix_product_2x3_at_2x2(const fp32_matrix2x3_t* matrix1, const fp32_matrix2x2_t* matrix2, fp32_matrix2x3_t* result)
|
||||||
{
|
{
|
||||||
const float r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1;
|
const float r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1;
|
||||||
const float r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2;
|
const float r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2;
|
||||||
|
@ -63,7 +63,7 @@ void bg_fp32_matrix_product_2x3_at_2x2(const BgFP32Matrix2x3* matrix1, const BgF
|
||||||
result->r3c2 = r3c2;
|
result->r3c2 = r3c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bg_fp64_matrix_product_2x3_at_2x2(const BgFP64Matrix2x3* matrix1, const BgFP64Matrix2x2* matrix2, BgFP64Matrix2x3* result)
|
void fp64_matrix_product_2x3_at_2x2(const fp64_matrix2x3_t* matrix1, const fp64_matrix2x2_t* matrix2, fp64_matrix2x3_t* result)
|
||||||
{
|
{
|
||||||
const double r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1;
|
const double r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1;
|
||||||
const double r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2;
|
const double r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2;
|
||||||
|
@ -86,7 +86,7 @@ void bg_fp64_matrix_product_2x3_at_2x2(const BgFP64Matrix2x3* matrix1, const BgF
|
||||||
|
|
||||||
// ========== Matrix Product 2x3 at 3x2 ========= //
|
// ========== Matrix Product 2x3 at 3x2 ========= //
|
||||||
|
|
||||||
void bg_fp32_matrix_product_2x3_at_3x2(const BgFP32Matrix2x3* matrix1, const BgFP32Matrix3x2* matrix2, BgFP32Matrix3x3* result)
|
void fp32_matrix_product_2x3_at_3x2(const fp32_matrix2x3_t* matrix1, const fp32_matrix3x2_t* matrix2, fp32_matrix3x3_t* result)
|
||||||
{
|
{
|
||||||
result->r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1;
|
result->r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1;
|
||||||
result->r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2;
|
result->r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2;
|
||||||
|
@ -101,7 +101,7 @@ void bg_fp32_matrix_product_2x3_at_3x2(const BgFP32Matrix2x3* matrix1, const BgF
|
||||||
result->r3c3 = matrix1->r3c1 * matrix2->r1c3 + matrix1->r3c2 * matrix2->r2c3;
|
result->r3c3 = matrix1->r3c1 * matrix2->r1c3 + matrix1->r3c2 * matrix2->r2c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bg_fp64_matrix_product_2x3_at_3x2(const BgFP64Matrix2x3* matrix1, const BgFP64Matrix3x2* matrix2, BgFP64Matrix3x3* result)
|
void fp64_matrix_product_2x3_at_3x2(const fp64_matrix2x3_t* matrix1, const fp64_matrix3x2_t* matrix2, fp64_matrix3x3_t* result)
|
||||||
{
|
{
|
||||||
result->r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1;
|
result->r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1;
|
||||||
result->r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2;
|
result->r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2;
|
||||||
|
@ -118,7 +118,7 @@ void bg_fp64_matrix_product_2x3_at_3x2(const BgFP64Matrix2x3* matrix1, const BgF
|
||||||
|
|
||||||
// ========== Matrix Product 3x2 at 2x3 ========= //
|
// ========== Matrix Product 3x2 at 2x3 ========= //
|
||||||
|
|
||||||
void bg_fp32_matrix_product_3x2_at_2x3(const BgFP32Matrix3x2* matrix1, const BgFP32Matrix2x3* matrix2, BgFP32Matrix2x2* result)
|
void fp32_matrix_product_3x2_at_2x3(const fp32_matrix3x2_t* matrix1, const fp32_matrix2x3_t* matrix2, fp32_matrix2x2_t* result)
|
||||||
{
|
{
|
||||||
result->r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1;
|
result->r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1;
|
||||||
result->r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2;
|
result->r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2;
|
||||||
|
@ -127,7 +127,7 @@ void bg_fp32_matrix_product_3x2_at_2x3(const BgFP32Matrix3x2* matrix1, const BgF
|
||||||
result->r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2 + matrix1->r2c3 * matrix2->r3c2;
|
result->r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2 + matrix1->r2c3 * matrix2->r3c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bg_fp64_matrix_product_3x2_at_2x3(const BgFP64Matrix3x2* matrix1, const BgFP64Matrix2x3* matrix2, BgFP64Matrix2x2* result)
|
void fp64_matrix_product_3x2_at_2x3(const fp64_matrix3x2_t* matrix1, const fp64_matrix2x3_t* matrix2, fp64_matrix2x2_t* result)
|
||||||
{
|
{
|
||||||
result->r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1;
|
result->r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1;
|
||||||
result->r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2;
|
result->r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2;
|
||||||
|
@ -138,7 +138,7 @@ void bg_fp64_matrix_product_3x2_at_2x3(const BgFP64Matrix3x2* matrix1, const BgF
|
||||||
|
|
||||||
// ========== Matrix Product 3x2 at 3x3 ========= //
|
// ========== Matrix Product 3x2 at 3x3 ========= //
|
||||||
|
|
||||||
void bg_fp32_matrix_product_3x2_at_3x3(const BgFP32Matrix3x2* matrix1, const BgFP32Matrix3x3* matrix2, BgFP32Matrix3x2* result)
|
void fp32_matrix_product_3x2_at_3x3(const fp32_matrix3x2_t* matrix1, const fp32_matrix3x3_t* matrix2, fp32_matrix3x2_t* result)
|
||||||
{
|
{
|
||||||
const float r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1;
|
const float r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1;
|
||||||
const float r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2;
|
const float r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2;
|
||||||
|
@ -157,7 +157,7 @@ void bg_fp32_matrix_product_3x2_at_3x3(const BgFP32Matrix3x2* matrix1, const BgF
|
||||||
result->r2c3 = r2c3;
|
result->r2c3 = r2c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bg_fp64_matrix_product_3x2_at_3x3(const BgFP64Matrix3x2* matrix1, const BgFP64Matrix3x3* matrix2, BgFP64Matrix3x2* result)
|
void fp64_matrix_product_3x2_at_3x3(const fp64_matrix3x2_t* matrix1, const fp64_matrix3x3_t* matrix2, fp64_matrix3x2_t* result)
|
||||||
{
|
{
|
||||||
const double r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1;
|
const double r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1;
|
||||||
const double r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2;
|
const double r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2;
|
||||||
|
@ -178,7 +178,7 @@ void bg_fp64_matrix_product_3x2_at_3x3(const BgFP64Matrix3x2* matrix1, const BgF
|
||||||
|
|
||||||
// ========== Matrix Product 3x3 at 2x3 ========= //
|
// ========== Matrix Product 3x3 at 2x3 ========= //
|
||||||
|
|
||||||
void bg_fp32_matrix_product_3x3_at_2x3(const BgFP32Matrix3x3* matrix1, const BgFP32Matrix2x3* matrix2, BgFP32Matrix2x3* result)
|
void fp32_matrix_product_3x3_at_2x3(const fp32_matrix3x3_t* matrix1, const fp32_matrix2x3_t* matrix2, fp32_matrix2x3_t* result)
|
||||||
{
|
{
|
||||||
const float r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1;
|
const float r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1;
|
||||||
const float r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2;
|
const float r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2;
|
||||||
|
@ -199,7 +199,7 @@ void bg_fp32_matrix_product_3x3_at_2x3(const BgFP32Matrix3x3* matrix1, const BgF
|
||||||
result->r3c2 = r3c2;
|
result->r3c2 = r3c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bg_fp64_matrix_product_3x3_at_2x3(const BgFP64Matrix3x3* matrix1, const BgFP64Matrix2x3* matrix2, BgFP64Matrix2x3* result)
|
void fp64_matrix_product_3x3_at_2x3(const fp64_matrix3x3_t* matrix1, const fp64_matrix2x3_t* matrix2, fp64_matrix2x3_t* result)
|
||||||
{
|
{
|
||||||
const double r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1;
|
const double r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1;
|
||||||
const double r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2;
|
const double r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2;
|
||||||
|
@ -222,7 +222,7 @@ void bg_fp64_matrix_product_3x3_at_2x3(const BgFP64Matrix3x3* matrix1, const BgF
|
||||||
|
|
||||||
// ========== Matrix Product 3x3 at 3x3 ========= //
|
// ========== Matrix Product 3x3 at 3x3 ========= //
|
||||||
|
|
||||||
void bg_fp32_matrix_product_3x3_at_3x3(const BgFP32Matrix3x3* matrix1, const BgFP32Matrix3x3* matrix2, BgFP32Matrix3x3* result)
|
void fp32_matrix_product_3x3_at_3x3(const fp32_matrix3x3_t* matrix1, const fp32_matrix3x3_t* matrix2, fp32_matrix3x3_t* result)
|
||||||
{
|
{
|
||||||
const float r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1;
|
const float r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1;
|
||||||
const float r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2;
|
const float r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2;
|
||||||
|
@ -249,7 +249,7 @@ void bg_fp32_matrix_product_3x3_at_3x3(const BgFP32Matrix3x3* matrix1, const BgF
|
||||||
result->r3c3 = r3c3;
|
result->r3c3 = r3c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bg_fp64_matrix_product_3x3_at_3x3(const BgFP64Matrix3x3* matrix1, const BgFP64Matrix3x3* matrix2, BgFP64Matrix3x3* result)
|
void fp64_matrix_product_3x3_at_3x3(const fp64_matrix3x3_t* matrix1, const fp64_matrix3x3_t* matrix2, fp64_matrix3x3_t* result)
|
||||||
{
|
{
|
||||||
const double r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1;
|
const double r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1;
|
||||||
const double r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2;
|
const double r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2;
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
#ifndef _GEOMETRY_MATRIX_TYPES_H_
|
#ifndef _BASIC_GEOMETRY_MATRIX_TYPES_H_
|
||||||
#define _GEOMETRY_MATRIX_TYPES_H_
|
#define _BASIC_GEOMETRY_MATRIX_TYPES_H_
|
||||||
|
|
||||||
// ================== Matrix2x2 ================= //
|
// ================== Matrix2x2 ================= //
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
float r1c1, r1c2;
|
float r1c1, r1c2;
|
||||||
float r2c1, r2c2;
|
float r2c1, r2c2;
|
||||||
} BgFP32Matrix2x2;
|
} fp32_matrix2x2_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
double r1c1, r1c2;
|
double r1c1, r1c2;
|
||||||
double r2c1, r2c2;
|
double r2c1, r2c2;
|
||||||
} BgFP64Matrix2x2;
|
} fp64_matrix2x2_t;
|
||||||
|
|
||||||
// ================== Matrix2x3 ================= //
|
// ================== Matrix2x3 ================= //
|
||||||
|
|
||||||
|
@ -19,25 +19,25 @@ typedef struct {
|
||||||
float r1c1, r1c2;
|
float r1c1, r1c2;
|
||||||
float r2c1, r2c2;
|
float r2c1, r2c2;
|
||||||
float r3c1, r3c2;
|
float r3c1, r3c2;
|
||||||
} BgFP32Matrix2x3;
|
} fp32_matrix2x3_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
double r1c1, r1c2;
|
double r1c1, r1c2;
|
||||||
double r2c1, r2c2;
|
double r2c1, r2c2;
|
||||||
double r3c1, r3c2;
|
double r3c1, r3c2;
|
||||||
} BgFP64Matrix2x3;
|
} fp64_matrix2x3_t;
|
||||||
|
|
||||||
// ================== Matrix3x2 ================= //
|
// ================== Matrix3x2 ================= //
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
float r1c1, r1c2, r1c3;
|
float r1c1, r1c2, r1c3;
|
||||||
float r2c1, r2c2, r2c3;
|
float r2c1, r2c2, r2c3;
|
||||||
} BgFP32Matrix3x2;
|
} fp32_matrix3x2_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
double r1c1, r1c2, r1c3;
|
double r1c1, r1c2, r1c3;
|
||||||
double r2c1, r2c2, r2c3;
|
double r2c1, r2c2, r2c3;
|
||||||
} BgFP64Matrix3x2;
|
} fp64_matrix3x2_t;
|
||||||
|
|
||||||
// ================== Matrix3x3 ================= //
|
// ================== Matrix3x3 ================= //
|
||||||
|
|
||||||
|
@ -45,17 +45,17 @@ typedef struct {
|
||||||
float r1c1, r1c2, r1c3;
|
float r1c1, r1c2, r1c3;
|
||||||
float r2c1, r2c2, r2c3;
|
float r2c1, r2c2, r2c3;
|
||||||
float r3c1, r3c2, r3c3;
|
float r3c1, r3c2, r3c3;
|
||||||
} BgFP32Matrix3x3;
|
} fp32_matrix3x3_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
double r1c1, r1c2, r1c3;
|
double r1c1, r1c2, r1c3;
|
||||||
double r2c1, r2c2, r2c3;
|
double r2c1, r2c2, r2c3;
|
||||||
double r3c1, r3c2, r3c3;
|
double r3c1, r3c2, r3c3;
|
||||||
} BgFP64Matrix3x3;
|
} fp64_matrix3x3_t;
|
||||||
|
|
||||||
// ========== Matrix Product 2x2 at 2x2 ========= //
|
// ========== Matrix Product 2x2 at 2x2 ========= //
|
||||||
|
|
||||||
static inline void bg_fp32_matrix_product_2x2_at_2x2(const BgFP32Matrix2x2* matrix1, const BgFP32Matrix2x2* matrix2, BgFP32Matrix2x2* result)
|
static inline void fp32_matrix_product_2x2_at_2x2(const fp32_matrix2x2_t* matrix1, const fp32_matrix2x2_t* matrix2, fp32_matrix2x2_t* result)
|
||||||
{
|
{
|
||||||
const float r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1;
|
const float r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1;
|
||||||
const float r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2;
|
const float r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2;
|
||||||
|
@ -70,7 +70,7 @@ static inline void bg_fp32_matrix_product_2x2_at_2x2(const BgFP32Matrix2x2* matr
|
||||||
result->r2c2 = r2c2;
|
result->r2c2 = r2c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_matrix_product_2x2_at_2x2(const BgFP64Matrix2x2* matrix1, const BgFP64Matrix2x2* matrix2, BgFP64Matrix2x2* result)
|
static inline void fp64_matrix_product_2x2_at_2x2(const fp64_matrix2x2_t* matrix1, const fp64_matrix2x2_t* matrix2, fp64_matrix2x2_t* result)
|
||||||
{
|
{
|
||||||
const double r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1;
|
const double r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1;
|
||||||
const double r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2;
|
const double r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2;
|
||||||
|
@ -87,44 +87,44 @@ static inline void bg_fp64_matrix_product_2x2_at_2x2(const BgFP64Matrix2x2* matr
|
||||||
|
|
||||||
// ========== Matrix Product 2x2 at 3x2 ========= //
|
// ========== Matrix Product 2x2 at 3x2 ========= //
|
||||||
|
|
||||||
void bg_fp32_matrix_product_2x2_at_3x2(const BgFP32Matrix2x2* matrix1, const BgFP32Matrix3x2* matrix2, BgFP32Matrix3x2* result);
|
void fp32_matrix_product_2x2_at_3x2(const fp32_matrix2x2_t* matrix1, const fp32_matrix3x2_t* matrix2, fp32_matrix3x2_t* result);
|
||||||
|
|
||||||
void bg_fp64_matrix_product_2x2_at_3x2(const BgFP64Matrix2x2* matrix1, const BgFP64Matrix3x2* matrix2, BgFP64Matrix3x2* result);
|
void fp64_matrix_product_2x2_at_3x2(const fp64_matrix2x2_t* matrix1, const fp64_matrix3x2_t* matrix2, fp64_matrix3x2_t* result);
|
||||||
|
|
||||||
// ========== Matrix Product 2x3 at 2x2 ========= //
|
// ========== Matrix Product 2x3 at 2x2 ========= //
|
||||||
|
|
||||||
void bg_fp32_matrix_product_2x3_at_2x2(const BgFP32Matrix2x3* matrix1, const BgFP32Matrix2x2* matrix2, BgFP32Matrix2x3* result);
|
void fp32_matrix_product_2x3_at_2x2(const fp32_matrix2x3_t* matrix1, const fp32_matrix2x2_t* matrix2, fp32_matrix2x3_t* result);
|
||||||
|
|
||||||
void bg_fp64_matrix_product_2x3_at_2x2(const BgFP64Matrix2x3* matrix1, const BgFP64Matrix2x2* matrix2, BgFP64Matrix2x3* result);
|
void fp64_matrix_product_2x3_at_2x2(const fp64_matrix2x3_t* matrix1, const fp64_matrix2x2_t* matrix2, fp64_matrix2x3_t* result);
|
||||||
|
|
||||||
// ========== Matrix Product 2x3 at 3x2 ========= //
|
// ========== Matrix Product 2x3 at 3x2 ========= //
|
||||||
|
|
||||||
void bg_fp32_matrix_product_2x3_at_3x2(const BgFP32Matrix2x3* matrix1, const BgFP32Matrix3x2* matrix2, BgFP32Matrix3x3* result);
|
void fp32_matrix_product_2x3_at_3x2(const fp32_matrix2x3_t* matrix1, const fp32_matrix3x2_t* matrix2, fp32_matrix3x3_t* result);
|
||||||
|
|
||||||
void bg_fp64_matrix_product_2x3_at_3x2(const BgFP64Matrix2x3* matrix1, const BgFP64Matrix3x2* matrix2, BgFP64Matrix3x3* result);
|
void fp64_matrix_product_2x3_at_3x2(const fp64_matrix2x3_t* matrix1, const fp64_matrix3x2_t* matrix2, fp64_matrix3x3_t* result);
|
||||||
|
|
||||||
// ========== Matrix Product 3x2 at 2x3 ========= //
|
// ========== Matrix Product 3x2 at 2x3 ========= //
|
||||||
|
|
||||||
void bg_fp32_matrix_product_3x2_at_2x3(const BgFP32Matrix3x2* matrix1, const BgFP32Matrix2x3* matrix2, BgFP32Matrix2x2* result);
|
void fp32_matrix_product_3x2_at_2x3(const fp32_matrix3x2_t* matrix1, const fp32_matrix2x3_t* matrix2, fp32_matrix2x2_t* result);
|
||||||
|
|
||||||
void bg_fp64_matrix_product_3x2_at_2x3(const BgFP64Matrix3x2* matrix1, const BgFP64Matrix2x3* matrix2, BgFP64Matrix2x2* result);
|
void fp64_matrix_product_3x2_at_2x3(const fp64_matrix3x2_t* matrix1, const fp64_matrix2x3_t* matrix2, fp64_matrix2x2_t* result);
|
||||||
|
|
||||||
// ========== Matrix Product 3x2 at 3x3 ========= //
|
// ========== Matrix Product 3x2 at 3x3 ========= //
|
||||||
|
|
||||||
void bg_fp32_matrix_product_3x2_at_3x3(const BgFP32Matrix3x2* matrix1, const BgFP32Matrix3x3* matrix2, BgFP32Matrix3x2* result);
|
void fp32_matrix_product_3x2_at_3x3(const fp32_matrix3x2_t* matrix1, const fp32_matrix3x3_t* matrix2, fp32_matrix3x2_t* result);
|
||||||
|
|
||||||
void bg_fp64_matrix_product_3x2_at_3x3(const BgFP64Matrix3x2* matrix1, const BgFP64Matrix3x3* matrix2, BgFP64Matrix3x2* result);
|
void fp64_matrix_product_3x2_at_3x3(const fp64_matrix3x2_t* matrix1, const fp64_matrix3x3_t* matrix2, fp64_matrix3x2_t* result);
|
||||||
|
|
||||||
// ========== Matrix Product 3x3 at 2x3 ========= //
|
// ========== Matrix Product 3x3 at 2x3 ========= //
|
||||||
|
|
||||||
void bg_fp32_matrix_product_3x3_at_2x3(const BgFP32Matrix3x3* matrix1, const BgFP32Matrix2x3* matrix2, BgFP32Matrix2x3* result);
|
void fp32_matrix_product_3x3_at_2x3(const fp32_matrix3x3_t* matrix1, const fp32_matrix2x3_t* matrix2, fp32_matrix2x3_t* result);
|
||||||
|
|
||||||
void bg_fp64_matrix_product_3x3_at_2x3(const BgFP64Matrix3x3* matrix1, const BgFP64Matrix2x3* matrix2, BgFP64Matrix2x3* result);
|
void fp64_matrix_product_3x3_at_2x3(const fp64_matrix3x3_t* matrix1, const fp64_matrix2x3_t* matrix2, fp64_matrix2x3_t* result);
|
||||||
|
|
||||||
// ========== Matrix Product 3x3 at 3x3 ========= //
|
// ========== Matrix Product 3x3 at 3x3 ========= //
|
||||||
|
|
||||||
void bg_fp32_matrix_product_3x3_at_3x3(const BgFP32Matrix3x3* matrix1, const BgFP32Matrix3x3* matrix2, BgFP32Matrix3x3* result);
|
void fp32_matrix_product_3x3_at_3x3(const fp32_matrix3x3_t* matrix1, const fp32_matrix3x3_t* matrix2, fp32_matrix3x3_t* result);
|
||||||
|
|
||||||
void bg_fp64_matrix_product_3x3_at_3x3(const BgFP64Matrix3x3* matrix1, const BgFP64Matrix3x3* matrix2, BgFP64Matrix3x3* result);
|
void fp64_matrix_product_3x3_at_3x3(const fp64_matrix3x3_t* matrix1, const fp64_matrix3x3_t* matrix2, fp64_matrix3x3_t* result);
|
||||||
|
|
||||||
#endif // _GEOMETRY_MATRIX_TYPES_H_
|
#endif // _GEOMETRY_MATRIX_TYPES_H_
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#ifndef _GEOMETRY_QUATERNION_H_
|
#ifndef _BASIC_GEOMETRY_QUATERNION_H_
|
||||||
#define _GEOMETRY_QUATERNION_H_
|
#define _BASIC_GEOMETRY_QUATERNION_H_
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
@ -9,15 +9,15 @@
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
float s0, x1, x2, x3;
|
float s0, x1, x2, x3;
|
||||||
} BgFP32Quaternion;
|
} fp32_quaternion_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
double s0, x1, x2, x3;
|
double s0, x1, x2, x3;
|
||||||
} BgFP64Quaternion;
|
} fp64_quaternion_t;
|
||||||
|
|
||||||
// ==================== Reset =================== //
|
// ==================== Reset =================== //
|
||||||
|
|
||||||
static inline void bg_fp32_quaternion_reset(BgFP32Quaternion * quaternion)
|
static inline void fp32_quaternion_reset(fp32_quaternion_t * quaternion)
|
||||||
{
|
{
|
||||||
quaternion->s0 = 0.0f;
|
quaternion->s0 = 0.0f;
|
||||||
quaternion->x1 = 0.0f;
|
quaternion->x1 = 0.0f;
|
||||||
|
@ -25,7 +25,7 @@ static inline void bg_fp32_quaternion_reset(BgFP32Quaternion * quaternion)
|
||||||
quaternion->x3 = 0.0f;
|
quaternion->x3 = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_quaternion_reset(BgFP64Quaternion * quaternion)
|
static inline void fp64_quaternion_reset(fp64_quaternion_t * quaternion)
|
||||||
{
|
{
|
||||||
quaternion->s0 = 0.0;
|
quaternion->s0 = 0.0;
|
||||||
quaternion->x1 = 0.0;
|
quaternion->x1 = 0.0;
|
||||||
|
@ -35,7 +35,7 @@ static inline void bg_fp64_quaternion_reset(BgFP64Quaternion * quaternion)
|
||||||
|
|
||||||
// ================== Set Unit ================== //
|
// ================== Set Unit ================== //
|
||||||
|
|
||||||
static inline void bg_fp32_quaternion_set_identity(BgFP32Quaternion * quaternion)
|
static inline void fp32_quaternion_set_identity(fp32_quaternion_t * quaternion)
|
||||||
{
|
{
|
||||||
quaternion->s0 = 1.0f;
|
quaternion->s0 = 1.0f;
|
||||||
quaternion->x1 = 0.0f;
|
quaternion->x1 = 0.0f;
|
||||||
|
@ -43,7 +43,7 @@ static inline void bg_fp32_quaternion_set_identity(BgFP32Quaternion * quaternion
|
||||||
quaternion->x3 = 0.0f;
|
quaternion->x3 = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_quaternion_set_identity(BgFP64Quaternion * quaternion)
|
static inline void fp64_quaternion_set_identity(fp64_quaternion_t * quaternion)
|
||||||
{
|
{
|
||||||
quaternion->s0 = 1.0;
|
quaternion->s0 = 1.0;
|
||||||
quaternion->x1 = 0.0;
|
quaternion->x1 = 0.0;
|
||||||
|
@ -53,7 +53,7 @@ static inline void bg_fp64_quaternion_set_identity(BgFP64Quaternion * quaternion
|
||||||
|
|
||||||
// ==================== Set ===================== //
|
// ==================== Set ===================== //
|
||||||
|
|
||||||
static inline void bg_fp32_quaternion_set_values(const float s0, const float x1, const float x2, const float x3, BgFP32Quaternion * quaternion)
|
static inline void fp32_quaternion_set_values(const float s0, const float x1, const float x2, const float x3, fp32_quaternion_t * quaternion)
|
||||||
{
|
{
|
||||||
quaternion->s0 = s0;
|
quaternion->s0 = s0;
|
||||||
quaternion->x1 = x1;
|
quaternion->x1 = x1;
|
||||||
|
@ -61,7 +61,7 @@ static inline void bg_fp32_quaternion_set_values(const float s0, const float x1,
|
||||||
quaternion->x3 = x3;
|
quaternion->x3 = x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_quaternion_set_values(const double s0, const double x1, const double x2, const double x3, BgFP64Quaternion * quaternion)
|
static inline void fp64_quaternion_set_values(const double s0, const double x1, const double x2, const double x3, fp64_quaternion_t * quaternion)
|
||||||
{
|
{
|
||||||
quaternion->s0 = s0;
|
quaternion->s0 = s0;
|
||||||
quaternion->x1 = x1;
|
quaternion->x1 = x1;
|
||||||
|
@ -71,7 +71,7 @@ static inline void bg_fp64_quaternion_set_values(const double s0, const double x
|
||||||
|
|
||||||
// ==================== Copy ==================== //
|
// ==================== Copy ==================== //
|
||||||
|
|
||||||
static inline void bg_fp32_quaternion_copy(const BgFP32Quaternion* from, BgFP32Quaternion* to)
|
static inline void fp32_quaternion_copy(const fp32_quaternion_t* from, fp32_quaternion_t* to)
|
||||||
{
|
{
|
||||||
to->s0 = from->s0;
|
to->s0 = from->s0;
|
||||||
to->x1 = from->x1;
|
to->x1 = from->x1;
|
||||||
|
@ -79,7 +79,7 @@ static inline void bg_fp32_quaternion_copy(const BgFP32Quaternion* from, BgFP32Q
|
||||||
to->x3 = from->x3;
|
to->x3 = from->x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_quaternion_copy(const BgFP64Quaternion* from, BgFP64Quaternion* to)
|
static inline void fp64_quaternion_copy(const fp64_quaternion_t* from, fp64_quaternion_t* to)
|
||||||
{
|
{
|
||||||
to->s0 = from->s0;
|
to->s0 = from->s0;
|
||||||
to->x1 = from->x1;
|
to->x1 = from->x1;
|
||||||
|
@ -89,7 +89,7 @@ static inline void bg_fp64_quaternion_copy(const BgFP64Quaternion* from, BgFP64Q
|
||||||
|
|
||||||
// ==================== Swap ==================== //
|
// ==================== Swap ==================== //
|
||||||
|
|
||||||
static inline void bg_fp32_quaternion_swap(BgFP32Quaternion* quarternion1, BgFP32Quaternion* quarternion2)
|
static inline void fp32_quaternion_swap(fp32_quaternion_t* quarternion1, fp32_quaternion_t* quarternion2)
|
||||||
{
|
{
|
||||||
const float s0 = quarternion2->s0;
|
const float s0 = quarternion2->s0;
|
||||||
const float x1 = quarternion2->x1;
|
const float x1 = quarternion2->x1;
|
||||||
|
@ -107,7 +107,7 @@ static inline void bg_fp32_quaternion_swap(BgFP32Quaternion* quarternion1, BgFP3
|
||||||
quarternion1->x3 = x3;
|
quarternion1->x3 = x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_quaternion_swap(BgFP64Quaternion* quarternion1, BgFP64Quaternion* quarternion2)
|
static inline void fp64_quaternion_swap(fp64_quaternion_t* quarternion1, fp64_quaternion_t* quarternion2)
|
||||||
{
|
{
|
||||||
const double s0 = quarternion2->s0;
|
const double s0 = quarternion2->s0;
|
||||||
const double x1 = quarternion2->x1;
|
const double x1 = quarternion2->x1;
|
||||||
|
@ -127,7 +127,7 @@ static inline void bg_fp64_quaternion_swap(BgFP64Quaternion* quarternion1, BgFP6
|
||||||
|
|
||||||
// ============= Copy to twin type ============== //
|
// ============= Copy to twin type ============== //
|
||||||
|
|
||||||
static inline void bg_fp32_quaternion_set_from_fp64(const BgFP64Quaternion* quaternion, BgFP32Quaternion* result)
|
static inline void fp32_quaternion_set_from_fp64(const fp64_quaternion_t* quaternion, fp32_quaternion_t* result)
|
||||||
{
|
{
|
||||||
result->s0 = (float) quaternion->s0;
|
result->s0 = (float) quaternion->s0;
|
||||||
result->x1 = (float) quaternion->x1;
|
result->x1 = (float) quaternion->x1;
|
||||||
|
@ -135,7 +135,7 @@ static inline void bg_fp32_quaternion_set_from_fp64(const BgFP64Quaternion* quat
|
||||||
result->x3 = (float) quaternion->x3;
|
result->x3 = (float) quaternion->x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_quaternion_set_from_fp32(const BgFP32Quaternion* quaternion, BgFP64Quaternion* result)
|
static inline void fp64_quaternion_set_from_fp32(const fp32_quaternion_t* quaternion, fp64_quaternion_t* result)
|
||||||
{
|
{
|
||||||
result->s0 = quaternion->s0;
|
result->s0 = quaternion->s0;
|
||||||
result->x1 = quaternion->x1;
|
result->x1 = quaternion->x1;
|
||||||
|
@ -145,14 +145,14 @@ static inline void bg_fp64_quaternion_set_from_fp32(const BgFP32Quaternion* quat
|
||||||
|
|
||||||
// ================= Inversion ================== //
|
// ================= Inversion ================== //
|
||||||
|
|
||||||
static inline void bg_fp32_quaternion_conjugate(BgFP32Quaternion* quaternion)
|
static inline void fp32_quaternion_conjugate(fp32_quaternion_t* quaternion)
|
||||||
{
|
{
|
||||||
quaternion->x1 = -quaternion->x1;
|
quaternion->x1 = -quaternion->x1;
|
||||||
quaternion->x2 = -quaternion->x2;
|
quaternion->x2 = -quaternion->x2;
|
||||||
quaternion->x3 = -quaternion->x3;
|
quaternion->x3 = -quaternion->x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_quaternion_conjugate(BgFP64Quaternion* quaternion)
|
static inline void fp64_quaternion_conjugate(fp64_quaternion_t* quaternion)
|
||||||
{
|
{
|
||||||
quaternion->x1 = -quaternion->x1;
|
quaternion->x1 = -quaternion->x1;
|
||||||
quaternion->x2 = -quaternion->x2;
|
quaternion->x2 = -quaternion->x2;
|
||||||
|
@ -161,7 +161,7 @@ static inline void bg_fp64_quaternion_conjugate(BgFP64Quaternion* quaternion)
|
||||||
|
|
||||||
// ================ Set Conjugate =============== //
|
// ================ Set Conjugate =============== //
|
||||||
|
|
||||||
static inline void bg_fp32_quaternion_set_conjugate(const BgFP32Quaternion* quaternion, BgFP32Quaternion* result)
|
static inline void fp32_quaternion_set_conjugate(const fp32_quaternion_t* quaternion, fp32_quaternion_t* result)
|
||||||
{
|
{
|
||||||
result->s0 = quaternion->s0;
|
result->s0 = quaternion->s0;
|
||||||
result->x1 = -quaternion->x1;
|
result->x1 = -quaternion->x1;
|
||||||
|
@ -169,7 +169,7 @@ static inline void bg_fp32_quaternion_set_conjugate(const BgFP32Quaternion* quat
|
||||||
result->x3 = -quaternion->x3;
|
result->x3 = -quaternion->x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_quaternion_set_conjugate(const BgFP64Quaternion* quaternion, BgFP64Quaternion* result)
|
static inline void fp64_quaternion_set_conjugate(const fp64_quaternion_t* quaternion, fp64_quaternion_t* result)
|
||||||
{
|
{
|
||||||
result->s0 = quaternion->s0;
|
result->s0 = quaternion->s0;
|
||||||
result->x1 = -quaternion->x1;
|
result->x1 = -quaternion->x1;
|
||||||
|
@ -179,7 +179,7 @@ static inline void bg_fp64_quaternion_set_conjugate(const BgFP64Quaternion* quat
|
||||||
|
|
||||||
// ================ Set Conjugate =============== //
|
// ================ Set Conjugate =============== //
|
||||||
|
|
||||||
static inline void bg_fp32_quaternion_set_conjugate_fp64(const BgFP64Quaternion* quaternion, BgFP32Quaternion* result)
|
static inline void fp32_quaternion_set_conjugate_fp64(const fp64_quaternion_t* quaternion, fp32_quaternion_t* result)
|
||||||
{
|
{
|
||||||
result->s0 = (float) quaternion->s0;
|
result->s0 = (float) quaternion->s0;
|
||||||
result->x1 = (float) -quaternion->x1;
|
result->x1 = (float) -quaternion->x1;
|
||||||
|
@ -187,7 +187,7 @@ static inline void bg_fp32_quaternion_set_conjugate_fp64(const BgFP64Quaternion*
|
||||||
result->x3 = (float) -quaternion->x3;
|
result->x3 = (float) -quaternion->x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_quaternion_set_conjugate_fp32(const BgFP32Quaternion* quaternion, BgFP64Quaternion* result)
|
static inline void fp64_quaternion_set_conjugate_fp32(const fp32_quaternion_t* quaternion, fp64_quaternion_t* result)
|
||||||
{
|
{
|
||||||
result->s0 = quaternion->s0;
|
result->s0 = quaternion->s0;
|
||||||
result->x1 = -quaternion->x1;
|
result->x1 = -quaternion->x1;
|
||||||
|
@ -197,40 +197,40 @@ static inline void bg_fp64_quaternion_set_conjugate_fp32(const BgFP32Quaternion*
|
||||||
|
|
||||||
// ============= Get Square Modulus ============= //
|
// ============= Get Square Modulus ============= //
|
||||||
|
|
||||||
static inline float bg_fp32_quaternion_get_square_modulus(const BgFP32Quaternion* quaternion)
|
static inline float fp32_quaternion_get_square_modulus(const fp32_quaternion_t* quaternion)
|
||||||
{
|
{
|
||||||
return (quaternion->s0 * quaternion->s0 + quaternion->x1 * quaternion->x1) + (quaternion->x2 * quaternion->x2 + quaternion->x3 * quaternion->x3);
|
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)
|
static inline double fp64_quaternion_get_square_modulus(const fp64_quaternion_t* quaternion)
|
||||||
{
|
{
|
||||||
return (quaternion->s0 * quaternion->s0 + quaternion->x1 * quaternion->x1) + (quaternion->x2 * quaternion->x2 + quaternion->x3 * quaternion->x3);
|
return (quaternion->s0 * quaternion->s0 + quaternion->x1 * quaternion->x1) + (quaternion->x2 * quaternion->x2 + quaternion->x3 * quaternion->x3);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================ Get Modulus ================= //
|
// ================ Get Modulus ================= //
|
||||||
|
|
||||||
static inline float bg_fp32_quaternion_get_modulus(const BgFP32Quaternion* quaternion)
|
static inline float fp32_quaternion_get_modulus(const fp32_quaternion_t* quaternion)
|
||||||
{
|
{
|
||||||
return sqrtf(bg_fp32_quaternion_get_square_modulus(quaternion));
|
return sqrtf(fp32_quaternion_get_square_modulus(quaternion));
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline double bg_fp64_quaternion_get_modulus(const BgFP64Quaternion* quaternion)
|
static inline double fp64_quaternion_get_modulus(const fp64_quaternion_t* quaternion)
|
||||||
{
|
{
|
||||||
return sqrt(bg_fp64_quaternion_get_square_modulus(quaternion));
|
return sqrt(fp64_quaternion_get_square_modulus(quaternion));
|
||||||
}
|
}
|
||||||
|
|
||||||
// =============== Normalization ================ //
|
// =============== Normalization ================ //
|
||||||
|
|
||||||
static inline int bg_fp32_quaternion_normalize(BgFP32Quaternion* quaternion)
|
static inline int fp32_quaternion_normalize(fp32_quaternion_t* quaternion)
|
||||||
{
|
{
|
||||||
const float square_modulus = bg_fp32_quaternion_get_square_modulus(quaternion);
|
const float square_modulus = fp32_quaternion_get_square_modulus(quaternion);
|
||||||
|
|
||||||
if (1.0f - BG_FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + BG_FP32_TWO_EPSYLON) {
|
if (1.0f - FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + FP32_TWO_EPSYLON) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (square_modulus <= BG_FP32_SQUARE_EPSYLON) {
|
if (square_modulus <= FP32_SQUARE_EPSYLON) {
|
||||||
bg_fp32_quaternion_reset(quaternion);
|
fp32_quaternion_reset(quaternion);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,16 +244,16 @@ static inline int bg_fp32_quaternion_normalize(BgFP32Quaternion* quaternion)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int bg_fp64_quaternion_normalize(BgFP64Quaternion* quaternion)
|
static inline int fp64_quaternion_normalize(fp64_quaternion_t* quaternion)
|
||||||
{
|
{
|
||||||
const double square_modulus = bg_fp64_quaternion_get_square_modulus(quaternion);
|
const double square_modulus = fp64_quaternion_get_square_modulus(quaternion);
|
||||||
|
|
||||||
if (1.0 - BG_FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0 + BG_FP64_TWO_EPSYLON) {
|
if (1.0 - FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0 + FP64_TWO_EPSYLON) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (square_modulus <= BG_FP32_SQUARE_EPSYLON) {
|
if (square_modulus <= FP32_SQUARE_EPSYLON) {
|
||||||
bg_fp64_quaternion_reset(quaternion);
|
fp64_quaternion_reset(quaternion);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,7 +269,7 @@ static inline int bg_fp64_quaternion_normalize(BgFP64Quaternion* quaternion)
|
||||||
|
|
||||||
// ============ Make Rotation Matrix ============ //
|
// ============ Make Rotation Matrix ============ //
|
||||||
|
|
||||||
static inline void bg_fp32_quaternion_get_rotation_matrix(const BgFP32Quaternion* quaternion, BgFP32Matrix3x3* matrix)
|
static inline void fp32_quaternion_get_rotation_matrix(const fp32_quaternion_t* quaternion, fp32_matrix3x3_t* matrix)
|
||||||
{
|
{
|
||||||
const float s0s0 = quaternion->s0 * quaternion->s0;
|
const float s0s0 = quaternion->s0 * quaternion->s0;
|
||||||
const float x1x1 = quaternion->x1 * quaternion->x1;
|
const float x1x1 = quaternion->x1 * quaternion->x1;
|
||||||
|
@ -278,9 +278,9 @@ static inline void bg_fp32_quaternion_get_rotation_matrix(const BgFP32Quaternion
|
||||||
|
|
||||||
const float square_modulus = (s0s0 + x1x1) + (x2x2 + x3x3);
|
const float square_modulus = (s0s0 + x1x1) + (x2x2 + x3x3);
|
||||||
|
|
||||||
if (-BG_FP32_EPSYLON <= square_modulus && square_modulus <= BG_FP32_EPSYLON)
|
if (-FP32_EPSYLON <= square_modulus && square_modulus <= FP32_EPSYLON)
|
||||||
{
|
{
|
||||||
bg_fp32_matrix3x3_set_to_identity(matrix);
|
fp32_matrix3x3_set_to_identity(matrix);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -307,7 +307,7 @@ static inline void bg_fp32_quaternion_get_rotation_matrix(const BgFP32Quaternion
|
||||||
matrix->r1c3 = corrector2 * (x1x3 + s0x2);
|
matrix->r1c3 = corrector2 * (x1x3 + s0x2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_quaternion_get_rotation_matrix(const BgFP64Quaternion* quaternion, BgFP64Matrix3x3* matrix)
|
static inline void fp64_quaternion_get_rotation_matrix(const fp64_quaternion_t* quaternion, fp64_matrix3x3_t* matrix)
|
||||||
{
|
{
|
||||||
const double s0s0 = quaternion->s0 * quaternion->s0;
|
const double s0s0 = quaternion->s0 * quaternion->s0;
|
||||||
const double x1x1 = quaternion->x1 * quaternion->x1;
|
const double x1x1 = quaternion->x1 * quaternion->x1;
|
||||||
|
@ -316,9 +316,9 @@ static inline void bg_fp64_quaternion_get_rotation_matrix(const BgFP64Quaternion
|
||||||
|
|
||||||
const double square_modulus = (s0s0 + x1x1) + (x2x2 + x3x3);
|
const double square_modulus = (s0s0 + x1x1) + (x2x2 + x3x3);
|
||||||
|
|
||||||
if (-BG_FP64_EPSYLON <= square_modulus && square_modulus <= BG_FP64_EPSYLON)
|
if (-FP64_EPSYLON <= square_modulus && square_modulus <= FP64_EPSYLON)
|
||||||
{
|
{
|
||||||
bg_fp64_matrix3x3_set_to_identity(matrix);
|
fp64_matrix3x3_set_to_identity(matrix);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -347,7 +347,7 @@ static inline void bg_fp64_quaternion_get_rotation_matrix(const BgFP64Quaternion
|
||||||
|
|
||||||
// ============ Make Reverse Matrix ============= //
|
// ============ Make Reverse Matrix ============= //
|
||||||
|
|
||||||
static inline void bg_fp32_quaternion_get_reverse_matrix(const BgFP32Quaternion* quaternion, BgFP32Matrix3x3* matrix)
|
static inline void fp32_quaternion_get_reverse_matrix(const fp32_quaternion_t* quaternion, fp32_matrix3x3_t* matrix)
|
||||||
{
|
{
|
||||||
const float s0s0 = quaternion->s0 * quaternion->s0;
|
const float s0s0 = quaternion->s0 * quaternion->s0;
|
||||||
const float x1x1 = quaternion->x1 * quaternion->x1;
|
const float x1x1 = quaternion->x1 * quaternion->x1;
|
||||||
|
@ -356,9 +356,9 @@ static inline void bg_fp32_quaternion_get_reverse_matrix(const BgFP32Quaternion*
|
||||||
|
|
||||||
const float square_modulus = (s0s0 + x1x1) + (x2x2 + x3x3);
|
const float square_modulus = (s0s0 + x1x1) + (x2x2 + x3x3);
|
||||||
|
|
||||||
if (-BG_FP32_EPSYLON <= square_modulus && square_modulus <= BG_FP32_EPSYLON)
|
if (-FP32_EPSYLON <= square_modulus && square_modulus <= FP32_EPSYLON)
|
||||||
{
|
{
|
||||||
bg_fp32_matrix3x3_set_to_identity(matrix);
|
fp32_matrix3x3_set_to_identity(matrix);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -385,7 +385,7 @@ static inline void bg_fp32_quaternion_get_reverse_matrix(const BgFP32Quaternion*
|
||||||
matrix->r1c3 = corrector2 * (x1x3 - s0x2);
|
matrix->r1c3 = corrector2 * (x1x3 - s0x2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_quaternion_get_reverse_matrix(const BgFP64Quaternion* quaternion, BgFP64Matrix3x3* matrix)
|
static inline void fp64_quaternion_get_reverse_matrix(const fp64_quaternion_t* quaternion, fp64_matrix3x3_t* matrix)
|
||||||
{
|
{
|
||||||
const double s0s0 = quaternion->s0 * quaternion->s0;
|
const double s0s0 = quaternion->s0 * quaternion->s0;
|
||||||
const double x1x1 = quaternion->x1 * quaternion->x1;
|
const double x1x1 = quaternion->x1 * quaternion->x1;
|
||||||
|
@ -394,9 +394,9 @@ static inline void bg_fp64_quaternion_get_reverse_matrix(const BgFP64Quaternion*
|
||||||
|
|
||||||
const double square_modulus = (s0s0 + x1x1) + (x2x2 + x3x3);
|
const double square_modulus = (s0s0 + x1x1) + (x2x2 + x3x3);
|
||||||
|
|
||||||
if (-BG_FP64_EPSYLON <= square_modulus && square_modulus <= BG_FP64_EPSYLON)
|
if (-FP64_EPSYLON <= square_modulus && square_modulus <= FP64_EPSYLON)
|
||||||
{
|
{
|
||||||
bg_fp64_matrix3x3_set_to_identity(matrix);
|
fp64_matrix3x3_set_to_identity(matrix);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -425,7 +425,7 @@ static inline void bg_fp64_quaternion_get_reverse_matrix(const BgFP64Quaternion*
|
||||||
|
|
||||||
// ==================== Add ===================== //
|
// ==================== Add ===================== //
|
||||||
|
|
||||||
static inline void bg_fp32_quaternion_add(const BgFP32Quaternion * quaternion1, const BgFP32Quaternion * quaternion2, BgFP32Quaternion * result)
|
static inline void fp32_quaternion_add(const fp32_quaternion_t * quaternion1, const fp32_quaternion_t * quaternion2, fp32_quaternion_t * result)
|
||||||
{
|
{
|
||||||
result->s0 = quaternion1->s0 + quaternion2->s0;
|
result->s0 = quaternion1->s0 + quaternion2->s0;
|
||||||
result->x1 = quaternion1->x1 + quaternion2->x1;
|
result->x1 = quaternion1->x1 + quaternion2->x1;
|
||||||
|
@ -433,7 +433,7 @@ static inline void bg_fp32_quaternion_add(const BgFP32Quaternion * quaternion1,
|
||||||
result->x3 = quaternion1->x3 + quaternion2->x3;
|
result->x3 = quaternion1->x3 + quaternion2->x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_quaternion_add(const BgFP64Quaternion * quaternion1, const BgFP64Quaternion * quaternion2, BgFP64Quaternion * result)
|
static inline void fp64_quaternion_add(const fp64_quaternion_t * quaternion1, const fp64_quaternion_t * quaternion2, fp64_quaternion_t * result)
|
||||||
{
|
{
|
||||||
result->s0 = quaternion1->s0 + quaternion2->s0;
|
result->s0 = quaternion1->s0 + quaternion2->s0;
|
||||||
result->x1 = quaternion1->x1 + quaternion2->x1;
|
result->x1 = quaternion1->x1 + quaternion2->x1;
|
||||||
|
@ -443,7 +443,7 @@ static inline void bg_fp64_quaternion_add(const BgFP64Quaternion * quaternion1,
|
||||||
|
|
||||||
// ================== Subtract ================== //
|
// ================== Subtract ================== //
|
||||||
|
|
||||||
static inline void bg_fp32_quaternion_subtract(const BgFP32Quaternion * minuend, const BgFP32Quaternion * subtrahend, BgFP32Quaternion * difference)
|
static inline void fp32_quaternion_subtract(const fp32_quaternion_t * minuend, const fp32_quaternion_t * subtrahend, fp32_quaternion_t * difference)
|
||||||
{
|
{
|
||||||
difference->s0 = minuend->s0 - subtrahend->s0;
|
difference->s0 = minuend->s0 - subtrahend->s0;
|
||||||
difference->x1 = minuend->x1 - subtrahend->x1;
|
difference->x1 = minuend->x1 - subtrahend->x1;
|
||||||
|
@ -451,7 +451,7 @@ static inline void bg_fp32_quaternion_subtract(const BgFP32Quaternion * minuend,
|
||||||
difference->x3 = minuend->x3 - subtrahend->x3;
|
difference->x3 = minuend->x3 - subtrahend->x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_quaternion_subtract(const BgFP64Quaternion * minuend, const BgFP64Quaternion * subtrahend, BgFP64Quaternion * difference)
|
static inline void fp64_quaternion_subtract(const fp64_quaternion_t * minuend, const fp64_quaternion_t * subtrahend, fp64_quaternion_t * difference)
|
||||||
{
|
{
|
||||||
difference->s0 = minuend->s0 - subtrahend->s0;
|
difference->s0 = minuend->s0 - subtrahend->s0;
|
||||||
difference->x1 = minuend->x1 - subtrahend->x1;
|
difference->x1 = minuend->x1 - subtrahend->x1;
|
||||||
|
@ -461,7 +461,7 @@ static inline void bg_fp64_quaternion_subtract(const BgFP64Quaternion * minuend,
|
||||||
|
|
||||||
// =============== Multiplication =============== //
|
// =============== Multiplication =============== //
|
||||||
|
|
||||||
static inline void bg_fp32_quaternion_multiply(const BgFP32Quaternion* multiplicand, const float multipier, BgFP32Quaternion* product)
|
static inline void fp32_quaternion_multiply(const fp32_quaternion_t* multiplicand, const float multipier, fp32_quaternion_t* product)
|
||||||
{
|
{
|
||||||
product->s0 = multiplicand->s0 * multipier;
|
product->s0 = multiplicand->s0 * multipier;
|
||||||
product->x1 = multiplicand->x1 * multipier;
|
product->x1 = multiplicand->x1 * multipier;
|
||||||
|
@ -469,7 +469,7 @@ static inline void bg_fp32_quaternion_multiply(const BgFP32Quaternion* multiplic
|
||||||
product->x3 = multiplicand->x3 * multipier;
|
product->x3 = multiplicand->x3 * multipier;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_quaternion_multiply(const BgFP64Quaternion* multiplicand, const double multipier, BgFP64Quaternion* product)
|
static inline void fp64_quaternion_multiply(const fp64_quaternion_t* multiplicand, const double multipier, fp64_quaternion_t* product)
|
||||||
{
|
{
|
||||||
product->s0 = multiplicand->s0 * multipier;
|
product->s0 = multiplicand->s0 * multipier;
|
||||||
product->x1 = multiplicand->x1 * multipier;
|
product->x1 = multiplicand->x1 * multipier;
|
||||||
|
@ -479,19 +479,19 @@ static inline void bg_fp64_quaternion_multiply(const BgFP64Quaternion* multiplic
|
||||||
|
|
||||||
// ================== Division ================== //
|
// ================== Division ================== //
|
||||||
|
|
||||||
static inline void bg_fp32_quaternion_divide(const BgFP32Quaternion* dividend, const float divisor, BgFP32Quaternion* quotient)
|
static inline void fp32_quaternion_divide(const fp32_quaternion_t* dividend, const float divisor, fp32_quaternion_t* quotient)
|
||||||
{
|
{
|
||||||
bg_fp32_quaternion_multiply(dividend, 1.0f / divisor, quotient);
|
fp32_quaternion_multiply(dividend, 1.0f / divisor, quotient);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_quaternion_divide(const BgFP64Quaternion* dividend, const double divisor, BgFP64Quaternion* quotient)
|
static inline void fp64_quaternion_divide(const fp64_quaternion_t* dividend, const double divisor, fp64_quaternion_t* quotient)
|
||||||
{
|
{
|
||||||
bg_fp64_quaternion_multiply(dividend, 1.0 / divisor, quotient);
|
fp64_quaternion_multiply(dividend, 1.0 / divisor, quotient);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================== Product =================== //
|
// ================== Product =================== //
|
||||||
|
|
||||||
static inline void bg_fp32_quaternion_get_product(const BgFP32Quaternion* left, const BgFP32Quaternion* right, BgFP32Quaternion* product)
|
static inline void fp32_quaternion_get_product(const fp32_quaternion_t* left, const fp32_quaternion_t* right, fp32_quaternion_t* product)
|
||||||
{
|
{
|
||||||
const float s0 = (left->s0 * right->s0 - left->x1 * right->x1) - (left->x2 * right->x2 + left->x3 * right->x3);
|
const float s0 = (left->s0 * right->s0 - left->x1 * right->x1) - (left->x2 * right->x2 + left->x3 * right->x3);
|
||||||
const float x1 = (left->x1 * right->s0 + left->s0 * right->x1) - (left->x3 * right->x2 - left->x2 * right->x3);
|
const float x1 = (left->x1 * right->s0 + left->s0 * right->x1) - (left->x3 * right->x2 - left->x2 * right->x3);
|
||||||
|
@ -504,7 +504,7 @@ static inline void bg_fp32_quaternion_get_product(const BgFP32Quaternion* left,
|
||||||
product->x3 = x3;
|
product->x3 = x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_quaternion_get_product(const BgFP64Quaternion* left, const BgFP64Quaternion* right, BgFP64Quaternion* product)
|
static inline void fp64_quaternion_get_product(const fp64_quaternion_t* left, const fp64_quaternion_t* right, fp64_quaternion_t* product)
|
||||||
{
|
{
|
||||||
const double s0 = (left->s0 * right->s0 - left->x1 * right->x1) - (left->x2 * right->x2 + left->x3 * right->x3);
|
const double s0 = (left->s0 * right->s0 - left->x1 * right->x1) - (left->x2 * right->x2 + left->x3 * right->x3);
|
||||||
const double x1 = (left->x1 * right->s0 + left->s0 * right->x1) - (left->x3 * right->x2 - left->x2 * right->x3);
|
const double x1 = (left->x1 * right->s0 + left->s0 * right->x1) - (left->x3 * right->x2 - left->x2 * right->x3);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#include "rotation3.h"
|
#include "rotation3.h"
|
||||||
|
|
||||||
const BgFP32Rotation3 BG_FP32_IDLE_ROTATION3 = { {0.0f, 0.0f, 0.0f}, 0.0f};
|
const fp32_rotation3_t FP32_IDLE_ROTATION3 = { {0.0f, 0.0f, 0.0f}, 0.0f};
|
||||||
|
|
||||||
const BgFP64Rotation3 BG_FP64_IDLE_ROTATION3 = { {0.0, 0.0, 0.0}, 0.0};
|
const fp64_rotation3_t FP64_IDLE_ROTATION3 = { {0.0, 0.0, 0.0}, 0.0};
|
||||||
|
|
|
@ -1,27 +1,27 @@
|
||||||
#ifndef _GEOMETRY_ROTATION3_H_
|
#ifndef _BASIC_GEOMETRY_ROTATION3_H_
|
||||||
#define _GEOMETRY_ROTATION3_H_
|
#define _BASIC_GEOMETRY_ROTATION3_H_
|
||||||
|
|
||||||
#include "basis.h"
|
#include "basis.h"
|
||||||
#include "angle.h"
|
#include "angle.h"
|
||||||
#include "vector3.h"
|
#include "vector3.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
BgFP32Vector3 axis;
|
fp32_vector3_t axis;
|
||||||
float radians;
|
float radians;
|
||||||
} BgFP32Rotation3;
|
} fp32_rotation3_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
BgFP64Vector3 axis;
|
fp64_vector3_t axis;
|
||||||
double radians;
|
double radians;
|
||||||
} BgFP64Rotation3;
|
} fp64_rotation3_t;
|
||||||
|
|
||||||
extern const BgFP32Rotation3 BG_FP32_IDLE_ROTATION3;
|
extern const fp32_rotation3_t FP32_IDLE_ROTATION3;
|
||||||
|
|
||||||
extern const BgFP64Rotation3 BG_FP64_IDLE_ROTATION3;
|
extern const fp64_rotation3_t FP64_IDLE_ROTATION3;
|
||||||
|
|
||||||
// =================== Reset ==================== //
|
// =================== Reset ==================== //
|
||||||
|
|
||||||
static inline void bg_fp32_rotation_reset(BgFP32Rotation3* rotation)
|
static inline void fp32_rotation_reset(fp32_rotation3_t* rotation)
|
||||||
{
|
{
|
||||||
rotation->axis.x1 = 0.0f;
|
rotation->axis.x1 = 0.0f;
|
||||||
rotation->axis.x2 = 0.0f;
|
rotation->axis.x2 = 0.0f;
|
||||||
|
@ -30,7 +30,7 @@ static inline void bg_fp32_rotation_reset(BgFP32Rotation3* rotation)
|
||||||
rotation->radians = 0.0f;
|
rotation->radians = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_rotation_reset(BgFP64Rotation3* rotation)
|
static inline void fp64_rotation_reset(fp64_rotation3_t* rotation)
|
||||||
{
|
{
|
||||||
rotation->axis.x1 = 0.0;
|
rotation->axis.x1 = 0.0;
|
||||||
rotation->axis.x2 = 0.0;
|
rotation->axis.x2 = 0.0;
|
||||||
|
@ -41,14 +41,14 @@ static inline void bg_fp64_rotation_reset(BgFP64Rotation3* rotation)
|
||||||
|
|
||||||
// ==================== Make ==================== //
|
// ==================== Make ==================== //
|
||||||
|
|
||||||
static inline void bg_fp32_rotation_set_values(const float x1, const float x2, const float x3, const float angle, const angle_unit_t unit, BgFP32Rotation3* rotation)
|
static inline void fp32_rotation_set_values(const float x1, const float x2, const float x3, const float angle, const angle_unit_t unit, fp32_rotation3_t* rotation)
|
||||||
{
|
{
|
||||||
rotation->axis.x1 = x1;
|
rotation->axis.x1 = x1;
|
||||||
rotation->axis.x2 = x2;
|
rotation->axis.x2 = x2;
|
||||||
rotation->axis.x3 = x3;
|
rotation->axis.x3 = x3;
|
||||||
|
|
||||||
if (bg_fp32_vector3_normalize(&rotation->axis)) {
|
if (fp32_vector3_normalize(&rotation->axis)) {
|
||||||
rotation->radians = bg_fp32_angle_to_radians(angle, unit);
|
rotation->radians = fp32_angle_to_radians(angle, unit);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
rotation->radians = 0.0f;
|
rotation->radians = 0.0f;
|
||||||
|
@ -56,42 +56,42 @@ static inline void bg_fp32_rotation_set_values(const float x1, const float x2, c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline void bg_fp64_rotation_set_values(const double x1, const double x2, const double x3, const double angle, const angle_unit_t unit, BgFP64Rotation3* rotation)
|
static inline void fp64_rotation_set_values(const double x1, const double x2, const double x3, const double angle, const angle_unit_t unit, fp64_rotation3_t* rotation)
|
||||||
{
|
{
|
||||||
rotation->axis.x1 = x1;
|
rotation->axis.x1 = x1;
|
||||||
rotation->axis.x2 = x2;
|
rotation->axis.x2 = x2;
|
||||||
rotation->axis.x3 = x3;
|
rotation->axis.x3 = x3;
|
||||||
|
|
||||||
if (bg_fp64_vector3_normalize(&rotation->axis)) {
|
if (fp64_vector3_normalize(&rotation->axis)) {
|
||||||
rotation->radians = bg_fp64_angle_to_radians(angle, unit);
|
rotation->radians = fp64_angle_to_radians(angle, unit);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
rotation->radians = 0.0;
|
rotation->radians = 0.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp32_rotation_set_with_axis(const BgFP32Vector3* axis, const float angle, const angle_unit_t unit, BgFP32Rotation3* rotation)
|
static inline void fp32_rotation_set_with_axis(const fp32_vector3_t* axis, const float angle, const angle_unit_t unit, fp32_rotation3_t* rotation)
|
||||||
{
|
{
|
||||||
rotation->axis.x1 = axis->x1;
|
rotation->axis.x1 = axis->x1;
|
||||||
rotation->axis.x2 = axis->x2;
|
rotation->axis.x2 = axis->x2;
|
||||||
rotation->axis.x3 = axis->x3;
|
rotation->axis.x3 = axis->x3;
|
||||||
|
|
||||||
if (bg_fp32_vector3_normalize(&rotation->axis)) {
|
if (fp32_vector3_normalize(&rotation->axis)) {
|
||||||
rotation->radians = bg_fp32_angle_to_radians(angle, unit);
|
rotation->radians = fp32_angle_to_radians(angle, unit);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
rotation->radians = 0.0f;
|
rotation->radians = 0.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_rotation_set_with_axis(const BgFP64Vector3* axis, const double angle, const angle_unit_t unit, BgFP64Rotation3* rotation)
|
static inline void fp64_rotation_set_with_axis(const fp64_vector3_t* axis, const double angle, const angle_unit_t unit, fp64_rotation3_t* rotation)
|
||||||
{
|
{
|
||||||
rotation->axis.x1 = axis->x1;
|
rotation->axis.x1 = axis->x1;
|
||||||
rotation->axis.x2 = axis->x2;
|
rotation->axis.x2 = axis->x2;
|
||||||
rotation->axis.x3 = axis->x3;
|
rotation->axis.x3 = axis->x3;
|
||||||
|
|
||||||
if (bg_fp64_vector3_normalize(&rotation->axis)) {
|
if (fp64_vector3_normalize(&rotation->axis)) {
|
||||||
rotation->radians = bg_fp64_angle_to_radians(angle, unit);
|
rotation->radians = fp64_angle_to_radians(angle, unit);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
rotation->radians = 0.0;
|
rotation->radians = 0.0;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#include "tangent.h"
|
#include "tangent.h"
|
||||||
|
|
||||||
const BgFP32Tangent BG_FP32_IDLE_TANGENT = { 1.0f, 0.0f };
|
const fp32_tangent_t FP32_IDLE_TANGENT = { 1.0f, 0.0f };
|
||||||
|
|
||||||
const BgFP64Tangent BG_FP64_IDLE_TANGENT = { 1.0, 0.0 };
|
const fp64_tangent_t FP64_IDLE_TANGENT = { 1.0, 0.0 };
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#ifndef _GEOMETRY_TANGENT_H_
|
#ifndef _BASIC_GEOMETRY_TANGENT_H_
|
||||||
#define _GEOMETRY_TANGENT_H_
|
#define _BASIC_GEOMETRY_TANGENT_H_
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
@ -13,12 +13,12 @@
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
const float cos, sin;
|
const float cos, sin;
|
||||||
} BgFP32Tangent;
|
} fp32_tangent_t;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
const double cos, sin;
|
const double cos, sin;
|
||||||
} BgFP64Tangent;
|
} fp64_tangent_t;
|
||||||
|
|
||||||
// ================= Dark Twins ================= //
|
// ================= Dark Twins ================= //
|
||||||
|
|
||||||
|
@ -32,12 +32,12 @@ typedef struct {
|
||||||
|
|
||||||
// ================= Constants ================== //
|
// ================= Constants ================== //
|
||||||
|
|
||||||
extern const BgFP32Tangent BG_FP32_IDLE_TANGENT;
|
extern const fp32_tangent_t FP32_IDLE_TANGENT;
|
||||||
extern const BgFP64Tangent BG_FP64_IDLE_TANGENT;
|
extern const fp64_tangent_t FP64_IDLE_TANGENT;
|
||||||
|
|
||||||
// =================== Reset ==================== //
|
// =================== Reset ==================== //
|
||||||
|
|
||||||
static inline void bg_fp32_tangent_reset(BgFP32Tangent* tangent)
|
static inline void fp32_tangent_reset(fp32_tangent_t* tangent)
|
||||||
{
|
{
|
||||||
__BgFP32DarkTwinTangent* twin = (__BgFP32DarkTwinTangent*)tangent;
|
__BgFP32DarkTwinTangent* twin = (__BgFP32DarkTwinTangent*)tangent;
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ static inline void bg_fp32_tangent_reset(BgFP32Tangent* tangent)
|
||||||
twin->sin = 0.0f;
|
twin->sin = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_tangent_reset(BgFP64Tangent* tangent)
|
static inline void fp64_tangent_reset(fp64_tangent_t* tangent)
|
||||||
{
|
{
|
||||||
__BgFP64DarkTwinTangent* twin = (__BgFP64DarkTwinTangent*)tangent;
|
__BgFP64DarkTwinTangent* twin = (__BgFP64DarkTwinTangent*)tangent;
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ static inline void bg_fp64_tangent_reset(BgFP64Tangent* tangent)
|
||||||
|
|
||||||
// ==================== Set ===================== //
|
// ==================== Set ===================== //
|
||||||
|
|
||||||
static inline void bg_fp32_tangent_set_values(const float x1, const float x2, BgFP32Tangent* tangent)
|
static inline void fp32_tangent_set_values(const float x1, const float x2, fp32_tangent_t* tangent)
|
||||||
{
|
{
|
||||||
const float square_module = x1 * x1 + x2 * x2;
|
const float square_module = x1 * x1 + x2 * x2;
|
||||||
|
|
||||||
|
@ -64,11 +64,11 @@ static inline void bg_fp32_tangent_set_values(const float x1, const float x2, Bg
|
||||||
twin->cos = x1;
|
twin->cos = x1;
|
||||||
twin->sin = x2;
|
twin->sin = x2;
|
||||||
|
|
||||||
if (1.0f - BG_FP32_TWO_EPSYLON <= square_module && square_module <= 1.0f + BG_FP32_TWO_EPSYLON) {
|
if (1.0f - FP32_TWO_EPSYLON <= square_module && square_module <= 1.0f + FP32_TWO_EPSYLON) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (square_module <= BG_FP32_SQUARE_EPSYLON) {
|
if (square_module <= FP32_SQUARE_EPSYLON) {
|
||||||
twin->cos = 1.0f;
|
twin->cos = 1.0f;
|
||||||
twin->sin = 0.0f;
|
twin->sin = 0.0f;
|
||||||
return;
|
return;
|
||||||
|
@ -80,7 +80,7 @@ static inline void bg_fp32_tangent_set_values(const float x1, const float x2, Bg
|
||||||
twin->sin = x2 * multiplier;
|
twin->sin = x2 * multiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_tangent_set_values(const double x1, const double x2, BgFP64Tangent* tangent)
|
static inline void fp64_tangent_set_values(const double x1, const double x2, fp64_tangent_t* tangent)
|
||||||
{
|
{
|
||||||
const double square_module = x1 * x1 + x2 * x2;
|
const double square_module = x1 * x1 + x2 * x2;
|
||||||
|
|
||||||
|
@ -89,11 +89,11 @@ static inline void bg_fp64_tangent_set_values(const double x1, const double x2,
|
||||||
twin->cos = x1;
|
twin->cos = x1;
|
||||||
twin->sin = x2;
|
twin->sin = x2;
|
||||||
|
|
||||||
if (1.0 - BG_FP64_TWO_EPSYLON <= square_module && square_module <= 1.0 + BG_FP64_TWO_EPSYLON) {
|
if (1.0 - FP64_TWO_EPSYLON <= square_module && square_module <= 1.0 + FP64_TWO_EPSYLON) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (square_module <= BG_FP64_SQUARE_EPSYLON) {
|
if (square_module <= FP64_SQUARE_EPSYLON) {
|
||||||
twin->cos = 1.0;
|
twin->cos = 1.0;
|
||||||
twin->sin = 0.0;
|
twin->sin = 0.0;
|
||||||
return;
|
return;
|
||||||
|
@ -107,7 +107,7 @@ static inline void bg_fp64_tangent_set_values(const double x1, const double x2,
|
||||||
|
|
||||||
// ==================== Copy ==================== //
|
// ==================== Copy ==================== //
|
||||||
|
|
||||||
static inline void bg_fp32_tangent_copy(const BgFP32Tangent* from, BgFP32Tangent* to)
|
static inline void fp32_tangent_copy(const fp32_tangent_t* from, fp32_tangent_t* to)
|
||||||
{
|
{
|
||||||
__BgFP32DarkTwinTangent* twin = (__BgFP32DarkTwinTangent*)to;
|
__BgFP32DarkTwinTangent* twin = (__BgFP32DarkTwinTangent*)to;
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ static inline void bg_fp32_tangent_copy(const BgFP32Tangent* from, BgFP32Tangent
|
||||||
twin->sin = from->sin;
|
twin->sin = from->sin;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_tangent_copy(const BgFP64Tangent* from, BgFP64Tangent* to)
|
static inline void fp64_tangent_copy(const fp64_tangent_t* from, fp64_tangent_t* to)
|
||||||
{
|
{
|
||||||
__BgFP64DarkTwinTangent* twin = (__BgFP64DarkTwinTangent*)to;
|
__BgFP64DarkTwinTangent* twin = (__BgFP64DarkTwinTangent*)to;
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ static inline void bg_fp64_tangent_copy(const BgFP64Tangent* from, BgFP64Tangent
|
||||||
|
|
||||||
// ==================== Swap ==================== //
|
// ==================== Swap ==================== //
|
||||||
|
|
||||||
static inline void bg_fp32_tangent_swap(BgFP32Tangent* tangent1, BgFP32Tangent* tangent2)
|
static inline void fp32_tangent_swap(fp32_tangent_t* tangent1, fp32_tangent_t* tangent2)
|
||||||
{
|
{
|
||||||
const float cos = tangent1->cos;
|
const float cos = tangent1->cos;
|
||||||
const float sin = tangent1->sin;
|
const float sin = tangent1->sin;
|
||||||
|
@ -141,7 +141,7 @@ static inline void bg_fp32_tangent_swap(BgFP32Tangent* tangent1, BgFP32Tangent*
|
||||||
twin2->sin = sin;
|
twin2->sin = sin;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_tangent_swap(BgFP64Tangent* tangent1, BgFP64Tangent* tangent2)
|
static inline void fp64_tangent_swap(fp64_tangent_t* tangent1, fp64_tangent_t* tangent2)
|
||||||
{
|
{
|
||||||
const double cos = tangent1->cos;
|
const double cos = tangent1->cos;
|
||||||
const double sin = tangent1->sin;
|
const double sin = tangent1->sin;
|
||||||
|
@ -159,9 +159,9 @@ static inline void bg_fp64_tangent_swap(BgFP64Tangent* tangent1, BgFP64Tangent*
|
||||||
|
|
||||||
// ================== Set Turn ================== //
|
// ================== Set Turn ================== //
|
||||||
|
|
||||||
static inline void bg_fp32_tangent_set_turn(const float angle, const angle_unit_t unit, BgFP32Tangent* tangent)
|
static inline void fp32_tangent_set_turn(const float angle, const angle_unit_t unit, fp32_tangent_t* tangent)
|
||||||
{
|
{
|
||||||
const float radians = bg_fp32_angle_to_radians(angle, unit);
|
const float radians = fp32_angle_to_radians(angle, unit);
|
||||||
|
|
||||||
__BgFP32DarkTwinTangent* twin = (__BgFP32DarkTwinTangent*)tangent;
|
__BgFP32DarkTwinTangent* twin = (__BgFP32DarkTwinTangent*)tangent;
|
||||||
|
|
||||||
|
@ -169,9 +169,9 @@ static inline void bg_fp32_tangent_set_turn(const float angle, const angle_unit_
|
||||||
twin->sin = sinf(radians);
|
twin->sin = sinf(radians);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_tangent_set_turn(const double angle, const angle_unit_t unit, BgFP64Tangent* tangent)
|
static inline void fp64_tangent_set_turn(const double angle, const angle_unit_t unit, fp64_tangent_t* tangent)
|
||||||
{
|
{
|
||||||
const double radians = bg_fp64_angle_to_radians(angle, unit);
|
const double radians = fp64_angle_to_radians(angle, unit);
|
||||||
|
|
||||||
__BgFP64DarkTwinTangent* twin = (__BgFP64DarkTwinTangent*)tangent;
|
__BgFP64DarkTwinTangent* twin = (__BgFP64DarkTwinTangent*)tangent;
|
||||||
|
|
||||||
|
@ -181,31 +181,31 @@ static inline void bg_fp64_tangent_set_turn(const double angle, const angle_unit
|
||||||
|
|
||||||
// ============= Copy to twin type ============== //
|
// ============= Copy to twin type ============== //
|
||||||
|
|
||||||
static inline void bg_fp32_tangent_set_from_fp64(const BgFP64Tangent* from, BgFP32Tangent* to)
|
static inline void fp32_tangent_set_from_fp64(const fp64_tangent_t* from, fp32_tangent_t* to)
|
||||||
{
|
{
|
||||||
bg_fp32_tangent_set_values((float)from->cos, (float)from->sin, to);
|
fp32_tangent_set_values((float)from->cos, (float)from->sin, to);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_tangent_set_from_fp32(const BgFP32Tangent* from, BgFP64Tangent* to)
|
static inline void fp64_tangent_set_from_fp32(const fp32_tangent_t* from, fp64_tangent_t* to)
|
||||||
{
|
{
|
||||||
bg_fp64_tangent_set_values((double)from->cos, (double)from->sin, to);
|
fp64_tangent_set_values((double)from->cos, (double)from->sin, to);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================= Inversion ================== //
|
// ================= Inversion ================== //
|
||||||
|
|
||||||
static inline void bg_fp32_tangent_invert(BgFP32Tangent* tangent)
|
static inline void fp32_tangent_invert(fp32_tangent_t* tangent)
|
||||||
{
|
{
|
||||||
((__BgFP32DarkTwinTangent*)tangent)->sin = -tangent->sin;
|
((__BgFP32DarkTwinTangent*)tangent)->sin = -tangent->sin;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_tangent_invert(BgFP64Tangent* tangent)
|
static inline void fp64_tangent_invert(fp64_tangent_t* tangent)
|
||||||
{
|
{
|
||||||
((__BgFP64DarkTwinTangent*)tangent)->sin = -tangent->sin;
|
((__BgFP64DarkTwinTangent*)tangent)->sin = -tangent->sin;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================ Set Inverted ================ //
|
// ================ Set Inverted ================ //
|
||||||
|
|
||||||
static inline void bg_fp32_tangent_set_inverted(const BgFP32Tangent* tangent, BgFP32Tangent* result)
|
static inline void fp32_tangent_set_inverted(const fp32_tangent_t* tangent, fp32_tangent_t* result)
|
||||||
{
|
{
|
||||||
__BgFP32DarkTwinTangent* twin = (__BgFP32DarkTwinTangent*)result;
|
__BgFP32DarkTwinTangent* twin = (__BgFP32DarkTwinTangent*)result;
|
||||||
|
|
||||||
|
@ -213,7 +213,7 @@ static inline void bg_fp32_tangent_set_inverted(const BgFP32Tangent* tangent, Bg
|
||||||
twin->sin = -tangent->sin;
|
twin->sin = -tangent->sin;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_tangent_set_inverted(const BgFP64Tangent* tangent, BgFP64Tangent* result)
|
static inline void fp64_tangent_set_inverted(const fp64_tangent_t* tangent, fp64_tangent_t* result)
|
||||||
{
|
{
|
||||||
__BgFP64DarkTwinTangent* twin = (__BgFP64DarkTwinTangent*)result;
|
__BgFP64DarkTwinTangent* twin = (__BgFP64DarkTwinTangent*)result;
|
||||||
|
|
||||||
|
@ -223,7 +223,7 @@ static inline void bg_fp64_tangent_set_inverted(const BgFP64Tangent* tangent, Bg
|
||||||
|
|
||||||
// ============== Rotation Matrix =============== //
|
// ============== Rotation Matrix =============== //
|
||||||
|
|
||||||
static inline void bg_fp32_tangent_make_rotation_matrix(const BgFP32Tangent* tangent, BgFP32Matrix2x2* matrix)
|
static inline void fp32_tangent_make_rotation_matrix(const fp32_tangent_t* tangent, fp32_matrix2x2_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c1 = tangent->cos;
|
matrix->r1c1 = tangent->cos;
|
||||||
matrix->r1c2 = -tangent->sin;
|
matrix->r1c2 = -tangent->sin;
|
||||||
|
@ -231,7 +231,7 @@ static inline void bg_fp32_tangent_make_rotation_matrix(const BgFP32Tangent* tan
|
||||||
matrix->r2c2 = tangent->cos;
|
matrix->r2c2 = tangent->cos;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_tangent_make_rotation_matrix(const BgFP64Tangent* tangent, BgFP64Matrix2x2* matrix)
|
static inline void fp64_tangent_make_rotation_matrix(const fp64_tangent_t* tangent, fp64_matrix2x2_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c1 = tangent->cos;
|
matrix->r1c1 = tangent->cos;
|
||||||
matrix->r1c2 = -tangent->sin;
|
matrix->r1c2 = -tangent->sin;
|
||||||
|
@ -241,7 +241,7 @@ static inline void bg_fp64_tangent_make_rotation_matrix(const BgFP64Tangent* tan
|
||||||
|
|
||||||
// ============== Reverse Matrix ================ //
|
// ============== Reverse Matrix ================ //
|
||||||
|
|
||||||
static inline void bg_fp32_tangent_make_reverse_matrix(const BgFP32Tangent* tangent, BgFP32Matrix2x2* matrix)
|
static inline void fp32_tangent_make_reverse_matrix(const fp32_tangent_t* tangent, fp32_matrix2x2_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c1 = tangent->cos;
|
matrix->r1c1 = tangent->cos;
|
||||||
matrix->r1c2 = tangent->sin;
|
matrix->r1c2 = tangent->sin;
|
||||||
|
@ -249,7 +249,7 @@ static inline void bg_fp32_tangent_make_reverse_matrix(const BgFP32Tangent* tang
|
||||||
matrix->r2c2 = tangent->cos;
|
matrix->r2c2 = tangent->cos;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_tangent_make_reverse_matrix(const BgFP64Tangent* tangent, BgFP64Matrix2x2* matrix)
|
static inline void fp64_tangent_make_reverse_matrix(const fp64_tangent_t* tangent, fp64_matrix2x2_t* matrix)
|
||||||
{
|
{
|
||||||
matrix->r1c1 = tangent->cos;
|
matrix->r1c1 = tangent->cos;
|
||||||
matrix->r1c2 = tangent->sin;
|
matrix->r1c2 = tangent->sin;
|
||||||
|
@ -259,62 +259,62 @@ static inline void bg_fp64_tangent_make_reverse_matrix(const BgFP64Tangent* tang
|
||||||
|
|
||||||
// =================== Angle =================== //
|
// =================== Angle =================== //
|
||||||
|
|
||||||
static inline float bg_fp32_tangent_get_angle(const BgFP32Tangent* tangent, const angle_unit_t unit)
|
static inline float fp32_tangent_get_angle(const fp32_tangent_t* tangent, const angle_unit_t unit)
|
||||||
{
|
{
|
||||||
if (tangent->cos >= 1.0f - BG_FP32_TWO_EPSYLON) {
|
if (tangent->cos >= 1.0f - FP32_TWO_EPSYLON) {
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tangent->cos <= -1.0f + BG_FP32_TWO_EPSYLON) {
|
if (tangent->cos <= -1.0f + FP32_TWO_EPSYLON) {
|
||||||
return bg_fp32_angle_get_half_circle(unit);
|
return fp32_angle_get_half_circle(unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tangent->sin >= 1.0f - BG_FP32_TWO_EPSYLON) {
|
if (tangent->sin >= 1.0f - FP32_TWO_EPSYLON) {
|
||||||
return bg_fp32_angle_get_quater_circle(unit);
|
return fp32_angle_get_quater_circle(unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tangent->sin <= -1.0f + BG_FP32_TWO_EPSYLON) {
|
if (tangent->sin <= -1.0f + FP32_TWO_EPSYLON) {
|
||||||
return 0.75f * bg_fp32_angle_get_full_circle(unit);
|
return 0.75f * fp32_angle_get_full_circle(unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
return bg_fp32_radians_to_units(atan2f(tangent->cos, tangent->sin), unit);
|
return fp32_radians_to_units(atan2f(tangent->cos, tangent->sin), unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline double bg_fp64_tangent_get_angle(const BgFP64Tangent* tangent, const angle_unit_t unit)
|
static inline double fp64_tangent_get_angle(const fp64_tangent_t* tangent, const angle_unit_t unit)
|
||||||
{
|
{
|
||||||
if (tangent->cos >= 1.0 - BG_FP64_TWO_EPSYLON) {
|
if (tangent->cos >= 1.0 - FP64_TWO_EPSYLON) {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tangent->cos <= -1.0 + BG_FP64_TWO_EPSYLON) {
|
if (tangent->cos <= -1.0 + FP64_TWO_EPSYLON) {
|
||||||
return bg_fp64_angle_get_half_circle(unit);
|
return fp64_angle_get_half_circle(unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tangent->sin >= 1.0 - BG_FP64_TWO_EPSYLON) {
|
if (tangent->sin >= 1.0 - FP64_TWO_EPSYLON) {
|
||||||
return bg_fp64_angle_get_quater_circle(unit);
|
return fp64_angle_get_quater_circle(unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tangent->sin <= -1.0 + BG_FP64_TWO_EPSYLON) {
|
if (tangent->sin <= -1.0 + FP64_TWO_EPSYLON) {
|
||||||
return 0.75 * bg_fp64_angle_get_full_circle(unit);
|
return 0.75 * fp64_angle_get_full_circle(unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
return bg_fp64_radians_to_units(atan2(tangent->cos, tangent->sin), unit);
|
return fp64_radians_to_units(atan2(tangent->cos, tangent->sin), unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================ Combination ================= //
|
// ================ Combination ================= //
|
||||||
|
|
||||||
static inline void bg_fp32_tangent_combine(const BgFP32Tangent* tangent1, const BgFP32Tangent* tangent2, BgFP32Tangent* result)
|
static inline void fp32_tangent_combine(const fp32_tangent_t* tangent1, const fp32_tangent_t* tangent2, fp32_tangent_t* result)
|
||||||
{
|
{
|
||||||
bg_fp32_tangent_set_values(
|
fp32_tangent_set_values(
|
||||||
tangent1->cos * tangent2->cos - tangent1->sin * tangent2->sin,
|
tangent1->cos * tangent2->cos - tangent1->sin * tangent2->sin,
|
||||||
tangent1->cos * tangent2->sin + tangent1->sin * tangent2->cos,
|
tangent1->cos * tangent2->sin + tangent1->sin * tangent2->cos,
|
||||||
result
|
result
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_tangent_combine(const BgFP64Tangent* tangent1, const BgFP64Tangent* tangent2, BgFP64Tangent* result)
|
static inline void fp64_tangent_combine(const fp64_tangent_t* tangent1, const fp64_tangent_t* tangent2, fp64_tangent_t* result)
|
||||||
{
|
{
|
||||||
bg_fp64_tangent_set_values(
|
fp64_tangent_set_values(
|
||||||
tangent1->cos * tangent2->cos - tangent1->sin * tangent2->sin,
|
tangent1->cos * tangent2->cos - tangent1->sin * tangent2->sin,
|
||||||
tangent1->cos * tangent2->sin + tangent1->sin * tangent2->cos,
|
tangent1->cos * tangent2->sin + tangent1->sin * tangent2->cos,
|
||||||
result
|
result
|
||||||
|
@ -323,7 +323,7 @@ static inline void bg_fp64_tangent_combine(const BgFP64Tangent* tangent1, const
|
||||||
|
|
||||||
// ================ Turn Vector ================= //
|
// ================ Turn Vector ================= //
|
||||||
|
|
||||||
static inline void bg_fp32_tangent_turn(const BgFP32Tangent* tangent, const BgFP32Vector2* vector, BgFP32Vector2* result)
|
static inline void fp32_tangent_turn(const fp32_tangent_t* tangent, const fp32_vector2_t* vector, fp32_vector2_t* result)
|
||||||
{
|
{
|
||||||
const float x1 = tangent->cos * vector->x1 - tangent->sin * vector->x2;
|
const float x1 = tangent->cos * vector->x1 - tangent->sin * vector->x2;
|
||||||
const float x2 = tangent->sin * vector->x1 + tangent->cos * vector->x2;
|
const float x2 = tangent->sin * vector->x1 + tangent->cos * vector->x2;
|
||||||
|
@ -332,7 +332,7 @@ static inline void bg_fp32_tangent_turn(const BgFP32Tangent* tangent, const BgFP
|
||||||
result->x2 = x2;
|
result->x2 = x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_tangent_turn(const BgFP64Tangent* tangent, const BgFP64Vector2* vector, BgFP64Vector2* result)
|
static inline void fp64_tangent_turn(const fp64_tangent_t* tangent, const fp64_vector2_t* vector, fp64_vector2_t* result)
|
||||||
{
|
{
|
||||||
const double x1 = tangent->cos * vector->x1 - tangent->sin * vector->x2;
|
const double x1 = tangent->cos * vector->x1 - tangent->sin * vector->x2;
|
||||||
const double x2 = tangent->sin * vector->x1 + tangent->cos * vector->x2;
|
const double x2 = tangent->sin * vector->x1 + tangent->cos * vector->x2;
|
||||||
|
@ -343,7 +343,7 @@ static inline void bg_fp64_tangent_turn(const BgFP64Tangent* tangent, const BgFP
|
||||||
|
|
||||||
// ============ Turn Vector Backward ============ //
|
// ============ Turn Vector Backward ============ //
|
||||||
|
|
||||||
static inline void bg_fp32_tangent_turn_back(const BgFP32Tangent* tangent, const BgFP32Vector2* vector, BgFP32Vector2* result)
|
static inline void fp32_tangent_turn_back(const fp32_tangent_t* tangent, const fp32_vector2_t* vector, fp32_vector2_t* result)
|
||||||
{
|
{
|
||||||
const float x1 = tangent->sin * vector->x2 + tangent->cos * vector->x1;
|
const float x1 = tangent->sin * vector->x2 + tangent->cos * vector->x1;
|
||||||
const float x2 = tangent->cos * vector->x2 - tangent->sin * vector->x1;
|
const float x2 = tangent->cos * vector->x2 - tangent->sin * vector->x1;
|
||||||
|
@ -352,7 +352,7 @@ static inline void bg_fp32_tangent_turn_back(const BgFP32Tangent* tangent, const
|
||||||
result->x2 = x2;
|
result->x2 = x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_tangent_turn_back(const BgFP64Tangent* tangent, const BgFP64Vector2* vector, BgFP64Vector2* result)
|
static inline void fp64_tangent_turn_back(const fp64_tangent_t* tangent, const fp64_vector2_t* vector, fp64_vector2_t* result)
|
||||||
{
|
{
|
||||||
const double x1 = tangent->sin * vector->x2 + tangent->cos * vector->x1;
|
const double x1 = tangent->sin * vector->x2 + tangent->cos * vector->x1;
|
||||||
const double x2 = tangent->cos * vector->x2 - tangent->sin * vector->x1;
|
const double x2 = tangent->cos * vector->x2 - tangent->sin * vector->x1;
|
||||||
|
|
|
@ -2,64 +2,64 @@
|
||||||
|
|
||||||
// =================== Angle ==================== //
|
// =================== Angle ==================== //
|
||||||
|
|
||||||
float bg_fp32_vector2_get_angle(const BgFP32Vector2* vector1, const BgFP32Vector2* vector2, const angle_unit_t unit)
|
float fp32_vector2_get_angle(const fp32_vector2_t* vector1, const fp32_vector2_t* vector2, const angle_unit_t unit)
|
||||||
{
|
{
|
||||||
if (vector1 == 0 || vector2 == 0) {
|
if (vector1 == 0 || vector2 == 0) {
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
const float square_modulus1 = bg_fp32_vector2_get_square_modulus(vector1);
|
const float square_modulus1 = fp32_vector2_get_square_modulus(vector1);
|
||||||
|
|
||||||
if (square_modulus1 <= BG_FP32_SQUARE_EPSYLON) {
|
if (square_modulus1 <= FP32_SQUARE_EPSYLON) {
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
const float square_modulus2 = bg_fp32_vector2_get_square_modulus(vector2);
|
const float square_modulus2 = fp32_vector2_get_square_modulus(vector2);
|
||||||
|
|
||||||
if (square_modulus2 <= BG_FP32_SQUARE_EPSYLON) {
|
if (square_modulus2 <= FP32_SQUARE_EPSYLON) {
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
const float cosine = bg_fp32_vector2_scalar_product(vector1, vector2) / sqrtf(square_modulus1 * square_modulus2);
|
const float cosine = fp32_vector2_scalar_product(vector1, vector2) / sqrtf(square_modulus1 * square_modulus2);
|
||||||
|
|
||||||
if (cosine >= 1.0f - BG_FP32_EPSYLON) {
|
if (cosine >= 1.0f - FP32_EPSYLON) {
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cosine <= -1.0f + BG_FP32_EPSYLON) {
|
if (cosine <= -1.0f + FP32_EPSYLON) {
|
||||||
return bg_fp32_angle_get_half_circle(unit);
|
return fp32_angle_get_half_circle(unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
return bg_fp32_radians_to_units(acosf(cosine), unit);
|
return fp32_radians_to_units(acosf(cosine), unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
double bg_fp64_vector2_get_angle(const BgFP64Vector2* vector1, const BgFP64Vector2* vector2, const angle_unit_t unit)
|
double fp64_vector2_get_angle(const fp64_vector2_t* vector1, const fp64_vector2_t* vector2, const angle_unit_t unit)
|
||||||
{
|
{
|
||||||
if (vector1 == 0 || vector2 == 0) {
|
if (vector1 == 0 || vector2 == 0) {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const double square_modulus1 = bg_fp64_vector2_get_square_modulus(vector1);
|
const double square_modulus1 = fp64_vector2_get_square_modulus(vector1);
|
||||||
|
|
||||||
if (square_modulus1 <= BG_FP64_SQUARE_EPSYLON) {
|
if (square_modulus1 <= FP64_SQUARE_EPSYLON) {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const double square_modulus2 = bg_fp64_vector2_get_square_modulus(vector2);
|
const double square_modulus2 = fp64_vector2_get_square_modulus(vector2);
|
||||||
|
|
||||||
if (square_modulus2 <= BG_FP64_SQUARE_EPSYLON) {
|
if (square_modulus2 <= FP64_SQUARE_EPSYLON) {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const double cosine = bg_fp64_vector2_scalar_product(vector1, vector2) / sqrt(square_modulus1 * square_modulus2);
|
const double cosine = fp64_vector2_scalar_product(vector1, vector2) / sqrt(square_modulus1 * square_modulus2);
|
||||||
|
|
||||||
if (cosine >= 1.0 - BG_FP64_EPSYLON) {
|
if (cosine >= 1.0 - FP64_EPSYLON) {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cosine <= -1.0 + BG_FP64_EPSYLON) {
|
if (cosine <= -1.0 + FP64_EPSYLON) {
|
||||||
return bg_fp64_angle_get_half_circle(unit);
|
return fp64_angle_get_half_circle(unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
return bg_fp64_radians_to_units(acos(cosine), unit);
|
return fp64_radians_to_units(acos(cosine), unit);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#ifndef _GEOMETRY_VECTOR2_H_
|
#ifndef _BASIC_GEOMETRY_VECTOR2_H_
|
||||||
#define _GEOMETRY_VECTOR2_H_
|
#define _BASIC_GEOMETRY_VECTOR2_H_
|
||||||
|
|
||||||
#include "basis.h"
|
#include "basis.h"
|
||||||
#include "angle.h"
|
#include "angle.h"
|
||||||
|
@ -9,22 +9,22 @@
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
float x1, x2;
|
float x1, x2;
|
||||||
} BgFP32Vector2;
|
} fp32_vector2_t;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
double x1, x2;
|
double x1, x2;
|
||||||
} BgFP64Vector2;
|
} fp64_vector2_t;
|
||||||
|
|
||||||
// =================== Reset ==================== //
|
// =================== Reset ==================== //
|
||||||
|
|
||||||
static inline void bg_fp32_vector2_reset(BgFP32Vector2* vector)
|
static inline void fp32_vector2_reset(fp32_vector2_t* vector)
|
||||||
{
|
{
|
||||||
vector->x1 = 0.0f;
|
vector->x1 = 0.0f;
|
||||||
vector->x2 = 0.0f;
|
vector->x2 = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_vector2_reset(BgFP64Vector2* vector)
|
static inline void fp64_vector2_reset(fp64_vector2_t* vector)
|
||||||
{
|
{
|
||||||
vector->x1 = 0.0;
|
vector->x1 = 0.0;
|
||||||
vector->x2 = 0.0;
|
vector->x2 = 0.0;
|
||||||
|
@ -32,13 +32,13 @@ static inline void bg_fp64_vector2_reset(BgFP64Vector2* vector)
|
||||||
|
|
||||||
// ==================== Set ===================== //
|
// ==================== Set ===================== //
|
||||||
|
|
||||||
static inline void bg_fp32_vector2_set_values(const float x1, const float x2, BgFP32Vector2* to)
|
static inline void fp32_vector2_set_values(const float x1, const float x2, fp32_vector2_t* to)
|
||||||
{
|
{
|
||||||
to->x1 = x1;
|
to->x1 = x1;
|
||||||
to->x2 = x2;
|
to->x2 = x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_vector2_set_values(const double x1, const double x2, BgFP64Vector2* to)
|
static inline void fp64_vector2_set_values(const double x1, const double x2, fp64_vector2_t* to)
|
||||||
{
|
{
|
||||||
to->x1 = x1;
|
to->x1 = x1;
|
||||||
to->x2 = x2;
|
to->x2 = x2;
|
||||||
|
@ -46,13 +46,13 @@ static inline void bg_fp64_vector2_set_values(const double x1, const double x2,
|
||||||
|
|
||||||
// ==================== Copy ==================== //
|
// ==================== Copy ==================== //
|
||||||
|
|
||||||
static inline void bg_fp32_vector2_copy(const BgFP32Vector2* from, BgFP32Vector2* to)
|
static inline void fp32_vector2_copy(const fp32_vector2_t* from, fp32_vector2_t* to)
|
||||||
{
|
{
|
||||||
to->x1 = from->x1;
|
to->x1 = from->x1;
|
||||||
to->x2 = from->x2;
|
to->x2 = from->x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_vector2_copy(const BgFP64Vector2* from, BgFP64Vector2* to)
|
static inline void fp64_vector2_copy(const fp64_vector2_t* from, fp64_vector2_t* to)
|
||||||
{
|
{
|
||||||
to->x1 = from->x1;
|
to->x1 = from->x1;
|
||||||
to->x2 = from->x2;
|
to->x2 = from->x2;
|
||||||
|
@ -60,7 +60,7 @@ static inline void bg_fp64_vector2_copy(const BgFP64Vector2* from, BgFP64Vector2
|
||||||
|
|
||||||
// ==================== Swap ==================== //
|
// ==================== Swap ==================== //
|
||||||
|
|
||||||
static inline void bg_fp32_vector2_swap(BgFP32Vector2* vector1, BgFP32Vector2* vector2)
|
static inline void fp32_vector2_swap(fp32_vector2_t* vector1, fp32_vector2_t* vector2)
|
||||||
{
|
{
|
||||||
const float x1 = vector2->x1;
|
const float x1 = vector2->x1;
|
||||||
const float x2 = vector2->x2;
|
const float x2 = vector2->x2;
|
||||||
|
@ -72,7 +72,7 @@ static inline void bg_fp32_vector2_swap(BgFP32Vector2* vector1, BgFP32Vector2* v
|
||||||
vector1->x2 = x2;
|
vector1->x2 = x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_vector2_swap(BgFP64Vector2* vector1, BgFP64Vector2* vector2)
|
static inline void fp64_vector2_swap(fp64_vector2_t* vector1, fp64_vector2_t* vector2)
|
||||||
{
|
{
|
||||||
const double x1 = vector2->x1;
|
const double x1 = vector2->x1;
|
||||||
const double x2 = vector2->x2;
|
const double x2 = vector2->x2;
|
||||||
|
@ -86,13 +86,13 @@ static inline void bg_fp64_vector2_swap(BgFP64Vector2* vector1, BgFP64Vector2* v
|
||||||
|
|
||||||
// ============= Copy to twin type ============== //
|
// ============= Copy to twin type ============== //
|
||||||
|
|
||||||
static inline void bg_fp32_vector2_set_from_fp64(const BgFP64Vector2* from, BgFP32Vector2* to)
|
static inline void fp32_vector2_set_from_fp64(const fp64_vector2_t* from, fp32_vector2_t* to)
|
||||||
{
|
{
|
||||||
to->x1 = (float)from->x1;
|
to->x1 = (float)from->x1;
|
||||||
to->x2 = (float)from->x2;
|
to->x2 = (float)from->x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_vector2_set_from_fp32(const BgFP32Vector2* from, BgFP64Vector2* to)
|
static inline void fp64_vector2_set_from_fp32(const fp32_vector2_t* from, fp64_vector2_t* to)
|
||||||
{
|
{
|
||||||
to->x1 = from->x1;
|
to->x1 = from->x1;
|
||||||
to->x2 = from->x2;
|
to->x2 = from->x2;
|
||||||
|
@ -100,13 +100,13 @@ static inline void bg_fp64_vector2_set_from_fp32(const BgFP32Vector2* from, BgFP
|
||||||
|
|
||||||
// =================== Reverse ================== //
|
// =================== Reverse ================== //
|
||||||
|
|
||||||
static inline void bg_fp32_vector2_set_reverse(const BgFP32Vector2* from, BgFP32Vector2* to)
|
static inline void fp32_vector2_set_reverse(const fp32_vector2_t* from, fp32_vector2_t* to)
|
||||||
{
|
{
|
||||||
to->x1 = -from->x1;
|
to->x1 = -from->x1;
|
||||||
to->x2 = -from->x2;
|
to->x2 = -from->x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_vector2_set_reverse(const BgFP64Vector2* from, BgFP64Vector2* to)
|
static inline void fp64_vector2_set_reverse(const fp64_vector2_t* from, fp64_vector2_t* to)
|
||||||
{
|
{
|
||||||
to->x1 = -from->x1;
|
to->x1 = -from->x1;
|
||||||
to->x2 = -from->x2;
|
to->x2 = -from->x2;
|
||||||
|
@ -114,13 +114,13 @@ static inline void bg_fp64_vector2_set_reverse(const BgFP64Vector2* from, BgFP64
|
||||||
|
|
||||||
// ============= Reverse twin type ============== //
|
// ============= Reverse twin type ============== //
|
||||||
|
|
||||||
static inline void bg_fp32_vector2_set_reverse_fp64(const BgFP64Vector2* from, BgFP32Vector2* to)
|
static inline void fp32_vector2_set_reverse_fp64(const fp64_vector2_t* from, fp32_vector2_t* to)
|
||||||
{
|
{
|
||||||
to->x1 = (float) -from->x1;
|
to->x1 = (float) -from->x1;
|
||||||
to->x2 = (float) -from->x2;
|
to->x2 = (float) -from->x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_vector2_set_reverse_fp32(const BgFP32Vector2* from, BgFP64Vector2* to)
|
static inline void fp64_vector2_set_reverse_fp32(const fp32_vector2_t* from, fp64_vector2_t* to)
|
||||||
{
|
{
|
||||||
to->x1 = -from->x1;
|
to->x1 = -from->x1;
|
||||||
to->x2 = -from->x2;
|
to->x2 = -from->x2;
|
||||||
|
@ -128,61 +128,61 @@ static inline void bg_fp64_vector2_set_reverse_fp32(const BgFP32Vector2* from, B
|
||||||
|
|
||||||
// =================== Module =================== //
|
// =================== Module =================== //
|
||||||
|
|
||||||
static inline float bg_fp32_vector2_get_square_modulus(const BgFP32Vector2* vector)
|
static inline float fp32_vector2_get_square_modulus(const fp32_vector2_t* 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_modulus(const BgFP64Vector2* vector)
|
static inline double fp64_vector2_get_square_modulus(const fp64_vector2_t* 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_modulus(const BgFP32Vector2* vector)
|
static inline float fp32_vector2_get_modulus(const fp32_vector2_t* vector)
|
||||||
{
|
{
|
||||||
return sqrtf(bg_fp32_vector2_get_square_modulus(vector));
|
return sqrtf(fp32_vector2_get_square_modulus(vector));
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline double bg_fp64_vector2_get_modulus(const BgFP64Vector2* vector)
|
static inline double fp64_vector2_get_modulus(const fp64_vector2_t* vector)
|
||||||
{
|
{
|
||||||
return sqrt(bg_fp64_vector2_get_square_modulus(vector));
|
return sqrt(fp64_vector2_get_square_modulus(vector));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================= Comparison ================= //
|
// ================= Comparison ================= //
|
||||||
|
|
||||||
static inline int bg_fp32_vector2_is_zero(const BgFP32Vector2* vector)
|
static inline int fp32_vector2_is_zero(const fp32_vector2_t* vector)
|
||||||
{
|
{
|
||||||
return bg_fp32_vector2_get_square_modulus(vector) <= BG_FP32_SQUARE_EPSYLON;
|
return fp32_vector2_get_square_modulus(vector) <= FP32_SQUARE_EPSYLON;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int bg_fp64_vector2_is_zero(const BgFP64Vector2* vector)
|
static inline int fp64_vector2_is_zero(const fp64_vector2_t* vector)
|
||||||
{
|
{
|
||||||
return bg_fp64_vector2_get_square_modulus(vector) <= BG_FP64_SQUARE_EPSYLON;
|
return fp64_vector2_get_square_modulus(vector) <= FP64_SQUARE_EPSYLON;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int bg_fp32_vector2_is_unit(const BgFP32Vector2* vector)
|
static inline int fp32_vector2_is_unit(const fp32_vector2_t* vector)
|
||||||
{
|
{
|
||||||
const float square_modulus = bg_fp32_vector2_get_square_modulus(vector);
|
const float square_modulus = fp32_vector2_get_square_modulus(vector);
|
||||||
|
|
||||||
return 1.0f - BG_FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + BG_FP32_TWO_EPSYLON;
|
return 1.0f - FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + FP32_TWO_EPSYLON;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int bg_fp64_vector2_is_unit(const BgFP64Vector2* vector)
|
static inline int fp64_vector2_is_unit(const fp64_vector2_t* vector)
|
||||||
{
|
{
|
||||||
const double square_modulus = bg_fp64_vector2_get_square_modulus(vector);
|
const double square_modulus = fp64_vector2_get_square_modulus(vector);
|
||||||
|
|
||||||
return 1.0f - BG_FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + BG_FP64_TWO_EPSYLON;
|
return 1.0f - FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + FP64_TWO_EPSYLON;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==================== Add ===================== //
|
// ==================== Add ===================== //
|
||||||
|
|
||||||
static inline void bg_fp32_vector2_add(const BgFP32Vector2* vector1, const BgFP32Vector2* vector2, BgFP32Vector2* sum)
|
static inline void fp32_vector2_add(const fp32_vector2_t* vector1, const fp32_vector2_t* vector2, fp32_vector2_t* sum)
|
||||||
{
|
{
|
||||||
sum->x1 = vector1->x1 + vector2->x1;
|
sum->x1 = vector1->x1 + vector2->x1;
|
||||||
sum->x2 = vector1->x2 + vector2->x2;
|
sum->x2 = vector1->x2 + vector2->x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_vector2_add(const BgFP64Vector2* vector1, const BgFP64Vector2* vector2, BgFP64Vector2* sum)
|
static inline void fp64_vector2_add(const fp64_vector2_t* vector1, const fp64_vector2_t* vector2, fp64_vector2_t* sum)
|
||||||
{
|
{
|
||||||
sum->x1 = vector1->x1 + vector2->x1;
|
sum->x1 = vector1->x1 + vector2->x1;
|
||||||
sum->x2 = vector1->x2 + vector2->x2;
|
sum->x2 = vector1->x2 + vector2->x2;
|
||||||
|
@ -190,13 +190,13 @@ static inline void bg_fp64_vector2_add(const BgFP64Vector2* vector1, const BgFP6
|
||||||
|
|
||||||
// ================ Subtraction ================= //
|
// ================ Subtraction ================= //
|
||||||
|
|
||||||
static inline void bg_fp32_vector2_subtract(const BgFP32Vector2* minuend, const BgFP32Vector2* subtrahend, BgFP32Vector2* difference)
|
static inline void fp32_vector2_subtract(const fp32_vector2_t* minuend, const fp32_vector2_t* subtrahend, fp32_vector2_t* difference)
|
||||||
{
|
{
|
||||||
difference->x1 = minuend->x1 - subtrahend->x1;
|
difference->x1 = minuend->x1 - subtrahend->x1;
|
||||||
difference->x2 = minuend->x2 - subtrahend->x2;
|
difference->x2 = minuend->x2 - subtrahend->x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_vector2_subtract(const BgFP64Vector2* minuend, const BgFP64Vector2* subtrahend, BgFP64Vector2* difference)
|
static inline void fp64_vector2_subtract(const fp64_vector2_t* minuend, const fp64_vector2_t* subtrahend, fp64_vector2_t* difference)
|
||||||
{
|
{
|
||||||
difference->x1 = minuend->x1 - subtrahend->x1;
|
difference->x1 = minuend->x1 - subtrahend->x1;
|
||||||
difference->x2 = minuend->x2 - subtrahend->x2;
|
difference->x2 = minuend->x2 - subtrahend->x2;
|
||||||
|
@ -204,13 +204,13 @@ static inline void bg_fp64_vector2_subtract(const BgFP64Vector2* minuend, const
|
||||||
|
|
||||||
// =============== Multiplication =============== //
|
// =============== Multiplication =============== //
|
||||||
|
|
||||||
static inline void bg_fp32_vector2_multiply(const BgFP32Vector2* multiplicand, const float multiplier, BgFP32Vector2* product)
|
static inline void fp32_vector2_multiply(const fp32_vector2_t* multiplicand, const float multiplier, fp32_vector2_t* product)
|
||||||
{
|
{
|
||||||
product->x1 = multiplicand->x1 * multiplier;
|
product->x1 = multiplicand->x1 * multiplier;
|
||||||
product->x2 = multiplicand->x2 * multiplier;
|
product->x2 = multiplicand->x2 * multiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_vector2_multiply(const BgFP64Vector2* multiplicand, const double multiplier, BgFP64Vector2* product)
|
static inline void fp64_vector2_multiply(const fp64_vector2_t* multiplicand, const double multiplier, fp64_vector2_t* product)
|
||||||
{
|
{
|
||||||
product->x1 = multiplicand->x1 * multiplier;
|
product->x1 = multiplicand->x1 * multiplier;
|
||||||
product->x2 = multiplicand->x2 * multiplier;
|
product->x2 = multiplicand->x2 * multiplier;
|
||||||
|
@ -218,25 +218,25 @@ static inline void bg_fp64_vector2_multiply(const BgFP64Vector2* multiplicand, c
|
||||||
|
|
||||||
// ================== Division ================== //
|
// ================== Division ================== //
|
||||||
|
|
||||||
static inline void bg_fp32_vector2_divide(const BgFP32Vector2* dividend, const float divisor, BgFP32Vector2* quotient)
|
static inline void fp32_vector2_divide(const fp32_vector2_t* dividend, const float divisor, fp32_vector2_t* quotient)
|
||||||
{
|
{
|
||||||
bg_fp32_vector2_multiply(dividend, 1.0f / divisor, quotient);
|
fp32_vector2_multiply(dividend, 1.0f / divisor, quotient);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_vector2_divide(const BgFP64Vector2* dividend, const double divisor, BgFP64Vector2* quotient)
|
static inline void fp64_vector2_divide(const fp64_vector2_t* dividend, const double divisor, fp64_vector2_t* quotient)
|
||||||
{
|
{
|
||||||
bg_fp64_vector2_multiply(dividend, 1.0 / divisor, quotient);
|
fp64_vector2_multiply(dividend, 1.0 / divisor, quotient);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================ Append scaled =============== //
|
// ================ Append scaled =============== //
|
||||||
|
|
||||||
static inline void bg_fp32_vector2_append_scaled(BgFP32Vector2* basic_vector, const BgFP32Vector2* scalable_vector, const float scale)
|
static inline void fp32_vector2_append_scaled(fp32_vector2_t* basic_vector, const fp32_vector2_t* scalable_vector, const float scale)
|
||||||
{
|
{
|
||||||
basic_vector->x1 += scalable_vector->x1 * scale;
|
basic_vector->x1 += scalable_vector->x1 * scale;
|
||||||
basic_vector->x2 += scalable_vector->x2 * scale;
|
basic_vector->x2 += scalable_vector->x2 * scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_vector2_append_scaled(BgFP64Vector2* basic_vector, const BgFP64Vector2* scalable_vector, const double scale)
|
static inline void fp64_vector2_append_scaled(fp64_vector2_t* basic_vector, const fp64_vector2_t* scalable_vector, const double scale)
|
||||||
{
|
{
|
||||||
basic_vector->x1 += scalable_vector->x1 * scale;
|
basic_vector->x1 += scalable_vector->x1 * scale;
|
||||||
basic_vector->x2 += scalable_vector->x2 * scale;
|
basic_vector->x2 += scalable_vector->x2 * scale;
|
||||||
|
@ -244,13 +244,13 @@ static inline void bg_fp64_vector2_append_scaled(BgFP64Vector2* basic_vector, co
|
||||||
|
|
||||||
// ================== Average2 ================== //
|
// ================== Average2 ================== //
|
||||||
|
|
||||||
static inline void bg_fp32_vector2_get_mean2(const BgFP32Vector2* vector1, const BgFP32Vector2* vector2, BgFP32Vector2* result)
|
static inline void fp32_vector2_get_mean2(const fp32_vector2_t* vector1, const fp32_vector2_t* vector2, fp32_vector2_t* result)
|
||||||
{
|
{
|
||||||
result->x1 = (vector1->x1 + vector2->x1) * 0.5f;
|
result->x1 = (vector1->x1 + vector2->x1) * 0.5f;
|
||||||
result->x2 = (vector1->x2 + vector2->x2) * 0.5f;
|
result->x2 = (vector1->x2 + vector2->x2) * 0.5f;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_vector2_get_mean2(const BgFP64Vector2* vector1, const BgFP64Vector2* vector2, BgFP64Vector2* result)
|
static inline void fp64_vector2_get_mean2(const fp64_vector2_t* vector1, const fp64_vector2_t* vector2, fp64_vector2_t* result)
|
||||||
{
|
{
|
||||||
result->x1 = (vector1->x1 + vector2->x1) * 0.5;
|
result->x1 = (vector1->x1 + vector2->x1) * 0.5;
|
||||||
result->x2 = (vector1->x2 + vector2->x2) * 0.5;
|
result->x2 = (vector1->x2 + vector2->x2) * 0.5;
|
||||||
|
@ -258,45 +258,45 @@ static inline void bg_fp64_vector2_get_mean2(const BgFP64Vector2* vector1, const
|
||||||
|
|
||||||
// ================== Average3 ================== //
|
// ================== Average3 ================== //
|
||||||
|
|
||||||
static inline void bg_fp32_vector2_get_mean3(const BgFP32Vector2* vector1, const BgFP32Vector2* vector2, const BgFP32Vector2* vector3, BgFP32Vector2* result)
|
static inline void fp32_vector2_get_mean3(const fp32_vector2_t* vector1, const fp32_vector2_t* vector2, const fp32_vector2_t* vector3, fp32_vector2_t* result)
|
||||||
{
|
{
|
||||||
result->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * BG_FP32_ONE_THIRD;
|
result->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * FP32_ONE_THIRD;
|
||||||
result->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * BG_FP32_ONE_THIRD;
|
result->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * FP32_ONE_THIRD;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_vector2_get_mean3(const BgFP64Vector2* vector1, const BgFP64Vector2* vector2, const BgFP64Vector2* vector3, BgFP64Vector2* result)
|
static inline void fp64_vector2_get_mean3(const fp64_vector2_t* vector1, const fp64_vector2_t* vector2, const fp64_vector2_t* vector3, fp64_vector2_t* result)
|
||||||
{
|
{
|
||||||
result->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * BG_FP64_ONE_THIRD;
|
result->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * FP64_ONE_THIRD;
|
||||||
result->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * BG_FP64_ONE_THIRD;
|
result->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * FP64_ONE_THIRD;
|
||||||
}
|
}
|
||||||
|
|
||||||
// =============== Scalar Product =============== //
|
// =============== Scalar Product =============== //
|
||||||
|
|
||||||
static inline float bg_fp32_vector2_scalar_product(const BgFP32Vector2* vector1, const BgFP32Vector2* vector2)
|
static inline float fp32_vector2_scalar_product(const fp32_vector2_t* vector1, const fp32_vector2_t* vector2)
|
||||||
{
|
{
|
||||||
return vector1->x1 * vector2->x1 + vector1->x2 * vector2->x2;
|
return vector1->x1 * vector2->x1 + vector1->x2 * vector2->x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline double bg_fp64_vector2_scalar_product(const BgFP64Vector2* vector1, const BgFP64Vector2* vector2)
|
static inline double fp64_vector2_scalar_product(const fp64_vector2_t* vector1, const fp64_vector2_t* vector2)
|
||||||
{
|
{
|
||||||
return vector1->x1 * vector2->x1 + vector1->x2 * vector2->x2;
|
return vector1->x1 * vector2->x1 + vector1->x2 * vector2->x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// =============== Cross Product ================ //
|
// =============== Cross Product ================ //
|
||||||
|
|
||||||
static inline float bg_fp32_vector2_cross_product(const BgFP32Vector2* vector1, const BgFP32Vector2* vector2)
|
static inline float fp32_vector2_cross_product(const fp32_vector2_t* vector1, const fp32_vector2_t* vector2)
|
||||||
{
|
{
|
||||||
return vector1->x1 * vector2->x2 - vector1->x2 * vector2->x1;
|
return vector1->x1 * vector2->x2 - vector1->x2 * vector2->x1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline double bg_fp64_vector2_cross_product(const BgFP64Vector2* vector1, const BgFP64Vector2* vector2)
|
static inline double fp64_vector2_cross_product(const fp64_vector2_t* vector1, const fp64_vector2_t* vector2)
|
||||||
{
|
{
|
||||||
return vector1->x1 * vector2->x2 - vector1->x2 * vector2->x1;
|
return vector1->x1 * vector2->x2 - vector1->x2 * vector2->x1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============== Complex Product =============== //
|
// ============== Complex Product =============== //
|
||||||
|
|
||||||
static inline void bg_fp32_vector2_complex_product(const BgFP32Vector2* vector1, const BgFP32Vector2* vector2, BgFP32Vector2* result)
|
static inline void fp32_vector2_complex_product(const fp32_vector2_t* vector1, const fp32_vector2_t* vector2, fp32_vector2_t* result)
|
||||||
{
|
{
|
||||||
const float x1 = vector1->x1 * vector2->x1 - vector1->x2 * vector2->x2;
|
const float x1 = vector1->x1 * vector2->x1 - vector1->x2 * vector2->x2;
|
||||||
const float x2 = vector1->x1 * vector2->x2 + vector1->x2 * vector2->x1;
|
const float x2 = vector1->x1 * vector2->x2 + vector1->x2 * vector2->x1;
|
||||||
|
@ -305,7 +305,7 @@ static inline void bg_fp32_vector2_complex_product(const BgFP32Vector2* vector1,
|
||||||
result->x2 = x2;
|
result->x2 = x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_vector2_complex_product(const BgFP64Vector2* vector1, const BgFP64Vector2* vector2, BgFP64Vector2* result)
|
static inline void fp64_vector2_complex_product(const fp64_vector2_t* vector1, const fp64_vector2_t* vector2, fp64_vector2_t* result)
|
||||||
{
|
{
|
||||||
const double x1 = vector1->x1 * vector2->x1 - vector1->x2 * vector2->x2;
|
const double x1 = vector1->x1 * vector2->x1 - vector1->x2 * vector2->x2;
|
||||||
const double x2 = vector1->x1 * vector2->x2 + vector1->x2 * vector2->x1;
|
const double x2 = vector1->x1 * vector2->x2 + vector1->x2 * vector2->x1;
|
||||||
|
@ -316,63 +316,63 @@ static inline void bg_fp64_vector2_complex_product(const BgFP64Vector2* vector1,
|
||||||
|
|
||||||
// =============== Normalization ================ //
|
// =============== Normalization ================ //
|
||||||
|
|
||||||
static inline int bg_fp32_vector2_normalize(BgFP32Vector2* vector)
|
static inline int fp32_vector2_normalize(fp32_vector2_t* vector)
|
||||||
{
|
{
|
||||||
const float square_modulus = bg_fp32_vector2_get_square_modulus(vector);
|
const float square_modulus = fp32_vector2_get_square_modulus(vector);
|
||||||
|
|
||||||
if (1.0f - BG_FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + BG_FP32_TWO_EPSYLON) {
|
if (1.0f - FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + FP32_TWO_EPSYLON) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (square_modulus <= BG_FP32_SQUARE_EPSYLON) {
|
if (square_modulus <= FP32_SQUARE_EPSYLON) {
|
||||||
bg_fp32_vector2_reset(vector);
|
fp32_vector2_reset(vector);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bg_fp32_vector2_multiply(vector, sqrtf(1.0f / square_modulus), vector);
|
fp32_vector2_multiply(vector, sqrtf(1.0f / square_modulus), vector);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int bg_fp64_vector2_normalize(BgFP64Vector2* vector)
|
static inline int fp64_vector2_normalize(fp64_vector2_t* vector)
|
||||||
{
|
{
|
||||||
const double square_modulus = bg_fp64_vector2_get_square_modulus(vector);
|
const double square_modulus = fp64_vector2_get_square_modulus(vector);
|
||||||
|
|
||||||
if (1.0 - BG_FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0 + BG_FP64_TWO_EPSYLON) {
|
if (1.0 - FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0 + FP64_TWO_EPSYLON) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (square_modulus <= BG_FP64_SQUARE_EPSYLON) {
|
if (square_modulus <= FP64_SQUARE_EPSYLON) {
|
||||||
bg_fp64_vector2_reset(vector);
|
fp64_vector2_reset(vector);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bg_fp64_vector2_multiply(vector, sqrt(1.0 / square_modulus), vector);
|
fp64_vector2_multiply(vector, sqrt(1.0 / square_modulus), vector);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// =============== Get Normalized =============== //
|
// =============== Get Normalized =============== //
|
||||||
|
|
||||||
static inline int bg_fp32_vector2_set_normalized(const BgFP32Vector2* vector, BgFP32Vector2* result)
|
static inline int fp32_vector2_set_normalized(const fp32_vector2_t* vector, fp32_vector2_t* result)
|
||||||
{
|
{
|
||||||
bg_fp32_vector2_copy(vector, result);
|
fp32_vector2_copy(vector, result);
|
||||||
return bg_fp32_vector2_normalize(result);
|
return fp32_vector2_normalize(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int bg_fp64_vector2_set_normalized(const BgFP64Vector2* vector, BgFP64Vector2* result)
|
static inline int fp64_vector2_set_normalized(const fp64_vector2_t* vector, fp64_vector2_t* result)
|
||||||
{
|
{
|
||||||
bg_fp64_vector2_copy(vector, result);
|
fp64_vector2_copy(vector, result);
|
||||||
return bg_fp64_vector2_normalize(result);
|
return fp64_vector2_normalize(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// =================== Angle ==================== //
|
// =================== Angle ==================== //
|
||||||
|
|
||||||
float bg_fp32_vector2_get_angle(const BgFP32Vector2* vector1, const BgFP32Vector2* vector2, const angle_unit_t unit);
|
float fp32_vector2_get_angle(const fp32_vector2_t* vector1, const fp32_vector2_t* vector2, const angle_unit_t unit);
|
||||||
|
|
||||||
double bg_fp64_vector2_get_angle(const BgFP64Vector2* vector1, const BgFP64Vector2* vector2, const angle_unit_t unit);
|
double fp64_vector2_get_angle(const fp64_vector2_t* vector1, const fp64_vector2_t* vector2, const angle_unit_t unit);
|
||||||
|
|
||||||
// =============== Square Distance ============== //
|
// =============== Square Distance ============== //
|
||||||
|
|
||||||
static inline float bg_fp32_vector2_get_square_distance(const BgFP32Vector2* vector1, const BgFP32Vector2* vector2)
|
static inline float fp32_vector2_get_square_distance(const fp32_vector2_t* vector1, const fp32_vector2_t* vector2)
|
||||||
{
|
{
|
||||||
const float dx1 = (vector1->x1 - vector2->x1);
|
const float dx1 = (vector1->x1 - vector2->x1);
|
||||||
const float dx2 = (vector1->x2 - vector2->x2);
|
const float dx2 = (vector1->x2 - vector2->x2);
|
||||||
|
@ -380,7 +380,7 @@ static inline float bg_fp32_vector2_get_square_distance(const BgFP32Vector2* vec
|
||||||
return dx1 * dx1 + dx2 * dx2;
|
return dx1 * dx1 + dx2 * dx2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline double bg_fp64_vector2_get_square_distance(const BgFP64Vector2* vector1, const BgFP64Vector2* vector2)
|
static inline double fp64_vector2_get_square_distance(const fp64_vector2_t* vector1, const fp64_vector2_t* vector2)
|
||||||
{
|
{
|
||||||
const double dx1 = (vector1->x1 - vector2->x1);
|
const double dx1 = (vector1->x1 - vector2->x1);
|
||||||
const double dx2 = (vector1->x2 - vector2->x2);
|
const double dx2 = (vector1->x2 - vector2->x2);
|
||||||
|
@ -390,52 +390,52 @@ static inline double bg_fp64_vector2_get_square_distance(const BgFP64Vector2* ve
|
||||||
|
|
||||||
// ================== Distance ================== //
|
// ================== Distance ================== //
|
||||||
|
|
||||||
static inline float bg_fp32_vector2_get_distance(const BgFP32Vector2* vector1, const BgFP32Vector2* vector2)
|
static inline float fp32_vector2_get_distance(const fp32_vector2_t* vector1, const fp32_vector2_t* vector2)
|
||||||
{
|
{
|
||||||
return sqrtf(bg_fp32_vector2_get_square_distance(vector1, vector2));
|
return sqrtf(fp32_vector2_get_square_distance(vector1, vector2));
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline double bg_fp64_vector2_get_distance(const BgFP64Vector2* vector1, const BgFP64Vector2* vector2)
|
static inline double fp64_vector2_get_distance(const fp64_vector2_t* vector1, const fp64_vector2_t* vector2)
|
||||||
{
|
{
|
||||||
return sqrt(bg_fp64_vector2_get_square_distance(vector1, vector2));
|
return sqrt(fp64_vector2_get_square_distance(vector1, vector2));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================== Are Equal ================= //
|
// ================== Are Equal ================= //
|
||||||
|
|
||||||
static inline int bg_fp32_vector2_are_equal(const BgFP32Vector2* vector1, const BgFP32Vector2* vector2)
|
static inline int fp32_vector2_are_equal(const fp32_vector2_t* vector1, const fp32_vector2_t* vector2)
|
||||||
{
|
{
|
||||||
const float square_modulus1 = bg_fp32_vector2_get_square_modulus(vector1);
|
const float square_modulus1 = fp32_vector2_get_square_modulus(vector1);
|
||||||
const float square_modulus2 = bg_fp32_vector2_get_square_modulus(vector2);
|
const float square_modulus2 = fp32_vector2_get_square_modulus(vector2);
|
||||||
const float square_modulus3 = bg_fp32_vector2_get_square_distance(vector1, vector2);
|
const float square_modulus3 = fp32_vector2_get_square_distance(vector1, vector2);
|
||||||
|
|
||||||
// 2.0f means dimension amount
|
// 2.0f means dimension amount
|
||||||
if (square_modulus1 < BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT || square_modulus2 < BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT) {
|
if (square_modulus1 < FP32_EPSYLON_EFFECTIVENESS_LIMIT || square_modulus2 < FP32_EPSYLON_EFFECTIVENESS_LIMIT) {
|
||||||
return square_modulus3 < (2.0f * BG_FP32_SQUARE_EPSYLON);
|
return square_modulus3 < (2.0f * FP32_SQUARE_EPSYLON);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (square_modulus1 <= square_modulus2) {
|
if (square_modulus1 <= square_modulus2) {
|
||||||
return square_modulus3 <= (2.0f * BG_FP32_SQUARE_EPSYLON) * square_modulus2;
|
return square_modulus3 <= (2.0f * FP32_SQUARE_EPSYLON) * square_modulus2;
|
||||||
}
|
}
|
||||||
|
|
||||||
return square_modulus3 <= (2.0f * BG_FP32_SQUARE_EPSYLON) * square_modulus1;
|
return square_modulus3 <= (2.0f * FP32_SQUARE_EPSYLON) * square_modulus1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int bg_fp64_vector2_are_equal(const BgFP64Vector2* vector1, const BgFP64Vector2* vector2)
|
static inline int fp64_vector2_are_equal(const fp64_vector2_t* vector1, const fp64_vector2_t* vector2)
|
||||||
{
|
{
|
||||||
const double square_modulus1 = bg_fp64_vector2_get_square_modulus(vector1);
|
const double square_modulus1 = fp64_vector2_get_square_modulus(vector1);
|
||||||
const double square_modulus2 = bg_fp64_vector2_get_square_modulus(vector2);
|
const double square_modulus2 = fp64_vector2_get_square_modulus(vector2);
|
||||||
const double square_modulus3 = bg_fp64_vector2_get_square_distance(vector1, vector2);
|
const double square_modulus3 = fp64_vector2_get_square_distance(vector1, vector2);
|
||||||
|
|
||||||
// 2.0 means dimension amount
|
// 2.0 means dimension amount
|
||||||
if (square_modulus1 < BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT || square_modulus2 < BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT) {
|
if (square_modulus1 < FP64_EPSYLON_EFFECTIVENESS_LIMIT || square_modulus2 < FP64_EPSYLON_EFFECTIVENESS_LIMIT) {
|
||||||
return square_modulus3 < (2.0 * BG_FP64_SQUARE_EPSYLON);
|
return square_modulus3 < (2.0 * FP64_SQUARE_EPSYLON);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (square_modulus1 <= square_modulus2) {
|
if (square_modulus1 <= square_modulus2) {
|
||||||
return square_modulus3 <= (2.0 * BG_FP64_SQUARE_EPSYLON) * square_modulus2;
|
return square_modulus3 <= (2.0 * FP64_SQUARE_EPSYLON) * square_modulus2;
|
||||||
}
|
}
|
||||||
|
|
||||||
return square_modulus3 <= (2.0 * BG_FP64_SQUARE_EPSYLON) * square_modulus1;
|
return square_modulus3 <= (2.0 * FP64_SQUARE_EPSYLON) * square_modulus1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -2,64 +2,64 @@
|
||||||
|
|
||||||
// =================== Angle ==================== //
|
// =================== Angle ==================== //
|
||||||
|
|
||||||
float bg_fp32_vector3_get_angle(const BgFP32Vector3* vector1, const BgFP32Vector3* vector2, const angle_unit_t unit)
|
float fp32_vector3_get_angle(const fp32_vector3_t* vector1, const fp32_vector3_t* vector2, const angle_unit_t unit)
|
||||||
{
|
{
|
||||||
if (vector1 == 0 || vector2 == 0) {
|
if (vector1 == 0 || vector2 == 0) {
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
const float square_modulus1 = bg_fp32_vector3_get_square_modulus(vector1);
|
const float square_modulus1 = fp32_vector3_get_square_modulus(vector1);
|
||||||
|
|
||||||
if (square_modulus1 <= BG_FP32_SQUARE_EPSYLON) {
|
if (square_modulus1 <= FP32_SQUARE_EPSYLON) {
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
const float square_modulus2 = bg_fp32_vector3_get_square_modulus(vector2);
|
const float square_modulus2 = fp32_vector3_get_square_modulus(vector2);
|
||||||
|
|
||||||
if (square_modulus2 <= BG_FP32_SQUARE_EPSYLON) {
|
if (square_modulus2 <= FP32_SQUARE_EPSYLON) {
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
const float cosine = bg_fp32_vector3_scalar_product(vector1, vector2) / sqrtf(square_modulus1 * square_modulus2);
|
const float cosine = fp32_vector3_scalar_product(vector1, vector2) / sqrtf(square_modulus1 * square_modulus2);
|
||||||
|
|
||||||
if (cosine >= 1.0f - BG_FP32_EPSYLON) {
|
if (cosine >= 1.0f - FP32_EPSYLON) {
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cosine <= -1.0f + BG_FP32_EPSYLON) {
|
if (cosine <= -1.0f + FP32_EPSYLON) {
|
||||||
return bg_fp32_angle_get_half_circle(unit);
|
return fp32_angle_get_half_circle(unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
return bg_fp32_radians_to_units(acosf(cosine), unit);
|
return fp32_radians_to_units(acosf(cosine), unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
double bg_fp64_vector3_get_angle(const BgFP64Vector3* vector1, const BgFP64Vector3* vector2, const angle_unit_t unit)
|
double fp64_vector3_get_angle(const fp64_vector3_t* vector1, const fp64_vector3_t* vector2, const angle_unit_t unit)
|
||||||
{
|
{
|
||||||
if (vector1 == 0 || vector2 == 0) {
|
if (vector1 == 0 || vector2 == 0) {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const double square_modulus1 = bg_fp64_vector3_get_square_modulus(vector1);
|
const double square_modulus1 = fp64_vector3_get_square_modulus(vector1);
|
||||||
|
|
||||||
if (square_modulus1 <= BG_FP64_SQUARE_EPSYLON) {
|
if (square_modulus1 <= FP64_SQUARE_EPSYLON) {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const double square_modulus2 = bg_fp64_vector3_get_square_modulus(vector2);
|
const double square_modulus2 = fp64_vector3_get_square_modulus(vector2);
|
||||||
|
|
||||||
if (square_modulus2 <= BG_FP64_SQUARE_EPSYLON) {
|
if (square_modulus2 <= FP64_SQUARE_EPSYLON) {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const double cosine = bg_fp64_vector3_scalar_product(vector1, vector2) / sqrt(square_modulus1 * square_modulus2);
|
const double cosine = fp64_vector3_scalar_product(vector1, vector2) / sqrt(square_modulus1 * square_modulus2);
|
||||||
|
|
||||||
if (cosine >= 1.0 - BG_FP64_EPSYLON) {
|
if (cosine >= 1.0 - FP64_EPSYLON) {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cosine <= -1.0 + BG_FP64_EPSYLON) {
|
if (cosine <= -1.0 + FP64_EPSYLON) {
|
||||||
return bg_fp64_angle_get_half_circle(unit);
|
return fp64_angle_get_half_circle(unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
return bg_fp64_radians_to_units(acos(cosine), unit);
|
return fp64_radians_to_units(acos(cosine), unit);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#ifndef _GEOMETRY_VECTOR3_H_
|
#ifndef _BASIC_GEOMETRY_VECTOR3_H_
|
||||||
#define _GEOMETRY_VECTOR3_H_
|
#define _BASIC_GEOMETRY_VECTOR3_H_
|
||||||
|
|
||||||
#include "basis.h"
|
#include "basis.h"
|
||||||
#include "angle.h"
|
#include "angle.h"
|
||||||
|
@ -11,23 +11,23 @@
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
float x1, x2, x3;
|
float x1, x2, x3;
|
||||||
} BgFP32Vector3;
|
} fp32_vector3_t;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
double x1, x2, x3;
|
double x1, x2, x3;
|
||||||
} BgFP64Vector3;
|
} fp64_vector3_t;
|
||||||
|
|
||||||
// =================== Reset ==================== //
|
// =================== Reset ==================== //
|
||||||
|
|
||||||
static inline void bg_fp32_vector3_reset(BgFP32Vector3* vector)
|
static inline void fp32_vector3_reset(fp32_vector3_t* vector)
|
||||||
{
|
{
|
||||||
vector->x1 = 0.0f;
|
vector->x1 = 0.0f;
|
||||||
vector->x2 = 0.0f;
|
vector->x2 = 0.0f;
|
||||||
vector->x3 = 0.0f;
|
vector->x3 = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_vector3_reset(BgFP64Vector3* vector)
|
static inline void fp64_vector3_reset(fp64_vector3_t* vector)
|
||||||
{
|
{
|
||||||
vector->x1 = 0.0;
|
vector->x1 = 0.0;
|
||||||
vector->x2 = 0.0;
|
vector->x2 = 0.0;
|
||||||
|
@ -36,14 +36,14 @@ static inline void bg_fp64_vector3_reset(BgFP64Vector3* vector)
|
||||||
|
|
||||||
// ==================== Set ===================== //
|
// ==================== Set ===================== //
|
||||||
|
|
||||||
static inline void bg_fp32_vector3_set_values(const float x1, const float x2, const float x3, BgFP32Vector3* to)
|
static inline void fp32_vector3_set_values(const float x1, const float x2, const float x3, fp32_vector3_t* to)
|
||||||
{
|
{
|
||||||
to->x1 = x1;
|
to->x1 = x1;
|
||||||
to->x2 = x2;
|
to->x2 = x2;
|
||||||
to->x3 = x3;
|
to->x3 = x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_vector3_set_values(const double x1, const double x2, const double x3, BgFP64Vector3* to)
|
static inline void fp64_vector3_set_values(const double x1, const double x2, const double x3, fp64_vector3_t* to)
|
||||||
{
|
{
|
||||||
to->x1 = x1;
|
to->x1 = x1;
|
||||||
to->x2 = x2;
|
to->x2 = x2;
|
||||||
|
@ -52,14 +52,14 @@ static inline void bg_fp64_vector3_set_values(const double x1, const double x2,
|
||||||
|
|
||||||
// ==================== Copy ==================== //
|
// ==================== Copy ==================== //
|
||||||
|
|
||||||
static inline void bg_fp32_vector3_copy(const BgFP32Vector3* from, BgFP32Vector3* to)
|
static inline void fp32_vector3_copy(const fp32_vector3_t* from, fp32_vector3_t* to)
|
||||||
{
|
{
|
||||||
to->x1 = from->x1;
|
to->x1 = from->x1;
|
||||||
to->x2 = from->x2;
|
to->x2 = from->x2;
|
||||||
to->x3 = from->x3;
|
to->x3 = from->x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_vector3_copy(const BgFP64Vector3* from, BgFP64Vector3* to)
|
static inline void fp64_vector3_copy(const fp64_vector3_t* from, fp64_vector3_t* to)
|
||||||
{
|
{
|
||||||
to->x1 = from->x1;
|
to->x1 = from->x1;
|
||||||
to->x2 = from->x2;
|
to->x2 = from->x2;
|
||||||
|
@ -68,7 +68,7 @@ static inline void bg_fp64_vector3_copy(const BgFP64Vector3* from, BgFP64Vector3
|
||||||
|
|
||||||
// ==================== Swap ==================== //
|
// ==================== Swap ==================== //
|
||||||
|
|
||||||
static inline void bg_fp32_vector3_swap(BgFP32Vector3* vector1, BgFP32Vector3* vector2)
|
static inline void fp32_vector3_swap(fp32_vector3_t* vector1, fp32_vector3_t* vector2)
|
||||||
{
|
{
|
||||||
const float x1 = vector2->x1;
|
const float x1 = vector2->x1;
|
||||||
const float x2 = vector2->x2;
|
const float x2 = vector2->x2;
|
||||||
|
@ -83,7 +83,7 @@ static inline void bg_fp32_vector3_swap(BgFP32Vector3* vector1, BgFP32Vector3* v
|
||||||
vector1->x3 = x3;
|
vector1->x3 = x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_vector3_swap(BgFP64Vector3* vector1, BgFP64Vector3* vector2)
|
static inline void fp64_vector3_swap(fp64_vector3_t* vector1, fp64_vector3_t* vector2)
|
||||||
{
|
{
|
||||||
const double x1 = vector2->x1;
|
const double x1 = vector2->x1;
|
||||||
const double x2 = vector2->x2;
|
const double x2 = vector2->x2;
|
||||||
|
@ -100,14 +100,14 @@ static inline void bg_fp64_vector3_swap(BgFP64Vector3* vector1, BgFP64Vector3* v
|
||||||
|
|
||||||
// ============= Copy to twin type ============== //
|
// ============= Copy to twin type ============== //
|
||||||
|
|
||||||
static inline void bg_fp32_vector3_set_from_fp64(const BgFP64Vector3* from, BgFP32Vector3* to)
|
static inline void fp32_vector3_set_from_fp64(const fp64_vector3_t* from, fp32_vector3_t* to)
|
||||||
{
|
{
|
||||||
to->x1 = (float) from->x1;
|
to->x1 = (float) from->x1;
|
||||||
to->x2 = (float) from->x2;
|
to->x2 = (float) from->x2;
|
||||||
to->x3 = (float) from->x3;
|
to->x3 = (float) from->x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_vector3_set_from_fp32(const BgFP32Vector3* from, BgFP64Vector3* to)
|
static inline void fp64_vector3_set_from_fp32(const fp32_vector3_t* from, fp64_vector3_t* to)
|
||||||
{
|
{
|
||||||
to->x1 = from->x1;
|
to->x1 = from->x1;
|
||||||
to->x2 = from->x2;
|
to->x2 = from->x2;
|
||||||
|
@ -116,14 +116,14 @@ static inline void bg_fp64_vector3_set_from_fp32(const BgFP32Vector3* from, BgFP
|
||||||
|
|
||||||
// =================== Reverse ================== //
|
// =================== Reverse ================== //
|
||||||
|
|
||||||
static inline void bg_fp32_vector3_set_reverse(const BgFP32Vector3* from, BgFP32Vector3* to)
|
static inline void fp32_vector3_set_reverse(const fp32_vector3_t* from, fp32_vector3_t* to)
|
||||||
{
|
{
|
||||||
to->x1 = -from->x1;
|
to->x1 = -from->x1;
|
||||||
to->x2 = -from->x2;
|
to->x2 = -from->x2;
|
||||||
to->x3 = -from->x3;
|
to->x3 = -from->x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_vector3_set_reverse(const BgFP64Vector3* from, BgFP64Vector3* to)
|
static inline void fp64_vector3_set_reverse(const fp64_vector3_t* from, fp64_vector3_t* to)
|
||||||
{
|
{
|
||||||
to->x1 = -from->x1;
|
to->x1 = -from->x1;
|
||||||
to->x2 = -from->x2;
|
to->x2 = -from->x2;
|
||||||
|
@ -132,14 +132,14 @@ static inline void bg_fp64_vector3_set_reverse(const BgFP64Vector3* from, BgFP64
|
||||||
|
|
||||||
// ============= Reverse twin type ============== //
|
// ============= Reverse twin type ============== //
|
||||||
|
|
||||||
static inline void bg_fp32_vector3_set_reverse_fp64(const BgFP64Vector3* from, BgFP32Vector3* to)
|
static inline void fp32_vector3_set_reverse_fp64(const fp64_vector3_t* from, fp32_vector3_t* to)
|
||||||
{
|
{
|
||||||
to->x1 = (float) -from->x1;
|
to->x1 = (float) -from->x1;
|
||||||
to->x2 = (float) -from->x2;
|
to->x2 = (float) -from->x2;
|
||||||
to->x3 = (float) -from->x3;
|
to->x3 = (float) -from->x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_vector3_set_reverse_fp32(const BgFP32Vector3* from, BgFP64Vector3* to)
|
static inline void fp64_vector3_set_reverse_fp32(const fp32_vector3_t* from, fp64_vector3_t* to)
|
||||||
{
|
{
|
||||||
to->x1 = -from->x1;
|
to->x1 = -from->x1;
|
||||||
to->x2 = -from->x2;
|
to->x2 = -from->x2;
|
||||||
|
@ -148,62 +148,62 @@ static inline void bg_fp64_vector3_set_reverse_fp32(const BgFP32Vector3* from, B
|
||||||
|
|
||||||
// =================== Module =================== //
|
// =================== Module =================== //
|
||||||
|
|
||||||
static inline float bg_fp32_vector3_get_square_modulus(const BgFP32Vector3* vector)
|
static inline float fp32_vector3_get_square_modulus(const fp32_vector3_t* 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_modulus(const BgFP64Vector3* vector)
|
static inline double fp64_vector3_get_square_modulus(const fp64_vector3_t* 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_modulus(const BgFP32Vector3* vector)
|
static inline float fp32_vector3_get_modulus(const fp32_vector3_t* vector)
|
||||||
{
|
{
|
||||||
return sqrtf(bg_fp32_vector3_get_square_modulus(vector));
|
return sqrtf(fp32_vector3_get_square_modulus(vector));
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline double bg_fp64_vector3_get_modulus(const BgFP64Vector3* vector)
|
static inline double fp64_vector3_get_modulus(const fp64_vector3_t* vector)
|
||||||
{
|
{
|
||||||
return sqrt(bg_fp64_vector3_get_square_modulus(vector));
|
return sqrt(fp64_vector3_get_square_modulus(vector));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================= Comparison ================= //
|
// ================= Comparison ================= //
|
||||||
|
|
||||||
static inline int bg_fp32_vector3_is_zero(const BgFP32Vector3* vector)
|
static inline int fp32_vector3_is_zero(const fp32_vector3_t* vector)
|
||||||
{
|
{
|
||||||
return bg_fp32_vector3_get_square_modulus(vector) <= BG_FP32_SQUARE_EPSYLON;
|
return fp32_vector3_get_square_modulus(vector) <= FP32_SQUARE_EPSYLON;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int bg_fp64_vector3_is_zero(const BgFP64Vector3* vector)
|
static inline int fp64_vector3_is_zero(const fp64_vector3_t* vector)
|
||||||
{
|
{
|
||||||
return bg_fp64_vector3_get_square_modulus(vector) <= BG_FP64_SQUARE_EPSYLON;
|
return fp64_vector3_get_square_modulus(vector) <= FP64_SQUARE_EPSYLON;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int bg_fp32_vector3_is_unit(const BgFP32Vector3* vector)
|
static inline int fp32_vector3_is_unit(const fp32_vector3_t* vector)
|
||||||
{
|
{
|
||||||
const float square_modulus = bg_fp32_vector3_get_square_modulus(vector);
|
const float square_modulus = fp32_vector3_get_square_modulus(vector);
|
||||||
|
|
||||||
return 1.0f - BG_FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + BG_FP32_TWO_EPSYLON;
|
return 1.0f - FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + FP32_TWO_EPSYLON;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int bg_fp64_vector3_is_unit(const BgFP64Vector3* vector)
|
static inline int fp64_vector3_is_unit(const fp64_vector3_t* vector)
|
||||||
{
|
{
|
||||||
const double square_modulus = bg_fp64_vector3_get_square_modulus(vector);
|
const double square_modulus = fp64_vector3_get_square_modulus(vector);
|
||||||
|
|
||||||
return 1.0f - BG_FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + BG_FP64_TWO_EPSYLON;
|
return 1.0f - FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + FP64_TWO_EPSYLON;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==================== Add ===================== //
|
// ==================== Add ===================== //
|
||||||
|
|
||||||
static inline void bg_fp32_vector3_add(const BgFP32Vector3* vector1, const BgFP32Vector3* vector2, BgFP32Vector3* sum)
|
static inline void fp32_vector3_add(const fp32_vector3_t* vector1, const fp32_vector3_t* vector2, fp32_vector3_t* sum)
|
||||||
{
|
{
|
||||||
sum->x1 = vector1->x1 + vector2->x1;
|
sum->x1 = vector1->x1 + vector2->x1;
|
||||||
sum->x2 = vector1->x2 + vector2->x2;
|
sum->x2 = vector1->x2 + vector2->x2;
|
||||||
sum->x3 = vector1->x3 + vector2->x3;
|
sum->x3 = vector1->x3 + vector2->x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_vector3_add(const BgFP64Vector3* vector1, const BgFP64Vector3* vector2, BgFP64Vector3* sum)
|
static inline void fp64_vector3_add(const fp64_vector3_t* vector1, const fp64_vector3_t* vector2, fp64_vector3_t* sum)
|
||||||
{
|
{
|
||||||
sum->x1 = vector1->x1 + vector2->x1;
|
sum->x1 = vector1->x1 + vector2->x1;
|
||||||
sum->x2 = vector1->x2 + vector2->x2;
|
sum->x2 = vector1->x2 + vector2->x2;
|
||||||
|
@ -212,14 +212,14 @@ static inline void bg_fp64_vector3_add(const BgFP64Vector3* vector1, const BgFP6
|
||||||
|
|
||||||
// ================ Subtraction ================= //
|
// ================ Subtraction ================= //
|
||||||
|
|
||||||
static inline void bg_fp32_vector3_subtract(const BgFP32Vector3* minuend, const BgFP32Vector3* subtrahend, BgFP32Vector3* difference)
|
static inline void fp32_vector3_subtract(const fp32_vector3_t* minuend, const fp32_vector3_t* subtrahend, fp32_vector3_t* difference)
|
||||||
{
|
{
|
||||||
difference->x1 = minuend->x1 - subtrahend->x1;
|
difference->x1 = minuend->x1 - subtrahend->x1;
|
||||||
difference->x2 = minuend->x2 - subtrahend->x2;
|
difference->x2 = minuend->x2 - subtrahend->x2;
|
||||||
difference->x3 = minuend->x3 - subtrahend->x3;
|
difference->x3 = minuend->x3 - subtrahend->x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_vector3_subtract(const BgFP64Vector3* minuend, const BgFP64Vector3* subtrahend, BgFP64Vector3* difference)
|
static inline void fp64_vector3_subtract(const fp64_vector3_t* minuend, const fp64_vector3_t* subtrahend, fp64_vector3_t* difference)
|
||||||
{
|
{
|
||||||
difference->x1 = minuend->x1 - subtrahend->x1;
|
difference->x1 = minuend->x1 - subtrahend->x1;
|
||||||
difference->x2 = minuend->x2 - subtrahend->x2;
|
difference->x2 = minuend->x2 - subtrahend->x2;
|
||||||
|
@ -228,14 +228,14 @@ static inline void bg_fp64_vector3_subtract(const BgFP64Vector3* minuend, const
|
||||||
|
|
||||||
// =============== Multiplication =============== //
|
// =============== Multiplication =============== //
|
||||||
|
|
||||||
static inline void bg_fp32_vector3_multiply(const BgFP32Vector3* multiplicand, const float multiplier, BgFP32Vector3* product)
|
static inline void fp32_vector3_multiply(const fp32_vector3_t* multiplicand, const float multiplier, fp32_vector3_t* product)
|
||||||
{
|
{
|
||||||
product->x1 = multiplicand->x1 * multiplier;
|
product->x1 = multiplicand->x1 * multiplier;
|
||||||
product->x2 = multiplicand->x2 * multiplier;
|
product->x2 = multiplicand->x2 * multiplier;
|
||||||
product->x3 = multiplicand->x3 * multiplier;
|
product->x3 = multiplicand->x3 * multiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_vector3_multiply(const BgFP64Vector3* multiplicand, const double multiplier, BgFP64Vector3* product)
|
static inline void fp64_vector3_multiply(const fp64_vector3_t* multiplicand, const double multiplier, fp64_vector3_t* product)
|
||||||
{
|
{
|
||||||
product->x1 = multiplicand->x1 * multiplier;
|
product->x1 = multiplicand->x1 * multiplier;
|
||||||
product->x2 = multiplicand->x2 * multiplier;
|
product->x2 = multiplicand->x2 * multiplier;
|
||||||
|
@ -244,26 +244,26 @@ static inline void bg_fp64_vector3_multiply(const BgFP64Vector3* multiplicand, c
|
||||||
|
|
||||||
// ================== Division ================== //
|
// ================== Division ================== //
|
||||||
|
|
||||||
static inline void bg_fp32_vector3_divide(const BgFP32Vector3* dividend, const float divisor, BgFP32Vector3* quotient)
|
static inline void fp32_vector3_divide(const fp32_vector3_t* dividend, const float divisor, fp32_vector3_t* quotient)
|
||||||
{
|
{
|
||||||
bg_fp32_vector3_multiply(dividend, 1.0f / divisor, quotient);
|
fp32_vector3_multiply(dividend, 1.0f / divisor, quotient);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_vector3_divide(const BgFP64Vector3* dividend, const double divisor, BgFP64Vector3* quotient)
|
static inline void fp64_vector3_divide(const fp64_vector3_t* dividend, const double divisor, fp64_vector3_t* quotient)
|
||||||
{
|
{
|
||||||
bg_fp64_vector3_multiply(dividend, 1.0 / divisor, quotient);
|
fp64_vector3_multiply(dividend, 1.0 / divisor, quotient);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================ Append scaled =============== //
|
// ================ Append scaled =============== //
|
||||||
|
|
||||||
static inline void bg_fp32_vector3_append_scaled(BgFP32Vector3* basic_vector, const BgFP32Vector3* scalable_vector, const float scale)
|
static inline void fp32_vector3_append_scaled(fp32_vector3_t* basic_vector, const fp32_vector3_t* scalable_vector, const float scale)
|
||||||
{
|
{
|
||||||
basic_vector->x1 += scalable_vector->x1 * scale;
|
basic_vector->x1 += scalable_vector->x1 * scale;
|
||||||
basic_vector->x2 += scalable_vector->x2 * scale;
|
basic_vector->x2 += scalable_vector->x2 * scale;
|
||||||
basic_vector->x3 += scalable_vector->x3 * scale;
|
basic_vector->x3 += scalable_vector->x3 * scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_vector3_append_scaled(BgFP64Vector3* basic_vector, const BgFP64Vector3* scalable_vector, const double scale)
|
static inline void fp64_vector3_append_scaled(fp64_vector3_t* basic_vector, const fp64_vector3_t* scalable_vector, const double scale)
|
||||||
{
|
{
|
||||||
basic_vector->x1 += scalable_vector->x1 * scale;
|
basic_vector->x1 += scalable_vector->x1 * scale;
|
||||||
basic_vector->x2 += scalable_vector->x2 * scale;
|
basic_vector->x2 += scalable_vector->x2 * scale;
|
||||||
|
@ -272,14 +272,14 @@ static inline void bg_fp64_vector3_append_scaled(BgFP64Vector3* basic_vector, co
|
||||||
|
|
||||||
// ================== Average2 ================== //
|
// ================== Average2 ================== //
|
||||||
|
|
||||||
static inline void bg_fp32_vector3_get_mean2(const BgFP32Vector3* vector1, const BgFP32Vector3* vector2, BgFP32Vector3* result)
|
static inline void fp32_vector3_get_mean2(const fp32_vector3_t* vector1, const fp32_vector3_t* vector2, fp32_vector3_t* result)
|
||||||
{
|
{
|
||||||
result->x1 = (vector1->x1 + vector2->x1) * 0.5f;
|
result->x1 = (vector1->x1 + vector2->x1) * 0.5f;
|
||||||
result->x2 = (vector1->x2 + vector2->x2) * 0.5f;
|
result->x2 = (vector1->x2 + vector2->x2) * 0.5f;
|
||||||
result->x3 = (vector1->x3 + vector2->x3) * 0.5f;
|
result->x3 = (vector1->x3 + vector2->x3) * 0.5f;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_vector3_get_mean2(const BgFP64Vector3* vector1, const BgFP64Vector3* vector2, BgFP64Vector3* result)
|
static inline void fp64_vector3_get_mean2(const fp64_vector3_t* vector1, const fp64_vector3_t* vector2, fp64_vector3_t* result)
|
||||||
{
|
{
|
||||||
result->x1 = (vector1->x1 + vector2->x1) * 0.5;
|
result->x1 = (vector1->x1 + vector2->x1) * 0.5;
|
||||||
result->x2 = (vector1->x2 + vector2->x2) * 0.5;
|
result->x2 = (vector1->x2 + vector2->x2) * 0.5;
|
||||||
|
@ -288,42 +288,42 @@ static inline void bg_fp64_vector3_get_mean2(const BgFP64Vector3* vector1, const
|
||||||
|
|
||||||
// ================== Average3 ================== //
|
// ================== Average3 ================== //
|
||||||
|
|
||||||
static inline void bg_fp32_vector3_get_mean3(const BgFP32Vector3* vector1, const BgFP32Vector3* vector2, const BgFP32Vector3* vector3, BgFP32Vector3* result)
|
static inline void fp32_vector3_get_mean3(const fp32_vector3_t* vector1, const fp32_vector3_t* vector2, const fp32_vector3_t* vector3, fp32_vector3_t* result)
|
||||||
{
|
{
|
||||||
result->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * BG_FP32_ONE_THIRD;
|
result->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * FP32_ONE_THIRD;
|
||||||
result->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * BG_FP32_ONE_THIRD;
|
result->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * FP32_ONE_THIRD;
|
||||||
result->x3 = (vector1->x3 + vector2->x3 + vector3->x3) * BG_FP32_ONE_THIRD;
|
result->x3 = (vector1->x3 + vector2->x3 + vector3->x3) * FP32_ONE_THIRD;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_vector3_get_mean3(const BgFP64Vector3* vector1, const BgFP64Vector3* vector2, const BgFP64Vector3* vector3, BgFP64Vector3* result)
|
static inline void fp64_vector3_get_mean3(const fp64_vector3_t* vector1, const fp64_vector3_t* vector2, const fp64_vector3_t* vector3, fp64_vector3_t* result)
|
||||||
{
|
{
|
||||||
result->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * BG_FP64_ONE_THIRD;
|
result->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * FP64_ONE_THIRD;
|
||||||
result->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * BG_FP64_ONE_THIRD;
|
result->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * FP64_ONE_THIRD;
|
||||||
result->x3 = (vector1->x3 + vector2->x3 + vector3->x3) * BG_FP64_ONE_THIRD;
|
result->x3 = (vector1->x3 + vector2->x3 + vector3->x3) * FP64_ONE_THIRD;
|
||||||
}
|
}
|
||||||
|
|
||||||
// =============== Scalar Product =============== //
|
// =============== Scalar Product =============== //
|
||||||
|
|
||||||
static inline float bg_fp32_vector3_scalar_product(const BgFP32Vector3* vector1, const BgFP32Vector3* vector2)
|
static inline float fp32_vector3_scalar_product(const fp32_vector3_t* vector1, const fp32_vector3_t* vector2)
|
||||||
{
|
{
|
||||||
return vector1->x1 * vector2->x1 + vector1->x2 * vector2->x2 + vector1->x3 * vector2->x3;
|
return vector1->x1 * vector2->x1 + vector1->x2 * vector2->x2 + vector1->x3 * vector2->x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline double bg_fp64_vector3_scalar_product(const BgFP64Vector3* vector1, const BgFP64Vector3* vector2)
|
static inline double fp64_vector3_scalar_product(const fp64_vector3_t* vector1, const fp64_vector3_t* vector2)
|
||||||
{
|
{
|
||||||
return vector1->x1 * vector2->x1 + vector1->x2 * vector2->x2 + vector1->x3 * vector2->x3;
|
return vector1->x1 * vector2->x1 + vector1->x2 * vector2->x2 + vector1->x3 * vector2->x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
// =============== Triple Product =============== //
|
// =============== Triple Product =============== //
|
||||||
|
|
||||||
static inline float bg_fp32_vector3_triple_product(const BgFP32Vector3* vector1, const BgFP32Vector3* vector2, const BgFP32Vector3* vector3)
|
static inline float fp32_vector3_triple_product(const fp32_vector3_t* vector1, const fp32_vector3_t* vector2, const fp32_vector3_t* vector3)
|
||||||
{
|
{
|
||||||
return vector1->x1 * (vector2->x2 * vector3->x3 - vector2->x3 * vector3->x2)
|
return vector1->x1 * (vector2->x2 * vector3->x3 - vector2->x3 * vector3->x2)
|
||||||
+ vector1->x2 * (vector2->x3 * vector3->x1 - vector2->x1 * vector3->x3)
|
+ vector1->x2 * (vector2->x3 * vector3->x1 - vector2->x1 * vector3->x3)
|
||||||
+ vector1->x3 * (vector2->x1 * vector3->x2 - vector2->x2 * vector3->x1);
|
+ vector1->x3 * (vector2->x1 * vector3->x2 - vector2->x2 * vector3->x1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline double bg_fp64_vector3_triple_product(const BgFP64Vector3* vector1, const BgFP64Vector3* vector2, const BgFP64Vector3* vector3)
|
static inline double fp64_vector3_triple_product(const fp64_vector3_t* vector1, const fp64_vector3_t* vector2, const fp64_vector3_t* vector3)
|
||||||
{
|
{
|
||||||
return vector1->x1 * (vector2->x2 * vector3->x3 - vector2->x3 * vector3->x2)
|
return vector1->x1 * (vector2->x2 * vector3->x3 - vector2->x3 * vector3->x2)
|
||||||
+ vector1->x2 * (vector2->x3 * vector3->x1 - vector2->x1 * vector3->x3)
|
+ vector1->x2 * (vector2->x3 * vector3->x1 - vector2->x1 * vector3->x3)
|
||||||
|
@ -332,7 +332,7 @@ static inline double bg_fp64_vector3_triple_product(const BgFP64Vector3* vector1
|
||||||
|
|
||||||
// =============== Cross Product ================ //
|
// =============== Cross Product ================ //
|
||||||
|
|
||||||
static inline void bg_fp32_vector3_cross_product(const BgFP32Vector3* vector1, const BgFP32Vector3* vector2, BgFP32Vector3* result)
|
static inline void fp32_vector3_cross_product(const fp32_vector3_t* vector1, const fp32_vector3_t* vector2, fp32_vector3_t* result)
|
||||||
{
|
{
|
||||||
const float x1 = vector1->x2 * vector2->x3 - vector1->x3 * vector2->x2;
|
const float x1 = vector1->x2 * vector2->x3 - vector1->x3 * vector2->x2;
|
||||||
const float x2 = vector1->x3 * vector2->x1 - vector1->x1 * vector2->x3;
|
const float x2 = vector1->x3 * vector2->x1 - vector1->x1 * vector2->x3;
|
||||||
|
@ -343,7 +343,7 @@ static inline void bg_fp32_vector3_cross_product(const BgFP32Vector3* vector1, c
|
||||||
result->x3 = x3;
|
result->x3 = x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_vector3_cross_product(const BgFP64Vector3* vector1, const BgFP64Vector3* vector2, BgFP64Vector3* result)
|
static inline void fp64_vector3_cross_product(const fp64_vector3_t* vector1, const fp64_vector3_t* vector2, fp64_vector3_t* result)
|
||||||
{
|
{
|
||||||
const double x1 = vector1->x2 * vector2->x3 - vector1->x3 * vector2->x2;
|
const double x1 = vector1->x2 * vector2->x3 - vector1->x3 * vector2->x2;
|
||||||
const double x2 = vector1->x3 * vector2->x1 - vector1->x1 * vector2->x3;
|
const double x2 = vector1->x3 * vector2->x1 - vector1->x1 * vector2->x3;
|
||||||
|
@ -356,20 +356,20 @@ static inline void bg_fp64_vector3_cross_product(const BgFP64Vector3* vector1, c
|
||||||
|
|
||||||
// ============ Double Cross Product ============ //
|
// ============ Double Cross Product ============ //
|
||||||
|
|
||||||
static inline void bg_fp32_vector3_double_cross_product(const BgFP32Vector3* vector1, const BgFP32Vector3* vector2, const BgFP32Vector3* vector3, BgFP32Vector3* result)
|
static inline void fp32_vector3_double_cross_product(const fp32_vector3_t* vector1, const fp32_vector3_t* vector2, const fp32_vector3_t* vector3, fp32_vector3_t* result)
|
||||||
{
|
{
|
||||||
const float ac = bg_fp32_vector3_scalar_product(vector1, vector3);
|
const float ac = fp32_vector3_scalar_product(vector1, vector3);
|
||||||
const float ab = bg_fp32_vector3_scalar_product(vector1, vector2);
|
const float ab = fp32_vector3_scalar_product(vector1, vector2);
|
||||||
|
|
||||||
result->x1 = vector2->x1 * ac - vector3->x1 * ab;
|
result->x1 = vector2->x1 * ac - vector3->x1 * ab;
|
||||||
result->x2 = vector2->x2 * ac - vector3->x2 * ab;
|
result->x2 = vector2->x2 * ac - vector3->x2 * ab;
|
||||||
result->x3 = vector2->x3 * ac - vector3->x3 * ab;
|
result->x3 = vector2->x3 * ac - vector3->x3 * ab;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_vector3_double_cross(const BgFP64Vector3* vector1, const BgFP64Vector3* vector2, const BgFP64Vector3* vector3, BgFP64Vector3* result)
|
static inline void fp64_vector3_double_cross(const fp64_vector3_t* vector1, const fp64_vector3_t* vector2, const fp64_vector3_t* vector3, fp64_vector3_t* result)
|
||||||
{
|
{
|
||||||
const double ac = bg_fp64_vector3_scalar_product(vector1, vector3);
|
const double ac = fp64_vector3_scalar_product(vector1, vector3);
|
||||||
const double ab = bg_fp64_vector3_scalar_product(vector1, vector2);
|
const double ab = fp64_vector3_scalar_product(vector1, vector2);
|
||||||
|
|
||||||
result->x1 = vector2->x1 * ac - vector3->x1 * ab;
|
result->x1 = vector2->x1 * ac - vector3->x1 * ab;
|
||||||
result->x2 = vector2->x2 * ac - vector3->x2 * ab;
|
result->x2 = vector2->x2 * ac - vector3->x2 * ab;
|
||||||
|
@ -378,63 +378,63 @@ static inline void bg_fp64_vector3_double_cross(const BgFP64Vector3* vector1, co
|
||||||
|
|
||||||
// =============== Normalization ================ //
|
// =============== Normalization ================ //
|
||||||
|
|
||||||
static inline int bg_fp32_vector3_normalize(BgFP32Vector3* vector)
|
static inline int fp32_vector3_normalize(fp32_vector3_t* vector)
|
||||||
{
|
{
|
||||||
const float square_modulus = bg_fp32_vector3_get_square_modulus(vector);
|
const float square_modulus = fp32_vector3_get_square_modulus(vector);
|
||||||
|
|
||||||
if (1.0f - BG_FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + BG_FP32_TWO_EPSYLON) {
|
if (1.0f - FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + FP32_TWO_EPSYLON) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (square_modulus <= BG_FP32_SQUARE_EPSYLON) {
|
if (square_modulus <= FP32_SQUARE_EPSYLON) {
|
||||||
bg_fp32_vector3_reset(vector);
|
fp32_vector3_reset(vector);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bg_fp32_vector3_multiply(vector, sqrtf(1.0f / square_modulus), vector);
|
fp32_vector3_multiply(vector, sqrtf(1.0f / square_modulus), vector);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int bg_fp64_vector3_normalize(BgFP64Vector3* vector)
|
static inline int fp64_vector3_normalize(fp64_vector3_t* vector)
|
||||||
{
|
{
|
||||||
const double square_modulus = bg_fp64_vector3_get_square_modulus(vector);
|
const double square_modulus = fp64_vector3_get_square_modulus(vector);
|
||||||
|
|
||||||
if (1.0 - BG_FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0 + BG_FP64_TWO_EPSYLON) {
|
if (1.0 - FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0 + FP64_TWO_EPSYLON) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (square_modulus <= BG_FP64_SQUARE_EPSYLON) {
|
if (square_modulus <= FP64_SQUARE_EPSYLON) {
|
||||||
bg_fp64_vector3_reset(vector);
|
fp64_vector3_reset(vector);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bg_fp64_vector3_multiply(vector, sqrt(1.0 / square_modulus), vector);
|
fp64_vector3_multiply(vector, sqrt(1.0 / square_modulus), vector);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// =============== Get Normalized =============== //
|
// =============== Get Normalized =============== //
|
||||||
|
|
||||||
static inline int bg_fp32_vector3_set_normalized(const BgFP32Vector3* vector, BgFP32Vector3* result)
|
static inline int fp32_vector3_set_normalized(const fp32_vector3_t* vector, fp32_vector3_t* result)
|
||||||
{
|
{
|
||||||
bg_fp32_vector3_copy(vector, result);
|
fp32_vector3_copy(vector, result);
|
||||||
return bg_fp32_vector3_normalize(result);
|
return fp32_vector3_normalize(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int bg_fp64_vector3_set_normalized(const BgFP64Vector3* vector, BgFP64Vector3* result)
|
static inline int fp64_vector3_set_normalized(const fp64_vector3_t* vector, fp64_vector3_t* result)
|
||||||
{
|
{
|
||||||
bg_fp64_vector3_copy(vector, result);
|
fp64_vector3_copy(vector, result);
|
||||||
return bg_fp64_vector3_normalize(result);
|
return fp64_vector3_normalize(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// =================== Angle ==================== //
|
// =================== Angle ==================== //
|
||||||
|
|
||||||
float bg_fp32_vector3_get_angle(const BgFP32Vector3* vector1, const BgFP32Vector3* vector2, const angle_unit_t unit);
|
float fp32_vector3_get_angle(const fp32_vector3_t* vector1, const fp32_vector3_t* vector2, const angle_unit_t unit);
|
||||||
|
|
||||||
double bg_fp64_vector3_get_angle(const BgFP64Vector3* vector1, const BgFP64Vector3* vector2, const angle_unit_t unit);
|
double fp64_vector3_get_angle(const fp64_vector3_t* vector1, const fp64_vector3_t* vector2, const angle_unit_t unit);
|
||||||
|
|
||||||
// =============== Square Distance ============== //
|
// =============== Square Distance ============== //
|
||||||
|
|
||||||
static inline float bg_fp32_vector3_get_square_distance(const BgFP32Vector3* vector1, const BgFP32Vector3* vector2)
|
static inline float fp32_vector3_get_square_distance(const fp32_vector3_t* vector1, const fp32_vector3_t* vector2)
|
||||||
{
|
{
|
||||||
const float dx1 = (vector1->x1 - vector2->x1);
|
const float dx1 = (vector1->x1 - vector2->x1);
|
||||||
const float dx2 = (vector1->x2 - vector2->x2);
|
const float dx2 = (vector1->x2 - vector2->x2);
|
||||||
|
@ -443,7 +443,7 @@ static inline float bg_fp32_vector3_get_square_distance(const BgFP32Vector3* vec
|
||||||
return dx1 * dx1 + dx2 * dx2 + dx3 * dx3;
|
return dx1 * dx1 + dx2 * dx2 + dx3 * dx3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline double bg_fp64_vector3_get_square_distance(const BgFP64Vector3* vector1, const BgFP64Vector3* vector2)
|
static inline double fp64_vector3_get_square_distance(const fp64_vector3_t* vector1, const fp64_vector3_t* vector2)
|
||||||
{
|
{
|
||||||
const double dx1 = (vector1->x1 - vector2->x1);
|
const double dx1 = (vector1->x1 - vector2->x1);
|
||||||
const double dx2 = (vector1->x2 - vector2->x2);
|
const double dx2 = (vector1->x2 - vector2->x2);
|
||||||
|
@ -454,52 +454,52 @@ static inline double bg_fp64_vector3_get_square_distance(const BgFP64Vector3* ve
|
||||||
|
|
||||||
// ================== Distance ================== //
|
// ================== Distance ================== //
|
||||||
|
|
||||||
static inline float bg_fp32_vector3_get_distance(const BgFP32Vector3* vector1, const BgFP32Vector3* vector2)
|
static inline float fp32_vector3_get_distance(const fp32_vector3_t* vector1, const fp32_vector3_t* vector2)
|
||||||
{
|
{
|
||||||
return sqrtf(bg_fp32_vector3_get_square_distance(vector1, vector2));
|
return sqrtf(fp32_vector3_get_square_distance(vector1, vector2));
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline double bg_fp64_vector3_get_distance(const BgFP64Vector3* vector1, const BgFP64Vector3* vector2)
|
static inline double fp64_vector3_get_distance(const fp64_vector3_t* vector1, const fp64_vector3_t* vector2)
|
||||||
{
|
{
|
||||||
return sqrt(bg_fp64_vector3_get_square_distance(vector1, vector2));
|
return sqrt(fp64_vector3_get_square_distance(vector1, vector2));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================== Are Equal ================= //
|
// ================== Are Equal ================= //
|
||||||
|
|
||||||
static inline int bg_fp32_vector3_are_equal(const BgFP32Vector3* vector1, const BgFP32Vector3* vector2)
|
static inline int fp32_vector3_are_equal(const fp32_vector3_t* vector1, const fp32_vector3_t* vector2)
|
||||||
{
|
{
|
||||||
const float square_modulus1 = bg_fp32_vector3_get_square_modulus(vector1);
|
const float square_modulus1 = fp32_vector3_get_square_modulus(vector1);
|
||||||
const float square_modulus2 = bg_fp32_vector3_get_square_modulus(vector2);
|
const float square_modulus2 = fp32_vector3_get_square_modulus(vector2);
|
||||||
const float square_modulus3 = bg_fp32_vector3_get_square_distance(vector1, vector2);
|
const float square_modulus3 = fp32_vector3_get_square_distance(vector1, vector2);
|
||||||
|
|
||||||
// 3.0f means dimension amount
|
// 3.0f means dimension amount
|
||||||
if (square_modulus1 < BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT || square_modulus2 < BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT) {
|
if (square_modulus1 < FP32_EPSYLON_EFFECTIVENESS_LIMIT || square_modulus2 < FP32_EPSYLON_EFFECTIVENESS_LIMIT) {
|
||||||
return square_modulus3 < (3.0f * BG_FP32_SQUARE_EPSYLON);
|
return square_modulus3 < (3.0f * FP32_SQUARE_EPSYLON);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (square_modulus1 <= square_modulus2) {
|
if (square_modulus1 <= square_modulus2) {
|
||||||
return square_modulus3 <= (3.0f * BG_FP32_SQUARE_EPSYLON) * square_modulus2;
|
return square_modulus3 <= (3.0f * FP32_SQUARE_EPSYLON) * square_modulus2;
|
||||||
}
|
}
|
||||||
|
|
||||||
return square_modulus3 <= (3.0f * BG_FP32_SQUARE_EPSYLON) * square_modulus1;
|
return square_modulus3 <= (3.0f * FP32_SQUARE_EPSYLON) * square_modulus1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int bg_fp64_vector3_are_equal(const BgFP64Vector3* vector1, const BgFP64Vector3* vector2)
|
static inline int fp64_vector3_are_equal(const fp64_vector3_t* vector1, const fp64_vector3_t* vector2)
|
||||||
{
|
{
|
||||||
const double square_modulus1 = bg_fp64_vector3_get_square_modulus(vector1);
|
const double square_modulus1 = fp64_vector3_get_square_modulus(vector1);
|
||||||
const double square_modulus2 = bg_fp64_vector3_get_square_modulus(vector2);
|
const double square_modulus2 = fp64_vector3_get_square_modulus(vector2);
|
||||||
const double square_modulus3 = bg_fp64_vector3_get_square_distance(vector1, vector2);
|
const double square_modulus3 = fp64_vector3_get_square_distance(vector1, vector2);
|
||||||
|
|
||||||
// 3.0 means dimension amount
|
// 3.0 means dimension amount
|
||||||
if (square_modulus1 < BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT || square_modulus2 < BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT) {
|
if (square_modulus1 < FP64_EPSYLON_EFFECTIVENESS_LIMIT || square_modulus2 < FP64_EPSYLON_EFFECTIVENESS_LIMIT) {
|
||||||
return square_modulus3 < (3.0 * BG_FP64_SQUARE_EPSYLON);
|
return square_modulus3 < (3.0 * FP64_SQUARE_EPSYLON);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (square_modulus1 <= square_modulus2) {
|
if (square_modulus1 <= square_modulus2) {
|
||||||
return square_modulus3 <= (3.0 * BG_FP64_SQUARE_EPSYLON) * square_modulus2;
|
return square_modulus3 <= (3.0 * FP64_SQUARE_EPSYLON) * square_modulus2;
|
||||||
}
|
}
|
||||||
|
|
||||||
return square_modulus3 <= (3.0 * BG_FP64_SQUARE_EPSYLON) * square_modulus1;
|
return square_modulus3 <= (3.0 * FP64_SQUARE_EPSYLON) * square_modulus1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -3,68 +3,68 @@
|
||||||
#include "angle.h"
|
#include "angle.h"
|
||||||
#include "versor.h"
|
#include "versor.h"
|
||||||
|
|
||||||
const BgFP32Versor BG_FP32_IDLE_VERSOR = { 1.0f, 0.0f, 0.0f, 0.0f };
|
const fp32_versor_t 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 fp64_versor_t FP64_IDLE_VERSOR = { 1.0, 0.0, 0.0, 0.0 };
|
||||||
|
|
||||||
// =============== Set Crude Turn =============== //
|
// =============== Set Crude Turn =============== //
|
||||||
|
|
||||||
void bg_fp32_versor_set_crude_turn(const float x1, const float x2, const float x3, const float angle, const angle_unit_t unit, BgFP32Versor* result)
|
void fp32_versor_set_crude_turn(const float x1, const float x2, const float x3, const float angle, const angle_unit_t unit, fp32_versor_t* result)
|
||||||
{
|
{
|
||||||
const float square_vector = x1 * x1 + x2 * x2 + x3 * x3;
|
const float square_vector = x1 * x1 + x2 * x2 + x3 * x3;
|
||||||
|
|
||||||
if (square_vector <= BG_FP32_SQUARE_EPSYLON) {
|
if (square_vector <= FP32_SQUARE_EPSYLON) {
|
||||||
bg_fp32_versor_reset(result);
|
fp32_versor_reset(result);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const float half_angle = bg_fp32_angle_to_radians(0.5f * angle, unit);
|
const float half_angle = fp32_angle_to_radians(0.5f * angle, unit);
|
||||||
|
|
||||||
const float sine = sinf(half_angle);
|
const float sine = sinf(half_angle);
|
||||||
|
|
||||||
if (-BG_FP32_EPSYLON <= sine && sine <= BG_FP32_EPSYLON) {
|
if (-FP32_EPSYLON <= sine && sine <= FP32_EPSYLON) {
|
||||||
bg_fp32_versor_reset(result);
|
fp32_versor_reset(result);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const float multiplier = sine / sqrtf(square_vector);
|
const float multiplier = sine / sqrtf(square_vector);
|
||||||
|
|
||||||
bg_fp32_versor_set_values(cosf(half_angle), x1 * multiplier, x2 * multiplier, x3 * multiplier, result);
|
fp32_versor_set_values(cosf(half_angle), x1 * multiplier, x2 * multiplier, x3 * multiplier, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void bg_fp64_versor_set_crude_turn(const double x1, const double x2, const double x3, const double angle, const angle_unit_t unit, BgFP64Versor* result)
|
void fp64_versor_set_crude_turn(const double x1, const double x2, const double x3, const double angle, const angle_unit_t unit, fp64_versor_t* result)
|
||||||
{
|
{
|
||||||
const double square_vector = x1 * x1 + x2 * x2 + x3 * x3;
|
const double square_vector = x1 * x1 + x2 * x2 + x3 * x3;
|
||||||
|
|
||||||
if (square_vector <= BG_FP64_SQUARE_EPSYLON) {
|
if (square_vector <= FP64_SQUARE_EPSYLON) {
|
||||||
bg_fp64_versor_reset(result);
|
fp64_versor_reset(result);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const double half_angle = bg_fp64_angle_to_radians(0.5 * angle, unit);
|
const double half_angle = fp64_angle_to_radians(0.5 * angle, unit);
|
||||||
|
|
||||||
const double sine = sin(half_angle);
|
const double sine = sin(half_angle);
|
||||||
|
|
||||||
if (-BG_FP64_EPSYLON <= sine && sine <= BG_FP64_EPSYLON) {
|
if (-FP64_EPSYLON <= sine && sine <= FP64_EPSYLON) {
|
||||||
bg_fp64_versor_reset(result);
|
fp64_versor_reset(result);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const double multiplier = sine / sqrt(square_vector);
|
const double multiplier = sine / sqrt(square_vector);
|
||||||
|
|
||||||
bg_fp64_versor_set_values(cos(half_angle), x1 * multiplier, x2 * multiplier, x3 * multiplier, result);
|
fp64_versor_set_values(cos(half_angle), x1 * multiplier, x2 * multiplier, x3 * multiplier, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================= Rotation3 ================== //
|
// ================= Rotation3 ================== //
|
||||||
|
|
||||||
void bg_fp32_versor_get_rotation(const BgFP32Versor* versor, BgFP32Rotation3* result)
|
void fp32_versor_get_rotation(const fp32_versor_t* versor, fp32_rotation3_t* result)
|
||||||
{
|
{
|
||||||
if (versor == 0 || result == 0) {
|
if (versor == 0 || result == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (versor->s0 <= -(1.0f - BG_FP32_EPSYLON) || 1.0f - BG_FP32_EPSYLON <= versor->s0) {
|
if (versor->s0 <= -(1.0f - FP32_EPSYLON) || 1.0f - FP32_EPSYLON <= versor->s0) {
|
||||||
bg_fp32_rotation_reset(result);
|
fp32_rotation_reset(result);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,14 +79,14 @@ void bg_fp32_versor_get_rotation(const BgFP32Versor* versor, BgFP32Rotation3* re
|
||||||
result->axis.x3 = versor->x3 * multiplier;
|
result->axis.x3 = versor->x3 * multiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bg_fp64_versor_get_rotation(const BgFP64Versor* versor, BgFP64Rotation3* result)
|
void fp64_versor_get_rotation(const fp64_versor_t* versor, fp64_rotation3_t* result)
|
||||||
{
|
{
|
||||||
if (versor == 0 || result == 0) {
|
if (versor == 0 || result == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (versor->s0 <= -(1.0 - BG_FP64_EPSYLON) || 1.0 - BG_FP64_EPSYLON <= versor->s0) {
|
if (versor->s0 <= -(1.0 - FP64_EPSYLON) || 1.0 - FP64_EPSYLON <= versor->s0) {
|
||||||
bg_fp64_rotation_reset(result);
|
fp64_rotation_reset(result);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#ifndef _GEOMETRY_VERSOR_H_
|
#ifndef _BASIC_GEOMETRY_VERSOR_H_
|
||||||
#define _GEOMETRY_VERSOR_H_
|
#define _BASIC_GEOMETRY_VERSOR_H_
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
@ -13,11 +13,11 @@
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const float s0, x1, x2, x3;
|
const float s0, x1, x2, x3;
|
||||||
} BgFP32Versor;
|
} fp32_versor_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const double s0, x1, x2, x3;
|
const double s0, x1, x2, x3;
|
||||||
} BgFP64Versor;
|
} fp64_versor_t;
|
||||||
|
|
||||||
// ================= Dark Twins ================= //
|
// ================= Dark Twins ================= //
|
||||||
|
|
||||||
|
@ -31,12 +31,12 @@ typedef struct {
|
||||||
|
|
||||||
// ================= Constants ================== //
|
// ================= Constants ================== //
|
||||||
|
|
||||||
extern const BgFP32Versor BG_FP32_IDLE_VERSOR;
|
extern const fp32_versor_t FP32_IDLE_VERSOR;
|
||||||
extern const BgFP64Versor BG_FP64_IDLE_VERSOR;
|
extern const fp64_versor_t FP64_IDLE_VERSOR;
|
||||||
|
|
||||||
// =================== Reset ==================== //
|
// =================== Reset ==================== //
|
||||||
|
|
||||||
static inline void bg_fp32_versor_reset(BgFP32Versor* versor)
|
static inline void fp32_versor_reset(fp32_versor_t* versor)
|
||||||
{
|
{
|
||||||
__BgFP32DarkTwinVersor* twin = (__BgFP32DarkTwinVersor*)versor;
|
__BgFP32DarkTwinVersor* twin = (__BgFP32DarkTwinVersor*)versor;
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ static inline void bg_fp32_versor_reset(BgFP32Versor* versor)
|
||||||
twin->x3 = 0.0f;
|
twin->x3 = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_versor_reset(BgFP64Versor* versor)
|
static inline void fp64_versor_reset(fp64_versor_t* versor)
|
||||||
{
|
{
|
||||||
__BgFP64DarkTwinVersor* twin = (__BgFP64DarkTwinVersor*)versor;
|
__BgFP64DarkTwinVersor* twin = (__BgFP64DarkTwinVersor*)versor;
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ static inline void bg_fp64_versor_reset(BgFP64Versor* versor)
|
||||||
|
|
||||||
// ==================== Set ===================== //
|
// ==================== Set ===================== //
|
||||||
|
|
||||||
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 fp32_versor_set_values(const float s0, const float x1, const float x2, const float x3, fp32_versor_t* versor)
|
||||||
{
|
{
|
||||||
__BgFP32DarkTwinVersor* twin = (__BgFP32DarkTwinVersor*)versor;
|
__BgFP32DarkTwinVersor* twin = (__BgFP32DarkTwinVersor*)versor;
|
||||||
|
|
||||||
|
@ -69,11 +69,11 @@ static inline void bg_fp32_versor_set_values(const float s0, const float x1, con
|
||||||
|
|
||||||
const float square_modulus = (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_modulus && square_modulus <= 1.0f + BG_FP32_TWO_EPSYLON) {
|
if (1.0f - FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + FP32_TWO_EPSYLON) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (square_modulus <= BG_FP32_SQUARE_EPSYLON) {
|
if (square_modulus <= FP32_SQUARE_EPSYLON) {
|
||||||
twin->s0 = 1.0f;
|
twin->s0 = 1.0f;
|
||||||
twin->x1 = 0.0f;
|
twin->x1 = 0.0f;
|
||||||
twin->x2 = 0.0f;
|
twin->x2 = 0.0f;
|
||||||
|
@ -89,7 +89,7 @@ static inline void bg_fp32_versor_set_values(const float s0, const float x1, con
|
||||||
twin->x3 *= multiplier;
|
twin->x3 *= multiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 fp64_versor_set_values(const double s0, const double x1, const double x2, const double x3, fp64_versor_t* versor)
|
||||||
{
|
{
|
||||||
__BgFP64DarkTwinVersor* twin = (__BgFP64DarkTwinVersor*)versor;
|
__BgFP64DarkTwinVersor* twin = (__BgFP64DarkTwinVersor*)versor;
|
||||||
|
|
||||||
|
@ -100,11 +100,11 @@ static inline void bg_fp64_versor_set_values(const double s0, const double x1, c
|
||||||
|
|
||||||
const double square_modulus = (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_modulus && square_modulus <= 1.0 + BG_FP64_TWO_EPSYLON) {
|
if (1.0 - FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0 + FP64_TWO_EPSYLON) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (square_modulus <= BG_FP64_SQUARE_EPSYLON) {
|
if (square_modulus <= FP64_SQUARE_EPSYLON) {
|
||||||
twin->s0 = 1.0;
|
twin->s0 = 1.0;
|
||||||
twin->x1 = 0.0;
|
twin->x1 = 0.0;
|
||||||
twin->x2 = 0.0;
|
twin->x2 = 0.0;
|
||||||
|
@ -122,7 +122,7 @@ static inline void bg_fp64_versor_set_values(const double s0, const double x1, c
|
||||||
|
|
||||||
// ==================== Copy ==================== //
|
// ==================== Copy ==================== //
|
||||||
|
|
||||||
static inline void bg_fp32_versor_copy(const BgFP32Versor* from, BgFP32Versor* to)
|
static inline void fp32_versor_copy(const fp32_versor_t* from, fp32_versor_t* to)
|
||||||
{
|
{
|
||||||
__BgFP32DarkTwinVersor* twin = (__BgFP32DarkTwinVersor*)to;
|
__BgFP32DarkTwinVersor* twin = (__BgFP32DarkTwinVersor*)to;
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ static inline void bg_fp32_versor_copy(const BgFP32Versor* from, BgFP32Versor* t
|
||||||
twin->x3 = from->x3;
|
twin->x3 = from->x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_versor_copy(const BgFP64Versor* from, BgFP64Versor* to)
|
static inline void fp64_versor_copy(const fp64_versor_t* from, fp64_versor_t* to)
|
||||||
{
|
{
|
||||||
__BgFP64DarkTwinVersor* twin = (__BgFP64DarkTwinVersor*)to;
|
__BgFP64DarkTwinVersor* twin = (__BgFP64DarkTwinVersor*)to;
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ static inline void bg_fp64_versor_copy(const BgFP64Versor* from, BgFP64Versor* t
|
||||||
|
|
||||||
// ==================== Swap ==================== //
|
// ==================== Swap ==================== //
|
||||||
|
|
||||||
static inline void bg_fp32_versor_swap(BgFP32Versor* versor1, BgFP32Versor* versor2)
|
static inline void fp32_versor_swap(fp32_versor_t* versor1, fp32_versor_t* versor2)
|
||||||
{
|
{
|
||||||
const float s0 = versor1->s0;
|
const float s0 = versor1->s0;
|
||||||
const float x1 = versor1->x1;
|
const float x1 = versor1->x1;
|
||||||
|
@ -166,7 +166,7 @@ static inline void bg_fp32_versor_swap(BgFP32Versor* versor1, BgFP32Versor* vers
|
||||||
twin2->x3 = x3;
|
twin2->x3 = x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_versor_swap(BgFP64Versor* versor1, BgFP64Versor* versor2)
|
static inline void fp64_versor_swap(fp64_versor_t* versor1, fp64_versor_t* versor2)
|
||||||
{
|
{
|
||||||
const double s0 = versor1->s0;
|
const double s0 = versor1->s0;
|
||||||
const double x1 = versor1->x1;
|
const double x1 = versor1->x1;
|
||||||
|
@ -190,51 +190,51 @@ static inline void bg_fp64_versor_swap(BgFP64Versor* versor1, BgFP64Versor* vers
|
||||||
|
|
||||||
// =============== Set Crude Turn =============== //
|
// =============== Set Crude Turn =============== //
|
||||||
|
|
||||||
void bg_fp32_versor_set_crude_turn(const float x1, const float x2, const float x3, const float angle, const angle_unit_t unit, BgFP32Versor* result);
|
void fp32_versor_set_crude_turn(const float x1, const float x2, const float x3, const float angle, const angle_unit_t unit, fp32_versor_t* result);
|
||||||
|
|
||||||
void bg_fp64_versor_set_crude_turn(const double x1, const double x2, const double x3, const double angle, const angle_unit_t unit, BgFP64Versor* result);
|
void fp64_versor_set_crude_turn(const double x1, const double x2, const double x3, const double angle, const angle_unit_t unit, fp64_versor_t* result);
|
||||||
|
|
||||||
// ================== Set Turn ================== //
|
// ================== Set Turn ================== //
|
||||||
|
|
||||||
static inline void bg_fp32_versor_set_turn(const BgFP32Vector3* axis, const float angle, const angle_unit_t unit, BgFP32Versor* result)
|
static inline void fp32_versor_set_turn(const fp32_vector3_t* axis, const float angle, const angle_unit_t unit, fp32_versor_t* result)
|
||||||
{
|
{
|
||||||
bg_fp32_versor_set_crude_turn(axis->x1, axis->x2, axis->x3, angle, unit, result);
|
fp32_versor_set_crude_turn(axis->x1, axis->x2, axis->x3, angle, unit, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_versor_set_turn(const BgFP32Vector3* axis, const double angle, const angle_unit_t unit, BgFP64Versor* result)
|
static inline void fp64_versor_set_turn(const fp32_vector3_t* axis, const double angle, const angle_unit_t unit, fp64_versor_t* result)
|
||||||
{
|
{
|
||||||
bg_fp64_versor_set_crude_turn(axis->x1, axis->x2, axis->x3, angle, unit, result);
|
fp64_versor_set_crude_turn(axis->x1, axis->x2, axis->x3, angle, unit, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================ Set Rotation ================ //
|
// ================ Set Rotation ================ //
|
||||||
|
|
||||||
static inline void bg_fp32_versor_set_rotation(const BgFP32Rotation3* rotation, BgFP32Versor* result)
|
static inline void fp32_versor_set_rotation(const fp32_rotation3_t* rotation, fp32_versor_t* result)
|
||||||
{
|
{
|
||||||
bg_fp32_versor_set_crude_turn(rotation->axis.x1, rotation->axis.x2, rotation->axis.x3, rotation->radians, BG_ANGLE_UNIT_RADIANS, result);
|
fp32_versor_set_crude_turn(rotation->axis.x1, rotation->axis.x2, rotation->axis.x3, rotation->radians, BG_ANGLE_UNIT_RADIANS, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_versor_set_rotation(const BgFP64Rotation3* rotation, BgFP64Versor* result)
|
static inline void fp64_versor_set_rotation(const fp64_rotation3_t* rotation, fp64_versor_t* result)
|
||||||
{
|
{
|
||||||
bg_fp64_versor_set_crude_turn(rotation->axis.x1, rotation->axis.x2, rotation->axis.x3, rotation->radians, BG_ANGLE_UNIT_RADIANS, result);
|
fp64_versor_set_crude_turn(rotation->axis.x1, rotation->axis.x2, rotation->axis.x3, rotation->radians, BG_ANGLE_UNIT_RADIANS, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================= Comparison ================= //
|
// ================= Comparison ================= //
|
||||||
|
|
||||||
static inline int bg_fp32_versor_is_idle(const BgFP32Versor* versor)
|
static inline int fp32_versor_is_idle(const fp32_versor_t* versor)
|
||||||
{
|
{
|
||||||
return 1.0f - BG_FP32_EPSYLON <= versor->s0 || versor->s0 <= -(1.0 - BG_FP32_EPSYLON);
|
return 1.0f - FP32_EPSYLON <= versor->s0 || versor->s0 <= -(1.0 - FP32_EPSYLON);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int bg_fp64_versor_is_idle(const BgFP64Versor* versor)
|
static inline int fp64_versor_is_idle(const fp64_versor_t* versor)
|
||||||
{
|
{
|
||||||
return 1.0 - BG_FP64_EPSYLON <= versor->s0 || versor->s0 <= -(1.0 - BG_FP64_EPSYLON);
|
return 1.0 - FP64_EPSYLON <= versor->s0 || versor->s0 <= -(1.0 - FP64_EPSYLON);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============= Copy to twin type ============== //
|
// ============= Copy to twin type ============== //
|
||||||
|
|
||||||
static inline void bg_fp32_versor_set_from_fp64(const BgFP64Versor* versor, BgFP32Versor* result)
|
static inline void fp32_versor_set_from_fp64(const fp64_versor_t* versor, fp32_versor_t* result)
|
||||||
{
|
{
|
||||||
bg_fp32_versor_set_values(
|
fp32_versor_set_values(
|
||||||
(float) versor->s0,
|
(float) versor->s0,
|
||||||
(float) versor->x1,
|
(float) versor->x1,
|
||||||
(float) versor->x2,
|
(float) versor->x2,
|
||||||
|
@ -243,9 +243,9 @@ static inline void bg_fp32_versor_set_from_fp64(const BgFP64Versor* versor, BgFP
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_versor_set_from_fp32(const BgFP32Versor* versor, BgFP64Versor* result)
|
static inline void fp64_versor_set_from_fp32(const fp32_versor_t* versor, fp64_versor_t* result)
|
||||||
{
|
{
|
||||||
bg_fp64_versor_set_values(
|
fp64_versor_set_values(
|
||||||
versor->s0,
|
versor->s0,
|
||||||
versor->x1,
|
versor->x1,
|
||||||
versor->x2,
|
versor->x2,
|
||||||
|
@ -256,7 +256,7 @@ static inline void bg_fp64_versor_set_from_fp32(const BgFP32Versor* versor, BgFP
|
||||||
|
|
||||||
// ================== Shorten =================== //
|
// ================== Shorten =================== //
|
||||||
|
|
||||||
static inline void bg_fp32_versor_shorten(BgFP32Versor* versor)
|
static inline void fp32_versor_shorten(fp32_versor_t* versor)
|
||||||
{
|
{
|
||||||
if (versor->s0 >= 0.0f) {
|
if (versor->s0 >= 0.0f) {
|
||||||
return;
|
return;
|
||||||
|
@ -269,7 +269,7 @@ static inline void bg_fp32_versor_shorten(BgFP32Versor* versor)
|
||||||
twin->x3 = -versor->x3;
|
twin->x3 = -versor->x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_versor_shorten(BgFP64Versor* versor)
|
static inline void fp64_versor_shorten(fp64_versor_t* versor)
|
||||||
{
|
{
|
||||||
if (versor->s0 >= 0.0f) {
|
if (versor->s0 >= 0.0f) {
|
||||||
return;
|
return;
|
||||||
|
@ -284,7 +284,7 @@ static inline void bg_fp64_versor_shorten(BgFP64Versor* versor)
|
||||||
|
|
||||||
// ================== Shorten =================== //
|
// ================== Shorten =================== //
|
||||||
|
|
||||||
static inline void bg_fp32_versor_set_shortened(const BgFP32Versor* versor, BgFP32Versor* shortened)
|
static inline void fp32_versor_set_shortened(const fp32_versor_t* versor, fp32_versor_t* shortened)
|
||||||
{
|
{
|
||||||
__BgFP32DarkTwinVersor* twin = (__BgFP32DarkTwinVersor*)shortened;
|
__BgFP32DarkTwinVersor* twin = (__BgFP32DarkTwinVersor*)shortened;
|
||||||
|
|
||||||
|
@ -302,7 +302,7 @@ static inline void bg_fp32_versor_set_shortened(const BgFP32Versor* versor, BgFP
|
||||||
twin->x3 = -versor->x3;
|
twin->x3 = -versor->x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_versor_set_shortened(const BgFP64Versor* versor, BgFP64Versor* shortened)
|
static inline void fp64_versor_set_shortened(const fp64_versor_t* versor, fp64_versor_t* shortened)
|
||||||
{
|
{
|
||||||
__BgFP64DarkTwinVersor* twin = (__BgFP64DarkTwinVersor*)shortened;
|
__BgFP64DarkTwinVersor* twin = (__BgFP64DarkTwinVersor*)shortened;
|
||||||
|
|
||||||
|
@ -322,7 +322,7 @@ static inline void bg_fp64_versor_set_shortened(const BgFP64Versor* versor, BgFP
|
||||||
|
|
||||||
// ================= Inversion ================== //
|
// ================= Inversion ================== //
|
||||||
|
|
||||||
static inline void bg_fp32_versor_invert(BgFP32Versor* versor)
|
static inline void fp32_versor_invert(fp32_versor_t* versor)
|
||||||
{
|
{
|
||||||
__BgFP32DarkTwinVersor* twin = (__BgFP32DarkTwinVersor*)versor;
|
__BgFP32DarkTwinVersor* twin = (__BgFP32DarkTwinVersor*)versor;
|
||||||
twin->x1 = -versor->x1;
|
twin->x1 = -versor->x1;
|
||||||
|
@ -330,7 +330,7 @@ static inline void bg_fp32_versor_invert(BgFP32Versor* versor)
|
||||||
twin->x3 = -versor->x3;
|
twin->x3 = -versor->x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_versor_invert(BgFP64Versor* versor)
|
static inline void fp64_versor_invert(fp64_versor_t* versor)
|
||||||
{
|
{
|
||||||
__BgFP64DarkTwinVersor* twin = (__BgFP64DarkTwinVersor*)versor;
|
__BgFP64DarkTwinVersor* twin = (__BgFP64DarkTwinVersor*)versor;
|
||||||
twin->x1 = -versor->x1;
|
twin->x1 = -versor->x1;
|
||||||
|
@ -340,7 +340,7 @@ static inline void bg_fp64_versor_invert(BgFP64Versor* versor)
|
||||||
|
|
||||||
// ================ Set Inverted ================ //
|
// ================ Set Inverted ================ //
|
||||||
|
|
||||||
static inline void bg_fp32_versor_set_inverted(const BgFP32Versor* versor, BgFP32Versor* to)
|
static inline void fp32_versor_set_inverted(const fp32_versor_t* versor, fp32_versor_t* to)
|
||||||
{
|
{
|
||||||
__BgFP32DarkTwinVersor* twin = (__BgFP32DarkTwinVersor*)to;
|
__BgFP32DarkTwinVersor* twin = (__BgFP32DarkTwinVersor*)to;
|
||||||
twin->s0 = versor->s0;
|
twin->s0 = versor->s0;
|
||||||
|
@ -349,7 +349,7 @@ static inline void bg_fp32_versor_set_inverted(const BgFP32Versor* versor, BgFP3
|
||||||
twin->x3 = -versor->x3;
|
twin->x3 = -versor->x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_versor_set_inverted(const BgFP64Versor* versor, BgFP64Versor* to)
|
static inline void fp64_versor_set_inverted(const fp64_versor_t* versor, fp64_versor_t* to)
|
||||||
{
|
{
|
||||||
__BgFP64DarkTwinVersor* twin = (__BgFP64DarkTwinVersor*)to;
|
__BgFP64DarkTwinVersor* twin = (__BgFP64DarkTwinVersor*)to;
|
||||||
twin->s0 = versor->s0;
|
twin->s0 = versor->s0;
|
||||||
|
@ -360,9 +360,9 @@ static inline void bg_fp64_versor_set_inverted(const BgFP64Versor* versor, BgFP6
|
||||||
|
|
||||||
// ================ Set Inverted ================ //
|
// ================ Set Inverted ================ //
|
||||||
|
|
||||||
static inline void bg_fp32_versor_set_inverted_fp64(const BgFP64Versor* versor, BgFP32Versor* to)
|
static inline void fp32_versor_set_inverted_fp64(const fp64_versor_t* versor, fp32_versor_t* to)
|
||||||
{
|
{
|
||||||
bg_fp32_versor_set_values(
|
fp32_versor_set_values(
|
||||||
(float) versor->s0,
|
(float) versor->s0,
|
||||||
(float) -versor->x1,
|
(float) -versor->x1,
|
||||||
(float) -versor->x2,
|
(float) -versor->x2,
|
||||||
|
@ -371,9 +371,9 @@ static inline void bg_fp32_versor_set_inverted_fp64(const BgFP64Versor* versor,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_versor_set_inverted_fp32(const BgFP32Versor* versor, BgFP64Versor* to)
|
static inline void fp64_versor_set_inverted_fp32(const fp32_versor_t* versor, fp64_versor_t* to)
|
||||||
{
|
{
|
||||||
bg_fp64_versor_set_values(
|
fp64_versor_set_values(
|
||||||
versor->s0,
|
versor->s0,
|
||||||
-versor->x1,
|
-versor->x1,
|
||||||
-versor->x2,
|
-versor->x2,
|
||||||
|
@ -384,7 +384,7 @@ static inline void bg_fp64_versor_set_inverted_fp32(const BgFP32Versor* versor,
|
||||||
|
|
||||||
// ================ Combination ================= //
|
// ================ Combination ================= //
|
||||||
|
|
||||||
static inline void bg_fp32_versor_combine(const BgFP32Versor* second, const BgFP32Versor* first, BgFP32Versor* result)
|
static inline void fp32_versor_combine(const fp32_versor_t* second, const fp32_versor_t* first, fp32_versor_t* result)
|
||||||
{
|
{
|
||||||
const float s0 = (second->s0 * first->s0 - second->x1 * first->x1) - (second->x2 * first->x2 + second->x3 * first->x3);
|
const float s0 = (second->s0 * first->s0 - second->x1 * first->x1) - (second->x2 * first->x2 + second->x3 * first->x3);
|
||||||
const float x1 = (second->x1 * first->s0 + second->s0 * first->x1) - (second->x3 * first->x2 - second->x2 * first->x3);
|
const float x1 = (second->x1 * first->s0 + second->s0 * first->x1) - (second->x3 * first->x2 - second->x2 * first->x3);
|
||||||
|
@ -400,7 +400,7 @@ 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_modulus && square_modulus <= 1.0f + BG_FP32_TWO_EPSYLON) {
|
if (1.0f - FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + FP32_TWO_EPSYLON) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -412,7 +412,7 @@ static inline void bg_fp32_versor_combine(const BgFP32Versor* second, const BgFP
|
||||||
twin->x3 *= multiplier;
|
twin->x3 *= multiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_versor_combine(const BgFP64Versor* second, const BgFP64Versor* first, BgFP64Versor* result)
|
static inline void fp64_versor_combine(const fp64_versor_t* second, const fp64_versor_t* first, fp64_versor_t* result)
|
||||||
{
|
{
|
||||||
const double s0 = (second->s0 * first->s0 - second->x1 * first->x1) - (second->x2 * first->x2 + second->x3 * first->x3);
|
const double s0 = (second->s0 * first->s0 - second->x1 * first->x1) - (second->x2 * first->x2 + second->x3 * first->x3);
|
||||||
const double x1 = (second->x1 * first->s0 + second->s0 * first->x1) - (second->x3 * first->x2 - second->x2 * first->x3);
|
const double x1 = (second->x1 * first->s0 + second->s0 * first->x1) - (second->x3 * first->x2 - second->x2 * first->x3);
|
||||||
|
@ -428,7 +428,7 @@ 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_modulus && square_modulus <= 1.0 + BG_FP64_TWO_EPSYLON) {
|
if (1.0 - FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0 + FP64_TWO_EPSYLON) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -442,7 +442,7 @@ static inline void bg_fp64_versor_combine(const BgFP64Versor* second, const BgFP
|
||||||
|
|
||||||
// ============ Combination of three ============ //
|
// ============ Combination of three ============ //
|
||||||
|
|
||||||
static inline void bg_fp32_versor_combine3(const BgFP32Versor* third, const BgFP32Versor* second, const BgFP32Versor* first, BgFP32Versor* result)
|
static inline void fp32_versor_combine3(const fp32_versor_t* third, const fp32_versor_t* second, const fp32_versor_t* first, fp32_versor_t* result)
|
||||||
{
|
{
|
||||||
const float s0a = (second->s0 * first->s0 - second->x1 * first->x1) - (second->x2 * first->x2 + second->x3 * first->x3);
|
const float s0a = (second->s0 * first->s0 - second->x1 * first->x1) - (second->x2 * first->x2 + second->x3 * first->x3);
|
||||||
const float x1a = (second->x1 * first->s0 + second->s0 * first->x1) - (second->x3 * first->x2 - second->x2 * first->x3);
|
const float x1a = (second->x1 * first->s0 + second->s0 * first->x1) - (second->x3 * first->x2 - second->x2 * first->x3);
|
||||||
|
@ -463,7 +463,7 @@ static inline void bg_fp32_versor_combine3(const BgFP32Versor* third, const BgFP
|
||||||
twin->x2 = x2b;
|
twin->x2 = x2b;
|
||||||
twin->x3 = x3b;
|
twin->x3 = x3b;
|
||||||
|
|
||||||
if (1.0f - BG_FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + BG_FP32_TWO_EPSYLON) {
|
if (1.0f - FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + FP32_TWO_EPSYLON) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -475,7 +475,7 @@ static inline void bg_fp32_versor_combine3(const BgFP32Versor* third, const BgFP
|
||||||
twin->x3 *= multiplier;
|
twin->x3 *= multiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_versor_combine3(const BgFP64Versor* third, const BgFP64Versor* second, const BgFP64Versor* first, BgFP64Versor* result)
|
static inline void fp64_versor_combine3(const fp64_versor_t* third, const fp64_versor_t* second, const fp64_versor_t* first, fp64_versor_t* result)
|
||||||
{
|
{
|
||||||
const double s0a = (second->s0 * first->s0 - second->x1 * first->x1) - (second->x2 * first->x2 + second->x3 * first->x3);
|
const double s0a = (second->s0 * first->s0 - second->x1 * first->x1) - (second->x2 * first->x2 + second->x3 * first->x3);
|
||||||
const double x1a = (second->x1 * first->s0 + second->s0 * first->x1) - (second->x3 * first->x2 - second->x2 * first->x3);
|
const double x1a = (second->x1 * first->s0 + second->s0 * first->x1) - (second->x3 * first->x2 - second->x2 * first->x3);
|
||||||
|
@ -496,7 +496,7 @@ static inline void bg_fp64_versor_combine3(const BgFP64Versor* third, const BgFP
|
||||||
twin->x2 = x2b;
|
twin->x2 = x2b;
|
||||||
twin->x3 = x3b;
|
twin->x3 = x3b;
|
||||||
|
|
||||||
if (1.0 - BG_FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0 + BG_FP64_TWO_EPSYLON) {
|
if (1.0 - FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0 + FP64_TWO_EPSYLON) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -510,7 +510,7 @@ static inline void bg_fp64_versor_combine3(const BgFP64Versor* third, const BgFP
|
||||||
|
|
||||||
// ================= Exclusion ================== //
|
// ================= Exclusion ================== //
|
||||||
|
|
||||||
static inline void bg_fp32_versor_exclude(const BgFP32Versor* basic, const BgFP32Versor* exclusion, BgFP32Versor* result)
|
static inline void fp32_versor_exclude(const fp32_versor_t* basic, const fp32_versor_t* exclusion, fp32_versor_t* result)
|
||||||
{
|
{
|
||||||
const float s0 = (basic->s0 * exclusion->s0 + basic->x1 * exclusion->x1) + (basic->x2 * exclusion->x2 + basic->x3 * exclusion->x3);
|
const float s0 = (basic->s0 * exclusion->s0 + basic->x1 * exclusion->x1) + (basic->x2 * exclusion->x2 + basic->x3 * exclusion->x3);
|
||||||
const float x1 = (basic->x1 * exclusion->s0 - basic->s0 * exclusion->x1) + (basic->x3 * exclusion->x2 - basic->x2 * exclusion->x3);
|
const float x1 = (basic->x1 * exclusion->s0 - basic->s0 * exclusion->x1) + (basic->x3 * exclusion->x2 - basic->x2 * exclusion->x3);
|
||||||
|
@ -526,7 +526,7 @@ static inline void bg_fp32_versor_exclude(const BgFP32Versor* basic, const BgFP3
|
||||||
twin->x2 = x2;
|
twin->x2 = x2;
|
||||||
twin->x3 = x3;
|
twin->x3 = x3;
|
||||||
|
|
||||||
if (1.0f - BG_FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + BG_FP32_TWO_EPSYLON) {
|
if (1.0f - FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + FP32_TWO_EPSYLON) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -538,7 +538,7 @@ static inline void bg_fp32_versor_exclude(const BgFP32Versor* basic, const BgFP3
|
||||||
twin->x3 *= multiplier;
|
twin->x3 *= multiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_versor_exclude(const BgFP64Versor* basic, const BgFP64Versor* exclusion, BgFP64Versor* result)
|
static inline void fp64_versor_exclude(const fp64_versor_t* basic, const fp64_versor_t* exclusion, fp64_versor_t* result)
|
||||||
{
|
{
|
||||||
const double s0 = (basic->s0 * exclusion->s0 + basic->x1 * exclusion->x1) + (basic->x2 * exclusion->x2 + basic->x3 * exclusion->x3);
|
const double s0 = (basic->s0 * exclusion->s0 + basic->x1 * exclusion->x1) + (basic->x2 * exclusion->x2 + basic->x3 * exclusion->x3);
|
||||||
const double x1 = (basic->x1 * exclusion->s0 - basic->s0 * exclusion->x1) + (basic->x3 * exclusion->x2 - basic->x2 * exclusion->x3);
|
const double x1 = (basic->x1 * exclusion->s0 - basic->s0 * exclusion->x1) + (basic->x3 * exclusion->x2 - basic->x2 * exclusion->x3);
|
||||||
|
@ -554,7 +554,7 @@ static inline void bg_fp64_versor_exclude(const BgFP64Versor* basic, const BgFP6
|
||||||
twin->x2 = x2;
|
twin->x2 = x2;
|
||||||
twin->x3 = x3;
|
twin->x3 = x3;
|
||||||
|
|
||||||
if (1.0 - BG_FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0 + BG_FP64_TWO_EPSYLON) {
|
if (1.0 - FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0 + FP64_TWO_EPSYLON) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -568,13 +568,13 @@ static inline void bg_fp64_versor_exclude(const BgFP64Versor* basic, const BgFP6
|
||||||
|
|
||||||
// ================= Rotation3 ================== //
|
// ================= Rotation3 ================== //
|
||||||
|
|
||||||
void bg_fp32_versor_get_rotation(const BgFP32Versor* versor, BgFP32Rotation3* result);
|
void fp32_versor_get_rotation(const fp32_versor_t* versor, fp32_rotation3_t* result);
|
||||||
|
|
||||||
void bg_fp64_versor_get_rotation(const BgFP64Versor* versor, BgFP64Rotation3* result);
|
void fp64_versor_get_rotation(const fp64_versor_t* versor, fp64_rotation3_t* result);
|
||||||
|
|
||||||
// =========== Make Rotation Matrix3x3 ========== //
|
// =========== Make Rotation Matrix3x3 ========== //
|
||||||
|
|
||||||
static inline void bg_fp32_versor_make_rotation_matrix(const BgFP32Versor* versor, BgFP32Matrix3x3* matrix)
|
static inline void fp32_versor_make_rotation_matrix(const fp32_versor_t* versor, fp32_matrix3x3_t* matrix)
|
||||||
{
|
{
|
||||||
const float s0s0 = versor->s0 * versor->s0;
|
const float s0s0 = versor->s0 * versor->s0;
|
||||||
const float x1x1 = versor->x1 * versor->x1;
|
const float x1x1 = versor->x1 * versor->x1;
|
||||||
|
@ -602,7 +602,7 @@ static inline void bg_fp32_versor_make_rotation_matrix(const BgFP32Versor* verso
|
||||||
matrix->r1c3 = x1x3 + s0x2;
|
matrix->r1c3 = x1x3 + s0x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_versor_make_rotation_matrix(const BgFP64Versor* versor, BgFP64Matrix3x3* matrix)
|
static inline void fp64_versor_make_rotation_matrix(const fp64_versor_t* versor, fp64_matrix3x3_t* matrix)
|
||||||
{
|
{
|
||||||
const double s0s0 = versor->s0 * versor->s0;
|
const double s0s0 = versor->s0 * versor->s0;
|
||||||
const double x1x1 = versor->x1 * versor->x1;
|
const double x1x1 = versor->x1 * versor->x1;
|
||||||
|
@ -632,7 +632,7 @@ static inline void bg_fp64_versor_make_rotation_matrix(const BgFP64Versor* verso
|
||||||
|
|
||||||
// =========== Make Reverse Matrix3x3 =========== //
|
// =========== Make Reverse Matrix3x3 =========== //
|
||||||
|
|
||||||
static inline void bg_fp32_versor_make_reverse_matrix(const BgFP32Versor* versor, BgFP32Matrix3x3* matrix)
|
static inline void fp32_versor_make_reverse_matrix(const fp32_versor_t* versor, fp32_matrix3x3_t* matrix)
|
||||||
{
|
{
|
||||||
const float s0s0 = versor->s0 * versor->s0;
|
const float s0s0 = versor->s0 * versor->s0;
|
||||||
const float x1x1 = versor->x1 * versor->x1;
|
const float x1x1 = versor->x1 * versor->x1;
|
||||||
|
@ -660,7 +660,7 @@ static inline void bg_fp32_versor_make_reverse_matrix(const BgFP32Versor* versor
|
||||||
matrix->r1c3 = x1x3 - s0x2;
|
matrix->r1c3 = x1x3 - s0x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_versor_make_reverse_matrix(const BgFP64Versor* versor, BgFP64Matrix3x3* matrix)
|
static inline void fp64_versor_make_reverse_matrix(const fp64_versor_t* versor, fp64_matrix3x3_t* matrix)
|
||||||
{
|
{
|
||||||
const double s0s0 = versor->s0 * versor->s0;
|
const double s0s0 = versor->s0 * versor->s0;
|
||||||
const double x1x1 = versor->x1 * versor->x1;
|
const double x1x1 = versor->x1 * versor->x1;
|
||||||
|
@ -690,7 +690,7 @@ static inline void bg_fp64_versor_make_reverse_matrix(const BgFP64Versor* versor
|
||||||
|
|
||||||
// ================ Turn Vector ================= //
|
// ================ Turn Vector ================= //
|
||||||
|
|
||||||
static inline void bg_fp32_versor_turn(const BgFP32Versor* versor, const BgFP32Vector3* vector, BgFP32Vector3* result)
|
static inline void fp32_versor_turn(const fp32_versor_t* versor, const fp32_vector3_t* vector, fp32_vector3_t* result)
|
||||||
{
|
{
|
||||||
const float tx1 = 2.0f * (versor->x2 * vector->x3 - versor->x3 * vector->x2);
|
const float tx1 = 2.0f * (versor->x2 * vector->x3 - versor->x3 * vector->x2);
|
||||||
const float tx2 = 2.0f * (versor->x3 * vector->x1 - versor->x1 * vector->x3);
|
const float tx2 = 2.0f * (versor->x3 * vector->x1 - versor->x1 * vector->x3);
|
||||||
|
@ -705,7 +705,7 @@ static inline void bg_fp32_versor_turn(const BgFP32Versor* versor, const BgFP32V
|
||||||
result->x3 = x3;
|
result->x3 = x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_versor_turn(const BgFP64Versor* versor, const BgFP64Vector3* vector, BgFP64Vector3* result)
|
static inline void fp64_versor_turn(const fp64_versor_t* versor, const fp64_vector3_t* vector, fp64_vector3_t* result)
|
||||||
{
|
{
|
||||||
const double tx1 = 2.0 * (versor->x2 * vector->x3 - versor->x3 * vector->x2);
|
const double tx1 = 2.0 * (versor->x2 * vector->x3 - versor->x3 * vector->x2);
|
||||||
const double tx2 = 2.0 * (versor->x3 * vector->x1 - versor->x1 * vector->x3);
|
const double tx2 = 2.0 * (versor->x3 * vector->x1 - versor->x1 * vector->x3);
|
||||||
|
@ -722,7 +722,7 @@ static inline void bg_fp64_versor_turn(const BgFP64Versor* versor, const BgFP64V
|
||||||
|
|
||||||
// ============== Turn Vector Back ============== //
|
// ============== Turn Vector Back ============== //
|
||||||
|
|
||||||
static inline void bg_fp32_versor_turn_back(const BgFP32Versor* versor, const BgFP32Vector3* vector, BgFP32Vector3* result)
|
static inline void fp32_versor_turn_back(const fp32_versor_t* versor, const fp32_vector3_t* vector, fp32_vector3_t* result)
|
||||||
{
|
{
|
||||||
const float tx1 = 2.0f * (versor->x2 * vector->x3 - versor->x3 * vector->x2);
|
const float tx1 = 2.0f * (versor->x2 * vector->x3 - versor->x3 * vector->x2);
|
||||||
const float tx2 = 2.0f * (versor->x3 * vector->x1 - versor->x1 * vector->x3);
|
const float tx2 = 2.0f * (versor->x3 * vector->x1 - versor->x1 * vector->x3);
|
||||||
|
@ -737,7 +737,7 @@ static inline void bg_fp32_versor_turn_back(const BgFP32Versor* versor, const Bg
|
||||||
result->x3 = x3;
|
result->x3 = x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void bg_fp64_versor_turn_back(const BgFP64Versor* versor, const BgFP64Vector3* vector, BgFP64Vector3* result)
|
static inline void fp64_versor_turn_back(const fp64_versor_t* versor, const fp64_vector3_t* vector, fp64_vector3_t* result)
|
||||||
{
|
{
|
||||||
const double tx1 = 2.0 * (versor->x2 * vector->x3 - versor->x3 * vector->x2);
|
const double tx1 = 2.0 * (versor->x2 * vector->x3 - versor->x3 * vector->x2);
|
||||||
const double tx2 = 2.0 * (versor->x3 * vector->x1 - versor->x1 * vector->x3);
|
const double tx2 = 2.0 * (versor->x3 * vector->x1 - versor->x1 * vector->x3);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue