Переход на версию 0.3: изменение подхода к именованию сущностей, добавление, изменение и удаление ряда функций

This commit is contained in:
Andrey Pokidov 2026-01-30 19:37:49 +07:00
parent d33daf4e2d
commit f7e41645fe
87 changed files with 4580 additions and 4051 deletions

View file

@ -6,7 +6,7 @@
// =================== Reset ==================== //
inline void bgc_matrix3x3_reset_fp32(BgcMatrix3x3FP32* matrix)
inline void bgc_fp32_matrix3x3_reset(BGC_FP32_Matrix3x3* matrix)
{
matrix->r1c1 = 0.0f;
matrix->r1c2 = 0.0f;
@ -21,7 +21,7 @@ inline void bgc_matrix3x3_reset_fp32(BgcMatrix3x3FP32* matrix)
matrix->r3c3 = 0.0f;
}
inline void bgc_matrix3x3_reset_fp64(BgcMatrix3x3FP64* matrix)
inline void bgc_fp64_matrix3x3_reset(BGC_FP64_Matrix3x3* matrix)
{
matrix->r1c1 = 0.0;
matrix->r1c2 = 0.0;
@ -38,7 +38,7 @@ inline void bgc_matrix3x3_reset_fp64(BgcMatrix3x3FP64* matrix)
// ================== Identity ================== //
inline void bgc_matrix3x3_set_to_identity_fp32(BgcMatrix3x3FP32* matrix)
inline void bgc_fp32_matrix3x3_make_identity(BGC_FP32_Matrix3x3* matrix)
{
matrix->r1c1 = 1.0f;
matrix->r1c2 = 0.0f;
@ -53,7 +53,7 @@ inline void bgc_matrix3x3_set_to_identity_fp32(BgcMatrix3x3FP32* matrix)
matrix->r3c3 = 1.0f;
}
inline void bgc_matrix3x3_set_to_identity_fp64(BgcMatrix3x3FP64* matrix)
inline void bgc_fp64_matrix3x3_make_identity(BGC_FP64_Matrix3x3* matrix)
{
matrix->r1c1 = 1.0;
matrix->r1c2 = 0.0;
@ -70,7 +70,7 @@ inline void bgc_matrix3x3_set_to_identity_fp64(BgcMatrix3x3FP64* matrix)
// ================ Set Diagonal ================ //
inline void bgc_matrix3x3_set_to_diagonal_fp32(const float d1, const float d2, const float d3, BgcMatrix3x3FP32* matrix)
inline void bgc_fp32_matrix3x3_make_diagonal(const float d1, const float d2, const float d3, BGC_FP32_Matrix3x3* matrix)
{
matrix->r1c1 = d1;
matrix->r1c2 = 0.0f;
@ -85,7 +85,7 @@ inline void bgc_matrix3x3_set_to_diagonal_fp32(const float d1, const float d2, c
matrix->r3c3 = d2;
}
inline void bgc_matrix3x3_set_to_diagonal_fp64(const double d1, const double d2, const double d3, BgcMatrix3x3FP64* matrix)
inline void bgc_fp64_matrix3x3_make_diagonal(const double d1, const double d2, const double d3, BGC_FP64_Matrix3x3* matrix)
{
matrix->r1c1 = d1;
matrix->r1c2 = 0.0;
@ -102,7 +102,7 @@ inline void bgc_matrix3x3_set_to_diagonal_fp64(const double d1, const double d2,
// ==================== Copy ==================== //
inline void bgc_matrix3x3_copy_fp32(const BgcMatrix3x3FP32* source, BgcMatrix3x3FP32* destination)
inline void bgc_fp32_matrix3x3_copy(const BGC_FP32_Matrix3x3* source, BGC_FP32_Matrix3x3* destination)
{
destination->r1c1 = source->r1c1;
destination->r1c2 = source->r1c2;
@ -117,7 +117,7 @@ inline void bgc_matrix3x3_copy_fp32(const BgcMatrix3x3FP32* source, BgcMatrix3x3
destination->r3c3 = source->r3c3;
}
inline void bgc_matrix3x3_copy_fp64(const BgcMatrix3x3FP64* source, BgcMatrix3x3FP64* destination)
inline void bgc_fp64_matrix3x3_copy(const BGC_FP64_Matrix3x3* source, BGC_FP64_Matrix3x3* destination)
{
destination->r1c1 = source->r1c1;
destination->r1c2 = source->r1c2;
@ -134,7 +134,7 @@ inline void bgc_matrix3x3_copy_fp64(const BgcMatrix3x3FP64* source, BgcMatrix3x3
// ==================== Swap ==================== //
inline void bgc_matrix3x3_swap_fp32(BgcMatrix3x3FP32* matrix1, BgcMatrix3x3FP32* matrix2)
inline void bgc_fp32_matrix3x3_swap(BGC_FP32_Matrix3x3* matrix1, BGC_FP32_Matrix3x3* matrix2)
{
const float r1c1 = matrix2->r1c1;
const float r1c2 = matrix2->r1c2;
@ -173,7 +173,7 @@ inline void bgc_matrix3x3_swap_fp32(BgcMatrix3x3FP32* matrix1, BgcMatrix3x3FP32*
matrix1->r3c3 = r3c3;
}
inline void bgc_matrix3x3_swap_fp64(BgcMatrix3x3FP64* matrix1, BgcMatrix3x3FP64* matrix2)
inline void bgc_fp64_matrix3x3_swap(BGC_FP64_Matrix3x3* matrix1, BGC_FP64_Matrix3x3* matrix2)
{
const double r1c1 = matrix2->r1c1;
const double r1c2 = matrix2->r1c2;
@ -214,7 +214,7 @@ inline void bgc_matrix3x3_swap_fp64(BgcMatrix3x3FP64* matrix1, BgcMatrix3x3FP64*
// ================== Convert =================== //
inline void bgc_matrix3x3_convert_fp64_to_fp32(const BgcMatrix3x3FP64* source, BgcMatrix3x3FP32* destination)
inline void bgc_fp64_matrix3x3_convert_to_fp32(const BGC_FP64_Matrix3x3* source, BGC_FP32_Matrix3x3* destination)
{
destination->r1c1 = (float)source->r1c1;
destination->r1c2 = (float)source->r1c2;
@ -229,7 +229,7 @@ inline void bgc_matrix3x3_convert_fp64_to_fp32(const BgcMatrix3x3FP64* source, B
destination->r3c3 = (float)source->r3c3;
}
inline void bgc_matrix3x3_convert_fp32_to_fp64(const BgcMatrix3x3FP32* source, BgcMatrix3x3FP64* destination)
inline void bgc_fp32_matrix3x3_convert_to_fp64(const BGC_FP32_Matrix3x3* source, BGC_FP64_Matrix3x3* destination)
{
destination->r1c1 = source->r1c1;
destination->r1c2 = source->r1c2;
@ -246,89 +246,141 @@ inline void bgc_matrix3x3_convert_fp32_to_fp64(const BgcMatrix3x3FP32* source, B
// ================ Determinant ================= //
inline float bgc_matrix3x3_get_determinant_fp32(const BgcMatrix3x3FP32* matrix)
inline float bgc_fp32_matrix3x3_get_determinant(const BGC_FP32_Matrix3x3* matrix)
{
return matrix->r1c1 * (matrix->r2c2 * matrix->r3c3 - matrix->r2c3 * matrix->r3c2)
+ matrix->r1c2 * (matrix->r2c3 * matrix->r3c1 - matrix->r2c1 * matrix->r3c3)
+ matrix->r1c3 * (matrix->r2c1 * matrix->r3c2 - matrix->r2c2 * matrix->r3c1);
}
inline double bgc_matrix3x3_get_determinant_fp64(const BgcMatrix3x3FP64* matrix)
inline double bgc_fp64_matrix3x3_get_determinant(const BGC_FP64_Matrix3x3* matrix)
{
return matrix->r1c1 * (matrix->r2c2 * matrix->r3c3 - matrix->r2c3 * matrix->r3c2)
+ matrix->r1c2 * (matrix->r2c3 * matrix->r3c1 - matrix->r2c1 * matrix->r3c3)
+ matrix->r1c3 * (matrix->r2c1 * matrix->r3c2 - matrix->r2c2 * matrix->r3c1);
}
// ================== Singular ================== //
// ================ Is Identity ================= //
inline int bgc_matrix3x3_is_singular_fp32(const BgcMatrix3x3FP32* matrix)
inline int bgc_fp32_matrix3x3_is_identity(const BGC_FP32_Matrix3x3* matrix)
{
return bgc_is_zero_fp32(bgc_matrix3x3_get_determinant_fp32(matrix));
return bgc_fp32_is_unit(matrix->r1c1) && bgc_fp32_is_zero(matrix->r1c2) && bgc_fp32_is_zero(matrix->r1c3)
&& bgc_fp32_is_zero(matrix->r2c1) && bgc_fp32_is_unit(matrix->r2c2) && bgc_fp32_is_zero(matrix->r2c3)
&& bgc_fp32_is_zero(matrix->r3c1) && bgc_fp32_is_zero(matrix->r3c2) && bgc_fp32_is_unit(matrix->r3c3);
}
inline int bgc_matrix3x3_is_singular_fp64(const BgcMatrix3x3FP64* matrix)
inline int bgc_fp64_matrix3x3_is_identity(const BGC_FP64_Matrix3x3* matrix)
{
return bgc_is_zero_fp64(bgc_matrix3x3_get_determinant_fp64(matrix));
return bgc_fp64_is_unit(matrix->r1c1) && bgc_fp64_is_zero(matrix->r1c2) && bgc_fp64_is_zero(matrix->r1c3)
&& bgc_fp64_is_zero(matrix->r2c1) && bgc_fp64_is_unit(matrix->r2c2) && bgc_fp64_is_zero(matrix->r2c3)
&& bgc_fp64_is_zero(matrix->r3c1) && bgc_fp64_is_zero(matrix->r3c2) && bgc_fp64_is_unit(matrix->r3c3);
}
// ================ Is Singular ================= //
inline int bgc_fp32_matrix3x3_is_singular(const BGC_FP32_Matrix3x3* matrix)
{
return bgc_fp32_is_zero(bgc_fp32_matrix3x3_get_determinant(matrix));
}
inline int bgc_fp64_matrix3x3_is_singular(const BGC_FP64_Matrix3x3* matrix)
{
return bgc_fp64_is_zero(bgc_fp64_matrix3x3_get_determinant(matrix));
}
// ================ Is Rotation ================= //
inline int bgc_matrix3x3_is_rotation_fp32(const BgcMatrix3x3FP32* matrix)
inline int bgc_fp32_matrix3x3_is_rotation(const BGC_FP32_Matrix3x3* matrix)
{
if (!bgc_is_unit_fp32(bgc_matrix3x3_get_determinant_fp32(matrix))) {
return 0;
}
BGC_FP32_Matrix3x3 product;
const float product_r1c1 = matrix->r1c1 * matrix->r1c1 + matrix->r1c2 * matrix->r2c1 + matrix->r1c3 * matrix->r3c1;
const float product_r1c2 = matrix->r1c1 * matrix->r1c2 + matrix->r1c2 * matrix->r2c2 + matrix->r1c3 * matrix->r3c2;
const float product_r1c3 = matrix->r1c1 * matrix->r1c3 + matrix->r1c2 * matrix->r2c3 + matrix->r1c3 * matrix->r3c3;
product.r1c1 = matrix->r1c1 * matrix->r1c1 + matrix->r1c2 * matrix->r2c1 + matrix->r1c3 * matrix->r3c1;
product.r1c2 = matrix->r1c1 * matrix->r1c2 + matrix->r1c2 * matrix->r2c2 + matrix->r1c3 * matrix->r3c2;
product.r1c3 = matrix->r1c1 * matrix->r1c3 + matrix->r1c2 * matrix->r2c3 + matrix->r1c3 * matrix->r3c3;
const float product_r2c1 = matrix->r2c1 * matrix->r1c1 + matrix->r2c2 * matrix->r2c1 + matrix->r2c3 * matrix->r3c1;
const float product_r2c2 = matrix->r2c1 * matrix->r1c2 + matrix->r2c2 * matrix->r2c2 + matrix->r2c3 * matrix->r3c2;
const float product_r2c3 = matrix->r2c1 * matrix->r1c3 + matrix->r2c2 * matrix->r2c3 + matrix->r2c3 * matrix->r3c3;
product.r2c1 = matrix->r2c1 * matrix->r1c1 + matrix->r2c2 * matrix->r2c1 + matrix->r2c3 * matrix->r3c1;
product.r2c2 = matrix->r2c1 * matrix->r1c2 + matrix->r2c2 * matrix->r2c2 + matrix->r2c3 * matrix->r3c2;
product.r2c3 = matrix->r2c1 * matrix->r1c3 + matrix->r2c2 * matrix->r2c3 + matrix->r2c3 * matrix->r3c3;
const float product_r3c1 = matrix->r3c1 * matrix->r1c1 + matrix->r3c2 * matrix->r2c1 + matrix->r3c3 * matrix->r3c1;
const float product_r3c2 = matrix->r3c1 * matrix->r1c2 + matrix->r3c2 * matrix->r2c2 + matrix->r3c3 * matrix->r3c2;
const float product_r3c3 = matrix->r3c1 * matrix->r1c3 + matrix->r3c2 * matrix->r2c3 + matrix->r3c3 * matrix->r3c3;
product.r3c1 = matrix->r3c1 * matrix->r1c1 + matrix->r3c2 * matrix->r2c1 + matrix->r3c3 * matrix->r3c1;
product.r3c2 = matrix->r3c1 * matrix->r1c2 + matrix->r3c2 * matrix->r2c2 + matrix->r3c3 * matrix->r3c2;
product.r3c3 = matrix->r3c1 * matrix->r1c3 + matrix->r3c2 * matrix->r2c3 + matrix->r3c3 * matrix->r3c3;
return bgc_is_unit_fp32(product_r1c1) && bgc_is_zero_fp32(product_r1c2) && bgc_is_zero_fp32(product_r1c3)
&& bgc_is_zero_fp32(product_r2c1) && bgc_is_unit_fp32(product_r2c2) && bgc_is_zero_fp32(product_r2c3)
&& bgc_is_zero_fp32(product_r3c1) && bgc_is_zero_fp32(product_r3c2) && bgc_is_unit_fp32(product_r3c3);
return bgc_fp32_matrix3x3_is_identity(&product);
}
inline int bgc_matrix3x3_is_rotation_fp64(const BgcMatrix3x3FP64* matrix)
inline int bgc_fp64_matrix3x3_is_rotation(const BGC_FP64_Matrix3x3* matrix)
{
if (!bgc_is_unit_fp64(bgc_matrix3x3_get_determinant_fp64(matrix))) {
return 0;
}
BGC_FP64_Matrix3x3 product;
const double product_r1c1 = matrix->r1c1 * matrix->r1c1 + matrix->r1c2 * matrix->r2c1 + matrix->r1c3 * matrix->r3c1;
const double product_r1c2 = matrix->r1c1 * matrix->r1c2 + matrix->r1c2 * matrix->r2c2 + matrix->r1c3 * matrix->r3c2;
const double product_r1c3 = matrix->r1c1 * matrix->r1c3 + matrix->r1c2 * matrix->r2c3 + matrix->r1c3 * matrix->r3c3;
product.r1c1 = matrix->r1c1 * matrix->r1c1 + matrix->r1c2 * matrix->r2c1 + matrix->r1c3 * matrix->r3c1;
product.r1c2 = matrix->r1c1 * matrix->r1c2 + matrix->r1c2 * matrix->r2c2 + matrix->r1c3 * matrix->r3c2;
product.r1c3 = matrix->r1c1 * matrix->r1c3 + matrix->r1c2 * matrix->r2c3 + matrix->r1c3 * matrix->r3c3;
const double product_r2c1 = matrix->r2c1 * matrix->r1c1 + matrix->r2c2 * matrix->r2c1 + matrix->r2c3 * matrix->r3c1;
const double product_r2c2 = matrix->r2c1 * matrix->r1c2 + matrix->r2c2 * matrix->r2c2 + matrix->r2c3 * matrix->r3c2;
const double product_r2c3 = matrix->r2c1 * matrix->r1c3 + matrix->r2c2 * matrix->r2c3 + matrix->r2c3 * matrix->r3c3;
product.r2c1 = matrix->r2c1 * matrix->r1c1 + matrix->r2c2 * matrix->r2c1 + matrix->r2c3 * matrix->r3c1;
product.r2c2 = matrix->r2c1 * matrix->r1c2 + matrix->r2c2 * matrix->r2c2 + matrix->r2c3 * matrix->r3c2;
product.r2c3 = matrix->r2c1 * matrix->r1c3 + matrix->r2c2 * matrix->r2c3 + matrix->r2c3 * matrix->r3c3;
const double product_r3c1 = matrix->r3c1 * matrix->r1c1 + matrix->r3c2 * matrix->r2c1 + matrix->r3c3 * matrix->r3c1;
const double product_r3c2 = matrix->r3c1 * matrix->r1c2 + matrix->r3c2 * matrix->r2c2 + matrix->r3c3 * matrix->r3c2;
const double product_r3c3 = matrix->r3c1 * matrix->r1c3 + matrix->r3c2 * matrix->r2c3 + matrix->r3c3 * matrix->r3c3;
product.r3c1 = matrix->r3c1 * matrix->r1c1 + matrix->r3c2 * matrix->r2c1 + matrix->r3c3 * matrix->r3c1;
product.r3c2 = matrix->r3c1 * matrix->r1c2 + matrix->r3c2 * matrix->r2c2 + matrix->r3c3 * matrix->r3c2;
product.r3c3 = matrix->r3c1 * matrix->r1c3 + matrix->r3c2 * matrix->r2c3 + matrix->r3c3 * matrix->r3c3;
return bgc_is_unit_fp64(product_r1c1) && bgc_is_zero_fp64(product_r1c2) && bgc_is_zero_fp64(product_r1c3)
&& bgc_is_zero_fp64(product_r2c1) && bgc_is_unit_fp64(product_r2c2) && bgc_is_zero_fp64(product_r2c3)
&& bgc_is_zero_fp64(product_r3c1) && bgc_is_zero_fp64(product_r3c2) && bgc_is_unit_fp64(product_r3c3);
return bgc_fp64_matrix3x3_is_identity(&product);
}
// ================ Get Inverse ================= //
int bgc_fp32_matrix3x3_get_inverse(const BGC_FP32_Matrix3x3* matrix, BGC_FP32_Matrix3x3* inverse);
int bgc_fp64_matrix3x3_get_inverse(const BGC_FP64_Matrix3x3* matrix, BGC_FP64_Matrix3x3* inverse);
// =================== Invert =================== //
int bgc_matrix3x3_invert_fp32(const BgcMatrix3x3FP32* matrix, BgcMatrix3x3FP32* inverted);
inline int bgc_fp32_matrix3x3_invert(BGC_FP32_Matrix3x3* matrix)
{
return bgc_fp32_matrix3x3_get_inverse(matrix, matrix);
}
int bgc_matrix3x3_invert_fp64(const BgcMatrix3x3FP64* matrix, BgcMatrix3x3FP64* inverted);
inline int bgc_fp64_matrix3x3_invert(BGC_FP64_Matrix3x3* matrix)
{
return bgc_fp64_matrix3x3_get_inverse(matrix, matrix);
}
// ================= Transpose ================== //
inline void bgc_matrix3x3_transpose_fp32(const BgcMatrix3x3FP32* matrix, BgcMatrix3x3FP32* transposed)
inline void bgc_fp32_matrix3x3_transpose(BGC_FP32_Matrix3x3* matrix)
{
const float r1c2 = matrix->r1c2;
const float r1c3 = matrix->r1c3;
const float r2c3 = matrix->r2c3;
matrix->r1c2 = matrix->r2c1;
matrix->r1c3 = matrix->r3c1;
matrix->r2c3 = matrix->r3c2;
matrix->r2c1 = r1c2;
matrix->r3c1 = r1c3;
matrix->r3c2 = r2c3;
}
inline void bgc_fp64_matrix3x3_transpose(BGC_FP64_Matrix3x3* matrix)
{
const double r1c2 = matrix->r1c2;
const double r1c3 = matrix->r1c3;
const double r2c3 = matrix->r2c3;
matrix->r1c2 = matrix->r2c1;
matrix->r1c3 = matrix->r3c1;
matrix->r2c3 = matrix->r3c2;
matrix->r2c1 = r1c2;
matrix->r3c1 = r1c3;
matrix->r3c2 = r2c3;
}
// =============== Get Transpose ================ //
inline void bgc_fp32_matrix3x3_get_transposed(const BGC_FP32_Matrix3x3* matrix, BGC_FP32_Matrix3x3* transposed)
{
transposed->r1c1 = matrix->r1c1;
transposed->r2c2 = matrix->r2c2;
@ -347,7 +399,7 @@ inline void bgc_matrix3x3_transpose_fp32(const BgcMatrix3x3FP32* matrix, BgcMatr
transposed->r3c2 = r2c3;
}
inline void bgc_matrix3x3_transpose_fp64(const BgcMatrix3x3FP64* matrix, BgcMatrix3x3FP64* transposed)
inline void bgc_fp64_matrix3x3_get_transposed(const BGC_FP64_Matrix3x3* matrix, BGC_FP64_Matrix3x3* transposed)
{
transposed->r1c1 = matrix->r1c1;
transposed->r2c2 = matrix->r2c2;
@ -366,105 +418,245 @@ inline void bgc_matrix3x3_transpose_fp64(const BgcMatrix3x3FP64* matrix, BgcMatr
transposed->r3c2 = r2c3;
}
// ================= Set Row 1 ================== //
// ================== Get Row -================== //
inline void bgc_matrix3x3_set_row1_fp32(const float c1, const float c2, const float c3, BgcMatrix3x3FP32* matrix)
inline void bgc_fp32_matrix3x3_get_row(const int number, const BGC_FP32_Matrix3x3* matrix, BGC_FP32_Vector3* row)
{
matrix->r1c1 = c1;
matrix->r1c2 = c2;
matrix->r1c3 = c3;
if (number == 1)
{
row->x1 = matrix->r1c1;
row->x2 = matrix->r1c2;
row->x3 = matrix->r1c3;
return;
}
if (number == 2)
{
row->x1 = matrix->r2c1;
row->x2 = matrix->r2c2;
row->x3 = matrix->r2c3;
return;
}
if (number == 3)
{
row->x1 = matrix->r3c1;
row->x2 = matrix->r3c2;
row->x3 = matrix->r3c3;
return;
}
row->x1 = 0.0f;
row->x2 = 0.0f;
row->x3 = 0.0f;
}
inline void bgc_matrix3x3_set_row1_fp64(const double c1, const double c2, const double c3, BgcMatrix3x3FP64* matrix)
inline void bgc_fp64_matrix3x3_get_row(const int number, const BGC_FP64_Matrix3x3* matrix, BGC_FP64_Vector3* row)
{
matrix->r1c1 = c1;
matrix->r1c2 = c2;
matrix->r1c3 = c3;
if (number == 1)
{
row->x1 = matrix->r1c1;
row->x2 = matrix->r1c2;
row->x3 = matrix->r1c3;
return;
}
if (number == 2)
{
row->x1 = matrix->r2c1;
row->x2 = matrix->r2c2;
row->x3 = matrix->r2c3;
return;
}
if (number == 3)
{
row->x1 = matrix->r3c1;
row->x2 = matrix->r3c2;
row->x3 = matrix->r3c3;
return;
}
row->x1 = 0.0;
row->x2 = 0.0;
row->x3 = 0.0;
}
// ================= Set Row 2 ================== //
// ================== Set Row =================== //
inline void bgc_matrix3x3_set_row2_fp32(const float c1, const float c2, const float c3, BgcMatrix3x3FP32* matrix)
inline void bgc_fp32_matrix3x3_set_row(const int number, const BGC_FP32_Vector3* row, BGC_FP32_Matrix3x3* matrix)
{
matrix->r2c1 = c1;
matrix->r2c2 = c2;
matrix->r2c3 = c3;
if (number == 1)
{
matrix->r1c1 = row->x1;
matrix->r1c2 = row->x2;
matrix->r1c3 = row->x3;
return;
}
if (number == 2)
{
matrix->r2c1 = row->x1;
matrix->r2c2 = row->x2;
matrix->r2c3 = row->x3;
return;
}
if (number == 3)
{
matrix->r3c1 = row->x1;
matrix->r3c2 = row->x2;
matrix->r3c3 = row->x3;
}
}
inline void bgc_matrix3x3_set_row2_fp64(const double c1, const double c2, const double c3, BgcMatrix3x3FP64* matrix)
inline void bgc_fp64_matrix3x3_set_row(const int number, const BGC_FP64_Vector3* row, BGC_FP64_Matrix3x3* matrix)
{
matrix->r2c1 = c1;
matrix->r2c2 = c2;
matrix->r2c3 = c3;
if (number == 1)
{
matrix->r1c1 = row->x1;
matrix->r1c2 = row->x2;
matrix->r1c3 = row->x3;
return;
}
if (number == 2)
{
matrix->r2c1 = row->x1;
matrix->r2c2 = row->x2;
matrix->r2c3 = row->x3;
return;
}
if (number == 3)
{
matrix->r3c1 = row->x1;
matrix->r3c2 = row->x2;
matrix->r3c3 = row->x3;
}
}
// ================= Set Row 3 ================== //
// ================= Get Column ================= //
inline void bgc_matrix3x3_set_row3_fp32(const float c1, const float c2, const float c3, BgcMatrix3x3FP32* matrix)
inline void bgc_fp32_matrix3x3_get_column(const int number, const BGC_FP32_Matrix3x3* matrix, BGC_FP32_Vector3* column)
{
matrix->r3c1 = c1;
matrix->r3c2 = c2;
matrix->r3c3 = c3;
if (number == 1)
{
column->x1 = matrix->r1c1;
column->x2 = matrix->r2c1;
column->x3 = matrix->r3c1;
return;
}
if (number == 2)
{
column->x1 = matrix->r1c2;
column->x2 = matrix->r2c2;
column->x3 = matrix->r3c2;
return;
}
if (number == 3)
{
column->x1 = matrix->r1c3;
column->x2 = matrix->r2c3;
column->x3 = matrix->r3c3;
return;
}
column->x1 = 0.0f;
column->x2 = 0.0f;
column->x3 = 0.0f;
}
inline void bgc_matrix3x3_set_row3_fp64(const double c1, const double c2, const double c3, BgcMatrix3x3FP64* matrix)
inline void bgc_fp64_matrix3x3_get_column(const int number, const BGC_FP64_Matrix3x3* matrix, BGC_FP64_Vector3* column)
{
matrix->r3c1 = c1;
matrix->r3c2 = c2;
matrix->r3c3 = c3;
if (number == 1)
{
column->x1 = matrix->r1c1;
column->x2 = matrix->r2c1;
column->x3 = matrix->r3c1;
return;
}
if (number == 2)
{
column->x1 = matrix->r1c2;
column->x2 = matrix->r2c2;
column->x3 = matrix->r3c2;
return;
}
if (number == 3)
{
column->x1 = matrix->r1c3;
column->x2 = matrix->r2c3;
column->x3 = matrix->r3c3;
return;
}
column->x1 = 0.0;
column->x2 = 0.0;
column->x3 = 0.0;
}
// ================ Set Column 1 ================ //
// ================= Set Column ================= //
inline void bgc_matrix3x3_set_column1_fp32(const float r1, const float r2, const float r3, BgcMatrix3x3FP32* matrix)
inline void bgc_fp32_matrix3x3_set_column(const int number, const BGC_FP32_Vector3* column, BGC_FP32_Matrix3x3* matrix)
{
matrix->r1c1 = r1;
matrix->r2c1 = r2;
matrix->r3c1 = r3;
if (number == 1)
{
matrix->r1c1 = column->x1;
matrix->r2c1 = column->x2;
matrix->r3c1 = column->x3;
return;
}
if (number == 2)
{
matrix->r1c2 = column->x1;
matrix->r2c2 = column->x2;
matrix->r3c2 = column->x3;
return;
}
if (number == 3)
{
matrix->r1c3 = column->x1;
matrix->r2c3 = column->x2;
matrix->r3c3 = column->x3;
}
}
inline void bgc_matrix3x3_set_column1_fp64(const double r1, const double r2, const double r3, BgcMatrix3x3FP64* matrix)
inline void bgc_fp64_matrix3x3_set_column(const int number, const BGC_FP64_Vector3* column, BGC_FP64_Matrix3x3* matrix)
{
matrix->r1c1 = r1;
matrix->r2c1 = r2;
matrix->r3c1 = r3;
}
if (number == 1)
{
matrix->r1c1 = column->x1;
matrix->r2c1 = column->x2;
matrix->r3c1 = column->x3;
return;
}
// ================ Set Column 2 ================ //
if (number == 2)
{
matrix->r1c2 = column->x1;
matrix->r2c2 = column->x2;
matrix->r3c2 = column->x3;
return;
}
inline void bgc_matrix3x3_set_column2_fp32(const float r1, const float r2, const float r3, BgcMatrix3x3FP32* matrix)
{
matrix->r1c2 = r1;
matrix->r2c2 = r2;
matrix->r3c2 = r3;
}
inline void bgc_matrix3x3_set_column2_fp64(const double r1, const double r2, const double r3, BgcMatrix3x3FP64* matrix)
{
matrix->r1c2 = r1;
matrix->r2c2 = r2;
matrix->r3c2 = r3;
}
// ================ Set Column 3 ================ //
inline void bgc_matrix3x3_set_column3_fp32(const float r1, const float r2, const float r3, BgcMatrix3x3FP32* matrix)
{
matrix->r1c3 = r1;
matrix->r2c3 = r2;
matrix->r3c3 = r3;
}
inline void bgc_matrix3x3_set_column3_fp64(const double r1, const double r2, const double r3, BgcMatrix3x3FP64* matrix)
{
matrix->r1c3 = r1;
matrix->r2c3 = r2;
matrix->r3c3 = r3;
if (number == 3)
{
matrix->r1c3 = column->x1;
matrix->r2c3 = column->x2;
matrix->r3c3 = column->x3;
}
}
// ==================== Add ===================== //
inline void bgc_matrix3x3_add_fp32(const BgcMatrix3x3FP32* matrix1, const BgcMatrix3x3FP32* matrix2, BgcMatrix3x3FP32* sum)
inline void bgc_fp32_matrix3x3_add(const BGC_FP32_Matrix3x3* matrix1, const BGC_FP32_Matrix3x3* matrix2, BGC_FP32_Matrix3x3* sum)
{
sum->r1c1 = matrix1->r1c1 + matrix2->r1c1;
sum->r1c2 = matrix1->r1c2 + matrix2->r1c2;
@ -479,7 +671,7 @@ inline void bgc_matrix3x3_add_fp32(const BgcMatrix3x3FP32* matrix1, const BgcMat
sum->r3c3 = matrix1->r3c3 + matrix2->r3c3;
}
inline void bgc_matrix3x3_add_fp64(const BgcMatrix3x3FP64* matrix1, const BgcMatrix3x3FP64* matrix2, BgcMatrix3x3FP64* sum)
inline void bgc_fp64_matrix3x3_add(const BGC_FP64_Matrix3x3* matrix1, const BGC_FP64_Matrix3x3* matrix2, BGC_FP64_Matrix3x3* sum)
{
sum->r1c1 = matrix1->r1c1 + matrix2->r1c1;
sum->r1c2 = matrix1->r1c2 + matrix2->r1c2;
@ -496,7 +688,7 @@ inline void bgc_matrix3x3_add_fp64(const BgcMatrix3x3FP64* matrix1, const BgcMat
// ================= Add scaled ================= //
inline void bgc_matrix3x3_add_scaled_fp32(const BgcMatrix3x3FP32* basic_matrix, const BgcMatrix3x3FP32* scalable_matrix, const float scale, BgcMatrix3x3FP32* sum)
inline void bgc_fp32_matrix3x3_add_scaled(const BGC_FP32_Matrix3x3* basic_matrix, const BGC_FP32_Matrix3x3* scalable_matrix, const float scale, BGC_FP32_Matrix3x3* sum)
{
sum->r1c1 = basic_matrix->r1c1 + scalable_matrix->r1c1 * scale;
sum->r1c2 = basic_matrix->r1c2 + scalable_matrix->r1c2 * scale;
@ -511,7 +703,7 @@ inline void bgc_matrix3x3_add_scaled_fp32(const BgcMatrix3x3FP32* basic_matrix,
sum->r3c3 = basic_matrix->r3c3 + scalable_matrix->r3c3 * scale;
}
inline void bgc_matrix3x3_add_scaled_fp64(const BgcMatrix3x3FP64* basic_matrix, const BgcMatrix3x3FP64* scalable_matrix, const double scale, BgcMatrix3x3FP64* sum)
inline void bgc_fp64_matrix3x3_add_scaled(const BGC_FP64_Matrix3x3* basic_matrix, const BGC_FP64_Matrix3x3* scalable_matrix, const double scale, BGC_FP64_Matrix3x3* sum)
{
sum->r1c1 = basic_matrix->r1c1 + scalable_matrix->r1c1 * scale;
sum->r1c2 = basic_matrix->r1c2 + scalable_matrix->r1c2 * scale;
@ -528,7 +720,7 @@ inline void bgc_matrix3x3_add_scaled_fp64(const BgcMatrix3x3FP64* basic_matrix,
// ================== Subtract ================== //
inline void bgc_matrix3x3_subtract_fp32(const BgcMatrix3x3FP32* minuend, const BgcMatrix3x3FP32* subtrahend, BgcMatrix3x3FP32* difference)
inline void bgc_fp32_matrix3x3_subtract(const BGC_FP32_Matrix3x3* minuend, const BGC_FP32_Matrix3x3* subtrahend, BGC_FP32_Matrix3x3* difference)
{
difference->r1c1 = minuend->r1c1 - subtrahend->r1c1;
difference->r1c2 = minuend->r1c2 - subtrahend->r1c2;
@ -543,7 +735,7 @@ inline void bgc_matrix3x3_subtract_fp32(const BgcMatrix3x3FP32* minuend, const B
difference->r3c3 = minuend->r3c3 - subtrahend->r3c3;
}
inline void bgc_matrix3x3_subtract_fp64(const BgcMatrix3x3FP64* minuend, const BgcMatrix3x3FP64* subtrahend, BgcMatrix3x3FP64* difference)
inline void bgc_fp64_matrix3x3_subtract(const BGC_FP64_Matrix3x3* minuend, const BGC_FP64_Matrix3x3* subtrahend, BGC_FP64_Matrix3x3* difference)
{
difference->r1c1 = minuend->r1c1 - subtrahend->r1c1;
difference->r1c2 = minuend->r1c2 - subtrahend->r1c2;
@ -558,41 +750,9 @@ inline void bgc_matrix3x3_subtract_fp64(const BgcMatrix3x3FP64* minuend, const B
difference->r3c3 = minuend->r3c3 - subtrahend->r3c3;
}
// ================= 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)
inline void bgc_fp32_matrix3x3_multiply(const BGC_FP32_Matrix3x3* multiplicand, const float multiplier, BGC_FP32_Matrix3x3* product)
{
product->r1c1 = multiplicand->r1c1 * multiplier;
product->r1c2 = multiplicand->r1c2 * multiplier;
@ -607,7 +767,7 @@ inline void bgc_matrix3x3_multiply_fp32(const BgcMatrix3x3FP32* multiplicand, co
product->r3c3 = multiplicand->r3c3 * multiplier;
}
inline void bgc_matrix3x3_multiply_fp64(const BgcMatrix3x3FP64* multiplicand, const double multiplier, BgcMatrix3x3FP64* product)
inline void bgc_fp64_matrix3x3_multiply(const BGC_FP64_Matrix3x3* multiplicand, const double multiplier, BGC_FP64_Matrix3x3* product)
{
product->r1c1 = multiplicand->r1c1 * multiplier;
product->r1c2 = multiplicand->r1c2 * multiplier;
@ -624,19 +784,55 @@ inline void bgc_matrix3x3_multiply_fp64(const BgcMatrix3x3FP64* multiplicand, co
// =================== Divide =================== //
inline void bgc_matrix3x3_divide_fp32(const BgcMatrix3x3FP32* dividend, const float divisor, BgcMatrix3x3FP32* quotient)
inline void bgc_fp32_matrix3x3_divide(const BGC_FP32_Matrix3x3* dividend, const float divisor, BGC_FP32_Matrix3x3* quotient)
{
bgc_matrix3x3_multiply_fp32(dividend, 1.0f / divisor, quotient);
bgc_fp32_matrix3x3_multiply(dividend, 1.0f / divisor, quotient);
}
inline void bgc_matrix3x3_divide_fp64(const BgcMatrix3x3FP64* dividend, const double divisor, BgcMatrix3x3FP64* quotient)
inline void bgc_fp64_matrix3x3_divide(const BGC_FP64_Matrix3x3* dividend, const double divisor, BGC_FP64_Matrix3x3* quotient)
{
bgc_matrix3x3_multiply_fp64(dividend, 1.0 / divisor, quotient);
bgc_fp64_matrix3x3_multiply(dividend, 1.0 / divisor, quotient);
}
// ================ Interpolate ================= //
inline void bgc_fp32_matrix3x3_interpolate(const BGC_FP32_Matrix3x3* first, const BGC_FP32_Matrix3x3* second, const float phase, BGC_FP32_Matrix3x3* interpolation)
{
const float counter_phase = 1.0f - phase;
interpolation->r1c1 = first->r1c1 * counter_phase + second->r1c1 * phase;
interpolation->r1c2 = first->r1c2 * counter_phase + second->r1c2 * phase;
interpolation->r1c3 = first->r1c3 * counter_phase + second->r1c3 * phase;
interpolation->r2c1 = first->r2c1 * counter_phase + second->r2c1 * phase;
interpolation->r2c2 = first->r2c2 * counter_phase + second->r2c2 * phase;
interpolation->r2c3 = first->r2c3 * counter_phase + second->r2c3 * phase;
interpolation->r3c1 = first->r3c1 * counter_phase + second->r3c1 * phase;
interpolation->r3c2 = first->r3c2 * counter_phase + second->r3c2 * phase;
interpolation->r3c3 = first->r3c3 * counter_phase + second->r3c3 * phase;
}
inline void bgc_fp64_matrix3x3_interpolate(const BGC_FP64_Matrix3x3* first, const BGC_FP64_Matrix3x3* second, const double phase, BGC_FP64_Matrix3x3* interpolation)
{
const double counter_phase = 1.0 - phase;
interpolation->r1c1 = first->r1c1 * counter_phase + second->r1c1 * phase;
interpolation->r1c2 = first->r1c2 * counter_phase + second->r1c2 * phase;
interpolation->r1c3 = first->r1c3 * counter_phase + second->r1c3 * phase;
interpolation->r2c1 = first->r2c1 * counter_phase + second->r2c1 * phase;
interpolation->r2c2 = first->r2c2 * counter_phase + second->r2c2 * phase;
interpolation->r2c3 = first->r2c3 * counter_phase + second->r2c3 * phase;
interpolation->r3c1 = first->r3c1 * counter_phase + second->r3c1 * phase;
interpolation->r3c2 = first->r3c2 * counter_phase + second->r3c2 * phase;
interpolation->r3c3 = first->r3c3 * counter_phase + second->r3c3 * phase;
}
// ============ Left Vector Product ============= //
inline void bgc_matrix3x3_get_left_product_fp32(const BgcVector3FP32* vector, const BgcMatrix3x3FP32* matrix, BgcVector3FP32* result)
inline void bgc_fp32_multiply_vector3_by_matrix3x3(const BGC_FP32_Vector3* vector, const BGC_FP32_Matrix3x3* matrix, BGC_FP32_Vector3* result)
{
const float x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1 + vector->x3 * matrix->r3c1;
const float x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2 + vector->x3 * matrix->r3c2;
@ -647,7 +843,7 @@ inline void bgc_matrix3x3_get_left_product_fp32(const BgcVector3FP32* vector, co
result->x3 = x3;
}
inline void bgc_matrix3x3_get_left_product_fp64(const BgcVector3FP64* vector, const BgcMatrix3x3FP64* matrix, BgcVector3FP64* result)
inline void bgc_fp64_multiply_vector3_by_matrix3x3(const BGC_FP64_Vector3* vector, const BGC_FP64_Matrix3x3* matrix, BGC_FP64_Vector3* result)
{
const double x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1 + vector->x3 * matrix->r3c1;
const double x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2 + vector->x3 * matrix->r3c2;
@ -660,7 +856,7 @@ inline void bgc_matrix3x3_get_left_product_fp64(const BgcVector3FP64* vector, co
// ============ Right Vector Product ============ //
inline void bgc_matrix3x3_get_right_product_fp32(const BgcMatrix3x3FP32* matrix, const BgcVector3FP32* vector, BgcVector3FP32* result)
inline void bgc_fp32_multiply_matrix3x3_by_vector3(const BGC_FP32_Matrix3x3* matrix, const BGC_FP32_Vector3* vector, BGC_FP32_Vector3* result)
{
const float x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2 + matrix->r1c3 * vector->x3;
const float x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2 + matrix->r2c3 * vector->x3;
@ -671,7 +867,7 @@ inline void bgc_matrix3x3_get_right_product_fp32(const BgcMatrix3x3FP32* matrix,
result->x3 = x3;
}
inline void bgc_matrix3x3_get_right_product_fp64(const BgcMatrix3x3FP64* matrix, const BgcVector3FP64* vector, BgcVector3FP64* result)
inline void bgc_fp64_multiply_matrix3x3_by_vector3(const BGC_FP64_Matrix3x3* matrix, const BGC_FP64_Vector3* vector, BGC_FP64_Vector3* result)
{
const double x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2 + matrix->r1c3 * vector->x3;
const double x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2 + matrix->r2c3 * vector->x3;