Рефакторинг и оптимизация вычислений / Refactoring and optimization of computations
This commit is contained in:
parent
03e390c1d0
commit
2655e43cb4
15 changed files with 810 additions and 829 deletions
|
|
@ -171,51 +171,9 @@ static inline void bg_fp64_matrix2x2_transpose(BgFP64Matrix2x2* matrix)
|
|||
|
||||
// ================= Inversion ================== //
|
||||
|
||||
static inline int bg_fp32_matrix2x2_invert(BgFP32Matrix2x2* matrix)
|
||||
{
|
||||
const float determinant = bg_fp32_matrix2x2_get_determinant(matrix);
|
||||
int bg_fp32_matrix2x2_invert(BgFP32Matrix2x2* matrix);
|
||||
|
||||
if (-BG_FP32_EPSYLON <= determinant && determinant <= BG_FP32_EPSYLON) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const float r1c1 = matrix->r2c2;
|
||||
const float r1c2 = -matrix->r1c2;
|
||||
|
||||
const float r2c1 = -matrix->r2c1;
|
||||
const float r2c2 = matrix->r1c1;
|
||||
|
||||
matrix->r1c1 = r1c1 / determinant;
|
||||
matrix->r1c2 = r1c2 / determinant;
|
||||
|
||||
matrix->r2c1 = r2c1 / determinant;
|
||||
matrix->r2c2 = r2c2 / determinant;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static inline int bg_fp64_matrix2x2_invert(BgFP64Matrix2x2* matrix)
|
||||
{
|
||||
const double determinant = bg_fp64_matrix2x2_get_determinant(matrix);
|
||||
|
||||
if (-BG_FP64_EPSYLON <= determinant && determinant <= BG_FP64_EPSYLON) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const double r1c1 = matrix->r2c2;
|
||||
const double r1c2 = -matrix->r1c2;
|
||||
|
||||
const double r2c1 = -matrix->r2c1;
|
||||
const double r2c2 = matrix->r1c1;
|
||||
|
||||
matrix->r1c1 = r1c1 / determinant;
|
||||
matrix->r1c2 = r1c2 / determinant;
|
||||
|
||||
matrix->r2c1 = r2c1 / determinant;
|
||||
matrix->r2c2 = r2c2 / determinant;
|
||||
|
||||
return 1;
|
||||
}
|
||||
int bg_fp64_matrix2x2_invert(BgFP64Matrix2x2* matrix);
|
||||
|
||||
// =============== Set Transposed =============== //
|
||||
|
||||
|
|
@ -243,51 +201,9 @@ static inline void bg_fp64_matrix2x2_set_transposed(const BgFP64Matrix2x2* from,
|
|||
|
||||
// ================ Set Inverted ================ //
|
||||
|
||||
static inline int bg_fp32_matrix2x2_set_inverted(const BgFP32Matrix2x2* from, BgFP32Matrix2x2* to)
|
||||
{
|
||||
const float determinant = bg_fp32_matrix2x2_get_determinant(from);
|
||||
int bg_fp32_matrix2x2_set_inverted(const BgFP32Matrix2x2* from, BgFP32Matrix2x2* to);
|
||||
|
||||
if (-BG_FP32_EPSYLON <= determinant && determinant <= BG_FP32_EPSYLON) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const float r1c1 = from->r2c2;
|
||||
const float r1c2 = -from->r1c2;
|
||||
|
||||
const float r2c1 = -from->r2c1;
|
||||
const float r2c2 = from->r1c1;
|
||||
|
||||
to->r1c1 = r1c1 / determinant;
|
||||
to->r1c2 = r1c2 / determinant;
|
||||
|
||||
to->r2c1 = r2c1 / determinant;
|
||||
to->r2c2 = r2c2 / determinant;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static inline int bg_fp64_matrix2x2_set_inverted(const BgFP64Matrix2x2* from, BgFP64Matrix2x2* to)
|
||||
{
|
||||
const double determinant = bg_fp64_matrix2x2_get_determinant(from);
|
||||
|
||||
if (-BG_FP64_EPSYLON <= determinant && determinant <= BG_FP64_EPSYLON) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const double r1c1 = from->r2c2;
|
||||
const double r1c2 = -from->r1c2;
|
||||
|
||||
const double r2c1 = -from->r2c1;
|
||||
const double r2c2 = from->r1c1;
|
||||
|
||||
to->r1c1 = r1c1 / determinant;
|
||||
to->r1c2 = r1c2 / determinant;
|
||||
|
||||
to->r2c1 = r2c1 / determinant;
|
||||
to->r2c2 = r2c2 / determinant;
|
||||
|
||||
return 1;
|
||||
}
|
||||
int bg_fp64_matrix2x2_set_inverted(const BgFP64Matrix2x2* from, BgFP64Matrix2x2* to);
|
||||
|
||||
// ================= Set Row 1 ================== //
|
||||
|
||||
|
|
@ -429,60 +345,52 @@ static inline void bg_fp64_matrix2x2_multiply(const BgFP64Matrix2x2* multiplican
|
|||
|
||||
static inline void bg_fp32_matrix2x2_divide(const BgFP32Matrix2x2* dividend, const float divisor, BgFP32Matrix2x2* quotient)
|
||||
{
|
||||
quotient->r1c1 = dividend->r1c1 / divisor;
|
||||
quotient->r1c2 = dividend->r1c2 / divisor;
|
||||
|
||||
quotient->r2c1 = dividend->r2c1 / divisor;
|
||||
quotient->r2c2 = dividend->r2c2 / divisor;
|
||||
bg_fp32_matrix2x2_multiply(dividend, 1.0f / divisor, quotient);
|
||||
}
|
||||
|
||||
static inline void bg_fp64_matrix2x2_divide(const BgFP64Matrix2x2* dividend, const double divisor, BgFP64Matrix2x2* quotient)
|
||||
{
|
||||
quotient->r1c1 = dividend->r1c1 / divisor;
|
||||
quotient->r1c2 = dividend->r1c2 / divisor;
|
||||
|
||||
quotient->r2c1 = dividend->r2c1 / divisor;
|
||||
quotient->r2c2 = dividend->r2c2 / divisor;
|
||||
bg_fp64_matrix2x2_multiply(dividend, 1.0 / divisor, quotient);
|
||||
}
|
||||
|
||||
// ============ Left Vector Product ============= //
|
||||
|
||||
static inline void bg_fp32_matrix2x2_left_product(const BgFP32Vector2* vector, const BgFP32Matrix2x2* matrix, BgFP32Vector2* result)
|
||||
{
|
||||
bg_fp32_vector2_set_values(
|
||||
vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1,
|
||||
vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2,
|
||||
result
|
||||
);
|
||||
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;
|
||||
}
|
||||
|
||||
static inline void bg_fp64_matrix2x2_left_product(const BgFP64Vector2* vector, const BgFP64Matrix2x2* matrix, BgFP64Vector2* result)
|
||||
{
|
||||
bg_fp64_vector2_set_values(
|
||||
vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1,
|
||||
vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2,
|
||||
result
|
||||
);
|
||||
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;
|
||||
}
|
||||
|
||||
// ============ Right Vector Product ============ //
|
||||
|
||||
static inline void bg_fp32_matrix2x2_right_product(const BgFP32Matrix2x2* matrix, const BgFP32Vector2* vector, BgFP32Vector2* result)
|
||||
{
|
||||
bg_fp32_vector2_set_values(
|
||||
matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2,
|
||||
matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2,
|
||||
result
|
||||
);
|
||||
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;
|
||||
}
|
||||
|
||||
static inline void bg_fp64_matrix2x2_right_product(const BgFP64Matrix2x2* matrix, const BgFP64Vector2* vector, BgFP64Vector2* result)
|
||||
{
|
||||
bg_fp64_vector2_set_values(
|
||||
matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2,
|
||||
matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2,
|
||||
result
|
||||
);
|
||||
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;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue