Рефакторинг и оптимизация вычислений / Refactoring and optimization of computations
This commit is contained in:
parent
03e390c1d0
commit
2655e43cb4
15 changed files with 810 additions and 829 deletions
|
@ -150,58 +150,56 @@ static inline int bg_fp64_vector2_is_unit(const BgFP64Vector2* vector)
|
|||
|
||||
// ==================== Add ===================== //
|
||||
|
||||
static inline void bg_fp32_vector2_add(const BgFP32Vector2* vector1, const BgFP32Vector2* vector2, BgFP32Vector2* result)
|
||||
static inline void bg_fp32_vector2_add(const BgFP32Vector2* vector1, const BgFP32Vector2* vector2, BgFP32Vector2* sum)
|
||||
{
|
||||
result->x1 = vector1->x1 + vector2->x1;
|
||||
result->x2 = vector1->x2 + vector2->x2;
|
||||
sum->x1 = vector1->x1 + vector2->x1;
|
||||
sum->x2 = vector1->x2 + vector2->x2;
|
||||
}
|
||||
|
||||
static inline void bg_fp64_vector2_add(const BgFP64Vector2* vector1, const BgFP64Vector2* vector2, BgFP64Vector2* result)
|
||||
static inline void bg_fp64_vector2_add(const BgFP64Vector2* vector1, const BgFP64Vector2* vector2, BgFP64Vector2* sum)
|
||||
{
|
||||
result->x1 = vector1->x1 + vector2->x1;
|
||||
result->x2 = vector1->x2 + vector2->x2;
|
||||
sum->x1 = vector1->x1 + vector2->x1;
|
||||
sum->x2 = vector1->x2 + vector2->x2;
|
||||
}
|
||||
|
||||
// ================ Subtraction ================= //
|
||||
|
||||
static inline void bg_fp32_vector2_subtract(const BgFP32Vector2* minuend, const BgFP32Vector2* subtrahend, BgFP32Vector2* result)
|
||||
static inline void bg_fp32_vector2_subtract(const BgFP32Vector2* minuend, const BgFP32Vector2* subtrahend, BgFP32Vector2* difference)
|
||||
{
|
||||
result->x1 = minuend->x1 - subtrahend->x1;
|
||||
result->x2 = minuend->x2 - subtrahend->x2;
|
||||
difference->x1 = minuend->x1 - subtrahend->x1;
|
||||
difference->x2 = minuend->x2 - subtrahend->x2;
|
||||
}
|
||||
|
||||
static inline void bg_fp64_vector2_subtract(const BgFP64Vector2* minuend, const BgFP64Vector2* subtrahend, BgFP64Vector2* result)
|
||||
static inline void bg_fp64_vector2_subtract(const BgFP64Vector2* minuend, const BgFP64Vector2* subtrahend, BgFP64Vector2* difference)
|
||||
{
|
||||
result->x1 = minuend->x1 - subtrahend->x1;
|
||||
result->x2 = minuend->x2 - subtrahend->x2;
|
||||
difference->x1 = minuend->x1 - subtrahend->x1;
|
||||
difference->x2 = minuend->x2 - subtrahend->x2;
|
||||
}
|
||||
|
||||
// =============== Multiplication =============== //
|
||||
|
||||
static inline void bg_fp32_vector2_multiply(const BgFP32Vector2* multiplicand, const float multiplier, BgFP32Vector2* result)
|
||||
static inline void bg_fp32_vector2_multiply(const BgFP32Vector2* multiplicand, const float multiplier, BgFP32Vector2* product)
|
||||
{
|
||||
result->x1 = multiplicand->x1 * multiplier;
|
||||
result->x2 = multiplicand->x2 * multiplier;
|
||||
product->x1 = multiplicand->x1 * multiplier;
|
||||
product->x2 = multiplicand->x2 * multiplier;
|
||||
}
|
||||
|
||||
static inline void bg_fp64_vector2_multiply(const BgFP64Vector2* multiplicand, const double multiplier, BgFP64Vector2* result)
|
||||
static inline void bg_fp64_vector2_multiply(const BgFP64Vector2* multiplicand, const double multiplier, BgFP64Vector2* product)
|
||||
{
|
||||
result->x1 = multiplicand->x1 * multiplier;
|
||||
result->x2 = multiplicand->x2 * multiplier;
|
||||
product->x1 = multiplicand->x1 * multiplier;
|
||||
product->x2 = multiplicand->x2 * multiplier;
|
||||
}
|
||||
|
||||
// ================== Division ================== //
|
||||
|
||||
static inline void bg_fp32_vector2_divide(const BgFP32Vector2* dividend, const float divisor, BgFP32Vector2* result)
|
||||
static inline void bg_fp32_vector2_divide(const BgFP32Vector2* dividend, const float divisor, BgFP32Vector2* quotient)
|
||||
{
|
||||
result->x1 = dividend->x1 / divisor;
|
||||
result->x2 = dividend->x2 / divisor;
|
||||
bg_fp32_vector2_multiply(dividend, 1.0f / divisor, quotient);
|
||||
}
|
||||
|
||||
static inline void bg_fp64_vector2_divide(const BgFP64Vector2* dividend, const double divisor, BgFP64Vector2* result)
|
||||
static inline void bg_fp64_vector2_divide(const BgFP64Vector2* dividend, const double divisor, BgFP64Vector2* quotient)
|
||||
{
|
||||
result->x1 = dividend->x1 / divisor;
|
||||
result->x2 = dividend->x2 / divisor;
|
||||
bg_fp64_vector2_multiply(dividend, 1.0 / divisor, quotient);
|
||||
}
|
||||
|
||||
// ================ Append scaled =============== //
|
||||
|
@ -248,12 +246,12 @@ static inline void bg_fp64_vector2_get_mean3(const BgFP64Vector2* vector1, const
|
|||
|
||||
// =============== Scalar Product =============== //
|
||||
|
||||
static inline float bg_fp32_vector2_dot_product(const BgFP32Vector2* vector1, const BgFP32Vector2* vector2)
|
||||
static inline float bg_fp32_vector2_scalar_product(const BgFP32Vector2* vector1, const BgFP32Vector2* vector2)
|
||||
{
|
||||
return vector1->x1 * vector2->x1 + vector1->x2 * vector2->x2;
|
||||
}
|
||||
|
||||
static inline double bg_fp64_vector2_dot_product(const BgFP64Vector2* vector1, const BgFP64Vector2* vector2)
|
||||
static inline double bg_fp64_vector2_scalar_product(const BgFP64Vector2* vector1, const BgFP64Vector2* vector2)
|
||||
{
|
||||
return vector1->x1 * vector2->x1 + vector1->x2 * vector2->x2;
|
||||
}
|
||||
|
@ -272,39 +270,9 @@ static inline double bg_fp64_vector2_cross_product(const BgFP64Vector2* vector1,
|
|||
|
||||
// =============== Normalization ================ //
|
||||
|
||||
static inline int bg_fp32_vector2_normalize(BgFP32Vector2* vector)
|
||||
{
|
||||
const float square_modulus = bg_fp32_vector2_get_square_modulus(vector);
|
||||
int bg_fp32_vector2_normalize(BgFP32Vector2* vector);
|
||||
|
||||
if (1.0f - BG_FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + BG_FP32_TWO_EPSYLON) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_modulus <= BG_FP32_SQUARE_EPSYLON) {
|
||||
bg_fp32_vector2_reset(vector);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bg_fp32_vector2_divide(vector, sqrtf(square_modulus), vector);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static inline int bg_fp64_vector2_normalize(BgFP64Vector2* vector)
|
||||
{
|
||||
const double square_modulus = bg_fp64_vector2_get_square_modulus(vector);
|
||||
|
||||
if (1.0 - BG_FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0 + BG_FP64_TWO_EPSYLON) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (square_modulus <= BG_FP64_SQUARE_EPSYLON) {
|
||||
bg_fp64_vector2_reset(vector);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bg_fp64_vector2_divide(vector, sqrt(square_modulus), vector);
|
||||
return 1;
|
||||
}
|
||||
int bg_fp64_vector2_normalize(BgFP64Vector2* vector);
|
||||
|
||||
// =============== Get Normalized =============== //
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue