Переход на версию 0.3: изменение подхода к именованию сущностей, добавление, изменение и удаление ряда функций
This commit is contained in:
parent
d33daf4e2d
commit
f7e41645fe
87 changed files with 4580 additions and 4051 deletions
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
// =================== Reset ==================== //
|
||||
|
||||
inline void bgc_matrix2x2_reset_fp32(BgcMatrix2x2FP32* matrix)
|
||||
inline void bgc_fp32_matrix2x2_reset(BGC_FP32_Matrix2x2* matrix)
|
||||
{
|
||||
matrix->r1c1 = 0.0f;
|
||||
matrix->r1c2 = 0.0f;
|
||||
|
|
@ -15,7 +15,7 @@ inline void bgc_matrix2x2_reset_fp32(BgcMatrix2x2FP32* matrix)
|
|||
matrix->r2c2 = 0.0f;
|
||||
}
|
||||
|
||||
inline void bgc_matrix2x2_reset_fp64(BgcMatrix2x2FP64* matrix)
|
||||
inline void bgc_fp64_matrix2x2_reset(BGC_FP64_Matrix2x2* matrix)
|
||||
{
|
||||
matrix->r1c1 = 0.0;
|
||||
matrix->r1c2 = 0.0;
|
||||
|
|
@ -25,7 +25,7 @@ inline void bgc_matrix2x2_reset_fp64(BgcMatrix2x2FP64* matrix)
|
|||
|
||||
// ================== Identity ================== //
|
||||
|
||||
inline void bgc_matrix2x2_set_to_identity_fp32(BgcMatrix2x2FP32* matrix)
|
||||
inline void bgc_fp32_matrix2x2_make_identity(BGC_FP32_Matrix2x2* matrix)
|
||||
{
|
||||
matrix->r1c1 = 1.0f;
|
||||
matrix->r1c2 = 0.0f;
|
||||
|
|
@ -33,7 +33,7 @@ inline void bgc_matrix2x2_set_to_identity_fp32(BgcMatrix2x2FP32* matrix)
|
|||
matrix->r2c2 = 1.0f;
|
||||
}
|
||||
|
||||
inline void bgc_matrix2x2_set_to_identity_fp64(BgcMatrix2x2FP64* matrix)
|
||||
inline void bgc_fp64_matrix2x2_make_identity(BGC_FP64_Matrix2x2* matrix)
|
||||
{
|
||||
matrix->r1c1 = 1.0;
|
||||
matrix->r1c2 = 0.0;
|
||||
|
|
@ -43,7 +43,7 @@ inline void bgc_matrix2x2_set_to_identity_fp64(BgcMatrix2x2FP64* matrix)
|
|||
|
||||
// ================ Set Diagonal ================ //
|
||||
|
||||
inline void bgc_matrix2x2_set_to_diagonal_fp32(const float d1, const float d2, BgcMatrix2x2FP32* matrix)
|
||||
inline void bgc_fp32_matrix2x2_make_diagonal(const float d1, const float d2, BGC_FP32_Matrix2x2* matrix)
|
||||
{
|
||||
matrix->r1c1 = d1;
|
||||
matrix->r1c2 = 0.0f;
|
||||
|
|
@ -51,7 +51,7 @@ inline void bgc_matrix2x2_set_to_diagonal_fp32(const float d1, const float d2, B
|
|||
matrix->r2c2 = d2;
|
||||
}
|
||||
|
||||
inline void bgc_matrix2x2_set_to_diagonal_fp64(const double d1, const double d2, BgcMatrix2x2FP64* matrix)
|
||||
inline void bgc_fp64_matrix2x2_make_diagonal(const double d1, const double d2, BGC_FP64_Matrix2x2* matrix)
|
||||
{
|
||||
matrix->r1c1 = d1;
|
||||
matrix->r1c2 = 0.0;
|
||||
|
|
@ -61,9 +61,9 @@ inline void bgc_matrix2x2_set_to_diagonal_fp64(const double d1, const double d2,
|
|||
|
||||
// ============== Rotation Matrix =============== //
|
||||
|
||||
inline void bgc_matrix2x2_set_turn_fp32(const float angle, const BgcAngleUnitEnum unit, BgcMatrix2x2FP32* matrix)
|
||||
inline void bgc_fp32_matrix2x2_make_for_turn(const float angle, const int angle_unit, BGC_FP32_Matrix2x2* matrix)
|
||||
{
|
||||
const float radians = bgc_angle_to_radians_fp32(angle, unit);
|
||||
const float radians = bgc_fp32_angle_to_radians(angle, angle_unit);
|
||||
const float cosine = cosf(radians);
|
||||
const float sine = sinf(radians);
|
||||
|
||||
|
|
@ -73,9 +73,9 @@ inline void bgc_matrix2x2_set_turn_fp32(const float angle, const BgcAngleUnitEnu
|
|||
matrix->r2c2 = cosine;
|
||||
}
|
||||
|
||||
inline void bgc_matrix2x2_set_turn_fp64(const double angle, const BgcAngleUnitEnum unit, BgcMatrix2x2FP64* matrix)
|
||||
inline void bgc_fp64_matrix2x2_make_for_turn(const double angle, const int angle_unit, BGC_FP64_Matrix2x2* matrix)
|
||||
{
|
||||
const double radians = bgc_angle_to_radians_fp64(angle, unit);
|
||||
const double radians = bgc_fp64_angle_to_radians(angle, angle_unit);
|
||||
const double cosine = cos(radians);
|
||||
const double sine = sin(radians);
|
||||
|
||||
|
|
@ -87,65 +87,73 @@ inline void bgc_matrix2x2_set_turn_fp64(const double angle, const BgcAngleUnitEn
|
|||
|
||||
// ================ Determinant ================= //
|
||||
|
||||
inline float bgc_matrix2x2_get_determinant_fp32(const BgcMatrix2x2FP32* matrix)
|
||||
inline float bgc_fp32_matrix2x2_get_determinant(const BGC_FP32_Matrix2x2* matrix)
|
||||
{
|
||||
return matrix->r1c1 * matrix->r2c2 - matrix->r1c2 * matrix->r2c1;
|
||||
}
|
||||
|
||||
inline double bgc_matrix2x2_get_determinant_fp64(const BgcMatrix2x2FP64* matrix)
|
||||
inline double bgc_fp64_matrix2x2_get_determinant(const BGC_FP64_Matrix2x2* matrix)
|
||||
{
|
||||
return matrix->r1c1 * matrix->r2c2 - matrix->r1c2 * matrix->r2c1;
|
||||
}
|
||||
|
||||
// ================== Singular ================== //
|
||||
// ================ Is Identity ================= //
|
||||
|
||||
inline int bgc_matrix2x2_is_singular_fp32(const BgcMatrix2x2FP32* matrix)
|
||||
inline int bgc_fp32_matrix2x2_is_identity(const BGC_FP32_Matrix2x2* matrix)
|
||||
{
|
||||
return bgc_is_zero_fp32(bgc_matrix2x2_get_determinant_fp32(matrix));
|
||||
return bgc_fp32_is_unit(matrix->r1c1) && bgc_fp32_is_zero(matrix->r1c2)
|
||||
&& bgc_fp32_is_zero(matrix->r2c1) && bgc_fp32_is_unit(matrix->r2c2);
|
||||
}
|
||||
|
||||
inline int bgc_matrix2x2_is_singular_fp64(const BgcMatrix2x2FP64* matrix)
|
||||
inline int bgc_fp64_matrix2x2_is_identity(const BGC_FP64_Matrix2x2* matrix)
|
||||
{
|
||||
return bgc_is_zero_fp64(bgc_matrix2x2_get_determinant_fp64(matrix));
|
||||
return bgc_fp64_is_unit(matrix->r1c1) && bgc_fp64_is_zero(matrix->r1c2)
|
||||
&& bgc_fp64_is_zero(matrix->r2c1) && bgc_fp64_is_unit(matrix->r2c2);
|
||||
}
|
||||
|
||||
// ================ Is Singular ================= //
|
||||
|
||||
inline int bgc_fp32_matrix2x2_is_singular(const BGC_FP32_Matrix2x2* matrix)
|
||||
{
|
||||
return bgc_fp32_is_zero(bgc_fp32_matrix2x2_get_determinant(matrix));
|
||||
}
|
||||
|
||||
inline int bgc_fp64_matrix2x2_is_singular(const BGC_FP64_Matrix2x2* matrix)
|
||||
{
|
||||
return bgc_fp64_is_zero(bgc_fp64_matrix2x2_get_determinant(matrix));
|
||||
}
|
||||
|
||||
// ================ Is Rotation ================= //
|
||||
|
||||
inline int bgc_matrix2x2_is_rotation_fp32(const BgcMatrix2x2FP32* matrix)
|
||||
inline int bgc_fp32_matrix2x2_is_rotation(const BGC_FP32_Matrix2x2* matrix)
|
||||
{
|
||||
if (!bgc_is_unit_fp32(bgc_matrix2x2_get_determinant_fp32(matrix))) {
|
||||
return 0;
|
||||
}
|
||||
BGC_FP32_Matrix2x2 product;
|
||||
|
||||
const float product_r1c1 = matrix->r1c1 * matrix->r1c1 + matrix->r1c2 * matrix->r2c1;
|
||||
const float product_r1c2 = matrix->r1c1 * matrix->r1c2 + matrix->r1c2 * matrix->r2c2;
|
||||
product.r1c1 = matrix->r1c1 * matrix->r1c1 + matrix->r1c2 * matrix->r2c1;
|
||||
product.r1c2 = matrix->r1c1 * matrix->r1c2 + matrix->r1c2 * matrix->r2c2;
|
||||
|
||||
const float product_r2c1 = matrix->r2c1 * matrix->r1c1 + matrix->r2c2 * matrix->r2c1;
|
||||
const float product_r2c2 = matrix->r2c1 * matrix->r1c2 + matrix->r2c2 * matrix->r2c2;
|
||||
product.r2c1 = matrix->r2c1 * matrix->r1c1 + matrix->r2c2 * matrix->r2c1;
|
||||
product.r2c2 = matrix->r2c1 * matrix->r1c2 + matrix->r2c2 * matrix->r2c2;
|
||||
|
||||
return bgc_is_unit_fp32(product_r1c1) && bgc_is_zero_fp32(product_r1c2)
|
||||
&& bgc_is_zero_fp32(product_r2c1) && bgc_is_unit_fp32(product_r2c2);
|
||||
return bgc_fp32_matrix2x2_is_identity(&product);
|
||||
}
|
||||
|
||||
inline int bgc_matrix2x2_is_rotation_fp64(const BgcMatrix2x2FP64* matrix)
|
||||
inline int bgc_fp64_matrix2x2_is_rotation(const BGC_FP64_Matrix2x2* matrix)
|
||||
{
|
||||
if (!bgc_is_unit_fp64(bgc_matrix2x2_get_determinant_fp64(matrix))) {
|
||||
return 0;
|
||||
}
|
||||
BGC_FP64_Matrix2x2 product;
|
||||
|
||||
const double product_r1c1 = matrix->r1c1 * matrix->r1c1 + matrix->r1c2 * matrix->r2c1;
|
||||
const double product_r1c2 = matrix->r1c1 * matrix->r1c2 + matrix->r1c2 * matrix->r2c2;
|
||||
product.r1c1 = matrix->r1c1 * matrix->r1c1 + matrix->r1c2 * matrix->r2c1;
|
||||
product.r1c2 = matrix->r1c1 * matrix->r1c2 + matrix->r1c2 * matrix->r2c2;
|
||||
|
||||
const double product_r2c1 = matrix->r2c1 * matrix->r1c1 + matrix->r2c2 * matrix->r2c1;
|
||||
const double product_r2c2 = matrix->r2c1 * matrix->r1c2 + matrix->r2c2 * matrix->r2c2;
|
||||
product.r2c1 = matrix->r2c1 * matrix->r1c1 + matrix->r2c2 * matrix->r2c1;
|
||||
product.r2c2 = matrix->r2c1 * matrix->r1c2 + matrix->r2c2 * matrix->r2c2;
|
||||
|
||||
return bgc_is_unit_fp64(product_r1c1) && bgc_is_zero_fp64(product_r1c2)
|
||||
&& bgc_is_zero_fp64(product_r2c1) && bgc_is_unit_fp64(product_r2c2);
|
||||
return bgc_fp64_matrix2x2_is_identity(&product);
|
||||
}
|
||||
|
||||
// ==================== Copy ==================== //
|
||||
|
||||
inline void bgc_matrix2x2_copy_fp32(const BgcMatrix2x2FP32* source, BgcMatrix2x2FP32* destination)
|
||||
inline void bgc_fp32_matrix2x2_copy(const BGC_FP32_Matrix2x2* source, BGC_FP32_Matrix2x2* destination)
|
||||
{
|
||||
destination->r1c1 = source->r1c1;
|
||||
destination->r1c2 = source->r1c2;
|
||||
|
|
@ -154,7 +162,7 @@ inline void bgc_matrix2x2_copy_fp32(const BgcMatrix2x2FP32* source, BgcMatrix2x2
|
|||
destination->r2c2 = source->r2c2;
|
||||
}
|
||||
|
||||
inline void bgc_matrix2x2_copy_fp64(const BgcMatrix2x2FP64* source, BgcMatrix2x2FP64* destination)
|
||||
inline void bgc_fp64_matrix2x2_copy(const BGC_FP64_Matrix2x2* source, BGC_FP64_Matrix2x2* destination)
|
||||
{
|
||||
destination->r1c1 = source->r1c1;
|
||||
destination->r1c2 = source->r1c2;
|
||||
|
|
@ -165,7 +173,7 @@ inline void bgc_matrix2x2_copy_fp64(const BgcMatrix2x2FP64* source, BgcMatrix2x2
|
|||
|
||||
// ==================== Swap ==================== //
|
||||
|
||||
inline void bgc_matrix2x2_swap_fp32(BgcMatrix2x2FP32* matrix1, BgcMatrix2x2FP32* matrix2)
|
||||
inline void bgc_fp32_matrix2x2_swap(BGC_FP32_Matrix2x2* matrix1, BGC_FP32_Matrix2x2* matrix2)
|
||||
{
|
||||
const float r1c1 = matrix2->r1c1;
|
||||
const float r1c2 = matrix2->r1c2;
|
||||
|
|
@ -186,7 +194,7 @@ inline void bgc_matrix2x2_swap_fp32(BgcMatrix2x2FP32* matrix1, BgcMatrix2x2FP32*
|
|||
matrix1->r2c2 = r2c2;
|
||||
}
|
||||
|
||||
inline void bgc_matrix2x2_swap_fp64(BgcMatrix2x2FP64* matrix1, BgcMatrix2x2FP64* matrix2)
|
||||
inline void bgc_fp64_matrix2x2_swap(BGC_FP64_Matrix2x2* matrix1, BGC_FP64_Matrix2x2* matrix2)
|
||||
{
|
||||
const double r1c1 = matrix2->r1c1;
|
||||
const double r1c2 = matrix2->r1c2;
|
||||
|
|
@ -209,7 +217,7 @@ inline void bgc_matrix2x2_swap_fp64(BgcMatrix2x2FP64* matrix1, BgcMatrix2x2FP64*
|
|||
|
||||
// ================== Convert =================== //
|
||||
|
||||
inline void bgc_matrix2x2_convert_fp64_to_fp32(const BgcMatrix2x2FP64* source, BgcMatrix2x2FP32* destination)
|
||||
inline void bgc_fp64_matrix2x2_convert_to_fp32(const BGC_FP64_Matrix2x2* source, BGC_FP32_Matrix2x2* destination)
|
||||
{
|
||||
destination->r1c1 = (float)source->r1c1;
|
||||
destination->r1c2 = (float)source->r1c2;
|
||||
|
|
@ -218,7 +226,7 @@ inline void bgc_matrix2x2_convert_fp64_to_fp32(const BgcMatrix2x2FP64* source, B
|
|||
destination->r2c2 = (float)source->r2c2;
|
||||
}
|
||||
|
||||
inline void bgc_matrix2x2_convert_fp32_to_fp64(const BgcMatrix2x2FP32* source, BgcMatrix2x2FP64* destination)
|
||||
inline void bgc_fp32_matrix2x2_convert_to_fp64(const BGC_FP32_Matrix2x2* source, BGC_FP64_Matrix2x2* destination)
|
||||
{
|
||||
destination->r1c1 = source->r1c1;
|
||||
destination->r1c2 = source->r1c2;
|
||||
|
|
@ -227,13 +235,13 @@ inline void bgc_matrix2x2_convert_fp32_to_fp64(const BgcMatrix2x2FP32* source, B
|
|||
destination->r2c2 = source->r2c2;
|
||||
}
|
||||
|
||||
// =================== Invert =================== //
|
||||
// ================ Get Inverse ================= //
|
||||
|
||||
inline int bgc_matrix2x2_invert_fp32(const BgcMatrix2x2FP32* matrix, BgcMatrix2x2FP32* inverted)
|
||||
inline int bgc_fp32_matrix2x2_get_inverse(const BGC_FP32_Matrix2x2* matrix, BGC_FP32_Matrix2x2* inverse)
|
||||
{
|
||||
const float determinant = bgc_matrix2x2_get_determinant_fp32(matrix);
|
||||
const float determinant = bgc_fp32_matrix2x2_get_determinant(matrix);
|
||||
|
||||
if (bgc_is_zero_fp32(determinant)) {
|
||||
if (bgc_fp32_is_zero(determinant)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -245,20 +253,20 @@ inline int bgc_matrix2x2_invert_fp32(const BgcMatrix2x2FP32* matrix, BgcMatrix2x
|
|||
|
||||
const float multiplier = 1.0f / determinant;
|
||||
|
||||
inverted->r1c1 = r1c1 * multiplier;
|
||||
inverted->r1c2 = r1c2 * multiplier;
|
||||
inverse->r1c1 = r1c1 * multiplier;
|
||||
inverse->r1c2 = r1c2 * multiplier;
|
||||
|
||||
inverted->r2c1 = r2c1 * multiplier;
|
||||
inverted->r2c2 = r2c2 * multiplier;
|
||||
inverse->r2c1 = r2c1 * multiplier;
|
||||
inverse->r2c2 = r2c2 * multiplier;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_matrix2x2_invert_fp64(const BgcMatrix2x2FP64* matrix, BgcMatrix2x2FP64* inverted)
|
||||
inline int bgc_fp64_matrix2x2_get_inverse(const BGC_FP64_Matrix2x2* matrix, BGC_FP64_Matrix2x2* inverse)
|
||||
{
|
||||
const double determinant = bgc_matrix2x2_get_determinant_fp64(matrix);
|
||||
const double determinant = bgc_fp64_matrix2x2_get_determinant(matrix);
|
||||
|
||||
if (bgc_is_zero_fp64(determinant)) {
|
||||
if (bgc_fp64_is_zero(determinant)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -270,18 +278,46 @@ inline int bgc_matrix2x2_invert_fp64(const BgcMatrix2x2FP64* matrix, BgcMatrix2x
|
|||
|
||||
const double multiplier = 1.0 / determinant;
|
||||
|
||||
inverted->r1c1 = r1c1 * multiplier;
|
||||
inverted->r1c2 = r1c2 * multiplier;
|
||||
inverse->r1c1 = r1c1 * multiplier;
|
||||
inverse->r1c2 = r1c2 * multiplier;
|
||||
|
||||
inverted->r2c1 = r2c1 * multiplier;
|
||||
inverted->r2c2 = r2c2 * multiplier;
|
||||
inverse->r2c1 = r2c1 * multiplier;
|
||||
inverse->r2c2 = r2c2 * multiplier;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// =================== Invert =================== //
|
||||
|
||||
inline int bgc_fp32_matrix2x2_invert(BGC_FP32_Matrix2x2* matrix)
|
||||
{
|
||||
return bgc_fp32_matrix2x2_get_inverse(matrix, matrix);
|
||||
}
|
||||
|
||||
inline int bgc_fp64_matrix2x2_invert(BGC_FP64_Matrix2x2* matrix)
|
||||
{
|
||||
return bgc_fp64_matrix2x2_get_inverse(matrix, matrix);
|
||||
}
|
||||
|
||||
// ================= Transpose ================== //
|
||||
|
||||
inline void bgc_matrix2x2_transpose_fp32(const BgcMatrix2x2FP32* matrix, BgcMatrix2x2FP32* transposed)
|
||||
inline void bgc_fp32_matrix2x2_transpose(BGC_FP32_Matrix2x2* matrix)
|
||||
{
|
||||
const float r1c2 = matrix->r1c2;
|
||||
matrix->r1c2 = matrix->r2c1;
|
||||
matrix->r2c1 = r1c2;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_matrix2x2_transpose(BGC_FP64_Matrix2x2* matrix)
|
||||
{
|
||||
const double r1c2 = matrix->r1c2;
|
||||
matrix->r1c2 = matrix->r2c1;
|
||||
matrix->r2c1 = r1c2;
|
||||
}
|
||||
|
||||
// =============== Get Transpose ================ //
|
||||
|
||||
inline void bgc_fp32_matrix2x2_get_transposed(const BGC_FP32_Matrix2x2* matrix, BGC_FP32_Matrix2x2* transposed)
|
||||
{
|
||||
const float r1c2 = matrix->r1c2;
|
||||
|
||||
|
|
@ -292,7 +328,7 @@ inline void bgc_matrix2x2_transpose_fp32(const BgcMatrix2x2FP32* matrix, BgcMatr
|
|||
transposed->r2c2 = matrix->r2c2;
|
||||
}
|
||||
|
||||
inline void bgc_matrix2x2_transpose_fp64(const BgcMatrix2x2FP64* matrix, BgcMatrix2x2FP64* transposed)
|
||||
inline void bgc_fp64_matrix2x2_get_transposed(const BGC_FP64_Matrix2x2* matrix, BGC_FP64_Matrix2x2* transposed)
|
||||
{
|
||||
const double r1c2 = matrix->r1c2;
|
||||
|
||||
|
|
@ -303,65 +339,145 @@ inline void bgc_matrix2x2_transpose_fp64(const BgcMatrix2x2FP64* matrix, BgcMatr
|
|||
transposed->r2c2 = matrix->r2c2;
|
||||
}
|
||||
|
||||
// ================= Set Row 1 ================== //
|
||||
// ================== Get Row =================== //
|
||||
|
||||
inline void bgc_matrix2x2_set_row1_fp32(const float c1, const float c2, BgcMatrix2x2FP32* matrix)
|
||||
inline void bgc_fp32_matrix2x2_get_row(const int number, const BGC_FP32_Matrix2x2* matrix, BGC_FP32_Vector2* row)
|
||||
{
|
||||
matrix->r1c1 = c1;
|
||||
matrix->r1c2 = c2;
|
||||
if (number == 1) {
|
||||
row->x1 = matrix->r1c1;
|
||||
row->x2 = matrix->r1c2;
|
||||
return;
|
||||
}
|
||||
|
||||
if (number == 2) {
|
||||
row->x1 = matrix->r2c1;
|
||||
row->x2 = matrix->r2c2;
|
||||
return;
|
||||
}
|
||||
|
||||
row->x1 = 0.0f;
|
||||
row->x2 = 0.0f;
|
||||
}
|
||||
|
||||
inline void bgc_matrix2x2_set_row1_fp64(const double c1, const double c2, BgcMatrix2x2FP64* matrix)
|
||||
inline void bgc_fp64_matrix2x2_get_row(const int number, const BGC_FP64_Matrix2x2* matrix, BGC_FP64_Vector2* row)
|
||||
{
|
||||
matrix->r1c1 = c1;
|
||||
matrix->r1c2 = c2;
|
||||
if (number == 1) {
|
||||
row->x1 = matrix->r1c1;
|
||||
row->x2 = matrix->r1c2;
|
||||
return;
|
||||
}
|
||||
|
||||
if (number == 2) {
|
||||
row->x1 = matrix->r2c1;
|
||||
row->x2 = matrix->r2c2;
|
||||
return;
|
||||
}
|
||||
|
||||
row->x1 = 0.0;
|
||||
row->x2 = 0.0;
|
||||
}
|
||||
|
||||
// ================= Set Row 2 ================== //
|
||||
// ================== Set Row =================== //
|
||||
|
||||
inline void bgc_matrix2x2_set_row2_fp32(const float c1, const float c2, BgcMatrix2x2FP32* matrix)
|
||||
inline void bgc_fp32_matrix2x2_set_row(const int number, const BGC_FP32_Vector2* row, BGC_FP32_Matrix2x2* matrix)
|
||||
{
|
||||
matrix->r2c1 = c1;
|
||||
matrix->r2c2 = c2;
|
||||
if (number == 1) {
|
||||
matrix->r1c1 = row->x1;
|
||||
matrix->r1c2 = row->x2;
|
||||
return;
|
||||
}
|
||||
|
||||
if (number == 2) {
|
||||
matrix->r2c1 = row->x1;
|
||||
matrix->r2c2 = row->x2;
|
||||
}
|
||||
}
|
||||
|
||||
inline void bgc_matrix2x2_set_row2_fp64(const double c1, const double c2, BgcMatrix2x2FP64* matrix)
|
||||
inline void bgc_fp64_matrix2x2_set_row(const int number, const BGC_FP64_Vector2* row, BGC_FP64_Matrix2x2* matrix)
|
||||
{
|
||||
matrix->r2c1 = c1;
|
||||
matrix->r2c2 = c2;
|
||||
if (number == 1) {
|
||||
matrix->r1c1 = row->x1;
|
||||
matrix->r1c2 = row->x2;
|
||||
return;
|
||||
}
|
||||
|
||||
if (number == 2) {
|
||||
matrix->r2c1 = row->x1;
|
||||
matrix->r2c2 = row->x2;
|
||||
}
|
||||
}
|
||||
|
||||
// ================ Set Column 1 ================ //
|
||||
// ================= Get Column ================= //
|
||||
|
||||
inline void bgc_matrix2x2_set_column1_fp32(const float r1, const float r2, BgcMatrix2x2FP32* matrix)
|
||||
inline void bgc_fp32_matrix2x2_get_column(const int number, const BGC_FP32_Matrix2x2* matrix, BGC_FP32_Vector2* column)
|
||||
{
|
||||
matrix->r1c1 = r1;
|
||||
matrix->r2c1 = r2;
|
||||
if (number == 1) {
|
||||
column->x1 = matrix->r1c1;
|
||||
column->x2 = matrix->r2c1;
|
||||
return;
|
||||
}
|
||||
|
||||
if (number == 2) {
|
||||
column->x1 = matrix->r1c2;
|
||||
column->x2 = matrix->r2c2;
|
||||
return;
|
||||
}
|
||||
|
||||
column->x1 = 0.0f;
|
||||
column->x2 = 0.0f;
|
||||
}
|
||||
|
||||
inline void bgc_matrix2x2_set_column1_fp64(const double r1, const double r2, BgcMatrix2x2FP64* matrix)
|
||||
inline void bgc_fp64_matrix2x2_get_column(const int number, const BGC_FP64_Matrix2x2* matrix, BGC_FP64_Vector2* column)
|
||||
{
|
||||
matrix->r1c1 = r1;
|
||||
matrix->r2c1 = r2;
|
||||
if (number == 1) {
|
||||
column->x1 = matrix->r1c1;
|
||||
column->x2 = matrix->r2c1;
|
||||
return;
|
||||
}
|
||||
|
||||
if (number == 2) {
|
||||
column->x1 = matrix->r1c2;
|
||||
column->x2 = matrix->r2c2;
|
||||
return;
|
||||
}
|
||||
|
||||
column->x1 = 0.0;
|
||||
column->x2 = 0.0;
|
||||
}
|
||||
|
||||
// ================ Set Column 2 ================ //
|
||||
// ================= Set Column ================= //
|
||||
|
||||
inline void bgc_matrix2x2_set_column2_fp32(const float r1, const float r2, BgcMatrix2x2FP32* matrix)
|
||||
inline void bgc_fp32_matrix2x2_set_column(const int number, const BGC_FP32_Vector2* column, BGC_FP32_Matrix2x2* matrix)
|
||||
{
|
||||
matrix->r1c2 = r1;
|
||||
matrix->r2c2 = r2;
|
||||
if (number == 1) {
|
||||
matrix->r1c1 = column->x1;
|
||||
matrix->r2c1 = column->x2;
|
||||
return;
|
||||
}
|
||||
|
||||
if (number == 2) {
|
||||
matrix->r1c2 = column->x1;
|
||||
matrix->r2c2 = column->x2;
|
||||
}
|
||||
}
|
||||
|
||||
inline void bgc_matrix2x2_set_column2_fp64(const double r1, const double r2, BgcMatrix2x2FP64* matrix)
|
||||
inline void bgc_fp64_matrix2x2_set_column(const int number, const BGC_FP64_Vector2* column, BGC_FP64_Matrix2x2* matrix)
|
||||
{
|
||||
matrix->r1c2 = r1;
|
||||
matrix->r2c2 = r2;
|
||||
if (number == 1) {
|
||||
matrix->r1c1 = column->x1;
|
||||
matrix->r2c1 = column->x2;
|
||||
return;
|
||||
}
|
||||
|
||||
if (number == 2) {
|
||||
matrix->r1c2 = column->x1;
|
||||
matrix->r2c2 = column->x2;
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== Add ===================== //
|
||||
|
||||
inline void bgc_matrix2x2_add_fp32(const BgcMatrix2x2FP32* matrix1, const BgcMatrix2x2FP32* matrix2, BgcMatrix2x2FP32* sum)
|
||||
inline void bgc_fp32_matrix2x2_add(const BGC_FP32_Matrix2x2* matrix1, const BGC_FP32_Matrix2x2* matrix2, BGC_FP32_Matrix2x2* sum)
|
||||
{
|
||||
sum->r1c1 = matrix1->r1c1 + matrix2->r1c1;
|
||||
sum->r1c2 = matrix1->r1c2 + matrix2->r1c2;
|
||||
|
|
@ -370,7 +486,7 @@ inline void bgc_matrix2x2_add_fp32(const BgcMatrix2x2FP32* matrix1, const BgcMat
|
|||
sum->r2c2 = matrix1->r2c2 + matrix2->r2c2;
|
||||
}
|
||||
|
||||
inline void bgc_matrix2x2_add_fp64(const BgcMatrix2x2FP64* matrix1, const BgcMatrix2x2FP64* matrix2, BgcMatrix2x2FP64* sum)
|
||||
inline void bgc_fp64_matrix2x2_add(const BGC_FP64_Matrix2x2* matrix1, const BGC_FP64_Matrix2x2* matrix2, BGC_FP64_Matrix2x2* sum)
|
||||
{
|
||||
sum->r1c1 = matrix1->r1c1 + matrix2->r1c1;
|
||||
sum->r1c2 = matrix1->r1c2 + matrix2->r1c2;
|
||||
|
|
@ -381,7 +497,7 @@ inline void bgc_matrix2x2_add_fp64(const BgcMatrix2x2FP64* matrix1, const BgcMat
|
|||
|
||||
// ================= Add scaled ================= //
|
||||
|
||||
inline void bgc_matrix2x2_add_scaled_fp32(const BgcMatrix2x2FP32* basic_matrix, const BgcMatrix2x2FP32* scalable_matrix, const float scale, BgcMatrix2x2FP32* sum)
|
||||
inline void bgc_fp32_matrix2x2_add_scaled(const BGC_FP32_Matrix2x2* basic_matrix, const BGC_FP32_Matrix2x2* scalable_matrix, const float scale, BGC_FP32_Matrix2x2* sum)
|
||||
{
|
||||
sum->r1c1 = basic_matrix->r1c1 + scalable_matrix->r1c1 * scale;
|
||||
sum->r1c2 = basic_matrix->r1c2 + scalable_matrix->r1c2 * scale;
|
||||
|
|
@ -390,7 +506,7 @@ inline void bgc_matrix2x2_add_scaled_fp32(const BgcMatrix2x2FP32* basic_matrix,
|
|||
sum->r2c2 = basic_matrix->r2c2 + scalable_matrix->r2c2 * scale;
|
||||
}
|
||||
|
||||
inline void bgc_matrix2x2_add_scaled_fp64(const BgcMatrix2x2FP64* basic_matrix, const BgcMatrix2x2FP64* scalable_matrix, const double scale, BgcMatrix2x2FP64* sum)
|
||||
inline void bgc_fp64_matrix2x2_add_scaled(const BGC_FP64_Matrix2x2* basic_matrix, const BGC_FP64_Matrix2x2* scalable_matrix, const double scale, BGC_FP64_Matrix2x2* sum)
|
||||
{
|
||||
sum->r1c1 = basic_matrix->r1c1 + scalable_matrix->r1c1 * scale;
|
||||
sum->r1c2 = basic_matrix->r1c2 + scalable_matrix->r1c2 * scale;
|
||||
|
|
@ -401,7 +517,7 @@ inline void bgc_matrix2x2_add_scaled_fp64(const BgcMatrix2x2FP64* basic_matrix,
|
|||
|
||||
// ================== Subtract ================== //
|
||||
|
||||
inline void bgc_matrix2x2_subtract_fp32(const BgcMatrix2x2FP32* minuend, const BgcMatrix2x2FP32* subtrahend, BgcMatrix2x2FP32* difference)
|
||||
inline void bgc_fp32_matrix2x2_subtract(const BGC_FP32_Matrix2x2* minuend, const BGC_FP32_Matrix2x2* subtrahend, BGC_FP32_Matrix2x2* difference)
|
||||
{
|
||||
difference->r1c1 = minuend->r1c1 - subtrahend->r1c1;
|
||||
difference->r1c2 = minuend->r1c2 - subtrahend->r1c2;
|
||||
|
|
@ -410,7 +526,7 @@ inline void bgc_matrix2x2_subtract_fp32(const BgcMatrix2x2FP32* minuend, const B
|
|||
difference->r2c2 = minuend->r2c2 - subtrahend->r2c2;
|
||||
}
|
||||
|
||||
inline void bgc_matrix2x2_subtract_fp64(const BgcMatrix2x2FP64* minuend, const BgcMatrix2x2FP64* subtrahend, BgcMatrix2x2FP64* difference)
|
||||
inline void bgc_fp64_matrix2x2_subtract(const BGC_FP64_Matrix2x2* minuend, const BGC_FP64_Matrix2x2* subtrahend, BGC_FP64_Matrix2x2* difference)
|
||||
{
|
||||
difference->r1c1 = minuend->r1c1 - subtrahend->r1c1;
|
||||
difference->r1c2 = minuend->r1c2 - subtrahend->r1c2;
|
||||
|
|
@ -419,29 +535,9 @@ inline void bgc_matrix2x2_subtract_fp64(const BgcMatrix2x2FP64* minuend, const B
|
|||
difference->r2c2 = minuend->r2c2 - subtrahend->r2c2;
|
||||
}
|
||||
|
||||
// ============== 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)
|
||||
inline void bgc_fp32_matrix2x2_multiply(const BGC_FP32_Matrix2x2* multiplicand, const float multiplier, BGC_FP32_Matrix2x2* product)
|
||||
{
|
||||
product->r1c1 = multiplicand->r1c1 * multiplier;
|
||||
product->r1c2 = multiplicand->r1c2 * multiplier;
|
||||
|
|
@ -450,7 +546,7 @@ inline void bgc_matrix2x2_multiply_fp32(const BgcMatrix2x2FP32* multiplicand, co
|
|||
product->r2c2 = multiplicand->r2c2 * multiplier;
|
||||
}
|
||||
|
||||
inline void bgc_matrix2x2_multiply_fp64(const BgcMatrix2x2FP64* multiplicand, const double multiplier, BgcMatrix2x2FP64* product)
|
||||
inline void bgc_fp64_matrix2x2_multiply(const BGC_FP64_Matrix2x2* multiplicand, const double multiplier, BGC_FP64_Matrix2x2* product)
|
||||
{
|
||||
product->r1c1 = multiplicand->r1c1 * multiplier;
|
||||
product->r1c2 = multiplicand->r1c2 * multiplier;
|
||||
|
|
@ -461,39 +557,43 @@ inline void bgc_matrix2x2_multiply_fp64(const BgcMatrix2x2FP64* multiplicand, co
|
|||
|
||||
// =================== Divide =================== //
|
||||
|
||||
inline void bgc_matrix2x2_divide_fp32(const BgcMatrix2x2FP32* dividend, const float divisor, BgcMatrix2x2FP32* quotient)
|
||||
inline void bgc_fp32_matrix2x2_divide(const BGC_FP32_Matrix2x2* dividend, const float divisor, BGC_FP32_Matrix2x2* quotient)
|
||||
{
|
||||
bgc_matrix2x2_multiply_fp32(dividend, 1.0f / divisor, quotient);
|
||||
bgc_fp32_matrix2x2_multiply(dividend, 1.0f / divisor, quotient);
|
||||
}
|
||||
|
||||
inline void bgc_matrix2x2_divide_fp64(const BgcMatrix2x2FP64* dividend, const double divisor, BgcMatrix2x2FP64* quotient)
|
||||
inline void bgc_fp64_matrix2x2_divide(const BGC_FP64_Matrix2x2* dividend, const double divisor, BGC_FP64_Matrix2x2* quotient)
|
||||
{
|
||||
bgc_matrix2x2_multiply_fp64(dividend, 1.0 / divisor, quotient);
|
||||
bgc_fp64_matrix2x2_multiply(dividend, 1.0 / divisor, quotient);
|
||||
}
|
||||
|
||||
// ============ Left Vector Product ============= //
|
||||
// ================ Interpolate ================= //
|
||||
|
||||
inline void bgc_matrix2x2_get_left_product_fp32(const BgcVector2FP32* vector, const BgcMatrix2x2FP32* matrix, BgcVector2FP32* product)
|
||||
inline void bgc_fp32_matrix2x2_interpolate(const BGC_FP32_Matrix2x2* first, const BGC_FP32_Matrix2x2* second, const float phase, BGC_FP32_Matrix2x2* interpolation)
|
||||
{
|
||||
const float x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1;
|
||||
const float x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2;
|
||||
const float counter_phase = 1.0f - phase;
|
||||
|
||||
product->x1 = x1;
|
||||
product->x2 = x2;
|
||||
interpolation->r1c1 = first->r1c1 * counter_phase + second->r1c1 * phase;
|
||||
interpolation->r1c2 = first->r1c2 * counter_phase + second->r1c2 * phase;
|
||||
|
||||
interpolation->r2c1 = first->r2c1 * counter_phase + second->r2c1 * phase;
|
||||
interpolation->r2c2 = first->r2c2 * counter_phase + second->r2c2 * phase;
|
||||
}
|
||||
|
||||
inline void bgc_matrix2x2_get_left_product_fp64(const BgcVector2FP64* vector, const BgcMatrix2x2FP64* matrix, BgcVector2FP64* product)
|
||||
inline void bgc_fp64_matrix2x2_interpolate(const BGC_FP64_Matrix2x2* first, const BGC_FP64_Matrix2x2* second, const double phase, BGC_FP64_Matrix2x2* interpolation)
|
||||
{
|
||||
const double x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1;
|
||||
const double x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2;
|
||||
const double counter_phase = 1.0 - phase;
|
||||
|
||||
product->x1 = x1;
|
||||
product->x2 = x2;
|
||||
interpolation->r1c1 = first->r1c1 * counter_phase + second->r1c1 * phase;
|
||||
interpolation->r1c2 = first->r1c2 * counter_phase + second->r1c2 * phase;
|
||||
|
||||
interpolation->r2c1 = first->r2c1 * counter_phase + second->r2c1 * phase;
|
||||
interpolation->r2c2 = first->r2c2 * counter_phase + second->r2c2 * phase;
|
||||
}
|
||||
|
||||
// ============ Right Vector Product ============ //
|
||||
|
||||
inline void bgc_matrix2x2_get_right_product_fp32(const BgcMatrix2x2FP32* matrix, const BgcVector2FP32* vector, BgcVector2FP32* product)
|
||||
inline void bgc_fp32_multiply_matrix2x2_by_vector2(const BGC_FP32_Matrix2x2* matrix, const BGC_FP32_Vector2* vector, BGC_FP32_Vector2* product)
|
||||
{
|
||||
const float x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2;
|
||||
const float x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2;
|
||||
|
|
@ -502,7 +602,7 @@ inline void bgc_matrix2x2_get_right_product_fp32(const BgcMatrix2x2FP32* matrix,
|
|||
product->x2 = x2;
|
||||
}
|
||||
|
||||
inline void bgc_matrix2x2_get_right_product_fp64(const BgcMatrix2x2FP64* matrix, const BgcVector2FP64* vector, BgcVector2FP64* product)
|
||||
inline void bgc_fp64_multiply_matrix2x2_by_vector2(const BGC_FP64_Matrix2x2* matrix, const BGC_FP64_Vector2* vector, BGC_FP64_Vector2* product)
|
||||
{
|
||||
const double x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2;
|
||||
const double x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2;
|
||||
|
|
@ -511,4 +611,24 @@ inline void bgc_matrix2x2_get_right_product_fp64(const BgcMatrix2x2FP64* matrix,
|
|||
product->x2 = x2;
|
||||
}
|
||||
|
||||
// ============ Left Vector Product ============= //
|
||||
|
||||
inline void bgc_fp32_multiply_vector2_by_matrix2x2(const BGC_FP32_Vector2* vector, const BGC_FP32_Matrix2x2* matrix, BGC_FP32_Vector2* product)
|
||||
{
|
||||
const float x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1;
|
||||
const float x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2;
|
||||
|
||||
product->x1 = x1;
|
||||
product->x2 = x2;
|
||||
}
|
||||
|
||||
inline void bgc_fp64_multiply_vector2_by_matrix2x2(const BGC_FP64_Vector2* vector, const BGC_FP64_Matrix2x2* matrix, BGC_FP64_Vector2* product)
|
||||
{
|
||||
const double x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1;
|
||||
const double x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2;
|
||||
|
||||
product->x1 = x1;
|
||||
product->x2 = x2;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue