Рефакторинг и оптимизация вычислений / Refactoring and optimization of computations
This commit is contained in:
parent
03e390c1d0
commit
2655e43cb4
15 changed files with 810 additions and 829 deletions
|
@ -1,5 +1,41 @@
|
|||
#include "vector3.h"
|
||||
|
||||
// =============== Normalization ================ //
|
||||
|
||||
int bg_fp32_vector3_normalize(BgFP32Vector3* vector)
|
||||
{
|
||||
const float square_modulus = bg_fp32_vector3_get_square_modulus(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_vector3_reset(vector);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bg_fp32_vector3_multiply(vector, sqrtf(1.0f / square_modulus), vector);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int bg_fp64_vector3_normalize(BgFP64Vector3* vector)
|
||||
{
|
||||
const double square_modulus = bg_fp64_vector3_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_vector3_reset(vector);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bg_fp64_vector3_multiply(vector, sqrt(1.0 / square_modulus), vector);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// =================== Angle ==================== //
|
||||
|
||||
float bg_fp32_vector3_get_angle(const BgFP32Vector3* vector1, const BgFP32Vector3* vector2, const angle_unit_t unit)
|
||||
|
@ -20,7 +56,7 @@ float bg_fp32_vector3_get_angle(const BgFP32Vector3* vector1, const BgFP32Vector
|
|||
return 0.0f;
|
||||
}
|
||||
|
||||
const float cosine = bg_fp32_vector3_dot_product(vector1, vector2) / sqrtf(square_modulus1 * square_modulus2);
|
||||
const float cosine = bg_fp32_vector3_scalar_product(vector1, vector2) / sqrtf(square_modulus1 * square_modulus2);
|
||||
|
||||
if (cosine >= 1.0f - BG_FP32_EPSYLON) {
|
||||
return 0.0f;
|
||||
|
@ -51,7 +87,7 @@ double bg_fp64_vector3_get_angle(const BgFP64Vector3* vector1, const BgFP64Vecto
|
|||
return 0.0;
|
||||
}
|
||||
|
||||
const double cosine = bg_fp64_vector3_dot_product(vector1, vector2) / sqrt(square_modulus1 * square_modulus2);
|
||||
const double cosine = bg_fp64_vector3_scalar_product(vector1, vector2) / sqrt(square_modulus1 * square_modulus2);
|
||||
|
||||
if (cosine >= 1.0 - BG_FP64_EPSYLON) {
|
||||
return 0.0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue