Большое переупорядочивание исходного кода
This commit is contained in:
parent
fffe2be43b
commit
43bf030295
26 changed files with 1225 additions and 1137 deletions
|
@ -27,10 +27,11 @@
|
|||
<Option type="1" />
|
||||
<Option compiler="gcc" />
|
||||
<Compiler>
|
||||
<Add option="-O2" />
|
||||
<Add option="-O3" />
|
||||
<Add directory="../basic-geometry" />
|
||||
</Compiler>
|
||||
<Linker>
|
||||
<Add option="-O3" />
|
||||
<Add option="-s" />
|
||||
<Add library="basic-geometry" />
|
||||
<Add library="m" />
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
/*
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
@ -12,8 +11,6 @@
|
|||
|
||||
typedef struct {
|
||||
BgcVersorFP32 versor1, versor2, result;
|
||||
//BgcMatrix3x3FP32 matrix;
|
||||
//BgcVector3FP32 vector1, vector2;
|
||||
} structure_fp32_t;
|
||||
|
||||
structure_fp32_t* allocate_structures(const unsigned int amount)
|
||||
|
@ -49,18 +46,6 @@ structure_fp32_t* make_structures(const unsigned int amount)
|
|||
);
|
||||
|
||||
bgc_versor_reset_fp32(&list[i].result);
|
||||
|
||||
//bgc_matrix3x3_set_to_identity_fp32(&list[i].matrix);
|
||||
/*
|
||||
bgc_vector3_set_values_fp32(
|
||||
rand() * multiplier - 1.0f,
|
||||
rand() * multiplier - 1.0f,
|
||||
rand() * multiplier - 1.0f,
|
||||
&list[i].vector1
|
||||
);
|
||||
|
||||
bgc_vector3_reset_fp32(&list[i].vector2);
|
||||
*//*
|
||||
}
|
||||
|
||||
return list;
|
||||
|
@ -94,7 +79,7 @@ void list_work(const uint_fast32_t amount, structure_fp32_t* list)
|
|||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
||||
int main()
|
||||
{
|
||||
const unsigned int amount = 1000000;
|
||||
|
@ -136,18 +121,3 @@ int main()
|
|||
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <basic-geometry.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
BgcVector3FP32 my_vector;
|
||||
|
||||
bgc_vector3_set_values_fp32(-2, 7, 10, &my_vector);
|
||||
|
||||
printf("x1 = %f, x2 = %f, x3 = %f\n", my_vector.x1, my_vector.x2, my_vector.x3);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -106,13 +106,13 @@ static const float _TEST_FP32_DATA_SQUARE_NONUNIT[] = {
|
|||
1.0f - 2.25f * BGC_EPSYLON_FP32
|
||||
};
|
||||
|
||||
int test_is_sqare_value_unit_fp32()
|
||||
int test_is_sqare_unit_fp32()
|
||||
{
|
||||
print_testing_name("bgc_is_sqare_value_unit_fp32");
|
||||
print_testing_name("bgc_is_sqare_unit_fp32");
|
||||
|
||||
// Testing unit values:
|
||||
for (int i = 0; i < _TEST_FP32_DATA_SQUARE_UNIT_AMOUNT; i++) {
|
||||
if (!bgc_is_sqare_value_unit_fp32(_TEST_FP32_DATA_SQUARE_UNIT[i])) {
|
||||
if (!bgc_is_sqare_unit_fp32(_TEST_FP32_DATA_SQUARE_UNIT[i])) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ int test_is_sqare_value_unit_fp32()
|
|||
|
||||
// Testing non-unit values:
|
||||
for (int i = 0; i < _TEST_FP32_DATA_SQUARE_NONUNIT_AMOUNT; i++) {
|
||||
if (bgc_is_sqare_value_unit_fp32(_TEST_FP32_DATA_SQUARE_NONUNIT[i])) {
|
||||
if (bgc_is_sqare_unit_fp32(_TEST_FP32_DATA_SQUARE_NONUNIT[i])) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
@ -149,13 +149,13 @@ static const double _TEST_FP64_DATA_SQUARE_NONUNIT[] = {
|
|||
1.0 - 2.25 * BGC_EPSYLON_FP64
|
||||
};
|
||||
|
||||
int test_is_sqare_value_unit_fp64()
|
||||
int test_is_sqare_unit_fp64()
|
||||
{
|
||||
print_testing_name("bgc_is_sqare_value_unit_fp64");
|
||||
print_testing_name("bgc_is_sqare_unit_fp64");
|
||||
|
||||
// Testing unit values:
|
||||
for (int i = 0; i < _TEST_FP64_DATA_SQUARE_UNIT_AMOUNT; i++) {
|
||||
if (!bgc_is_sqare_value_unit_fp64(_TEST_FP64_DATA_SQUARE_UNIT[i])) {
|
||||
if (!bgc_is_sqare_unit_fp64(_TEST_FP64_DATA_SQUARE_UNIT[i])) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ int test_is_sqare_value_unit_fp64()
|
|||
|
||||
// Testing non-unit values:
|
||||
for (int i = 0; i < _TEST_FP64_DATA_SQUARE_NONUNIT_AMOUNT; i++) {
|
||||
if (bgc_is_sqare_value_unit_fp64(_TEST_FP64_DATA_SQUARE_NONUNIT[i])) {
|
||||
if (bgc_is_sqare_unit_fp64(_TEST_FP64_DATA_SQUARE_NONUNIT[i])) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
@ -184,11 +184,11 @@ int test_is_unit()
|
|||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
if (test_is_sqare_value_unit_fp32() != TEST_SUCCES) {
|
||||
if (test_is_sqare_unit_fp32() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
if (test_is_sqare_value_unit_fp64() != TEST_SUCCES) {
|
||||
if (test_is_sqare_unit_fp64() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,9 +5,9 @@ int test_is_unit_fp32();
|
|||
|
||||
int test_is_unit_fp64();
|
||||
|
||||
int test_is_sqare_value_unit_fp32();
|
||||
int test_is_sqare_unit_fp32();
|
||||
|
||||
int test_is_sqare_value_unit_fp64();
|
||||
int test_is_sqare_unit_fp64();
|
||||
|
||||
int test_is_unit();
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ int test_vector2_fp32_square_modulus()
|
|||
return TEST_SUCCES;
|
||||
}
|
||||
|
||||
// =================== Module =================== //
|
||||
// ================== Modulus =================== //
|
||||
|
||||
const float FP32_VECTOR2_MODULUS_1[] = { 5.0f, 5.0f, 22360.68f, 10.0005f, 123.55626338f };
|
||||
|
||||
|
|
|
@ -52,7 +52,13 @@
|
|||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="matrix2x2.h" />
|
||||
<Unit filename="matrix2x3.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="matrix2x3.h" />
|
||||
<Unit filename="matrix3x2.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="matrix3x2.h" />
|
||||
<Unit filename="matrix3x3.c">
|
||||
<Option compilerVar="CC" />
|
||||
|
|
|
@ -9,8 +9,14 @@ extern inline void bgc_matrix2x2_set_to_identity_fp64(BgcMatrix2x2FP64* matrix);
|
|||
extern inline void bgc_matrix2x2_set_to_diagonal_fp32(const float d1, const float d2, BgcMatrix2x2FP32* matrix);
|
||||
extern inline void bgc_matrix2x2_set_to_diagonal_fp64(const double d1, const double d2, BgcMatrix2x2FP64* matrix);
|
||||
|
||||
extern inline void bgc_matrix2x2_make_rotation_fp32(const float angle, const BgcAngleUnitEnum unit, BgcMatrix2x2FP32* matrix);
|
||||
extern inline void bgc_matrix2x2_make_rotation_fp64(const double angle, const BgcAngleUnitEnum unit, BgcMatrix2x2FP64* matrix);
|
||||
extern inline void bgc_matrix2x2_set_turn_fp32(const float angle, const BgcAngleUnitEnum unit, BgcMatrix2x2FP32* matrix);
|
||||
extern inline void bgc_matrix2x2_set_turn_fp64(const double angle, const BgcAngleUnitEnum unit, BgcMatrix2x2FP64* matrix);
|
||||
|
||||
extern inline float bgc_matrix2x2_get_determinant_fp32(const BgcMatrix2x2FP32* matrix);
|
||||
extern inline double bgc_matrix2x2_get_determinant_fp64(const BgcMatrix2x2FP64* matrix);
|
||||
|
||||
extern inline int bgc_matrix2x2_is_singular_fp32(const BgcMatrix2x2FP32* matrix);
|
||||
extern inline int bgc_matrix2x2_is_singular_fp64(const BgcMatrix2x2FP64* matrix);
|
||||
|
||||
extern inline void bgc_matrix2x2_copy_fp32(const BgcMatrix2x2FP32* from, BgcMatrix2x2FP32* to);
|
||||
extern inline void bgc_matrix2x2_copy_fp64(const BgcMatrix2x2FP64* from, BgcMatrix2x2FP64* to);
|
||||
|
@ -21,23 +27,11 @@ extern inline void bgc_matrix2x2_swap_fp64(BgcMatrix2x2FP64* matrix1, BgcMatrix2
|
|||
extern inline void bgc_matrix2x2_convert_fp64_to_fp32(const BgcMatrix2x2FP64* from, BgcMatrix2x2FP32* to);
|
||||
extern inline void bgc_matrix2x2_convert_fp32_to_fp64(const BgcMatrix2x2FP32* from, BgcMatrix2x2FP64* to);
|
||||
|
||||
extern inline float bgc_matrix2x2_get_determinant_fp32(const BgcMatrix2x2FP32* matrix);
|
||||
extern inline double bgc_matrix2x2_get_determinant_fp64(const BgcMatrix2x2FP64* matrix);
|
||||
|
||||
extern inline int bgc_matrix2x2_is_singular_fp32(const BgcMatrix2x2FP32* matrix);
|
||||
extern inline int bgc_matrix2x2_is_singular_fp64(const BgcMatrix2x2FP64* matrix);
|
||||
|
||||
extern inline void bgc_matrix2x2_transpose_fp32(BgcMatrix2x2FP32* matrix);
|
||||
extern inline void bgc_matrix2x2_transpose_fp64(BgcMatrix2x2FP64* matrix);
|
||||
|
||||
extern inline int bgc_matrix2x2_invert_fp32(BgcMatrix2x2FP32* matrix);
|
||||
extern inline int bgc_matrix2x2_invert_fp64(BgcMatrix2x2FP64* matrix);
|
||||
|
||||
extern inline void bgc_matrix2x2_set_transposed_fp32(const BgcMatrix2x2FP32* from, BgcMatrix2x2FP32* to);
|
||||
extern inline void bgc_matrix2x2_set_transposed_fp64(const BgcMatrix2x2FP64* from, BgcMatrix2x2FP64* to);
|
||||
|
||||
extern inline int bgc_matrix2x2_set_inverted_fp32(const BgcMatrix2x2FP32* from, BgcMatrix2x2FP32* to);
|
||||
extern inline int bgc_matrix2x2_set_inverted_fp64(const BgcMatrix2x2FP64* from, BgcMatrix2x2FP64* to);
|
||||
extern inline void bgc_matrix2x2_transpose_fp32(BgcMatrix2x2FP32* matrix);
|
||||
extern inline void bgc_matrix2x2_transpose_fp64(BgcMatrix2x2FP64* matrix);
|
||||
|
||||
extern inline void bgc_matrix2x2_set_row1_fp32(const float c1, const float c2, BgcMatrix2x2FP32* matrix);
|
||||
extern inline void bgc_matrix2x2_set_row1_fp64(const double c1, const double c2, BgcMatrix2x2FP64* matrix);
|
||||
|
@ -51,6 +45,12 @@ extern inline void bgc_matrix2x2_set_column1_fp64(const double r1, const double
|
|||
extern inline void bgc_matrix2x2_set_column2_fp32(const float r1, const float r2, BgcMatrix2x2FP32* matrix);
|
||||
extern inline void bgc_matrix2x2_set_column2_fp64(const double r1, const double r2, BgcMatrix2x2FP64* matrix);
|
||||
|
||||
extern inline int bgc_matrix2x2_make_inverted_fp32(const BgcMatrix2x2FP32* from, BgcMatrix2x2FP32* to);
|
||||
extern inline int bgc_matrix2x2_make_inverted_fp64(const BgcMatrix2x2FP64* from, BgcMatrix2x2FP64* to);
|
||||
|
||||
extern inline void bgc_matrix2x2_make_transposed_fp32(const BgcMatrix2x2FP32* from, BgcMatrix2x2FP32* to);
|
||||
extern inline void bgc_matrix2x2_make_transposed_fp64(const BgcMatrix2x2FP64* from, BgcMatrix2x2FP64* to);
|
||||
|
||||
extern inline void bgc_matrix2x2_add_fp32(const BgcMatrix2x2FP32* matrix1, const BgcMatrix2x2FP32* matrix2, BgcMatrix2x2FP32* sum);
|
||||
extern inline void bgc_matrix2x2_add_fp64(const BgcMatrix2x2FP64* matrix1, const BgcMatrix2x2FP64* matrix2, BgcMatrix2x2FP64* sum);
|
||||
|
||||
|
@ -60,14 +60,18 @@ extern inline void bgc_matrix2x2_add_scaled_fp64(const BgcMatrix2x2FP64* basic_m
|
|||
extern inline void bgc_matrix2x2_subtract_fp32(const BgcMatrix2x2FP32* minuend, const BgcMatrix2x2FP32* subtrahend, BgcMatrix2x2FP32* difference);
|
||||
extern inline void bgc_matrix2x2_subtract_fp64(const BgcMatrix2x2FP64* minuend, const BgcMatrix2x2FP64* subtrahend, BgcMatrix2x2FP64* difference);
|
||||
|
||||
extern inline void bgc_matrix2x2_subtract_scaled_fp32(const BgcMatrix2x2FP32* basic_matrix, const BgcMatrix2x2FP32* scalable_matrix, const float scale, BgcMatrix2x2FP32* difference);
|
||||
extern inline void bgc_matrix2x2_subtract_scaled_fp64(const BgcMatrix2x2FP64* basic_matrix, const BgcMatrix2x2FP64* scalable_matrix, const double scale, BgcMatrix2x2FP64* difference);
|
||||
|
||||
extern inline void bgc_matrix2x2_multiply_fp32(const BgcMatrix2x2FP32* multiplicand, const float multiplier, BgcMatrix2x2FP32* product);
|
||||
extern inline void bgc_matrix2x2_multiply_fp64(const BgcMatrix2x2FP64* multiplicand, const double multiplier, BgcMatrix2x2FP64* product);
|
||||
|
||||
extern inline void bgc_matrix2x2_divide_fp32(const BgcMatrix2x2FP32* dividend, const float divisor, BgcMatrix2x2FP32* quotient);
|
||||
extern inline void bgc_matrix2x2_divide_fp64(const BgcMatrix2x2FP64* dividend, const double divisor, BgcMatrix2x2FP64* quotient);
|
||||
|
||||
extern inline void bgc_matrix2x2_left_product_fp32(const BgcVector2FP32* vector, const BgcMatrix2x2FP32* matrix, BgcVector2FP32* result);
|
||||
extern inline void bgc_matrix2x2_left_product_fp64(const BgcVector2FP64* vector, const BgcMatrix2x2FP64* matrix, BgcVector2FP64* result);
|
||||
extern inline void bgc_matrix2x2_left_product_fp32(const BgcVector2FP32* vector, const BgcMatrix2x2FP32* matrix, BgcVector2FP32* product);
|
||||
extern inline void bgc_matrix2x2_left_product_fp64(const BgcVector2FP64* vector, const BgcMatrix2x2FP64* matrix, BgcVector2FP64* product);
|
||||
|
||||
extern inline void bgc_matrix2x2_right_product_fp32(const BgcMatrix2x2FP32* matrix, const BgcVector2FP32* vector, BgcVector2FP32* product);
|
||||
extern inline void bgc_matrix2x2_right_product_fp64(const BgcMatrix2x2FP64* matrix, const BgcVector2FP64* vector, BgcVector2FP64* product);
|
||||
|
||||
extern inline void bgc_matrix2x2_right_product_fp32(const BgcMatrix2x2FP32* matrix, const BgcVector2FP32* vector, BgcVector2FP32* result);
|
||||
extern inline void bgc_matrix2x2_right_product_fp64(const BgcMatrix2x2FP64* matrix, const BgcVector2FP64* vector, BgcVector2FP64* result);
|
||||
|
|
|
@ -61,7 +61,7 @@ inline void bgc_matrix2x2_set_to_diagonal_fp64(const double d1, const double d2,
|
|||
|
||||
// ============== Rotation Matrix =============== //
|
||||
|
||||
inline void bgc_matrix2x2_make_rotation_fp32(const float angle, const BgcAngleUnitEnum unit, BgcMatrix2x2FP32* matrix)
|
||||
inline void bgc_matrix2x2_set_turn_fp32(const float angle, const BgcAngleUnitEnum unit, BgcMatrix2x2FP32* matrix)
|
||||
{
|
||||
const float radians = bgc_angle_to_radians_fp32(angle, unit);
|
||||
const float cosine = cosf(radians);
|
||||
|
@ -73,7 +73,7 @@ inline void bgc_matrix2x2_make_rotation_fp32(const float angle, const BgcAngleUn
|
|||
matrix->r2c2 = cosine;
|
||||
}
|
||||
|
||||
inline void bgc_matrix2x2_make_rotation_fp64(const double angle, const BgcAngleUnitEnum unit, BgcMatrix2x2FP64* matrix)
|
||||
inline void bgc_matrix2x2_set_turn_fp64(const double angle, const BgcAngleUnitEnum unit, BgcMatrix2x2FP64* matrix)
|
||||
{
|
||||
const double radians = bgc_angle_to_radians_fp64(angle, unit);
|
||||
const double cosine = cos(radians);
|
||||
|
@ -85,6 +85,30 @@ inline void bgc_matrix2x2_make_rotation_fp64(const double angle, const BgcAngleU
|
|||
matrix->r2c2 = cosine;
|
||||
}
|
||||
|
||||
// ================ Determinant ================= //
|
||||
|
||||
inline float bgc_matrix2x2_get_determinant_fp32(const BgcMatrix2x2FP32* matrix)
|
||||
{
|
||||
return matrix->r1c1 * matrix->r2c2 - matrix->r1c2 * matrix->r2c1;
|
||||
}
|
||||
|
||||
inline double bgc_matrix2x2_get_determinant_fp64(const BgcMatrix2x2FP64* matrix)
|
||||
{
|
||||
return matrix->r1c1 * matrix->r2c2 - matrix->r1c2 * matrix->r2c1;
|
||||
}
|
||||
|
||||
// ================== Singular ================== //
|
||||
|
||||
inline int bgc_matrix2x2_is_singular_fp32(const BgcMatrix2x2FP32* matrix)
|
||||
{
|
||||
return bgc_is_zero_fp32(bgc_matrix2x2_get_determinant_fp32(matrix));
|
||||
}
|
||||
|
||||
inline int bgc_matrix2x2_is_singular_fp64(const BgcMatrix2x2FP64* matrix)
|
||||
{
|
||||
return bgc_is_zero_fp64(bgc_matrix2x2_get_determinant_fp64(matrix));
|
||||
}
|
||||
|
||||
// ==================== Copy ==================== //
|
||||
|
||||
inline void bgc_matrix2x2_copy_fp32(const BgcMatrix2x2FP32* from, BgcMatrix2x2FP32* to)
|
||||
|
@ -149,7 +173,7 @@ inline void bgc_matrix2x2_swap_fp64(BgcMatrix2x2FP64* matrix1, BgcMatrix2x2FP64*
|
|||
matrix1->r2c2 = r2c2;
|
||||
}
|
||||
|
||||
// ============= Copy to twin type ============== //
|
||||
// ================== Convert =================== //
|
||||
|
||||
inline void bgc_matrix2x2_convert_fp64_to_fp32(const BgcMatrix2x2FP64* from, BgcMatrix2x2FP32* to)
|
||||
{
|
||||
|
@ -169,47 +193,7 @@ inline void bgc_matrix2x2_convert_fp32_to_fp64(const BgcMatrix2x2FP32* from, Bgc
|
|||
to->r2c2 = from->r2c2;
|
||||
}
|
||||
|
||||
// ================ Determinant ================= //
|
||||
|
||||
inline float bgc_matrix2x2_get_determinant_fp32(const BgcMatrix2x2FP32* matrix)
|
||||
{
|
||||
return matrix->r1c1 * matrix->r2c2 - matrix->r1c2 * matrix->r2c1;
|
||||
}
|
||||
|
||||
inline double bgc_matrix2x2_get_determinant_fp64(const BgcMatrix2x2FP64* matrix)
|
||||
{
|
||||
return matrix->r1c1 * matrix->r2c2 - matrix->r1c2 * matrix->r2c1;
|
||||
}
|
||||
|
||||
// ================== Singular ================== //
|
||||
|
||||
inline int bgc_matrix2x2_is_singular_fp32(const BgcMatrix2x2FP32* matrix)
|
||||
{
|
||||
return bgc_is_zero_fp32(bgc_matrix2x2_get_determinant_fp32(matrix));
|
||||
}
|
||||
|
||||
inline int bgc_matrix2x2_is_singular_fp64(const BgcMatrix2x2FP64* matrix)
|
||||
{
|
||||
return bgc_is_zero_fp64(bgc_matrix2x2_get_determinant_fp64(matrix));
|
||||
}
|
||||
|
||||
// =============== Transposition ================ //
|
||||
|
||||
inline void bgc_matrix2x2_transpose_fp32(BgcMatrix2x2FP32* matrix)
|
||||
{
|
||||
const float tmp = matrix->r1c2;
|
||||
matrix->r1c2 = matrix->r2c1;
|
||||
matrix->r2c1 = tmp;
|
||||
}
|
||||
|
||||
inline void bgc_matrix2x2_transpose_fp64(BgcMatrix2x2FP64* matrix)
|
||||
{
|
||||
const double tmp = matrix->r1c2;
|
||||
matrix->r1c2 = matrix->r2c1;
|
||||
matrix->r2c1 = tmp;
|
||||
}
|
||||
|
||||
// ================= Inversion ================== //
|
||||
// =================== Invert =================== //
|
||||
|
||||
inline int bgc_matrix2x2_invert_fp32(BgcMatrix2x2FP32* matrix)
|
||||
{
|
||||
|
@ -261,80 +245,20 @@ inline int bgc_matrix2x2_invert_fp64(BgcMatrix2x2FP64* matrix)
|
|||
return 1;
|
||||
}
|
||||
|
||||
// =============== Set Transposed =============== //
|
||||
// ================= Transpose ================== //
|
||||
|
||||
inline void bgc_matrix2x2_set_transposed_fp32(const BgcMatrix2x2FP32* from, BgcMatrix2x2FP32* to)
|
||||
inline void bgc_matrix2x2_transpose_fp32(BgcMatrix2x2FP32* matrix)
|
||||
{
|
||||
float tmp = from->r1c2;
|
||||
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r2c1;
|
||||
|
||||
to->r2c1 = tmp;
|
||||
to->r2c2 = from->r2c2;
|
||||
const float tmp = matrix->r1c2;
|
||||
matrix->r1c2 = matrix->r2c1;
|
||||
matrix->r2c1 = tmp;
|
||||
}
|
||||
|
||||
inline void bgc_matrix2x2_set_transposed_fp64(const BgcMatrix2x2FP64* from, BgcMatrix2x2FP64* to)
|
||||
inline void bgc_matrix2x2_transpose_fp64(BgcMatrix2x2FP64* matrix)
|
||||
{
|
||||
double tmp = from->r1c2;
|
||||
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r2c1;
|
||||
|
||||
to->r2c1 = tmp;
|
||||
to->r2c2 = from->r2c2;
|
||||
}
|
||||
|
||||
// ================ Set Inverted ================ //
|
||||
|
||||
inline int bgc_matrix2x2_set_inverted_fp32(const BgcMatrix2x2FP32* from, BgcMatrix2x2FP32* to)
|
||||
{
|
||||
const float determinant = bgc_matrix2x2_get_determinant_fp32(from);
|
||||
|
||||
if (bgc_is_zero_fp32(determinant)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const float r1c1 = from->r2c2;
|
||||
const float r1c2 = -from->r1c2;
|
||||
|
||||
const float r2c1 = -from->r2c1;
|
||||
const float r2c2 = from->r1c1;
|
||||
|
||||
const float multiplier = 1.0f / determinant;
|
||||
|
||||
to->r1c1 = r1c1 * multiplier;
|
||||
to->r1c2 = r1c2 * multiplier;
|
||||
|
||||
to->r2c1 = r2c1 * multiplier;
|
||||
to->r2c2 = r2c2 * multiplier;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_matrix2x2_set_inverted_fp64(const BgcMatrix2x2FP64* from, BgcMatrix2x2FP64* to)
|
||||
{
|
||||
const double determinant = bgc_matrix2x2_get_determinant_fp64(from);
|
||||
|
||||
if (bgc_is_zero_fp64(determinant)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const double r1c1 = from->r2c2;
|
||||
const double r1c2 = -from->r1c2;
|
||||
|
||||
const double r2c1 = -from->r2c1;
|
||||
const double r2c2 = from->r1c1;
|
||||
|
||||
const double multiplier = 1.0 / determinant;
|
||||
|
||||
to->r1c1 = r1c1 * multiplier;
|
||||
to->r1c2 = r1c2 * multiplier;
|
||||
|
||||
to->r2c1 = r2c1 * multiplier;
|
||||
to->r2c2 = r2c2 * multiplier;
|
||||
|
||||
return 1;
|
||||
const double tmp = matrix->r1c2;
|
||||
matrix->r1c2 = matrix->r2c1;
|
||||
matrix->r2c1 = tmp;
|
||||
}
|
||||
|
||||
// ================= Set Row 1 ================== //
|
||||
|
@ -393,7 +317,83 @@ inline void bgc_matrix2x2_set_column2_fp64(const double r1, const double r2, Bgc
|
|||
matrix->r2c2 = r2;
|
||||
}
|
||||
|
||||
// ================== Addition ================== //
|
||||
// =============== Make Inverted ================ //
|
||||
|
||||
inline int bgc_matrix2x2_make_inverted_fp32(const BgcMatrix2x2FP32* matrix, BgcMatrix2x2FP32* inverted)
|
||||
{
|
||||
const float determinant = bgc_matrix2x2_get_determinant_fp32(matrix);
|
||||
|
||||
if (bgc_is_zero_fp32(determinant)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const float r1c1 = matrix->r2c2;
|
||||
const float r1c2 = -matrix->r1c2;
|
||||
|
||||
const float r2c1 = -matrix->r2c1;
|
||||
const float r2c2 = matrix->r1c1;
|
||||
|
||||
const float multiplier = 1.0f / determinant;
|
||||
|
||||
inverted->r1c1 = r1c1 * multiplier;
|
||||
inverted->r1c2 = r1c2 * multiplier;
|
||||
|
||||
inverted->r2c1 = r2c1 * multiplier;
|
||||
inverted->r2c2 = r2c2 * multiplier;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_matrix2x2_make_inverted_fp64(const BgcMatrix2x2FP64* matrix, BgcMatrix2x2FP64* inverted)
|
||||
{
|
||||
const double determinant = bgc_matrix2x2_get_determinant_fp64(matrix);
|
||||
|
||||
if (bgc_is_zero_fp64(determinant)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const double r1c1 = matrix->r2c2;
|
||||
const double r1c2 = -matrix->r1c2;
|
||||
|
||||
const double r2c1 = -matrix->r2c1;
|
||||
const double r2c2 = matrix->r1c1;
|
||||
|
||||
const double multiplier = 1.0 / determinant;
|
||||
|
||||
inverted->r1c1 = r1c1 * multiplier;
|
||||
inverted->r1c2 = r1c2 * multiplier;
|
||||
|
||||
inverted->r2c1 = r2c1 * multiplier;
|
||||
inverted->r2c2 = r2c2 * multiplier;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ============== Make Transposed =============== //
|
||||
|
||||
inline void bgc_matrix2x2_make_transposed_fp32(const BgcMatrix2x2FP32* matrix, BgcMatrix2x2FP32* transposed)
|
||||
{
|
||||
float tmp = matrix->r1c2;
|
||||
|
||||
transposed->r1c1 = matrix->r1c1;
|
||||
transposed->r1c2 = matrix->r2c1;
|
||||
|
||||
transposed->r2c1 = tmp;
|
||||
transposed->r2c2 = matrix->r2c2;
|
||||
}
|
||||
|
||||
inline void bgc_matrix2x2_make_transposed_fp64(const BgcMatrix2x2FP64* matrix, BgcMatrix2x2FP64* transposed)
|
||||
{
|
||||
double tmp = matrix->r1c2;
|
||||
|
||||
transposed->r1c1 = matrix->r1c1;
|
||||
transposed->r1c2 = matrix->r2c1;
|
||||
|
||||
transposed->r2c1 = tmp;
|
||||
transposed->r2c2 = matrix->r2c2;
|
||||
}
|
||||
|
||||
// ==================== Add ===================== //
|
||||
|
||||
inline void bgc_matrix2x2_add_fp32(const BgcMatrix2x2FP32* matrix1, const BgcMatrix2x2FP32* matrix2, BgcMatrix2x2FP32* sum)
|
||||
{
|
||||
|
@ -433,7 +433,7 @@ inline void bgc_matrix2x2_add_scaled_fp64(const BgcMatrix2x2FP64* basic_matrix,
|
|||
sum->r2c2 = basic_matrix->r2c2 + scalable_matrix->r2c2 * scale;
|
||||
}
|
||||
|
||||
// ================ Subtraction ================= //
|
||||
// ================== Subtract ================== //
|
||||
|
||||
inline void bgc_matrix2x2_subtract_fp32(const BgcMatrix2x2FP32* minuend, const BgcMatrix2x2FP32* subtrahend, BgcMatrix2x2FP32* difference)
|
||||
{
|
||||
|
@ -453,7 +453,27 @@ inline void bgc_matrix2x2_subtract_fp64(const BgcMatrix2x2FP64* minuend, const B
|
|||
difference->r2c2 = minuend->r2c2 - subtrahend->r2c2;
|
||||
}
|
||||
|
||||
// =============== Multiplication =============== //
|
||||
// ============== Subtract scaled =============== //
|
||||
|
||||
inline void bgc_matrix2x2_subtract_scaled_fp32(const BgcMatrix2x2FP32* basic_matrix, const BgcMatrix2x2FP32* scalable_matrix, const float scale, BgcMatrix2x2FP32* difference)
|
||||
{
|
||||
difference->r1c1 = basic_matrix->r1c1 - scalable_matrix->r1c1 * scale;
|
||||
difference->r1c2 = basic_matrix->r1c2 - scalable_matrix->r1c2 * scale;
|
||||
|
||||
difference->r2c1 = basic_matrix->r2c1 - scalable_matrix->r2c1 * scale;
|
||||
difference->r2c2 = basic_matrix->r2c2 - scalable_matrix->r2c2 * scale;
|
||||
}
|
||||
|
||||
inline void bgc_matrix2x2_subtract_scaled_fp64(const BgcMatrix2x2FP64* basic_matrix, const BgcMatrix2x2FP64* scalable_matrix, const double scale, BgcMatrix2x2FP64* difference)
|
||||
{
|
||||
difference->r1c1 = basic_matrix->r1c1 - scalable_matrix->r1c1 * scale;
|
||||
difference->r1c2 = basic_matrix->r1c2 - scalable_matrix->r1c2 * scale;
|
||||
|
||||
difference->r2c1 = basic_matrix->r2c1 - scalable_matrix->r2c1 * scale;
|
||||
difference->r2c2 = basic_matrix->r2c2 - scalable_matrix->r2c2 * scale;
|
||||
}
|
||||
|
||||
// ================== Multiply ================== //
|
||||
|
||||
inline void bgc_matrix2x2_multiply_fp32(const BgcMatrix2x2FP32* multiplicand, const float multiplier, BgcMatrix2x2FP32* product)
|
||||
{
|
||||
|
@ -473,7 +493,7 @@ inline void bgc_matrix2x2_multiply_fp64(const BgcMatrix2x2FP64* multiplicand, co
|
|||
product->r2c2 = multiplicand->r2c2 * multiplier;
|
||||
}
|
||||
|
||||
// ================== Division ================== //
|
||||
// =================== Divide =================== //
|
||||
|
||||
inline void bgc_matrix2x2_divide_fp32(const BgcMatrix2x2FP32* dividend, const float divisor, BgcMatrix2x2FP32* quotient)
|
||||
{
|
||||
|
@ -487,42 +507,42 @@ inline void bgc_matrix2x2_divide_fp64(const BgcMatrix2x2FP64* dividend, const do
|
|||
|
||||
// ============ Left Vector Product ============= //
|
||||
|
||||
inline void bgc_matrix2x2_left_product_fp32(const BgcVector2FP32* vector, const BgcMatrix2x2FP32* matrix, BgcVector2FP32* result)
|
||||
inline void bgc_matrix2x2_left_product_fp32(const BgcVector2FP32* vector, const BgcMatrix2x2FP32* matrix, BgcVector2FP32* product)
|
||||
{
|
||||
const float x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1;
|
||||
const float x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2;
|
||||
|
||||
result->x1 = x1;
|
||||
result->x2 = x2;
|
||||
product->x1 = x1;
|
||||
product->x2 = x2;
|
||||
}
|
||||
|
||||
inline void bgc_matrix2x2_left_product_fp64(const BgcVector2FP64* vector, const BgcMatrix2x2FP64* matrix, BgcVector2FP64* result)
|
||||
inline void bgc_matrix2x2_left_product_fp64(const BgcVector2FP64* vector, const BgcMatrix2x2FP64* matrix, BgcVector2FP64* product)
|
||||
{
|
||||
const double x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1;
|
||||
const double x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2;
|
||||
|
||||
result->x1 = x1;
|
||||
result->x2 = x2;
|
||||
product->x1 = x1;
|
||||
product->x2 = x2;
|
||||
}
|
||||
|
||||
// ============ Right Vector Product ============ //
|
||||
|
||||
inline void bgc_matrix2x2_right_product_fp32(const BgcMatrix2x2FP32* matrix, const BgcVector2FP32* vector, BgcVector2FP32* result)
|
||||
inline void bgc_matrix2x2_right_product_fp32(const BgcMatrix2x2FP32* matrix, const BgcVector2FP32* vector, BgcVector2FP32* product)
|
||||
{
|
||||
const float x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2;
|
||||
const float x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2;
|
||||
|
||||
result->x1 = x1;
|
||||
result->x2 = x2;
|
||||
product->x1 = x1;
|
||||
product->x2 = x2;
|
||||
}
|
||||
|
||||
inline void bgc_matrix2x2_right_product_fp64(const BgcMatrix2x2FP64* matrix, const BgcVector2FP64* vector, BgcVector2FP64* result)
|
||||
inline void bgc_matrix2x2_right_product_fp64(const BgcMatrix2x2FP64* matrix, const BgcVector2FP64* vector, BgcVector2FP64* product)
|
||||
{
|
||||
const double x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2;
|
||||
const double x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2;
|
||||
|
||||
result->x1 = x1;
|
||||
result->x2 = x2;
|
||||
product->x1 = x1;
|
||||
product->x2 = x2;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -12,12 +12,6 @@ extern inline void bgc_matrix2x3_swap_fp64(BgcMatrix2x3FP64* matrix1, BgcMatrix2
|
|||
extern inline void bgc_matrix2x3_convert_fp64_to_fp32(const BgcMatrix2x3FP64* from, BgcMatrix2x3FP32* to);
|
||||
extern inline void bgc_matrix2x3_convert_fp32_to_fp64(const BgcMatrix2x3FP32* from, BgcMatrix2x3FP64* to);
|
||||
|
||||
extern inline void bgc_matrix2x3_set_transposed_fp32(const BgcMatrix3x2FP32* from, BgcMatrix2x3FP32* to);
|
||||
extern inline void bgc_matrix2x3_set_transposed_fp64(const BgcMatrix3x2FP64* from, BgcMatrix2x3FP64* to);
|
||||
|
||||
extern inline void bgc_matrix2x3_set_transposed_fp32_fp64(const BgcMatrix3x2FP64* from, BgcMatrix2x3FP32* to);
|
||||
extern inline void bgc_matrix2x3_set_transposed_fp64_fp32(const BgcMatrix3x2FP32* from, BgcMatrix2x3FP64* to);
|
||||
|
||||
extern inline void bgc_matrix2x3_set_row1_fp32(const float c1, const float c2, BgcMatrix2x3FP32* matrix);
|
||||
extern inline void bgc_matrix2x3_set_row1_fp64(const double c1, const double c2, BgcMatrix2x3FP64* matrix);
|
||||
|
||||
|
@ -33,6 +27,9 @@ extern inline void bgc_matrix2x3_set_column1_fp64(const double r1, const double
|
|||
extern inline void bgc_matrix2x3_set_column2_fp32(const float r1, const float r2, const float r3, BgcMatrix2x3FP32* matrix);
|
||||
extern inline void bgc_matrix2x3_set_column2_fp64(const double r1, const double r2, const double r3, BgcMatrix2x3FP64* matrix);
|
||||
|
||||
extern inline void bgc_matrix2x3_make_transposed_fp32(const BgcMatrix3x2FP32* from, BgcMatrix2x3FP32* to);
|
||||
extern inline void bgc_matrix2x3_make_transposed_fp64(const BgcMatrix3x2FP64* from, BgcMatrix2x3FP64* to);
|
||||
|
||||
extern inline void bgc_matrix2x3_add_fp32(const BgcMatrix2x3FP32* matrix1, const BgcMatrix2x3FP32* matrix2, BgcMatrix2x3FP32* sum);
|
||||
extern inline void bgc_matrix2x3_add_fp64(const BgcMatrix2x3FP64* matrix1, const BgcMatrix2x3FP64* matrix2, BgcMatrix2x3FP64* sum);
|
||||
|
||||
|
@ -42,6 +39,9 @@ extern inline void bgc_matrix2x3_add_scaled_fp64(const BgcMatrix2x3FP64* basic_m
|
|||
extern inline void bgc_matrix2x3_subtract_fp32(const BgcMatrix2x3FP32* minuend, const BgcMatrix2x3FP32* subtrahend, BgcMatrix2x3FP32* difference);
|
||||
extern inline void bgc_matrix2x3_subtract_fp64(const BgcMatrix2x3FP64* minuend, const BgcMatrix2x3FP64* subtrahend, BgcMatrix2x3FP64* difference);
|
||||
|
||||
extern inline void bgc_matrix2x3_subtract_scaled_fp32(const BgcMatrix2x3FP32* basic_matrix, const BgcMatrix2x3FP32* scalable_matrix, const float scale, BgcMatrix2x3FP32* difference);
|
||||
extern inline void bgc_matrix2x3_subtract_scaled_fp64(const BgcMatrix2x3FP64* basic_matrix, const BgcMatrix2x3FP64* scalable_matrix, const double scale, BgcMatrix2x3FP64* difference);
|
||||
|
||||
extern inline void bgc_matrix2x3_multiply_fp32(const BgcMatrix2x3FP32* multiplicand, const float multiplier, BgcMatrix2x3FP32* product);
|
||||
extern inline void bgc_matrix2x3_multiply_fp64(const BgcMatrix2x3FP64* multiplicand, const double multiplier, BgcMatrix2x3FP64* product);
|
||||
|
||||
|
|
|
@ -119,7 +119,7 @@ inline void bgc_matrix2x3_swap_fp64(BgcMatrix2x3FP64* matrix1, BgcMatrix2x3FP64*
|
|||
matrix1->r3c2 = r3c2;
|
||||
}
|
||||
|
||||
// ============= Copy to twin type ============== //
|
||||
// ================== Convert =================== //
|
||||
|
||||
inline void bgc_matrix2x3_convert_fp64_to_fp32(const BgcMatrix2x3FP64* from, BgcMatrix2x3FP32* to)
|
||||
{
|
||||
|
@ -145,58 +145,6 @@ inline void bgc_matrix2x3_convert_fp32_to_fp64(const BgcMatrix2x3FP32* from, Bgc
|
|||
to->r3c2 = from->r3c2;
|
||||
}
|
||||
|
||||
// =============== Set transposed =============== //
|
||||
|
||||
inline void bgc_matrix2x3_set_transposed_fp32(const BgcMatrix3x2FP32* from, BgcMatrix2x3FP32* to)
|
||||
{
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r2c1;
|
||||
|
||||
to->r2c1 = from->r1c2;
|
||||
to->r2c2 = from->r2c2;
|
||||
|
||||
to->r3c1 = from->r1c3;
|
||||
to->r3c2 = from->r2c3;
|
||||
}
|
||||
|
||||
inline void bgc_matrix2x3_set_transposed_fp64(const BgcMatrix3x2FP64* from, BgcMatrix2x3FP64* to)
|
||||
{
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r2c1;
|
||||
|
||||
to->r2c1 = from->r1c2;
|
||||
to->r2c2 = from->r2c2;
|
||||
|
||||
to->r3c1 = from->r1c3;
|
||||
to->r3c2 = from->r2c3;
|
||||
}
|
||||
|
||||
// =============== Set transposed =============== //
|
||||
|
||||
inline void bgc_matrix2x3_set_transposed_fp32_fp64(const BgcMatrix3x2FP64* from, BgcMatrix2x3FP32* to)
|
||||
{
|
||||
to->r1c1 = (float) from->r1c1;
|
||||
to->r1c2 = (float) from->r2c1;
|
||||
|
||||
to->r2c1 = (float) from->r1c2;
|
||||
to->r2c2 = (float) from->r2c2;
|
||||
|
||||
to->r3c1 = (float) from->r1c3;
|
||||
to->r3c2 = (float) from->r2c3;
|
||||
}
|
||||
|
||||
inline void bgc_matrix2x3_set_transposed_fp64_fp32(const BgcMatrix3x2FP32* from, BgcMatrix2x3FP64* to)
|
||||
{
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r2c1;
|
||||
|
||||
to->r2c1 = from->r1c2;
|
||||
to->r2c2 = from->r2c2;
|
||||
|
||||
to->r3c1 = from->r1c3;
|
||||
to->r3c2 = from->r2c3;
|
||||
}
|
||||
|
||||
// ================= Set Row 1 ================== //
|
||||
|
||||
inline void bgc_matrix2x3_set_row1_fp32(const float c1, const float c2, BgcMatrix2x3FP32* matrix)
|
||||
|
@ -271,7 +219,34 @@ inline void bgc_matrix2x3_set_column2_fp64(const double r1, const double r2, con
|
|||
matrix->r3c2 = r3;
|
||||
}
|
||||
|
||||
// ================== Addition ================== //
|
||||
// ============== Make transposed =============== //
|
||||
|
||||
inline void bgc_matrix2x3_make_transposed_fp32(const BgcMatrix3x2FP32* matrix, BgcMatrix2x3FP32* transposed)
|
||||
{
|
||||
transposed->r1c1 = matrix->r1c1;
|
||||
transposed->r1c2 = matrix->r2c1;
|
||||
|
||||
transposed->r2c1 = matrix->r1c2;
|
||||
transposed->r2c2 = matrix->r2c2;
|
||||
|
||||
transposed->r3c1 = matrix->r1c3;
|
||||
transposed->r3c2 = matrix->r2c3;
|
||||
}
|
||||
|
||||
inline void bgc_matrix2x3_make_transposed_fp64(const BgcMatrix3x2FP64* matrix, BgcMatrix2x3FP64* transposed)
|
||||
{
|
||||
transposed->r1c1 = matrix->r1c1;
|
||||
transposed->r1c2 = matrix->r2c1;
|
||||
|
||||
transposed->r2c1 = matrix->r1c2;
|
||||
transposed->r2c2 = matrix->r2c2;
|
||||
|
||||
transposed->r3c1 = matrix->r1c3;
|
||||
transposed->r3c2 = matrix->r2c3;
|
||||
}
|
||||
|
||||
|
||||
// ==================== Add ===================== //
|
||||
|
||||
inline void bgc_matrix2x3_add_fp32(const BgcMatrix2x3FP32* matrix1, const BgcMatrix2x3FP32* matrix2, BgcMatrix2x3FP32* sum)
|
||||
{
|
||||
|
@ -323,7 +298,7 @@ inline void bgc_matrix2x3_add_scaled_fp64(const BgcMatrix2x3FP64* basic_matrix,
|
|||
sum->r3c2 = basic_matrix->r3c2 + scalable_matrix->r3c2 * scale;
|
||||
}
|
||||
|
||||
// ================ Subtraction ================= //
|
||||
// ================== Subtract ================== //
|
||||
|
||||
inline void bgc_matrix2x3_subtract_fp32(const BgcMatrix2x3FP32* minuend, const BgcMatrix2x3FP32* subtrahend, BgcMatrix2x3FP32* difference)
|
||||
{
|
||||
|
@ -349,7 +324,33 @@ inline void bgc_matrix2x3_subtract_fp64(const BgcMatrix2x3FP64* minuend, const B
|
|||
difference->r3c2 = minuend->r3c2 - subtrahend->r3c2;
|
||||
}
|
||||
|
||||
// =============== Multiplication =============== //
|
||||
// ============== Subtract scaled =============== //
|
||||
|
||||
inline void bgc_matrix2x3_subtract_scaled_fp32(const BgcMatrix2x3FP32* basic_matrix, const BgcMatrix2x3FP32* scalable_matrix, const float scale, BgcMatrix2x3FP32* difference)
|
||||
{
|
||||
difference->r1c1 = basic_matrix->r1c1 - scalable_matrix->r1c1 * scale;
|
||||
difference->r1c2 = basic_matrix->r1c2 - scalable_matrix->r1c2 * scale;
|
||||
|
||||
difference->r2c1 = basic_matrix->r2c1 - scalable_matrix->r2c1 * scale;
|
||||
difference->r2c2 = basic_matrix->r2c2 - scalable_matrix->r2c2 * scale;
|
||||
|
||||
difference->r3c1 = basic_matrix->r3c1 - scalable_matrix->r3c1 * scale;
|
||||
difference->r3c2 = basic_matrix->r3c2 - scalable_matrix->r3c2 * scale;
|
||||
}
|
||||
|
||||
inline void bgc_matrix2x3_subtract_scaled_fp64(const BgcMatrix2x3FP64* basic_matrix, const BgcMatrix2x3FP64* scalable_matrix, const double scale, BgcMatrix2x3FP64* difference)
|
||||
{
|
||||
difference->r1c1 = basic_matrix->r1c1 - scalable_matrix->r1c1 * scale;
|
||||
difference->r1c2 = basic_matrix->r1c2 - scalable_matrix->r1c2 * scale;
|
||||
|
||||
difference->r2c1 = basic_matrix->r2c1 - scalable_matrix->r2c1 * scale;
|
||||
difference->r2c2 = basic_matrix->r2c2 - scalable_matrix->r2c2 * scale;
|
||||
|
||||
difference->r3c1 = basic_matrix->r3c1 - scalable_matrix->r3c1 * scale;
|
||||
difference->r3c2 = basic_matrix->r3c2 - scalable_matrix->r3c2 * scale;
|
||||
}
|
||||
|
||||
// ================== Multiply ================== //
|
||||
|
||||
inline void bgc_matrix2x3_multiply_fp32(const BgcMatrix2x3FP32* multiplicand, const float multiplier, BgcMatrix2x3FP32* product)
|
||||
{
|
||||
|
@ -375,7 +376,7 @@ inline void bgc_matrix2x3_multiply_fp64(const BgcMatrix2x3FP64* multiplicand, co
|
|||
product->r3c2 = multiplicand->r3c2 * multiplier;
|
||||
}
|
||||
|
||||
// ================== Division ================== //
|
||||
// =================== Divide =================== //
|
||||
|
||||
inline void bgc_matrix2x3_divide_fp32(const BgcMatrix2x3FP32* dividend, const float divisor, BgcMatrix2x3FP32* quotient)
|
||||
{
|
||||
|
|
|
@ -12,12 +12,6 @@ extern inline void bgc_matrix3x2_swap_fp64(BgcMatrix3x2FP64* matrix1, BgcMatrix3
|
|||
extern inline void bgc_matrix3x2_convert_fp64_to_fp32(const BgcMatrix3x2FP64* from, BgcMatrix3x2FP32* to);
|
||||
extern inline void bgc_matrix3x2_convert_fp32_to_fp64(const BgcMatrix3x2FP32* from, BgcMatrix3x2FP64* to);
|
||||
|
||||
extern inline void bgc_matrix3x2_set_transposed_fp32(const BgcMatrix2x3FP32* from, BgcMatrix3x2FP32* to);
|
||||
extern inline void bgc_matrix3x2_set_transposed_fp64(const BgcMatrix2x3FP64* from, BgcMatrix3x2FP64* to);
|
||||
|
||||
extern inline void bgc_matrix3x2_set_transposed_fp32_fp64(const BgcMatrix2x3FP64* from, BgcMatrix3x2FP32* to);
|
||||
extern inline void bgc_matrix3x2_set_transposed_fp64_fp32(const BgcMatrix2x3FP32* from, BgcMatrix3x2FP64* to);
|
||||
|
||||
extern inline void bgc_matrix3x2_set_row1_fp32(const float c1, const float c2, const float c3, BgcMatrix3x2FP32* matrix);
|
||||
extern inline void bgc_matrix3x2_set_row1_fp64(const double c1, const double c2, const double c3, BgcMatrix3x2FP64* matrix);
|
||||
|
||||
|
@ -33,6 +27,9 @@ extern inline void bgc_matrix3x2_set_column2_fp64(const double r1, const double
|
|||
extern inline void bgc_matrix3x2_set_column3_fp32(const float r1, const float r2, BgcMatrix3x2FP32* matrix);
|
||||
extern inline void bgc_matrix3x2_set_column3_fp64(const double r1, const double r2, BgcMatrix3x2FP64* matrix);
|
||||
|
||||
extern inline void bgc_matrix3x2_make_transposed_fp32(const BgcMatrix2x3FP32* from, BgcMatrix3x2FP32* to);
|
||||
extern inline void bgc_matrix3x2_make_transposed_fp64(const BgcMatrix2x3FP64* from, BgcMatrix3x2FP64* to);
|
||||
|
||||
extern inline void bgc_matrix3x2_add_fp32(const BgcMatrix3x2FP32* matrix1, const BgcMatrix3x2FP32* matrix2, BgcMatrix3x2FP32* sum);
|
||||
extern inline void bgc_matrix3x2_add_fp64(const BgcMatrix3x2FP64* matrix1, const BgcMatrix3x2FP64* matrix2, BgcMatrix3x2FP64* sum);
|
||||
|
||||
|
@ -42,6 +39,9 @@ extern inline void bgc_matrix3x2_add_scaled_fp64(const BgcMatrix3x2FP64* basic_m
|
|||
extern inline void bgc_matrix3x2_subtract_fp32(const BgcMatrix3x2FP32* minuend, const BgcMatrix3x2FP32* subtrahend, BgcMatrix3x2FP32* difference);
|
||||
extern inline void bgc_matrix3x2_subtract_fp64(const BgcMatrix3x2FP64* minuend, const BgcMatrix3x2FP64* subtrahend, BgcMatrix3x2FP64* difference);
|
||||
|
||||
extern inline void bgc_matrix3x2_subtract_scaled_fp32(const BgcMatrix3x2FP32* basic_matrix, const BgcMatrix3x2FP32* scalable_matrix, const float scale, BgcMatrix3x2FP32* difference);
|
||||
extern inline void bgc_matrix3x2_subtract_scaled_fp64(const BgcMatrix3x2FP64* basic_matrix, const BgcMatrix3x2FP64* scalable_matrix, const double scale, BgcMatrix3x2FP64* difference);
|
||||
|
||||
extern inline void bgc_matrix3x2_multiply_fp32(const BgcMatrix3x2FP32* multiplicand, const float multiplier, BgcMatrix3x2FP32* product);
|
||||
extern inline void bgc_matrix3x2_multiply_fp64(const BgcMatrix3x2FP64* multiplicand, const double multiplier, BgcMatrix3x2FP64* product);
|
||||
|
||||
|
|
|
@ -109,7 +109,7 @@ inline void bgc_matrix3x2_swap_fp64(BgcMatrix3x2FP64* matrix1, BgcMatrix3x2FP64*
|
|||
matrix1->r2c3 = r2c3;
|
||||
}
|
||||
|
||||
// ============= Set from twin type ============= //
|
||||
// ================== Convert =================== //
|
||||
|
||||
inline void bgc_matrix3x2_convert_fp64_to_fp32(const BgcMatrix3x2FP64* from, BgcMatrix3x2FP32* to)
|
||||
{
|
||||
|
@ -133,54 +133,6 @@ inline void bgc_matrix3x2_convert_fp32_to_fp64(const BgcMatrix3x2FP32* from, Bgc
|
|||
to->r2c3 = from->r2c3;
|
||||
}
|
||||
|
||||
// =============== Set transposed =============== //
|
||||
|
||||
inline void bgc_matrix3x2_set_transposed_fp32(const BgcMatrix2x3FP32* from, BgcMatrix3x2FP32* to)
|
||||
{
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r2c1;
|
||||
to->r1c3 = from->r3c1;
|
||||
|
||||
to->r2c1 = from->r1c2;
|
||||
to->r2c2 = from->r2c2;
|
||||
to->r2c3 = from->r3c2;
|
||||
}
|
||||
|
||||
inline void bgc_matrix3x2_set_transposed_fp64(const BgcMatrix2x3FP64* from, BgcMatrix3x2FP64* to)
|
||||
{
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r2c1;
|
||||
to->r1c3 = from->r3c1;
|
||||
|
||||
to->r2c1 = from->r1c2;
|
||||
to->r2c2 = from->r2c2;
|
||||
to->r2c3 = from->r3c2;
|
||||
}
|
||||
|
||||
// =============== Set transposed =============== //
|
||||
|
||||
inline void bgc_matrix3x2_set_transposed_fp32_fp64(const BgcMatrix2x3FP64* from, BgcMatrix3x2FP32* to)
|
||||
{
|
||||
to->r1c1 = (float) from->r1c1;
|
||||
to->r1c2 = (float) from->r2c1;
|
||||
to->r1c3 = (float) from->r3c1;
|
||||
|
||||
to->r2c1 = (float) from->r1c2;
|
||||
to->r2c2 = (float) from->r2c2;
|
||||
to->r2c3 = (float) from->r3c2;
|
||||
}
|
||||
|
||||
inline void bgc_matrix3x2_set_transposed_fp64_fp32(const BgcMatrix2x3FP32* from, BgcMatrix3x2FP64* to)
|
||||
{
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r2c1;
|
||||
to->r1c3 = from->r3c1;
|
||||
|
||||
to->r2c1 = from->r1c2;
|
||||
to->r2c2 = from->r2c2;
|
||||
to->r2c3 = from->r3c2;
|
||||
}
|
||||
|
||||
// ================= Set Row 1 ================== //
|
||||
|
||||
inline void bgc_matrix3x2_set_row1_fp32(const float c1, const float c2, const float c3, BgcMatrix3x2FP32* matrix)
|
||||
|
@ -255,7 +207,31 @@ inline void bgc_matrix3x2_set_column3_fp64(const double r1, const double r2, Bgc
|
|||
matrix->r2c3 = r2;
|
||||
}
|
||||
|
||||
// ================== Addition ================== //
|
||||
// ============== Make transposed =============== //
|
||||
|
||||
inline void bgc_matrix3x2_make_transposed_fp32(const BgcMatrix2x3FP32* from, BgcMatrix3x2FP32* to)
|
||||
{
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r2c1;
|
||||
to->r1c3 = from->r3c1;
|
||||
|
||||
to->r2c1 = from->r1c2;
|
||||
to->r2c2 = from->r2c2;
|
||||
to->r2c3 = from->r3c2;
|
||||
}
|
||||
|
||||
inline void bgc_matrix3x2_make_transposed_fp64(const BgcMatrix2x3FP64* from, BgcMatrix3x2FP64* to)
|
||||
{
|
||||
to->r1c1 = from->r1c1;
|
||||
to->r1c2 = from->r2c1;
|
||||
to->r1c3 = from->r3c1;
|
||||
|
||||
to->r2c1 = from->r1c2;
|
||||
to->r2c2 = from->r2c2;
|
||||
to->r2c3 = from->r3c2;
|
||||
}
|
||||
|
||||
// ==================== Add ===================== //
|
||||
|
||||
inline void bgc_matrix3x2_add_fp32(const BgcMatrix3x2FP32* matrix1, const BgcMatrix3x2FP32* matrix2, BgcMatrix3x2FP32* sum)
|
||||
{
|
||||
|
@ -303,7 +279,7 @@ inline void bgc_matrix3x2_add_scaled_fp64(const BgcMatrix3x2FP64* basic_matrix,
|
|||
sum->r2c3 = basic_matrix->r2c3 + scalable_matrix->r2c3 * scale;
|
||||
}
|
||||
|
||||
// ================ Subtraction ================= //
|
||||
// ================== Subtract ================== //
|
||||
|
||||
inline void bgc_matrix3x2_subtract_fp32(const BgcMatrix3x2FP32* minuend, const BgcMatrix3x2FP32* subtrahend, BgcMatrix3x2FP32* difference)
|
||||
{
|
||||
|
@ -327,7 +303,31 @@ inline void bgc_matrix3x2_subtract_fp64(const BgcMatrix3x2FP64* minuend, const B
|
|||
difference->r2c3 = minuend->r2c3 - subtrahend->r2c3;
|
||||
}
|
||||
|
||||
// =============== Multiplication =============== //
|
||||
// ============== Subtract scaled =============== //
|
||||
|
||||
inline void bgc_matrix3x2_subtract_scaled_fp32(const BgcMatrix3x2FP32* basic_matrix, const BgcMatrix3x2FP32* scalable_matrix, const float scale, BgcMatrix3x2FP32* difference)
|
||||
{
|
||||
difference->r1c1 = basic_matrix->r1c1 - scalable_matrix->r1c1 * scale;
|
||||
difference->r1c2 = basic_matrix->r1c2 - scalable_matrix->r1c2 * scale;
|
||||
difference->r1c3 = basic_matrix->r1c3 - scalable_matrix->r1c3 * scale;
|
||||
|
||||
difference->r2c1 = basic_matrix->r2c1 - scalable_matrix->r2c1 * scale;
|
||||
difference->r2c2 = basic_matrix->r2c2 - scalable_matrix->r2c2 * scale;
|
||||
difference->r2c3 = basic_matrix->r2c3 - scalable_matrix->r2c3 * scale;
|
||||
}
|
||||
|
||||
inline void bgc_matrix3x2_subtract_scaled_fp64(const BgcMatrix3x2FP64* basic_matrix, const BgcMatrix3x2FP64* scalable_matrix, const double scale, BgcMatrix3x2FP64* difference)
|
||||
{
|
||||
difference->r1c1 = basic_matrix->r1c1 - scalable_matrix->r1c1 * scale;
|
||||
difference->r1c2 = basic_matrix->r1c2 - scalable_matrix->r1c2 * scale;
|
||||
difference->r1c3 = basic_matrix->r1c3 - scalable_matrix->r1c3 * scale;
|
||||
|
||||
difference->r2c1 = basic_matrix->r2c1 - scalable_matrix->r2c1 * scale;
|
||||
difference->r2c2 = basic_matrix->r2c2 - scalable_matrix->r2c2 * scale;
|
||||
difference->r2c3 = basic_matrix->r2c3 - scalable_matrix->r2c3 * scale;
|
||||
}
|
||||
|
||||
// ================== Multiply ================== //
|
||||
|
||||
inline void bgc_matrix3x2_multiply_fp32(const BgcMatrix3x2FP32* multiplicand, const float multiplier, BgcMatrix3x2FP32* product)
|
||||
{
|
||||
|
@ -351,7 +351,7 @@ inline void bgc_matrix3x2_multiply_fp64(const BgcMatrix3x2FP64* multiplicand, co
|
|||
product->r2c3 = multiplicand->r2c3 * multiplier;
|
||||
}
|
||||
|
||||
// ================== Division ================== //
|
||||
// =================== Divide =================== //
|
||||
|
||||
inline void bgc_matrix3x2_divide_fp32(const BgcMatrix3x2FP32* dividend, const float divisor, BgcMatrix3x2FP32* quotient)
|
||||
{
|
||||
|
|
|
@ -27,9 +27,6 @@ extern inline int bgc_matrix3x3_is_singular_fp64(const BgcMatrix3x3FP64* matrix)
|
|||
extern inline void bgc_matrix3x3_transpose_fp32(BgcMatrix3x3FP32* matrix);
|
||||
extern inline void bgc_matrix3x3_transpose_fp64(BgcMatrix3x3FP64* matrix);
|
||||
|
||||
extern inline void bgc_matrix3x3_set_transposed_fp32(const BgcMatrix3x3FP32* matrix, BgcMatrix3x3FP32* result);
|
||||
extern inline void bgc_matrix3x3_set_transposed_fp64(const BgcMatrix3x3FP64* matrix, BgcMatrix3x3FP64* result);
|
||||
|
||||
extern inline void bgc_matrix3x3_set_row1_fp32(const float c1, const float c2, const float c3, BgcMatrix3x3FP32* matrix);
|
||||
extern inline void bgc_matrix3x3_set_row1_fp64(const double c1, const double c2, const double c3, BgcMatrix3x3FP64* matrix);
|
||||
|
||||
|
@ -48,6 +45,9 @@ extern inline void bgc_matrix3x3_set_column2_fp64(const double r1, const double
|
|||
extern inline void bgc_matrix3x3_set_column3_fp32(const float r1, const float r2, const float r3, BgcMatrix3x3FP32* matrix);
|
||||
extern inline void bgc_matrix3x3_set_column3_fp64(const double r1, const double r2, const double r3, BgcMatrix3x3FP64* matrix);
|
||||
|
||||
extern inline void bgc_matrix3x3_make_transposed_fp32(const BgcMatrix3x3FP32* matrix, BgcMatrix3x3FP32* result);
|
||||
extern inline void bgc_matrix3x3_make_transposed_fp64(const BgcMatrix3x3FP64* matrix, BgcMatrix3x3FP64* result);
|
||||
|
||||
extern inline void bgc_matrix3x3_add_fp32(const BgcMatrix3x3FP32* matrix1, const BgcMatrix3x3FP32* matrix2, BgcMatrix3x3FP32* sum);
|
||||
extern inline void bgc_matrix3x3_add_fp64(const BgcMatrix3x3FP64* matrix1, const BgcMatrix3x3FP64* matrix2, BgcMatrix3x3FP64* sum);
|
||||
|
||||
|
@ -57,6 +57,9 @@ extern inline void bgc_matrix3x3_add_scaled_fp64(const BgcMatrix3x3FP64* basic_m
|
|||
extern inline void bgc_matrix3x3_subtract_fp32(const BgcMatrix3x3FP32* minuend, const BgcMatrix3x3FP32* subtrahend, BgcMatrix3x3FP32* difference);
|
||||
extern inline void bgc_matrix3x3_subtract_fp64(const BgcMatrix3x3FP64* minuend, const BgcMatrix3x3FP64* subtrahend, BgcMatrix3x3FP64* difference);
|
||||
|
||||
extern inline void bgc_matrix3x3_subtract_scaled_fp32(const BgcMatrix3x3FP32* basic_matrix, const BgcMatrix3x3FP32* scalable_matrix, const float scale, BgcMatrix3x3FP32* difference);
|
||||
extern inline void bgc_matrix3x3_subtract_scaled_fp64(const BgcMatrix3x3FP64* basic_matrix, const BgcMatrix3x3FP64* scalable_matrix, const double scale, BgcMatrix3x3FP64* difference);
|
||||
|
||||
extern inline void bgc_matrix3x3_multiply_fp32(const BgcMatrix3x3FP32* multiplicand, const float multiplier, BgcMatrix3x3FP32* product);
|
||||
extern inline void bgc_matrix3x3_multiply_fp64(const BgcMatrix3x3FP64* multiplicand, const double multiplier, BgcMatrix3x3FP64* product);
|
||||
|
||||
|
@ -69,7 +72,7 @@ extern inline void bgc_matrix3x3_left_product_fp64(const BgcVector3FP64* vector,
|
|||
extern inline void bgc_matrix3x3_right_product_fp32(const BgcMatrix3x3FP32* matrix, const BgcVector3FP32* vector, BgcVector3FP32* result);
|
||||
extern inline void bgc_matrix3x3_right_product_fp64(const BgcMatrix3x3FP64* matrix, const BgcVector3FP64* vector, BgcVector3FP64* result);
|
||||
|
||||
// ================= Inversion ================== //
|
||||
// =================== Invert =================== //
|
||||
|
||||
int bgc_matrix3x3_invert_fp32(BgcMatrix3x3FP32* matrix)
|
||||
{
|
||||
|
@ -147,7 +150,7 @@ int bgc_matrix3x3_invert_fp64(BgcMatrix3x3FP64* matrix)
|
|||
|
||||
// ================ Make Inverted =============== //
|
||||
|
||||
int bgc_matrix3x3_set_inverted_fp32(const BgcMatrix3x3FP32* matrix, BgcMatrix3x3FP32* result)
|
||||
int bgc_matrix3x3_make_inverted_fp32(const BgcMatrix3x3FP32* matrix, BgcMatrix3x3FP32* result)
|
||||
{
|
||||
const float determinant = bgc_matrix3x3_get_determinant_fp32(matrix);
|
||||
|
||||
|
@ -184,7 +187,7 @@ int bgc_matrix3x3_set_inverted_fp32(const BgcMatrix3x3FP32* matrix, BgcMatrix3x3
|
|||
return 1;
|
||||
}
|
||||
|
||||
int bgc_matrix3x3_set_inverted_fp64(const BgcMatrix3x3FP64* matrix, BgcMatrix3x3FP64* result)
|
||||
int bgc_matrix3x3_make_inverted_fp64(const BgcMatrix3x3FP64* matrix, BgcMatrix3x3FP64* result)
|
||||
{
|
||||
const double determinant = bgc_matrix3x3_get_determinant_fp64(matrix);
|
||||
|
||||
|
|
|
@ -212,7 +212,7 @@ inline void bgc_matrix3x3_swap_fp64(BgcMatrix3x3FP64* matrix1, BgcMatrix3x3FP64*
|
|||
matrix1->r3c3 = r3c3;
|
||||
}
|
||||
|
||||
// ============= Set from twin type ============= //
|
||||
// ================== Convert =================== //
|
||||
|
||||
inline void bgc_matrix3x3_convert_fp64_to_fp32(const BgcMatrix3x3FP64* from, BgcMatrix3x3FP32* to)
|
||||
{
|
||||
|
@ -272,13 +272,13 @@ inline int bgc_matrix3x3_is_singular_fp64(const BgcMatrix3x3FP64* matrix)
|
|||
return bgc_is_zero_fp64(bgc_matrix3x3_get_determinant_fp64(matrix));
|
||||
}
|
||||
|
||||
// ================= Inversion ================== //
|
||||
// =================== Invert =================== //
|
||||
|
||||
int bgc_matrix3x3_invert_fp32(BgcMatrix3x3FP32* matrix);
|
||||
|
||||
int bgc_matrix3x3_invert_fp64(BgcMatrix3x3FP64* matrix);
|
||||
|
||||
// =============== Transposition ================ //
|
||||
// ================= Transpose ================== //
|
||||
|
||||
inline void bgc_matrix3x3_transpose_fp32(BgcMatrix3x3FP32* matrix)
|
||||
{
|
||||
|
@ -310,54 +310,6 @@ inline void bgc_matrix3x3_transpose_fp64(BgcMatrix3x3FP64* matrix)
|
|||
matrix->r3c2 = tmp;
|
||||
}
|
||||
|
||||
// ================ Make Inverted =============== //
|
||||
|
||||
int bgc_matrix3x3_set_inverted_fp32(const BgcMatrix3x3FP32* matrix, BgcMatrix3x3FP32* result);
|
||||
|
||||
int bgc_matrix3x3_set_inverted_fp64(const BgcMatrix3x3FP64* matrix, BgcMatrix3x3FP64* result);
|
||||
|
||||
// =============== Make Transposed ============== //
|
||||
|
||||
inline void bgc_matrix3x3_set_transposed_fp32(const BgcMatrix3x3FP32* matrix, BgcMatrix3x3FP32* result)
|
||||
{
|
||||
if (matrix == result) {
|
||||
bgc_matrix3x3_transpose_fp32(result);
|
||||
return;
|
||||
}
|
||||
|
||||
result->r1c1 = matrix->r1c1;
|
||||
result->r1c2 = matrix->r2c1;
|
||||
result->r1c3 = matrix->r3c1;
|
||||
|
||||
result->r2c1 = matrix->r1c2;
|
||||
result->r2c2 = matrix->r2c2;
|
||||
result->r2c3 = matrix->r3c2;
|
||||
|
||||
result->r3c1 = matrix->r1c3;
|
||||
result->r3c2 = matrix->r2c3;
|
||||
result->r3c3 = matrix->r3c3;
|
||||
}
|
||||
|
||||
inline void bgc_matrix3x3_set_transposed_fp64(const BgcMatrix3x3FP64* matrix, BgcMatrix3x3FP64* result)
|
||||
{
|
||||
if (matrix == result) {
|
||||
bgc_matrix3x3_transpose_fp64(result);
|
||||
return;
|
||||
}
|
||||
|
||||
result->r1c1 = matrix->r1c1;
|
||||
result->r1c2 = matrix->r2c1;
|
||||
result->r1c3 = matrix->r3c1;
|
||||
|
||||
result->r2c1 = matrix->r1c2;
|
||||
result->r2c2 = matrix->r2c2;
|
||||
result->r2c3 = matrix->r3c2;
|
||||
|
||||
result->r3c1 = matrix->r1c3;
|
||||
result->r3c2 = matrix->r2c3;
|
||||
result->r3c3 = matrix->r3c3;
|
||||
}
|
||||
|
||||
// ================= Set Row 1 ================== //
|
||||
|
||||
inline void bgc_matrix3x3_set_row1_fp32(const float c1, const float c2, const float c3, BgcMatrix3x3FP32* matrix)
|
||||
|
@ -454,7 +406,55 @@ inline void bgc_matrix3x3_set_column3_fp64(const double r1, const double r2, con
|
|||
matrix->r3c3 = r3;
|
||||
}
|
||||
|
||||
// ================== Addition ================== //
|
||||
// ================ Make Inverted =============== //
|
||||
|
||||
int bgc_matrix3x3_make_inverted_fp32(const BgcMatrix3x3FP32* matrix, BgcMatrix3x3FP32* result);
|
||||
|
||||
int bgc_matrix3x3_make_inverted_fp64(const BgcMatrix3x3FP64* matrix, BgcMatrix3x3FP64* result);
|
||||
|
||||
// =============== Make Transposed ============== //
|
||||
|
||||
inline void bgc_matrix3x3_make_transposed_fp32(const BgcMatrix3x3FP32* matrix, BgcMatrix3x3FP32* result)
|
||||
{
|
||||
if (matrix == result) {
|
||||
bgc_matrix3x3_transpose_fp32(result);
|
||||
return;
|
||||
}
|
||||
|
||||
result->r1c1 = matrix->r1c1;
|
||||
result->r1c2 = matrix->r2c1;
|
||||
result->r1c3 = matrix->r3c1;
|
||||
|
||||
result->r2c1 = matrix->r1c2;
|
||||
result->r2c2 = matrix->r2c2;
|
||||
result->r2c3 = matrix->r3c2;
|
||||
|
||||
result->r3c1 = matrix->r1c3;
|
||||
result->r3c2 = matrix->r2c3;
|
||||
result->r3c3 = matrix->r3c3;
|
||||
}
|
||||
|
||||
inline void bgc_matrix3x3_make_transposed_fp64(const BgcMatrix3x3FP64* matrix, BgcMatrix3x3FP64* result)
|
||||
{
|
||||
if (matrix == result) {
|
||||
bgc_matrix3x3_transpose_fp64(result);
|
||||
return;
|
||||
}
|
||||
|
||||
result->r1c1 = matrix->r1c1;
|
||||
result->r1c2 = matrix->r2c1;
|
||||
result->r1c3 = matrix->r3c1;
|
||||
|
||||
result->r2c1 = matrix->r1c2;
|
||||
result->r2c2 = matrix->r2c2;
|
||||
result->r2c3 = matrix->r3c2;
|
||||
|
||||
result->r3c1 = matrix->r1c3;
|
||||
result->r3c2 = matrix->r2c3;
|
||||
result->r3c3 = matrix->r3c3;
|
||||
}
|
||||
|
||||
// ==================== Add ===================== //
|
||||
|
||||
inline void bgc_matrix3x3_add_fp32(const BgcMatrix3x3FP32* matrix1, const BgcMatrix3x3FP32* matrix2, BgcMatrix3x3FP32* sum)
|
||||
{
|
||||
|
@ -518,7 +518,7 @@ inline void bgc_matrix3x3_add_scaled_fp64(const BgcMatrix3x3FP64* basic_matrix,
|
|||
sum->r3c3 = basic_matrix->r3c3 + scalable_matrix->r3c3 * scale;
|
||||
}
|
||||
|
||||
// ================ Subtraction ================= //
|
||||
// ================== Subtract ================== //
|
||||
|
||||
inline void bgc_matrix3x3_subtract_fp32(const BgcMatrix3x3FP32* minuend, const BgcMatrix3x3FP32* subtrahend, BgcMatrix3x3FP32* difference)
|
||||
{
|
||||
|
@ -550,7 +550,39 @@ inline void bgc_matrix3x3_subtract_fp64(const BgcMatrix3x3FP64* minuend, const B
|
|||
difference->r3c3 = minuend->r3c3 - subtrahend->r3c3;
|
||||
}
|
||||
|
||||
// =============== Multiplication =============== //
|
||||
// ================= Add scaled ================= //
|
||||
|
||||
inline void bgc_matrix3x3_subtract_scaled_fp32(const BgcMatrix3x3FP32* basic_matrix, const BgcMatrix3x3FP32* scalable_matrix, const float scale, BgcMatrix3x3FP32* difference)
|
||||
{
|
||||
difference->r1c1 = basic_matrix->r1c1 - scalable_matrix->r1c1 * scale;
|
||||
difference->r1c2 = basic_matrix->r1c2 - scalable_matrix->r1c2 * scale;
|
||||
difference->r1c3 = basic_matrix->r1c3 - scalable_matrix->r1c3 * scale;
|
||||
|
||||
difference->r2c1 = basic_matrix->r2c1 - scalable_matrix->r2c1 * scale;
|
||||
difference->r2c2 = basic_matrix->r2c2 - scalable_matrix->r2c2 * scale;
|
||||
difference->r2c3 = basic_matrix->r2c3 - scalable_matrix->r2c3 * scale;
|
||||
|
||||
difference->r3c1 = basic_matrix->r3c1 - scalable_matrix->r3c1 * scale;
|
||||
difference->r3c2 = basic_matrix->r3c2 - scalable_matrix->r3c2 * scale;
|
||||
difference->r3c3 = basic_matrix->r3c3 - scalable_matrix->r3c3 * scale;
|
||||
}
|
||||
|
||||
inline void bgc_matrix3x3_subtract_scaled_fp64(const BgcMatrix3x3FP64* basic_matrix, const BgcMatrix3x3FP64* scalable_matrix, const double scale, BgcMatrix3x3FP64* difference)
|
||||
{
|
||||
difference->r1c1 = basic_matrix->r1c1 - scalable_matrix->r1c1 * scale;
|
||||
difference->r1c2 = basic_matrix->r1c2 - scalable_matrix->r1c2 * scale;
|
||||
difference->r1c3 = basic_matrix->r1c3 - scalable_matrix->r1c3 * scale;
|
||||
|
||||
difference->r2c1 = basic_matrix->r2c1 - scalable_matrix->r2c1 * scale;
|
||||
difference->r2c2 = basic_matrix->r2c2 - scalable_matrix->r2c2 * scale;
|
||||
difference->r2c3 = basic_matrix->r2c3 - scalable_matrix->r2c3 * scale;
|
||||
|
||||
difference->r3c1 = basic_matrix->r3c1 - scalable_matrix->r3c1 * scale;
|
||||
difference->r3c2 = basic_matrix->r3c2 - scalable_matrix->r3c2 * scale;
|
||||
difference->r3c3 = basic_matrix->r3c3 - scalable_matrix->r3c3 * scale;
|
||||
}
|
||||
|
||||
// ================== Multiply ================== //
|
||||
|
||||
inline void bgc_matrix3x3_multiply_fp32(const BgcMatrix3x3FP32* multiplicand, const float multiplier, BgcMatrix3x3FP32* product)
|
||||
{
|
||||
|
@ -582,7 +614,7 @@ inline void bgc_matrix3x3_multiply_fp64(const BgcMatrix3x3FP64* multiplicand, co
|
|||
product->r3c3 = multiplicand->r3c3 * multiplier;
|
||||
}
|
||||
|
||||
// ================== Division ================== //
|
||||
// =================== Divide =================== //
|
||||
|
||||
inline void bgc_matrix3x3_divide_fp32(const BgcMatrix3x3FP32* dividend, const float divisor, BgcMatrix3x3FP32* quotient)
|
||||
{
|
||||
|
|
|
@ -9,24 +9,6 @@ extern inline void bgc_quaternion_set_to_identity_fp64(BgcQuaternionFP64* quater
|
|||
extern inline void bgc_quaternion_set_values_fp32(const float s0, const float x1, const float x2, const float x3, BgcQuaternionFP32* quaternion);
|
||||
extern inline void bgc_quaternion_set_values_fp64(const double s0, const double x1, const double x2, const double x3, BgcQuaternionFP64* quaternion);
|
||||
|
||||
extern inline void bgc_quaternion_copy_fp32(const BgcQuaternionFP32* from, BgcQuaternionFP32* to);
|
||||
extern inline void bgc_quaternion_copy_fp64(const BgcQuaternionFP64* from, BgcQuaternionFP64* to);
|
||||
|
||||
extern inline void bgc_quaternion_swap_fp32(BgcQuaternionFP32* quarternion1, BgcQuaternionFP32* quarternion2);
|
||||
extern inline void bgc_quaternion_swap_fp64(BgcQuaternionFP64* quarternion1, BgcQuaternionFP64* quarternion2);
|
||||
|
||||
extern inline void bgc_quaternion_convert_fp64_to_fp32(const BgcQuaternionFP64* quaternion, BgcQuaternionFP32* result);
|
||||
extern inline void bgc_quaternion_convert_fp32_to_fp64(const BgcQuaternionFP32* quaternion, BgcQuaternionFP64* result);
|
||||
|
||||
extern inline void bgc_quaternion_conjugate_fp32(BgcQuaternionFP32* quaternion);
|
||||
extern inline void bgc_quaternion_conjugate_fp64(BgcQuaternionFP64* quaternion);
|
||||
|
||||
extern inline void bgc_quaternion_set_conjugate_fp32(const BgcQuaternionFP32* quaternion, BgcQuaternionFP32* result);
|
||||
extern inline void bgc_quaternion_set_conjugate_fp64(const BgcQuaternionFP64* quaternion, BgcQuaternionFP64* result);
|
||||
|
||||
extern inline void bgc_quaternion_set_conjugate_fp64_to_fp32(const BgcQuaternionFP64* quaternion, BgcQuaternionFP32* result);
|
||||
extern inline void bgc_quaternion_set_conjugate_fp32_to_fp64(const BgcQuaternionFP32* quaternion, BgcQuaternionFP64* result);
|
||||
|
||||
extern inline float bgc_quaternion_get_square_modulus_fp32(const BgcQuaternionFP32* quaternion);
|
||||
extern inline double bgc_quaternion_get_square_modulus_fp64(const BgcQuaternionFP64* quaternion);
|
||||
|
||||
|
@ -39,14 +21,35 @@ extern inline int bgc_quaternion_is_zero_fp64(const BgcQuaternionFP64* quaternio
|
|||
extern inline int bgc_quaternion_is_unit_fp32(const BgcQuaternionFP32* quaternion);
|
||||
extern inline int bgc_quaternion_is_unit_fp64(const BgcQuaternionFP64* quaternion);
|
||||
|
||||
extern inline void bgc_quaternion_copy_fp32(const BgcQuaternionFP32* from, BgcQuaternionFP32* to);
|
||||
extern inline void bgc_quaternion_copy_fp64(const BgcQuaternionFP64* from, BgcQuaternionFP64* to);
|
||||
|
||||
extern inline void bgc_quaternion_swap_fp32(BgcQuaternionFP32* quarternion1, BgcQuaternionFP32* quarternion2);
|
||||
extern inline void bgc_quaternion_swap_fp64(BgcQuaternionFP64* quarternion1, BgcQuaternionFP64* quarternion2);
|
||||
|
||||
extern inline void bgc_quaternion_convert_fp64_to_fp32(const BgcQuaternionFP64* quaternion, BgcQuaternionFP32* result);
|
||||
extern inline void bgc_quaternion_convert_fp32_to_fp64(const BgcQuaternionFP32* quaternion, BgcQuaternionFP64* result);
|
||||
|
||||
extern inline void bgc_quaternion_conjugate_fp32(BgcQuaternionFP32* quaternion);
|
||||
extern inline void bgc_quaternion_conjugate_fp64(BgcQuaternionFP64* quaternion);
|
||||
|
||||
extern inline int bgc_quaternion_normalize_fp32(BgcQuaternionFP32* quaternion);
|
||||
extern inline int bgc_quaternion_normalize_fp64(BgcQuaternionFP64* quaternion);
|
||||
|
||||
extern inline void bgc_quaternion_get_rotation_matrix_fp32(const BgcQuaternionFP32* quaternion, BgcMatrix3x3FP32* matrix);
|
||||
extern inline void bgc_quaternion_get_rotation_matrix_fp64(const BgcQuaternionFP64* quaternion, BgcMatrix3x3FP64* matrix);
|
||||
extern inline void bgc_quaternion_make_conjugate_fp32(const BgcQuaternionFP32* quaternion, BgcQuaternionFP32* conjugate);
|
||||
extern inline void bgc_quaternion_make_conjugate_fp64(const BgcQuaternionFP64* quaternion, BgcQuaternionFP64* conjugate);
|
||||
|
||||
extern inline void bgc_quaternion_get_reverse_matrix_fp32(const BgcQuaternionFP32* quaternion, BgcMatrix3x3FP32* matrix);
|
||||
extern inline void bgc_quaternion_get_reverse_matrix_fp64(const BgcQuaternionFP64* quaternion, BgcMatrix3x3FP64* matrix);
|
||||
extern inline int bgc_quaternion_make_normalized_fp32(const BgcQuaternionFP32* quaternion, BgcQuaternionFP32* normalized);
|
||||
extern inline int bgc_quaternion_make_normalized_fp64(const BgcQuaternionFP64* quaternion, BgcQuaternionFP64* normalized);
|
||||
|
||||
extern inline void bgc_quaternion_make_product_fp32(const BgcQuaternionFP32* left, const BgcQuaternionFP32* right, BgcQuaternionFP32* product);
|
||||
extern inline void bgc_quaternion_make_product_fp64(const BgcQuaternionFP64* left, const BgcQuaternionFP64* right, BgcQuaternionFP64* product);
|
||||
|
||||
extern inline void bgc_quaternion_make_rotation_matrix_fp32(const BgcQuaternionFP32* quaternion, BgcMatrix3x3FP32* rotation);
|
||||
extern inline void bgc_quaternion_make_rotation_matrix_fp64(const BgcQuaternionFP64* quaternion, BgcMatrix3x3FP64* rotation);
|
||||
|
||||
extern inline void bgc_quaternion_make_reverse_matrix_fp32(const BgcQuaternionFP32* quaternion, BgcMatrix3x3FP32* reverse);
|
||||
extern inline void bgc_quaternion_make_reverse_matrix_fp64(const BgcQuaternionFP64* quaternion, BgcMatrix3x3FP64* reverse);
|
||||
|
||||
extern inline void bgc_quaternion_add_fp32(const BgcQuaternionFP32* quaternion1, const BgcQuaternionFP32* quaternion2, BgcQuaternionFP32* sum);
|
||||
extern inline void bgc_quaternion_add_fp64(const BgcQuaternionFP64* quaternion1, const BgcQuaternionFP64* quaternion2, BgcQuaternionFP64* sum);
|
||||
|
@ -57,14 +60,14 @@ extern inline void bgc_quaternion_add_scaled_fp64(const BgcQuaternionFP64* basic
|
|||
extern inline void bgc_quaternion_subtract_fp32(const BgcQuaternionFP32* minuend, const BgcQuaternionFP32* subtrahend, BgcQuaternionFP32* difference);
|
||||
extern inline void bgc_quaternion_subtract_fp64(const BgcQuaternionFP64* minuend, const BgcQuaternionFP64* subtrahend, BgcQuaternionFP64* difference);
|
||||
|
||||
extern inline void bgc_quaternion_subtract_scaled_fp32(const BgcQuaternionFP32* basic_quaternion, const BgcQuaternionFP32* scalable_quaternion, const float scale, BgcQuaternionFP32* difference);
|
||||
extern inline void bgc_quaternion_subtract_scaled_fp64(const BgcQuaternionFP64* basic_quaternion, const BgcQuaternionFP64* scalable_quaternion, const double scale, BgcQuaternionFP64* difference);
|
||||
|
||||
extern inline void bgc_quaternion_multiply_fp32(const BgcQuaternionFP32* multiplicand, const float multipier, BgcQuaternionFP32* product);
|
||||
extern inline void bgc_quaternion_multiply_fp64(const BgcQuaternionFP64* multiplicand, const double multipier, BgcQuaternionFP64* product);
|
||||
|
||||
extern inline void bgc_quaternion_divide_fp32(const BgcQuaternionFP32* dividend, const float divisor, BgcQuaternionFP32* quotient);
|
||||
extern inline void bgc_quaternion_divide_fp64(const BgcQuaternionFP64* dividend, const double divisor, BgcQuaternionFP64* quotient);
|
||||
|
||||
extern inline void bgc_quaternion_get_product_fp32(const BgcQuaternionFP32* left, const BgcQuaternionFP32* right, BgcQuaternionFP32* product);
|
||||
extern inline void bgc_quaternion_get_product_fp64(const BgcQuaternionFP64* left, const BgcQuaternionFP64* right, BgcQuaternionFP64* product);
|
||||
|
||||
extern inline int bgc_quaternion_are_close_fp32(const BgcQuaternionFP32* quaternion1, const BgcQuaternionFP32* quaternion2);
|
||||
extern inline int bgc_quaternion_are_close_fp32(const BgcQuaternionFP32* quaternion1, const BgcQuaternionFP32* quaternion2);
|
||||
|
|
|
@ -69,6 +69,54 @@ inline void bgc_quaternion_set_values_fp64(const double s0, const double x1, con
|
|||
quaternion->x3 = x3;
|
||||
}
|
||||
|
||||
// ============= Get Square Modulus ============= //
|
||||
|
||||
inline float bgc_quaternion_get_square_modulus_fp32(const BgcQuaternionFP32* quaternion)
|
||||
{
|
||||
return (quaternion->s0 * quaternion->s0 + quaternion->x1 * quaternion->x1) + (quaternion->x2 * quaternion->x2 + quaternion->x3 * quaternion->x3);
|
||||
}
|
||||
|
||||
inline double bgc_quaternion_get_square_modulus_fp64(const BgcQuaternionFP64* quaternion)
|
||||
{
|
||||
return (quaternion->s0 * quaternion->s0 + quaternion->x1 * quaternion->x1) + (quaternion->x2 * quaternion->x2 + quaternion->x3 * quaternion->x3);
|
||||
}
|
||||
|
||||
// ================ Get Modulus ================= //
|
||||
|
||||
inline float bgc_quaternion_get_modulus_fp32(const BgcQuaternionFP32* quaternion)
|
||||
{
|
||||
return sqrtf(bgc_quaternion_get_square_modulus_fp32(quaternion));
|
||||
}
|
||||
|
||||
inline double bgc_quaternion_get_modulus_fp64(const BgcQuaternionFP64* quaternion)
|
||||
{
|
||||
return sqrt(bgc_quaternion_get_square_modulus_fp64(quaternion));
|
||||
}
|
||||
|
||||
// ================== Is Zero =================== //
|
||||
|
||||
inline int bgc_quaternion_is_zero_fp32(const BgcQuaternionFP32* quaternion)
|
||||
{
|
||||
return bgc_quaternion_get_square_modulus_fp32(quaternion) <= BGC_SQUARE_EPSYLON_FP32;
|
||||
}
|
||||
|
||||
inline int bgc_quaternion_is_zero_fp64(const BgcQuaternionFP64* quaternion)
|
||||
{
|
||||
return bgc_quaternion_get_square_modulus_fp64(quaternion) <= BGC_SQUARE_EPSYLON_FP64;
|
||||
}
|
||||
|
||||
// ================== Is Unit =================== //
|
||||
|
||||
inline int bgc_quaternion_is_unit_fp32(const BgcQuaternionFP32* quaternion)
|
||||
{
|
||||
return bgc_is_sqare_unit_fp32(bgc_quaternion_get_square_modulus_fp32(quaternion));
|
||||
}
|
||||
|
||||
inline int bgc_quaternion_is_unit_fp64(const BgcQuaternionFP64* quaternion)
|
||||
{
|
||||
return bgc_is_sqare_unit_fp64(bgc_quaternion_get_square_modulus_fp64(quaternion));
|
||||
}
|
||||
|
||||
// ==================== Copy ==================== //
|
||||
|
||||
inline void bgc_quaternion_copy_fp32(const BgcQuaternionFP32* from, BgcQuaternionFP32* to)
|
||||
|
@ -125,7 +173,7 @@ inline void bgc_quaternion_swap_fp64(BgcQuaternionFP64* quarternion1, BgcQuatern
|
|||
quarternion1->x3 = x3;
|
||||
}
|
||||
|
||||
// ============= Copy to twin type ============== //
|
||||
// ================== Convert =================== //
|
||||
|
||||
inline void bgc_quaternion_convert_fp64_to_fp32(const BgcQuaternionFP64* quaternion, BgcQuaternionFP32* result)
|
||||
{
|
||||
|
@ -143,7 +191,7 @@ inline void bgc_quaternion_convert_fp32_to_fp64(const BgcQuaternionFP32* quatern
|
|||
result->x3 = quaternion->x3;
|
||||
}
|
||||
|
||||
// ================= Inversion ================== //
|
||||
// ================= Conjugate ================== //
|
||||
|
||||
inline void bgc_quaternion_conjugate_fp32(BgcQuaternionFP32* quaternion)
|
||||
{
|
||||
|
@ -159,101 +207,17 @@ inline void bgc_quaternion_conjugate_fp64(BgcQuaternionFP64* quaternion)
|
|||
quaternion->x3 = -quaternion->x3;
|
||||
}
|
||||
|
||||
// ================ Set Conjugate =============== //
|
||||
|
||||
inline void bgc_quaternion_set_conjugate_fp32(const BgcQuaternionFP32* quaternion, BgcQuaternionFP32* result)
|
||||
{
|
||||
result->s0 = quaternion->s0;
|
||||
result->x1 = -quaternion->x1;
|
||||
result->x2 = -quaternion->x2;
|
||||
result->x3 = -quaternion->x3;
|
||||
}
|
||||
|
||||
inline void bgc_quaternion_set_conjugate_fp64(const BgcQuaternionFP64* quaternion, BgcQuaternionFP64* result)
|
||||
{
|
||||
result->s0 = quaternion->s0;
|
||||
result->x1 = -quaternion->x1;
|
||||
result->x2 = -quaternion->x2;
|
||||
result->x3 = -quaternion->x3;
|
||||
}
|
||||
|
||||
// ================ Set Conjugate =============== //
|
||||
|
||||
inline void bgc_quaternion_set_conjugate_fp64_to_fp32(const BgcQuaternionFP64* quaternion, BgcQuaternionFP32* result)
|
||||
{
|
||||
result->s0 = (float) quaternion->s0;
|
||||
result->x1 = (float) -quaternion->x1;
|
||||
result->x2 = (float) -quaternion->x2;
|
||||
result->x3 = (float) -quaternion->x3;
|
||||
}
|
||||
|
||||
inline void bgc_quaternion_set_conjugate_fp32_to_fp64(const BgcQuaternionFP32* quaternion, BgcQuaternionFP64* result)
|
||||
{
|
||||
result->s0 = quaternion->s0;
|
||||
result->x1 = -quaternion->x1;
|
||||
result->x2 = -quaternion->x2;
|
||||
result->x3 = -quaternion->x3;
|
||||
}
|
||||
|
||||
// ============= Get Square Modulus ============= //
|
||||
|
||||
inline float bgc_quaternion_get_square_modulus_fp32(const BgcQuaternionFP32* quaternion)
|
||||
{
|
||||
return (quaternion->s0 * quaternion->s0 + quaternion->x1 * quaternion->x1) + (quaternion->x2 * quaternion->x2 + quaternion->x3 * quaternion->x3);
|
||||
}
|
||||
|
||||
inline double bgc_quaternion_get_square_modulus_fp64(const BgcQuaternionFP64* quaternion)
|
||||
{
|
||||
return (quaternion->s0 * quaternion->s0 + quaternion->x1 * quaternion->x1) + (quaternion->x2 * quaternion->x2 + quaternion->x3 * quaternion->x3);
|
||||
}
|
||||
|
||||
// ================ Get Modulus ================= //
|
||||
|
||||
inline float bgc_quaternion_get_modulus_fp32(const BgcQuaternionFP32* quaternion)
|
||||
{
|
||||
return sqrtf(bgc_quaternion_get_square_modulus_fp32(quaternion));
|
||||
}
|
||||
|
||||
inline double bgc_quaternion_get_modulus_fp64(const BgcQuaternionFP64* quaternion)
|
||||
{
|
||||
return sqrt(bgc_quaternion_get_square_modulus_fp64(quaternion));
|
||||
}
|
||||
|
||||
// ================== Is Zero =================== //
|
||||
|
||||
inline int bgc_quaternion_is_zero_fp32(const BgcQuaternionFP32* quaternion)
|
||||
{
|
||||
return bgc_quaternion_get_square_modulus_fp32(quaternion) <= BGC_SQUARE_EPSYLON_FP32;
|
||||
}
|
||||
|
||||
inline int bgc_quaternion_is_zero_fp64(const BgcQuaternionFP64* quaternion)
|
||||
{
|
||||
return bgc_quaternion_get_square_modulus_fp64(quaternion) <= BGC_SQUARE_EPSYLON_FP64;
|
||||
}
|
||||
|
||||
// ================== Is Unit =================== //
|
||||
|
||||
inline int bgc_quaternion_is_unit_fp32(const BgcQuaternionFP32* quaternion)
|
||||
{
|
||||
return bgc_is_sqare_value_unit_fp32(bgc_quaternion_get_square_modulus_fp32(quaternion));
|
||||
}
|
||||
|
||||
inline int bgc_quaternion_is_unit_fp64(const BgcQuaternionFP64* quaternion)
|
||||
{
|
||||
return bgc_is_sqare_value_unit_fp64(bgc_quaternion_get_square_modulus_fp64(quaternion));
|
||||
}
|
||||
|
||||
// =============== Normalization ================ //
|
||||
// ================= Normalize ================== //
|
||||
|
||||
inline int bgc_quaternion_normalize_fp32(BgcQuaternionFP32* quaternion)
|
||||
{
|
||||
const float square_modulus = bgc_quaternion_get_square_modulus_fp32(quaternion);
|
||||
|
||||
if (bgc_is_sqare_value_unit_fp32(square_modulus)) {
|
||||
if (bgc_is_sqare_unit_fp32(square_modulus)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32) {
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32 || square_modulus != square_modulus) {
|
||||
bgc_quaternion_reset_fp32(quaternion);
|
||||
return 0;
|
||||
}
|
||||
|
@ -272,11 +236,11 @@ inline int bgc_quaternion_normalize_fp64(BgcQuaternionFP64* quaternion)
|
|||
{
|
||||
const double square_modulus = bgc_quaternion_get_square_modulus_fp64(quaternion);
|
||||
|
||||
if (bgc_is_sqare_value_unit_fp64(square_modulus)) {
|
||||
if (bgc_is_sqare_unit_fp64(square_modulus)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32) {
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP64 || square_modulus != square_modulus) {
|
||||
bgc_quaternion_reset_fp64(quaternion);
|
||||
return 0;
|
||||
}
|
||||
|
@ -291,9 +255,69 @@ inline int bgc_quaternion_normalize_fp64(BgcQuaternionFP64* quaternion)
|
|||
return 1;
|
||||
}
|
||||
|
||||
// =============== Make Conjugate =============== //
|
||||
|
||||
inline void bgc_quaternion_make_conjugate_fp32(const BgcQuaternionFP32* quaternion, BgcQuaternionFP32* conjugate)
|
||||
{
|
||||
conjugate->s0 = quaternion->s0;
|
||||
conjugate->x1 = -quaternion->x1;
|
||||
conjugate->x2 = -quaternion->x2;
|
||||
conjugate->x3 = -quaternion->x3;
|
||||
}
|
||||
|
||||
inline void bgc_quaternion_make_conjugate_fp64(const BgcQuaternionFP64* quaternion, BgcQuaternionFP64* conjugate)
|
||||
{
|
||||
conjugate->s0 = quaternion->s0;
|
||||
conjugate->x1 = -quaternion->x1;
|
||||
conjugate->x2 = -quaternion->x2;
|
||||
conjugate->x3 = -quaternion->x3;
|
||||
}
|
||||
|
||||
// ============== Make Normalized =============== //
|
||||
|
||||
inline int bgc_quaternion_make_normalized_fp32(const BgcQuaternionFP32* quaternion, BgcQuaternionFP32* normalized)
|
||||
{
|
||||
bgc_quaternion_copy_fp32(quaternion, normalized);
|
||||
return bgc_quaternion_normalize_fp32(normalized);
|
||||
}
|
||||
|
||||
inline int bgc_quaternion_make_normalized_fp64(const BgcQuaternionFP64* quaternion, BgcQuaternionFP64* normalized)
|
||||
{
|
||||
bgc_quaternion_copy_fp64(quaternion, normalized);
|
||||
return bgc_quaternion_normalize_fp64(normalized);
|
||||
}
|
||||
|
||||
// ================== Product =================== //
|
||||
|
||||
inline void bgc_quaternion_make_product_fp32(const BgcQuaternionFP32* left, const BgcQuaternionFP32* right, BgcQuaternionFP32* product)
|
||||
{
|
||||
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 x2 = (left->x2 * right->s0 + left->s0 * right->x2) - (left->x1 * right->x3 - left->x3 * right->x1);
|
||||
const float x3 = (left->x3 * right->s0 + left->s0 * right->x3) - (left->x2 * right->x1 - left->x1 * right->x2);
|
||||
|
||||
product->s0 = s0;
|
||||
product->x1 = x1;
|
||||
product->x2 = x2;
|
||||
product->x3 = x3;
|
||||
}
|
||||
|
||||
inline void bgc_quaternion_make_product_fp64(const BgcQuaternionFP64* left, const BgcQuaternionFP64* right, BgcQuaternionFP64* product)
|
||||
{
|
||||
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 x2 = (left->x2 * right->s0 + left->s0 * right->x2) - (left->x1 * right->x3 - left->x3 * right->x1);
|
||||
const double x3 = (left->x3 * right->s0 + left->s0 * right->x3) - (left->x2 * right->x1 - left->x1 * right->x2);
|
||||
|
||||
product->s0 = s0;
|
||||
product->x1 = x1;
|
||||
product->x2 = x2;
|
||||
product->x3 = x3;
|
||||
}
|
||||
|
||||
// ============ Make Rotation Matrix ============ //
|
||||
|
||||
inline void bgc_quaternion_get_rotation_matrix_fp32(const BgcQuaternionFP32* quaternion, BgcMatrix3x3FP32* matrix)
|
||||
inline void bgc_quaternion_make_rotation_matrix_fp32(const BgcQuaternionFP32* quaternion, BgcMatrix3x3FP32* rotation)
|
||||
{
|
||||
const float s0s0 = quaternion->s0 * quaternion->s0;
|
||||
const float x1x1 = quaternion->x1 * quaternion->x1;
|
||||
|
@ -302,14 +326,13 @@ inline void bgc_quaternion_get_rotation_matrix_fp32(const BgcQuaternionFP32* qua
|
|||
|
||||
const float square_modulus = (s0s0 + x1x1) + (x2x2 + x3x3);
|
||||
|
||||
if (bgc_is_zero_fp32(square_modulus))
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32 || square_modulus != square_modulus)
|
||||
{
|
||||
bgc_matrix3x3_set_to_identity_fp32(matrix);
|
||||
bgc_matrix3x3_set_to_identity_fp32(rotation);
|
||||
return;
|
||||
}
|
||||
|
||||
const float corrector1 = 1.0f / square_modulus;
|
||||
const float corrector2 = 2.0f * corrector1;
|
||||
|
||||
const float s0x1 = quaternion->s0 * quaternion->x1;
|
||||
const float s0x2 = quaternion->s0 * quaternion->x2;
|
||||
|
@ -318,20 +341,22 @@ inline void bgc_quaternion_get_rotation_matrix_fp32(const BgcQuaternionFP32* qua
|
|||
const float x1x3 = quaternion->x1 * quaternion->x3;
|
||||
const float x2x3 = quaternion->x2 * quaternion->x3;
|
||||
|
||||
matrix->r1c1 = corrector1 * ((s0s0 + x1x1) - (x2x2 + x3x3));
|
||||
matrix->r2c2 = corrector1 * ((s0s0 + x2x2) - (x1x1 + x3x3));
|
||||
matrix->r3c3 = corrector1 * ((s0s0 + x3x3) - (x1x1 + x2x2));
|
||||
const float corrector2 = 2.0f * corrector1;
|
||||
|
||||
matrix->r1c2 = corrector2 * (x1x2 - s0x3);
|
||||
matrix->r2c3 = corrector2 * (x2x3 - s0x1);
|
||||
matrix->r3c1 = corrector2 * (x1x3 - s0x2);
|
||||
rotation->r1c1 = corrector1 * ((s0s0 + x1x1) - (x2x2 + x3x3));
|
||||
rotation->r2c2 = corrector1 * ((s0s0 + x2x2) - (x1x1 + x3x3));
|
||||
rotation->r3c3 = corrector1 * ((s0s0 + x3x3) - (x1x1 + x2x2));
|
||||
|
||||
matrix->r2c1 = corrector2 * (x1x2 + s0x3);
|
||||
matrix->r3c2 = corrector2 * (x2x3 + s0x1);
|
||||
matrix->r1c3 = corrector2 * (x1x3 + s0x2);
|
||||
rotation->r1c2 = corrector2 * (x1x2 - s0x3);
|
||||
rotation->r2c3 = corrector2 * (x2x3 - s0x1);
|
||||
rotation->r3c1 = corrector2 * (x1x3 - s0x2);
|
||||
|
||||
rotation->r2c1 = corrector2 * (x1x2 + s0x3);
|
||||
rotation->r3c2 = corrector2 * (x2x3 + s0x1);
|
||||
rotation->r1c3 = corrector2 * (x1x3 + s0x2);
|
||||
}
|
||||
|
||||
inline void bgc_quaternion_get_rotation_matrix_fp64(const BgcQuaternionFP64* quaternion, BgcMatrix3x3FP64* matrix)
|
||||
inline void bgc_quaternion_make_rotation_matrix_fp64(const BgcQuaternionFP64* quaternion, BgcMatrix3x3FP64* rotation)
|
||||
{
|
||||
const double s0s0 = quaternion->s0 * quaternion->s0;
|
||||
const double x1x1 = quaternion->x1 * quaternion->x1;
|
||||
|
@ -340,14 +365,13 @@ inline void bgc_quaternion_get_rotation_matrix_fp64(const BgcQuaternionFP64* qua
|
|||
|
||||
const double square_modulus = (s0s0 + x1x1) + (x2x2 + x3x3);
|
||||
|
||||
if (bgc_is_zero_fp64(square_modulus))
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP64 || square_modulus != square_modulus)
|
||||
{
|
||||
bgc_matrix3x3_set_to_identity_fp64(matrix);
|
||||
bgc_matrix3x3_set_to_identity_fp64(rotation);
|
||||
return;
|
||||
}
|
||||
|
||||
const double corrector1 = 1.0f / square_modulus;
|
||||
const double corrector2 = 2.0f * corrector1;
|
||||
|
||||
const double s0x1 = quaternion->s0 * quaternion->x1;
|
||||
const double s0x2 = quaternion->s0 * quaternion->x2;
|
||||
|
@ -356,22 +380,24 @@ inline void bgc_quaternion_get_rotation_matrix_fp64(const BgcQuaternionFP64* qua
|
|||
const double x1x3 = quaternion->x1 * quaternion->x3;
|
||||
const double x2x3 = quaternion->x2 * quaternion->x3;
|
||||
|
||||
matrix->r1c1 = corrector1 * ((s0s0 + x1x1) - (x2x2 + x3x3));
|
||||
matrix->r2c2 = corrector1 * ((s0s0 + x2x2) - (x1x1 + x3x3));
|
||||
matrix->r3c3 = corrector1 * ((s0s0 + x3x3) - (x1x1 + x2x2));
|
||||
const double corrector2 = 2.0f * corrector1;
|
||||
|
||||
matrix->r1c2 = corrector2 * (x1x2 - s0x3);
|
||||
matrix->r2c3 = corrector2 * (x2x3 - s0x1);
|
||||
matrix->r3c1 = corrector2 * (x1x3 - s0x2);
|
||||
rotation->r1c1 = corrector1 * ((s0s0 + x1x1) - (x2x2 + x3x3));
|
||||
rotation->r2c2 = corrector1 * ((s0s0 + x2x2) - (x1x1 + x3x3));
|
||||
rotation->r3c3 = corrector1 * ((s0s0 + x3x3) - (x1x1 + x2x2));
|
||||
|
||||
matrix->r2c1 = corrector2 * (x1x2 + s0x3);
|
||||
matrix->r3c2 = corrector2 * (x2x3 + s0x1);
|
||||
matrix->r1c3 = corrector2 * (x1x3 + s0x2);
|
||||
rotation->r1c2 = corrector2 * (x1x2 - s0x3);
|
||||
rotation->r2c3 = corrector2 * (x2x3 - s0x1);
|
||||
rotation->r3c1 = corrector2 * (x1x3 - s0x2);
|
||||
|
||||
rotation->r2c1 = corrector2 * (x1x2 + s0x3);
|
||||
rotation->r3c2 = corrector2 * (x2x3 + s0x1);
|
||||
rotation->r1c3 = corrector2 * (x1x3 + s0x2);
|
||||
}
|
||||
|
||||
// ============ Make Reverse Matrix ============= //
|
||||
|
||||
inline void bgc_quaternion_get_reverse_matrix_fp32(const BgcQuaternionFP32* quaternion, BgcMatrix3x3FP32* matrix)
|
||||
inline void bgc_quaternion_make_reverse_matrix_fp32(const BgcQuaternionFP32* quaternion, BgcMatrix3x3FP32* reverse)
|
||||
{
|
||||
const float s0s0 = quaternion->s0 * quaternion->s0;
|
||||
const float x1x1 = quaternion->x1 * quaternion->x1;
|
||||
|
@ -380,14 +406,13 @@ inline void bgc_quaternion_get_reverse_matrix_fp32(const BgcQuaternionFP32* quat
|
|||
|
||||
const float square_modulus = (s0s0 + x1x1) + (x2x2 + x3x3);
|
||||
|
||||
if (-BGC_EPSYLON_FP32 <= square_modulus && square_modulus <= BGC_EPSYLON_FP32)
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32 || square_modulus != square_modulus)
|
||||
{
|
||||
bgc_matrix3x3_set_to_identity_fp32(matrix);
|
||||
bgc_matrix3x3_set_to_identity_fp32(reverse);
|
||||
return;
|
||||
}
|
||||
|
||||
const float corrector1 = 1.0f / square_modulus;
|
||||
const float corrector2 = 2.0f * corrector1;
|
||||
|
||||
const float s0x1 = quaternion->s0 * quaternion->x1;
|
||||
const float s0x2 = quaternion->s0 * quaternion->x2;
|
||||
|
@ -396,20 +421,22 @@ inline void bgc_quaternion_get_reverse_matrix_fp32(const BgcQuaternionFP32* quat
|
|||
const float x1x3 = quaternion->x1 * quaternion->x3;
|
||||
const float x2x3 = quaternion->x2 * quaternion->x3;
|
||||
|
||||
matrix->r1c1 = corrector1 * ((s0s0 + x1x1) - (x2x2 + x3x3));
|
||||
matrix->r2c2 = corrector1 * ((s0s0 + x2x2) - (x1x1 + x3x3));
|
||||
matrix->r3c3 = corrector1 * ((s0s0 + x3x3) - (x1x1 + x2x2));
|
||||
const float corrector2 = 2.0f * corrector1;
|
||||
|
||||
matrix->r1c2 = corrector2 * (x1x2 + s0x3);
|
||||
matrix->r2c3 = corrector2 * (x2x3 + s0x1);
|
||||
matrix->r3c1 = corrector2 * (x1x3 + s0x2);
|
||||
reverse->r1c1 = corrector1 * ((s0s0 + x1x1) - (x2x2 + x3x3));
|
||||
reverse->r2c2 = corrector1 * ((s0s0 + x2x2) - (x1x1 + x3x3));
|
||||
reverse->r3c3 = corrector1 * ((s0s0 + x3x3) - (x1x1 + x2x2));
|
||||
|
||||
matrix->r2c1 = corrector2 * (x1x2 - s0x3);
|
||||
matrix->r3c2 = corrector2 * (x2x3 - s0x1);
|
||||
matrix->r1c3 = corrector2 * (x1x3 - s0x2);
|
||||
reverse->r1c2 = corrector2 * (x1x2 + s0x3);
|
||||
reverse->r2c3 = corrector2 * (x2x3 + s0x1);
|
||||
reverse->r3c1 = corrector2 * (x1x3 + s0x2);
|
||||
|
||||
reverse->r2c1 = corrector2 * (x1x2 - s0x3);
|
||||
reverse->r3c2 = corrector2 * (x2x3 - s0x1);
|
||||
reverse->r1c3 = corrector2 * (x1x3 - s0x2);
|
||||
}
|
||||
|
||||
inline void bgc_quaternion_get_reverse_matrix_fp64(const BgcQuaternionFP64* quaternion, BgcMatrix3x3FP64* matrix)
|
||||
inline void bgc_quaternion_make_reverse_matrix_fp64(const BgcQuaternionFP64* quaternion, BgcMatrix3x3FP64* reverse)
|
||||
{
|
||||
const double s0s0 = quaternion->s0 * quaternion->s0;
|
||||
const double x1x1 = quaternion->x1 * quaternion->x1;
|
||||
|
@ -418,14 +445,13 @@ inline void bgc_quaternion_get_reverse_matrix_fp64(const BgcQuaternionFP64* quat
|
|||
|
||||
const double square_modulus = (s0s0 + x1x1) + (x2x2 + x3x3);
|
||||
|
||||
if (-BGC_EPSYLON_FP64 <= square_modulus && square_modulus <= BGC_EPSYLON_FP64)
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP64 || square_modulus != square_modulus)
|
||||
{
|
||||
bgc_matrix3x3_set_to_identity_fp64(matrix);
|
||||
bgc_matrix3x3_set_to_identity_fp64(reverse);
|
||||
return;
|
||||
}
|
||||
|
||||
const double corrector1 = 1.0f / square_modulus;
|
||||
const double corrector2 = 2.0f * corrector1;
|
||||
|
||||
const double s0x1 = quaternion->s0 * quaternion->x1;
|
||||
const double s0x2 = quaternion->s0 * quaternion->x2;
|
||||
|
@ -434,17 +460,19 @@ inline void bgc_quaternion_get_reverse_matrix_fp64(const BgcQuaternionFP64* quat
|
|||
const double x1x3 = quaternion->x1 * quaternion->x3;
|
||||
const double x2x3 = quaternion->x2 * quaternion->x3;
|
||||
|
||||
matrix->r1c1 = corrector1 * ((s0s0 + x1x1) - (x2x2 + x3x3));
|
||||
matrix->r2c2 = corrector1 * ((s0s0 + x2x2) - (x1x1 + x3x3));
|
||||
matrix->r3c3 = corrector1 * ((s0s0 + x3x3) - (x1x1 + x2x2));
|
||||
const double corrector2 = 2.0f * corrector1;
|
||||
|
||||
matrix->r1c2 = corrector2 * (x1x2 + s0x3);
|
||||
matrix->r2c3 = corrector2 * (x2x3 + s0x1);
|
||||
matrix->r3c1 = corrector2 * (x1x3 + s0x2);
|
||||
reverse->r1c1 = corrector1 * ((s0s0 + x1x1) - (x2x2 + x3x3));
|
||||
reverse->r2c2 = corrector1 * ((s0s0 + x2x2) - (x1x1 + x3x3));
|
||||
reverse->r3c3 = corrector1 * ((s0s0 + x3x3) - (x1x1 + x2x2));
|
||||
|
||||
matrix->r2c1 = corrector2 * (x1x2 - s0x3);
|
||||
matrix->r3c2 = corrector2 * (x2x3 - s0x1);
|
||||
matrix->r1c3 = corrector2 * (x1x3 - s0x2);
|
||||
reverse->r1c2 = corrector2 * (x1x2 + s0x3);
|
||||
reverse->r2c3 = corrector2 * (x2x3 + s0x1);
|
||||
reverse->r3c1 = corrector2 * (x1x3 + s0x2);
|
||||
|
||||
reverse->r2c1 = corrector2 * (x1x2 - s0x3);
|
||||
reverse->r3c2 = corrector2 * (x2x3 - s0x1);
|
||||
reverse->r1c3 = corrector2 * (x1x3 - s0x2);
|
||||
}
|
||||
|
||||
// ==================== Add ===================== //
|
||||
|
@ -501,7 +529,25 @@ inline void bgc_quaternion_subtract_fp64(const BgcQuaternionFP64 * minuend, cons
|
|||
difference->x3 = minuend->x3 - subtrahend->x3;
|
||||
}
|
||||
|
||||
// =============== Multiplication =============== //
|
||||
// ============== Subtract scaled =============== //
|
||||
|
||||
inline void bgc_quaternion_subtract_scaled_fp32(const BgcQuaternionFP32 * basic_quaternion, const BgcQuaternionFP32 * scalable_quaternion, const float scale, BgcQuaternionFP32 * difference)
|
||||
{
|
||||
difference->s0 = basic_quaternion->s0 - scalable_quaternion->s0 * scale;
|
||||
difference->x1 = basic_quaternion->x1 - scalable_quaternion->x1 * scale;
|
||||
difference->x2 = basic_quaternion->x2 - scalable_quaternion->x2 * scale;
|
||||
difference->x3 = basic_quaternion->x3 - scalable_quaternion->x3 * scale;
|
||||
}
|
||||
|
||||
inline void bgc_quaternion_subtract_scaled_fp64(const BgcQuaternionFP64 * basic_quaternion, const BgcQuaternionFP64 * scalable_quaternion, const double scale, BgcQuaternionFP64 * difference)
|
||||
{
|
||||
difference->s0 = basic_quaternion->s0 - scalable_quaternion->s0 * scale;
|
||||
difference->x1 = basic_quaternion->x1 - scalable_quaternion->x1 * scale;
|
||||
difference->x2 = basic_quaternion->x2 - scalable_quaternion->x2 * scale;
|
||||
difference->x3 = basic_quaternion->x3 - scalable_quaternion->x3 * scale;
|
||||
}
|
||||
|
||||
// ================== Multiply ================== //
|
||||
|
||||
inline void bgc_quaternion_multiply_fp32(const BgcQuaternionFP32* multiplicand, const float multipier, BgcQuaternionFP32* product)
|
||||
{
|
||||
|
@ -519,7 +565,7 @@ inline void bgc_quaternion_multiply_fp64(const BgcQuaternionFP64* multiplicand,
|
|||
product->x3 = multiplicand->x3 * multipier;
|
||||
}
|
||||
|
||||
// ================== Division ================== //
|
||||
// =================== Divide =================== //
|
||||
|
||||
inline void bgc_quaternion_divide_fp32(const BgcQuaternionFP32* dividend, const float divisor, BgcQuaternionFP32* quotient)
|
||||
{
|
||||
|
@ -531,34 +577,6 @@ inline void bgc_quaternion_divide_fp64(const BgcQuaternionFP64* dividend, const
|
|||
bgc_quaternion_multiply_fp64(dividend, 1.0 / divisor, quotient);
|
||||
}
|
||||
|
||||
// ================== Product =================== //
|
||||
|
||||
inline void bgc_quaternion_get_product_fp32(const BgcQuaternionFP32* left, const BgcQuaternionFP32* right, BgcQuaternionFP32* product)
|
||||
{
|
||||
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 x2 = (left->x2 * right->s0 + left->s0 * right->x2) - (left->x1 * right->x3 - left->x3 * right->x1);
|
||||
const float x3 = (left->x3 * right->s0 + left->s0 * right->x3) - (left->x2 * right->x1 - left->x1 * right->x2);
|
||||
|
||||
product->s0 = s0;
|
||||
product->x1 = x1;
|
||||
product->x2 = x2;
|
||||
product->x3 = x3;
|
||||
}
|
||||
|
||||
inline void bgc_quaternion_get_product_fp64(const BgcQuaternionFP64* left, const BgcQuaternionFP64* right, BgcQuaternionFP64* product)
|
||||
{
|
||||
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 x2 = (left->x2 * right->s0 + left->s0 * right->x2) - (left->x1 * right->x3 - left->x3 * right->x1);
|
||||
const double x3 = (left->x3 * right->s0 + left->s0 * right->x3) - (left->x2 * right->x1 - left->x1 * right->x2);
|
||||
|
||||
product->s0 = s0;
|
||||
product->x1 = x1;
|
||||
product->x2 = x2;
|
||||
product->x3 = x3;
|
||||
}
|
||||
|
||||
// ================== Are Close ================= //
|
||||
|
||||
inline int bgc_quaternion_are_close_fp32(const BgcQuaternionFP32* quaternion1, const BgcQuaternionFP32* quaternion2)
|
||||
|
|
|
@ -10,23 +10,29 @@ extern inline void bgc_tangent_pair_reset_fp64(BgcTangentPairFP64* tangent);
|
|||
extern inline void bgc_tangent_pair_set_values_fp32(const float x1, const float x2, BgcTangentPairFP32* tangent);
|
||||
extern inline void bgc_tangent_pair_set_values_fp64(const double x1, const double x2, BgcTangentPairFP64* tangent);
|
||||
|
||||
extern inline void bgc_tangent_pair_set_turn_fp32(const float angle, const BgcAngleUnitEnum unit, BgcTangentPairFP32* tangent);
|
||||
extern inline void bgc_tangent_pair_set_turn_fp64(const double angle, const BgcAngleUnitEnum unit, BgcTangentPairFP64* tangent);
|
||||
|
||||
extern inline float bgc_tangent_pair_get_angle_fp32(const BgcTangentPairFP32* tangent, const BgcAngleUnitEnum unit);
|
||||
extern inline double bgc_tangent_pair_get_angle_fp64(const BgcTangentPairFP64* tangent, const BgcAngleUnitEnum unit);
|
||||
|
||||
extern inline void bgc_tangent_pair_copy_fp32(const BgcTangentPairFP32* from, BgcTangentPairFP32* to);
|
||||
extern inline void bgc_tangent_pair_copy_fp64(const BgcTangentPairFP64* from, BgcTangentPairFP64* to);
|
||||
|
||||
extern inline void bgc_tangent_pair_swap_fp32(BgcTangentPairFP32* tangent1, BgcTangentPairFP32* tangent2);
|
||||
extern inline void bgc_tangent_pair_swap_fp64(BgcTangentPairFP64* tangent1, BgcTangentPairFP64* tangent2);
|
||||
|
||||
extern inline void bgc_tangent_pair_set_turn_fp32(const float angle, const BgcAngleUnitEnum unit, BgcTangentPairFP32* tangent);
|
||||
extern inline void bgc_tangent_pair_set_turn_fp64(const double angle, const BgcAngleUnitEnum unit, BgcTangentPairFP64* tangent);
|
||||
|
||||
extern inline void bgc_tangent_pair_convert_fp64_to_fp32(const BgcTangentPairFP64* from, BgcTangentPairFP32* to);
|
||||
extern inline void bgc_tangent_pair_convert_fp32_to_fp64(const BgcTangentPairFP32* from, BgcTangentPairFP64* to);
|
||||
|
||||
extern inline void bgc_tangent_pair_invert_fp32(BgcTangentPairFP32* tangent);
|
||||
extern inline void bgc_tangent_pair_invert_fp64(BgcTangentPairFP64* tangent);
|
||||
|
||||
extern inline void bgc_tangent_pair_set_inverted_fp32(const BgcTangentPairFP32* tangent, BgcTangentPairFP32* result);
|
||||
extern inline void bgc_tangent_pair_set_inverted_fp64(const BgcTangentPairFP64* tangent, BgcTangentPairFP64* result);
|
||||
extern inline void bgc_tangent_pair_combine_fp32(const BgcTangentPairFP32* tangent1, const BgcTangentPairFP32* tangent2, BgcTangentPairFP32* result);
|
||||
extern inline void bgc_tangent_pair_combine_fp64(const BgcTangentPairFP64* tangent1, const BgcTangentPairFP64* tangent2, BgcTangentPairFP64* result);
|
||||
|
||||
extern inline void bgc_tangent_pair_make_inverted_fp32(const BgcTangentPairFP32* tangent, BgcTangentPairFP32* result);
|
||||
extern inline void bgc_tangent_pair_make_inverted_fp64(const BgcTangentPairFP64* tangent, BgcTangentPairFP64* result);
|
||||
|
||||
extern inline void bgc_tangent_pair_make_rotation_matrix_fp32(const BgcTangentPairFP32* tangent, BgcMatrix2x2FP32* matrix);
|
||||
extern inline void bgc_tangent_pair_make_rotation_matrix_fp64(const BgcTangentPairFP64* tangent, BgcMatrix2x2FP64* matrix);
|
||||
|
@ -34,12 +40,6 @@ extern inline void bgc_tangent_pair_make_rotation_matrix_fp64(const BgcTangentPa
|
|||
extern inline void bgc_tangent_pair_make_reverse_matrix_fp32(const BgcTangentPairFP32* tangent, BgcMatrix2x2FP32* matrix);
|
||||
extern inline void bgc_tangent_pair_make_reverse_matrix_fp64(const BgcTangentPairFP64* tangent, BgcMatrix2x2FP64* matrix);
|
||||
|
||||
extern inline float bgc_tangent_pair_get_angle_fp32(const BgcTangentPairFP32* tangent, const BgcAngleUnitEnum unit);
|
||||
extern inline double bgc_tangent_pair_get_angle_fp64(const BgcTangentPairFP64* tangent, const BgcAngleUnitEnum unit);
|
||||
|
||||
extern inline void bgc_tangent_pair_combine_fp32(const BgcTangentPairFP32* tangent1, const BgcTangentPairFP32* tangent2, BgcTangentPairFP32* result);
|
||||
extern inline void bgc_tangent_pair_combine_fp64(const BgcTangentPairFP64* tangent1, const BgcTangentPairFP64* tangent2, BgcTangentPairFP64* result);
|
||||
|
||||
extern inline void bgc_tangent_pair_turn_vector_fp32(const BgcTangentPairFP32* tangent, const BgcVector2FP32* vector, BgcVector2FP32* result);
|
||||
extern inline void bgc_tangent_pair_turn_vector_fp64(const BgcTangentPairFP64* tangent, const BgcVector2FP64* vector, BgcVector2FP64* result);
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ inline void bgc_tangent_pair_set_values_fp32(const float x1, const float x2, Bgc
|
|||
twin->cos = x1;
|
||||
twin->sin = x2;
|
||||
|
||||
if (!bgc_is_sqare_value_unit_fp32(square_modulus)) {
|
||||
if (!bgc_is_sqare_unit_fp32(square_modulus)) {
|
||||
_bgc_tangent_pair_normalize_fp32(square_modulus, twin);
|
||||
}
|
||||
}
|
||||
|
@ -82,11 +82,77 @@ inline void bgc_tangent_pair_set_values_fp64(const double x1, const double x2, B
|
|||
twin->cos = x1;
|
||||
twin->sin = x2;
|
||||
|
||||
if (!bgc_is_sqare_value_unit_fp64(square_modulus)) {
|
||||
if (!bgc_is_sqare_unit_fp64(square_modulus)) {
|
||||
_bgc_tangent_pair_normalize_fp64(square_modulus, twin);
|
||||
}
|
||||
}
|
||||
|
||||
// ================== Set Turn ================== //
|
||||
|
||||
inline void bgc_tangent_pair_set_turn_fp32(const float angle, const BgcAngleUnitEnum unit, BgcTangentPairFP32* tangent)
|
||||
{
|
||||
const float radians = bgc_angle_to_radians_fp32(angle, unit);
|
||||
|
||||
_BgcTwinTangentPairFP32* twin = (_BgcTwinTangentPairFP32*)tangent;
|
||||
|
||||
twin->cos = cosf(radians);
|
||||
twin->sin = sinf(radians);
|
||||
}
|
||||
|
||||
inline void bgc_tangent_pair_set_turn_fp64(const double angle, const BgcAngleUnitEnum unit, BgcTangentPairFP64* tangent)
|
||||
{
|
||||
const double radians = bgc_angle_to_radians_fp64(angle, unit);
|
||||
|
||||
_BgcTwinTangentPairFP64* twin = (_BgcTwinTangentPairFP64*)tangent;
|
||||
|
||||
twin->cos = cos(radians);
|
||||
twin->sin = sin(radians);
|
||||
}
|
||||
|
||||
// =================== Angle =================== //
|
||||
|
||||
inline float bgc_tangent_pair_get_angle_fp32(const BgcTangentPairFP32* tangent, const BgcAngleUnitEnum unit)
|
||||
{
|
||||
if (tangent->cos >= 1.0f - BGC_EPSYLON_FP32) {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
if (tangent->cos <= -1.0f + BGC_EPSYLON_FP32) {
|
||||
return bgc_angle_get_half_circle_fp32(unit);
|
||||
}
|
||||
|
||||
if (tangent->sin >= 1.0f - BGC_EPSYLON_FP32) {
|
||||
return bgc_angle_get_quater_circle_fp32(unit);
|
||||
}
|
||||
|
||||
if (tangent->sin <= -1.0f + BGC_EPSYLON_FP32) {
|
||||
return 0.75f * bgc_angle_get_full_circle_fp32(unit);
|
||||
}
|
||||
|
||||
return bgc_radians_to_units_fp32(atan2f(tangent->cos, tangent->sin), unit);
|
||||
}
|
||||
|
||||
inline double bgc_tangent_pair_get_angle_fp64(const BgcTangentPairFP64* tangent, const BgcAngleUnitEnum unit)
|
||||
{
|
||||
if (tangent->cos >= 1.0 - BGC_EPSYLON_FP64) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
if (tangent->cos <= -1.0 + BGC_EPSYLON_FP64) {
|
||||
return bgc_angle_get_half_circle_fp64(unit);
|
||||
}
|
||||
|
||||
if (tangent->sin >= 1.0 - BGC_EPSYLON_FP64) {
|
||||
return bgc_angle_get_quater_circle_fp64(unit);
|
||||
}
|
||||
|
||||
if (tangent->sin <= -1.0 + BGC_EPSYLON_FP64) {
|
||||
return 0.75 * bgc_angle_get_full_circle_fp64(unit);
|
||||
}
|
||||
|
||||
return bgc_radians_to_units_fp64(atan2(tangent->cos, tangent->sin), unit);
|
||||
}
|
||||
|
||||
// ==================== Copy ==================== //
|
||||
|
||||
inline void bgc_tangent_pair_copy_fp32(const BgcTangentPairFP32* from, BgcTangentPairFP32* to)
|
||||
|
@ -139,29 +205,7 @@ inline void bgc_tangent_pair_swap_fp64(BgcTangentPairFP64* tangent1, BgcTangentP
|
|||
twin2->sin = sin;
|
||||
}
|
||||
|
||||
// ================== Set Turn ================== //
|
||||
|
||||
inline void bgc_tangent_pair_set_turn_fp32(const float angle, const BgcAngleUnitEnum unit, BgcTangentPairFP32* tangent)
|
||||
{
|
||||
const float radians = bgc_angle_to_radians_fp32(angle, unit);
|
||||
|
||||
_BgcTwinTangentPairFP32* twin = (_BgcTwinTangentPairFP32*)tangent;
|
||||
|
||||
twin->cos = cosf(radians);
|
||||
twin->sin = sinf(radians);
|
||||
}
|
||||
|
||||
inline void bgc_tangent_pair_set_turn_fp64(const double angle, const BgcAngleUnitEnum unit, BgcTangentPairFP64* tangent)
|
||||
{
|
||||
const double radians = bgc_angle_to_radians_fp64(angle, unit);
|
||||
|
||||
_BgcTwinTangentPairFP64* twin = (_BgcTwinTangentPairFP64*)tangent;
|
||||
|
||||
twin->cos = cos(radians);
|
||||
twin->sin = sin(radians);
|
||||
}
|
||||
|
||||
// ============= Copy to twin type ============== //
|
||||
// ================== Convert =================== //
|
||||
|
||||
inline void bgc_tangent_pair_convert_fp64_to_fp32(const BgcTangentPairFP64* from, BgcTangentPairFP32* to)
|
||||
{
|
||||
|
@ -173,7 +217,7 @@ inline void bgc_tangent_pair_convert_fp32_to_fp64(const BgcTangentPairFP32* from
|
|||
bgc_tangent_pair_set_values_fp64((double)from->cos, (double)from->sin, to);
|
||||
}
|
||||
|
||||
// ================= Inversion ================== //
|
||||
// =================== Invert =================== //
|
||||
|
||||
inline void bgc_tangent_pair_invert_fp32(BgcTangentPairFP32* tangent)
|
||||
{
|
||||
|
@ -185,9 +229,29 @@ inline void bgc_tangent_pair_invert_fp64(BgcTangentPairFP64* tangent)
|
|||
((_BgcTwinTangentPairFP64*)tangent)->sin = -tangent->sin;
|
||||
}
|
||||
|
||||
// ================ Combination ================= //
|
||||
|
||||
inline void bgc_tangent_pair_combine_fp32(const BgcTangentPairFP32* tangent1, const BgcTangentPairFP32* tangent2, BgcTangentPairFP32* result)
|
||||
{
|
||||
bgc_tangent_pair_set_values_fp32(
|
||||
tangent1->cos * tangent2->cos - tangent1->sin * tangent2->sin,
|
||||
tangent1->cos * tangent2->sin + tangent1->sin * tangent2->cos,
|
||||
result
|
||||
);
|
||||
}
|
||||
|
||||
inline void bgc_tangent_pair_combine_fp64(const BgcTangentPairFP64* tangent1, const BgcTangentPairFP64* tangent2, BgcTangentPairFP64* result)
|
||||
{
|
||||
bgc_tangent_pair_set_values_fp64(
|
||||
tangent1->cos * tangent2->cos - tangent1->sin * tangent2->sin,
|
||||
tangent1->cos * tangent2->sin + tangent1->sin * tangent2->cos,
|
||||
result
|
||||
);
|
||||
}
|
||||
|
||||
// ================ Set Inverted ================ //
|
||||
|
||||
inline void bgc_tangent_pair_set_inverted_fp32(const BgcTangentPairFP32* tangent, BgcTangentPairFP32* result)
|
||||
inline void bgc_tangent_pair_make_inverted_fp32(const BgcTangentPairFP32* tangent, BgcTangentPairFP32* result)
|
||||
{
|
||||
_BgcTwinTangentPairFP32* twin = (_BgcTwinTangentPairFP32*)result;
|
||||
|
||||
|
@ -195,7 +259,7 @@ inline void bgc_tangent_pair_set_inverted_fp32(const BgcTangentPairFP32* tangent
|
|||
twin->sin = -tangent->sin;
|
||||
}
|
||||
|
||||
inline void bgc_tangent_pair_set_inverted_fp64(const BgcTangentPairFP64* tangent, BgcTangentPairFP64* result)
|
||||
inline void bgc_tangent_pair_make_inverted_fp64(const BgcTangentPairFP64* tangent, BgcTangentPairFP64* result)
|
||||
{
|
||||
_BgcTwinTangentPairFP64* twin = (_BgcTwinTangentPairFP64*)result;
|
||||
|
||||
|
@ -239,70 +303,6 @@ inline void bgc_tangent_pair_make_reverse_matrix_fp64(const BgcTangentPairFP64*
|
|||
matrix->r2c2 = tangent->cos;
|
||||
}
|
||||
|
||||
// =================== Angle =================== //
|
||||
|
||||
inline float bgc_tangent_pair_get_angle_fp32(const BgcTangentPairFP32* tangent, const BgcAngleUnitEnum unit)
|
||||
{
|
||||
if (tangent->cos >= 1.0f - BGC_EPSYLON_FP32) {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
if (tangent->cos <= -1.0f + BGC_EPSYLON_FP32) {
|
||||
return bgc_angle_get_half_circle_fp32(unit);
|
||||
}
|
||||
|
||||
if (tangent->sin >= 1.0f - BGC_EPSYLON_FP32) {
|
||||
return bgc_angle_get_quater_circle_fp32(unit);
|
||||
}
|
||||
|
||||
if (tangent->sin <= -1.0f + BGC_EPSYLON_FP32) {
|
||||
return 0.75f * bgc_angle_get_full_circle_fp32(unit);
|
||||
}
|
||||
|
||||
return bgc_radians_to_units_fp32(atan2f(tangent->cos, tangent->sin), unit);
|
||||
}
|
||||
|
||||
inline double bgc_tangent_pair_get_angle_fp64(const BgcTangentPairFP64* tangent, const BgcAngleUnitEnum unit)
|
||||
{
|
||||
if (tangent->cos >= 1.0 - BGC_EPSYLON_FP64) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
if (tangent->cos <= -1.0 + BGC_EPSYLON_FP64) {
|
||||
return bgc_angle_get_half_circle_fp64(unit);
|
||||
}
|
||||
|
||||
if (tangent->sin >= 1.0 - BGC_EPSYLON_FP64) {
|
||||
return bgc_angle_get_quater_circle_fp64(unit);
|
||||
}
|
||||
|
||||
if (tangent->sin <= -1.0 + BGC_EPSYLON_FP64) {
|
||||
return 0.75 * bgc_angle_get_full_circle_fp64(unit);
|
||||
}
|
||||
|
||||
return bgc_radians_to_units_fp64(atan2(tangent->cos, tangent->sin), unit);
|
||||
}
|
||||
|
||||
// ================ Combination ================= //
|
||||
|
||||
inline void bgc_tangent_pair_combine_fp32(const BgcTangentPairFP32* tangent1, const BgcTangentPairFP32* tangent2, BgcTangentPairFP32* result)
|
||||
{
|
||||
bgc_tangent_pair_set_values_fp32(
|
||||
tangent1->cos * tangent2->cos - tangent1->sin * tangent2->sin,
|
||||
tangent1->cos * tangent2->sin + tangent1->sin * tangent2->cos,
|
||||
result
|
||||
);
|
||||
}
|
||||
|
||||
inline void bgc_tangent_pair_combine_fp64(const BgcTangentPairFP64* tangent1, const BgcTangentPairFP64* tangent2, BgcTangentPairFP64* result)
|
||||
{
|
||||
bgc_tangent_pair_set_values_fp64(
|
||||
tangent1->cos * tangent2->cos - tangent1->sin * tangent2->sin,
|
||||
tangent1->cos * tangent2->sin + tangent1->sin * tangent2->cos,
|
||||
result
|
||||
);
|
||||
}
|
||||
|
||||
// ================ Turn Vector ================= //
|
||||
|
||||
inline void bgc_tangent_pair_turn_vector_fp32(const BgcTangentPairFP32* tangent, const BgcVector2FP32* vector, BgcVector2FP32* result)
|
||||
|
|
|
@ -7,8 +7,8 @@ extern inline int bgc_is_zero_fp64(const double square_value);
|
|||
extern inline int bgc_is_unit_fp32(const float square_value);
|
||||
extern inline int bgc_is_unit_fp64(const double square_value);
|
||||
|
||||
extern inline int bgc_is_sqare_value_unit_fp32(const float square_value);
|
||||
extern inline int bgc_is_sqare_value_unit_fp64(const double square_value);
|
||||
extern inline int bgc_is_sqare_unit_fp32(const float square_value);
|
||||
extern inline int bgc_is_sqare_unit_fp64(const double square_value);
|
||||
|
||||
extern inline int bgc_are_close_fp32(const float value1, const float value2);
|
||||
extern inline int bgc_are_close_fp64(const double value1, const double value2);
|
||||
|
|
|
@ -47,12 +47,12 @@ inline int bgc_is_unit_fp64(const double square_value)
|
|||
}
|
||||
|
||||
|
||||
inline int bgc_is_sqare_value_unit_fp32(const float square_value)
|
||||
inline int bgc_is_sqare_unit_fp32(const float square_value)
|
||||
{
|
||||
return (1.0f - 2.0f * BGC_EPSYLON_FP32 <= square_value) && (square_value <= 1.0f + 2.0f * BGC_EPSYLON_FP32);
|
||||
}
|
||||
|
||||
inline int bgc_is_sqare_value_unit_fp64(const double square_value)
|
||||
inline int bgc_is_sqare_unit_fp64(const double square_value)
|
||||
{
|
||||
return (1.0 - 2.0 * BGC_EPSYLON_FP64 <= square_value) && (square_value <= 1.0 + 2.0 * BGC_EPSYLON_FP64);
|
||||
}
|
||||
|
|
|
@ -6,21 +6,6 @@ extern inline void bgc_vector2_reset_fp64(BgcVector2FP64* vector);
|
|||
extern inline void bgc_vector2_set_values_fp32(const float x1, const float x2, BgcVector2FP32* to);
|
||||
extern inline void bgc_vector2_set_values_fp64(const double x1, const double x2, BgcVector2FP64* to);
|
||||
|
||||
extern inline void bgc_vector2_copy_fp32(const BgcVector2FP32* from, BgcVector2FP32* to);
|
||||
extern inline void bgc_vector2_copy_fp64(const BgcVector2FP64* from, BgcVector2FP64* to);
|
||||
|
||||
extern inline void bgc_vector2_swap_fp32(BgcVector2FP32* vector1, BgcVector2FP32* vector2);
|
||||
extern inline void bgc_vector2_swap_fp64(BgcVector2FP64* vector1, BgcVector2FP64* vector2);
|
||||
|
||||
extern inline void bgc_vector2_convert_fp64_to_fp32(const BgcVector2FP64* from, BgcVector2FP32* to);
|
||||
extern inline void bgc_vector2_convert_fp32_to_fp64(const BgcVector2FP32* from, BgcVector2FP64* to);
|
||||
|
||||
extern inline void bgc_vector2_set_reverse_fp32(const BgcVector2FP32* from, BgcVector2FP32* to);
|
||||
extern inline void bgc_vector2_set_reverse_fp64(const BgcVector2FP64* from, BgcVector2FP64* to);
|
||||
|
||||
extern inline void bgc_vector2_set_reverse_fp64_to_fp32(const BgcVector2FP64* from, BgcVector2FP32* to);
|
||||
extern inline void bgc_vector2_set_reverse_fp32_to_fp64(const BgcVector2FP32* from, BgcVector2FP64* to);
|
||||
|
||||
extern inline float bgc_vector2_get_square_modulus_fp32(const BgcVector2FP32* vector);
|
||||
extern inline double bgc_vector2_get_square_modulus_fp64(const BgcVector2FP64* vector);
|
||||
|
||||
|
@ -33,6 +18,27 @@ extern inline int bgc_vector2_is_zero_fp64(const BgcVector2FP64* vector);
|
|||
extern inline int bgc_vector2_is_unit_fp32(const BgcVector2FP32* vector);
|
||||
extern inline int bgc_vector2_is_unit_fp64(const BgcVector2FP64* vector);
|
||||
|
||||
extern inline void bgc_vector2_copy_fp32(const BgcVector2FP32* from, BgcVector2FP32* to);
|
||||
extern inline void bgc_vector2_copy_fp64(const BgcVector2FP64* from, BgcVector2FP64* to);
|
||||
|
||||
extern inline void bgc_vector2_swap_fp32(BgcVector2FP32* vector1, BgcVector2FP32* vector2);
|
||||
extern inline void bgc_vector2_swap_fp64(BgcVector2FP64* vector1, BgcVector2FP64* vector2);
|
||||
|
||||
extern inline void bgc_vector2_convert_fp64_to_fp32(const BgcVector2FP64* from, BgcVector2FP32* to);
|
||||
extern inline void bgc_vector2_convert_fp32_to_fp64(const BgcVector2FP32* from, BgcVector2FP64* to);
|
||||
|
||||
extern inline void bgc_vector2_reverse_fp32(BgcVector2FP32* vector);
|
||||
extern inline void bgc_vector2_reverse_fp64(BgcVector2FP64* vector);
|
||||
|
||||
extern inline int bgc_vector2_normalize_fp32(BgcVector2FP32* vector);
|
||||
extern inline int bgc_vector2_normalize_fp64(BgcVector2FP64* vector);
|
||||
|
||||
extern inline void bgc_vector2_make_reverse_fp32(const BgcVector2FP32* vector, BgcVector2FP32* reverse);
|
||||
extern inline void bgc_vector2_make_reverse_fp64(const BgcVector2FP64* vector, BgcVector2FP64* reverse);
|
||||
|
||||
extern inline int bgc_vector2_make_normalized_fp32(const BgcVector2FP32* vector, BgcVector2FP32* result);
|
||||
extern inline int bgc_vector2_make_normalized_fp64(const BgcVector2FP64* vector, BgcVector2FP64* result);
|
||||
|
||||
extern inline void bgc_vector2_add_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2, BgcVector2FP32* sum);
|
||||
extern inline void bgc_vector2_add_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2, BgcVector2FP64* sum);
|
||||
|
||||
|
@ -42,17 +48,20 @@ extern inline void bgc_vector2_add_scaled_fp64(const BgcVector2FP64* basic_vecto
|
|||
extern inline void bgc_vector2_subtract_fp32(const BgcVector2FP32* minuend, const BgcVector2FP32* subtrahend, BgcVector2FP32* difference);
|
||||
extern inline void bgc_vector2_subtract_fp64(const BgcVector2FP64* minuend, const BgcVector2FP64* subtrahend, BgcVector2FP64* difference);
|
||||
|
||||
extern inline void bgc_vector2_subtract_scaled_fp32(const BgcVector2FP32* basic_vector, const BgcVector2FP32* scalable_vector, const float scale, BgcVector2FP32* difference);
|
||||
extern inline void bgc_vector2_subtract_scaled_fp64(const BgcVector2FP64* basic_vector, const BgcVector2FP64* scalable_vector, const double scale, BgcVector2FP64* difference);
|
||||
|
||||
extern inline void bgc_vector2_multiply_fp32(const BgcVector2FP32* multiplicand, const float multiplier, BgcVector2FP32* product);
|
||||
extern inline void bgc_vector2_multiply_fp64(const BgcVector2FP64* multiplicand, const double multiplier, BgcVector2FP64* product);
|
||||
|
||||
extern inline void bgc_vector2_divide_fp32(const BgcVector2FP32* dividend, const float divisor, BgcVector2FP32* quotient);
|
||||
extern inline void bgc_vector2_divide_fp64(const BgcVector2FP64* dividend, const double divisor, BgcVector2FP64* quotient);
|
||||
|
||||
extern inline void bgc_vector2_mean_of_two_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2, BgcVector2FP32* result);
|
||||
extern inline void bgc_vector2_mean_of_two_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2, BgcVector2FP64* result);
|
||||
extern inline void bgc_vector2_mean_of_two_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2, BgcVector2FP32* mean);
|
||||
extern inline void bgc_vector2_mean_of_two_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2, BgcVector2FP64* mean);
|
||||
|
||||
extern inline void bgc_vector2_mean_of_three_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2, const BgcVector2FP32* vector3, BgcVector2FP32* result);
|
||||
extern inline void bgc_vector2_mean_of_three_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2, const BgcVector2FP64* vector3, BgcVector2FP64* result);
|
||||
extern inline void bgc_vector2_mean_of_three_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2, const BgcVector2FP32* vector3, BgcVector2FP32* mean);
|
||||
extern inline void bgc_vector2_mean_of_three_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2, const BgcVector2FP64* vector3, BgcVector2FP64* mean);
|
||||
|
||||
extern inline float bgc_vector2_scalar_product_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2);
|
||||
extern inline double bgc_vector2_scalar_product_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2);
|
||||
|
@ -60,14 +69,8 @@ extern inline double bgc_vector2_scalar_product_fp64(const BgcVector2FP64* vecto
|
|||
extern inline float bgc_vector2_cross_product_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2);
|
||||
extern inline double bgc_vector2_cross_product_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2);
|
||||
|
||||
extern inline void bgc_vector2_complex_product_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2, BgcVector2FP32* result);
|
||||
extern inline void bgc_vector2_complex_product_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2, BgcVector2FP64* result);
|
||||
|
||||
extern inline int bgc_vector2_normalize_fp32(BgcVector2FP32* vector);
|
||||
extern inline int bgc_vector2_normalize_fp64(BgcVector2FP64* vector);
|
||||
|
||||
extern inline int bgc_vector2_set_normalized_fp32(const BgcVector2FP32* vector, BgcVector2FP32* result);
|
||||
extern inline int bgc_vector2_set_normalized_fp64(const BgcVector2FP64* vector, BgcVector2FP64* result);
|
||||
extern inline void bgc_vector2_complex_product_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2, BgcVector2FP32* product);
|
||||
extern inline void bgc_vector2_complex_product_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2, BgcVector2FP64* product);
|
||||
|
||||
extern inline float bgc_vector2_get_square_distance_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2);
|
||||
extern inline double bgc_vector2_get_square_distance_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2);
|
||||
|
@ -85,10 +88,6 @@ extern inline int bgc_vector2_are_close_fp64(const BgcVector2FP64* vector1, cons
|
|||
|
||||
float bgc_vector2_get_angle_fp32(const BgcVector2FP32* vector1, const BgcVector2FP32* vector2, const BgcAngleUnitEnum unit)
|
||||
{
|
||||
if (vector1 == 0 || vector2 == 0) {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
const float square_modulus1 = bgc_vector2_get_square_modulus_fp32(vector1);
|
||||
|
||||
if (square_modulus1 <= BGC_SQUARE_EPSYLON_FP32) {
|
||||
|
@ -116,10 +115,6 @@ float bgc_vector2_get_angle_fp32(const BgcVector2FP32* vector1, const BgcVector2
|
|||
|
||||
double bgc_vector2_get_angle_fp64(const BgcVector2FP64* vector1, const BgcVector2FP64* vector2, const BgcAngleUnitEnum unit)
|
||||
{
|
||||
if (vector1 == 0 || vector2 == 0) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
const double square_modulus1 = bgc_vector2_get_square_modulus_fp64(vector1);
|
||||
|
||||
if (square_modulus1 <= BGC_SQUARE_EPSYLON_FP64) {
|
||||
|
|
|
@ -44,6 +44,50 @@ inline void bgc_vector2_set_values_fp64(const double x1, const double x2, BgcVec
|
|||
to->x2 = x2;
|
||||
}
|
||||
|
||||
// ================== Modulus =================== //
|
||||
|
||||
inline float bgc_vector2_get_square_modulus_fp32(const BgcVector2FP32* vector)
|
||||
{
|
||||
return vector->x1 * vector->x1 + vector->x2 * vector->x2;
|
||||
}
|
||||
|
||||
inline double bgc_vector2_get_square_modulus_fp64(const BgcVector2FP64* vector)
|
||||
{
|
||||
return vector->x1 * vector->x1 + vector->x2 * vector->x2;
|
||||
}
|
||||
|
||||
inline float bgc_vector2_get_modulus_fp32(const BgcVector2FP32* vector)
|
||||
{
|
||||
return sqrtf(bgc_vector2_get_square_modulus_fp32(vector));
|
||||
}
|
||||
|
||||
inline double bgc_vector2_get_modulus_fp64(const BgcVector2FP64* vector)
|
||||
{
|
||||
return sqrt(bgc_vector2_get_square_modulus_fp64(vector));
|
||||
}
|
||||
|
||||
// ================= Comparison ================= //
|
||||
|
||||
inline int bgc_vector2_is_zero_fp32(const BgcVector2FP32* vector)
|
||||
{
|
||||
return bgc_vector2_get_square_modulus_fp32(vector) <= BGC_SQUARE_EPSYLON_FP32;
|
||||
}
|
||||
|
||||
inline int bgc_vector2_is_zero_fp64(const BgcVector2FP64* vector)
|
||||
{
|
||||
return bgc_vector2_get_square_modulus_fp64(vector) <= BGC_SQUARE_EPSYLON_FP64;
|
||||
}
|
||||
|
||||
inline int bgc_vector2_is_unit_fp32(const BgcVector2FP32* vector)
|
||||
{
|
||||
return bgc_is_sqare_unit_fp32(bgc_vector2_get_square_modulus_fp32(vector));
|
||||
}
|
||||
|
||||
inline int bgc_vector2_is_unit_fp64(const BgcVector2FP64* vector)
|
||||
{
|
||||
return bgc_is_sqare_unit_fp64(bgc_vector2_get_square_modulus_fp64(vector));
|
||||
}
|
||||
|
||||
// ==================== Copy ==================== //
|
||||
|
||||
inline void bgc_vector2_copy_fp32(const BgcVector2FP32* from, BgcVector2FP32* to)
|
||||
|
@ -84,7 +128,7 @@ inline void bgc_vector2_swap_fp64(BgcVector2FP64* vector1, BgcVector2FP64* vecto
|
|||
vector1->x2 = x2;
|
||||
}
|
||||
|
||||
// ============= Copy to twin type ============== //
|
||||
// ================== Convert =================== //
|
||||
|
||||
inline void bgc_vector2_convert_fp64_to_fp32(const BgcVector2FP64* from, BgcVector2FP32* to)
|
||||
{
|
||||
|
@ -98,76 +142,118 @@ inline void bgc_vector2_convert_fp32_to_fp64(const BgcVector2FP32* from, BgcVect
|
|||
to->x2 = from->x2;
|
||||
}
|
||||
|
||||
// =================== Reverse ================== //
|
||||
// ================== Reverse =================== //
|
||||
|
||||
inline void bgc_vector2_set_reverse_fp32(const BgcVector2FP32* from, BgcVector2FP32* to)
|
||||
inline void bgc_vector2_reverse_fp32(BgcVector2FP32* vector)
|
||||
{
|
||||
to->x1 = -from->x1;
|
||||
to->x2 = -from->x2;
|
||||
vector->x1 = -vector->x1;
|
||||
vector->x2 = -vector->x2;
|
||||
}
|
||||
|
||||
inline void bgc_vector2_set_reverse_fp64(const BgcVector2FP64* from, BgcVector2FP64* to)
|
||||
inline void bgc_vector2_reverse_fp64(BgcVector2FP64* vector)
|
||||
{
|
||||
to->x1 = -from->x1;
|
||||
to->x2 = -from->x2;
|
||||
vector->x1 = -vector->x1;
|
||||
vector->x2 = -vector->x2;
|
||||
}
|
||||
|
||||
// ============= Reverse twin type ============== //
|
||||
// ================= Normalize ================== //
|
||||
|
||||
inline void bgc_vector2_set_reverse_fp64_to_fp32(const BgcVector2FP64* from, BgcVector2FP32* to)
|
||||
inline int bgc_vector2_normalize_fp32(BgcVector2FP32* vector)
|
||||
{
|
||||
to->x1 = (float) -from->x1;
|
||||
to->x2 = (float) -from->x2;
|
||||
const float square_modulus = bgc_vector2_get_square_modulus_fp32(vector);
|
||||
|
||||
if (bgc_is_sqare_unit_fp32(square_modulus)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP32 || square_modulus != square_modulus) {
|
||||
vector->x1 = 0.0f;
|
||||
vector->x2 = 0.0f;
|
||||
return 0;
|
||||
}
|
||||
|
||||
const float multiplicand = sqrtf(1.0f / square_modulus);
|
||||
|
||||
vector->x1 *= multiplicand;
|
||||
vector->x2 *= multiplicand;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline void bgc_vector2_set_reverse_fp32_to_fp64(const BgcVector2FP32* from, BgcVector2FP64* to)
|
||||
inline int bgc_vector2_normalize_fp64(BgcVector2FP64* vector)
|
||||
{
|
||||
to->x1 = -from->x1;
|
||||
to->x2 = -from->x2;
|
||||
const double square_modulus = bgc_vector2_get_square_modulus_fp64(vector);
|
||||
|
||||
if (bgc_is_sqare_unit_fp64(square_modulus)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_modulus <= BGC_SQUARE_EPSYLON_FP64 || square_modulus != square_modulus) {
|
||||
vector->x1 = 0.0;
|
||||
vector->x2 = 0.0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
const double multiplicand = sqrt(1.0 / square_modulus);
|
||||
|
||||
vector->x1 *= multiplicand;
|
||||
vector->x2 *= multiplicand;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// =================== Module =================== //
|
||||
// ============= Complex Conjugate ============== //
|
||||
|
||||
inline float bgc_vector2_get_square_modulus_fp32(const BgcVector2FP32* vector)
|
||||
inline void bgc_vector2_complex_conjugate_fp32(BgcVector2FP32* vector)
|
||||
{
|
||||
return vector->x1 * vector->x1 + vector->x2 * vector->x2;
|
||||
vector->x2 = -vector->x2;
|
||||
}
|
||||
|
||||
inline double bgc_vector2_get_square_modulus_fp64(const BgcVector2FP64* vector)
|
||||
inline void bgc_vector2_complex_conjugate_fp64(BgcVector2FP64* vector)
|
||||
{
|
||||
return vector->x1 * vector->x1 + vector->x2 * vector->x2;
|
||||
vector->x2 = -vector->x2;
|
||||
}
|
||||
|
||||
inline float bgc_vector2_get_modulus_fp32(const BgcVector2FP32* vector)
|
||||
// ================ Make Reverse ================ //
|
||||
|
||||
inline void bgc_vector2_make_reverse_fp32(const BgcVector2FP32* vector, BgcVector2FP32* reverse)
|
||||
{
|
||||
return sqrtf(bgc_vector2_get_square_modulus_fp32(vector));
|
||||
reverse->x1 = -vector->x1;
|
||||
reverse->x2 = -vector->x2;
|
||||
}
|
||||
|
||||
inline double bgc_vector2_get_modulus_fp64(const BgcVector2FP64* vector)
|
||||
inline void bgc_vector2_make_reverse_fp64(const BgcVector2FP64* vector, BgcVector2FP64* reverse)
|
||||
{
|
||||
return sqrt(bgc_vector2_get_square_modulus_fp64(vector));
|
||||
reverse->x1 = -vector->x1;
|
||||
reverse->x2 = -vector->x2;
|
||||
}
|
||||
|
||||
// ================= Comparison ================= //
|
||||
// ============== Make Normalized =============== //
|
||||
|
||||
inline int bgc_vector2_is_zero_fp32(const BgcVector2FP32* vector)
|
||||
inline int bgc_vector2_make_normalized_fp32(const BgcVector2FP32* vector, BgcVector2FP32* normalized)
|
||||
{
|
||||
return bgc_vector2_get_square_modulus_fp32(vector) <= BGC_SQUARE_EPSYLON_FP32;
|
||||
bgc_vector2_copy_fp32(vector, normalized);
|
||||
return bgc_vector2_normalize_fp32(normalized);
|
||||
}
|
||||
|
||||
inline int bgc_vector2_is_zero_fp64(const BgcVector2FP64* vector)
|
||||
inline int bgc_vector2_make_normalized_fp64(const BgcVector2FP64* vector, BgcVector2FP64* normalized)
|
||||
{
|
||||
return bgc_vector2_get_square_modulus_fp64(vector) <= BGC_SQUARE_EPSYLON_FP64;
|
||||
bgc_vector2_copy_fp64(vector, normalized);
|
||||
return bgc_vector2_normalize_fp64(normalized);
|
||||
}
|
||||
|
||||
inline int bgc_vector2_is_unit_fp32(const BgcVector2FP32* vector)
|
||||
// =========== Make Complex Conjugate =========== //
|
||||
|
||||
inline void bgc_vector2_make_complex_conjugate_fp32(const BgcVector2FP32* vector, BgcVector2FP32* conjugate)
|
||||
{
|
||||