Добавлены функции модуля для версоров и кватернионо / Functions of modulus have been added for versors and quaternions

This commit is contained in:
Andrey Pokidov 2024-11-25 19:47:45 +07:00
parent bef7ab98f4
commit 03e390c1d0
12 changed files with 246 additions and 211 deletions

View file

@ -102,50 +102,50 @@ static inline void bg_fp64_vector2_set_reverse_fp32(const BgFP32Vector2* from, B
// =================== Module =================== //
static inline float bg_fp32_vector2_get_square_module(const BgFP32Vector2* vector)
static inline float bg_fp32_vector2_get_square_modulus(const BgFP32Vector2* vector)
{
return vector->x1 * vector->x1 + vector->x2 * vector->x2;
}
static inline double bg_fp64_vector2_get_square_module(const BgFP64Vector2* vector)
static inline double bg_fp64_vector2_get_square_modulus(const BgFP64Vector2* vector)
{
return vector->x1 * vector->x1 + vector->x2 * vector->x2;
}
static inline float bg_fp32_vector2_get_module(const BgFP32Vector2* vector)
static inline float bg_fp32_vector2_get_modulus(const BgFP32Vector2* vector)
{
return sqrtf(bg_fp32_vector2_get_square_module(vector));
return sqrtf(bg_fp32_vector2_get_square_modulus(vector));
}
static inline double bg_fp64_vector2_get_module(const BgFP64Vector2* vector)
static inline double bg_fp64_vector2_get_modulus(const BgFP64Vector2* vector)
{
return sqrt(bg_fp64_vector2_get_square_module(vector));
return sqrt(bg_fp64_vector2_get_square_modulus(vector));
}
// ================= Comparison ================= //
static inline int bg_fp32_vector2_is_zero(const BgFP32Vector2* vector)
{
return bg_fp32_vector2_get_square_module(vector) <= BG_FP32_SQUARE_EPSYLON;
return bg_fp32_vector2_get_square_modulus(vector) <= BG_FP32_SQUARE_EPSYLON;
}
static inline int bg_fp64_vector2_is_zero(const BgFP64Vector2* vector)
{
return bg_fp64_vector2_get_square_module(vector) <= BG_FP64_SQUARE_EPSYLON;
return bg_fp64_vector2_get_square_modulus(vector) <= BG_FP64_SQUARE_EPSYLON;
}
static inline int bg_fp32_vector2_is_unit(const BgFP32Vector2* vector)
{
const float square_module = bg_fp32_vector2_get_square_module(vector);
const float square_modulus = bg_fp32_vector2_get_square_modulus(vector);
return 1.0f - BG_FP32_TWO_EPSYLON <= square_module && square_module <= 1.0f + BG_FP32_TWO_EPSYLON;
return 1.0f - BG_FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + BG_FP32_TWO_EPSYLON;
}
static inline int bg_fp64_vector2_is_unit(const BgFP64Vector2* vector)
{
const double square_module = bg_fp64_vector2_get_square_module(vector);
const double square_modulus = bg_fp64_vector2_get_square_modulus(vector);
return 1.0f - BG_FP64_TWO_EPSYLON <= square_module && square_module <= 1.0f + BG_FP64_TWO_EPSYLON;
return 1.0f - BG_FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + BG_FP64_TWO_EPSYLON;
}
// ==================== Add ===================== //
@ -274,35 +274,35 @@ static inline double bg_fp64_vector2_cross_product(const BgFP64Vector2* vector1,
static inline int bg_fp32_vector2_normalize(BgFP32Vector2* vector)
{
const float square_module = bg_fp32_vector2_get_square_module(vector);
const float square_modulus = bg_fp32_vector2_get_square_modulus(vector);
if (1.0f - BG_FP32_TWO_EPSYLON <= square_module && square_module <= 1.0f + BG_FP32_TWO_EPSYLON) {
if (1.0f - BG_FP32_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0f + BG_FP32_TWO_EPSYLON) {
return 1;
}
if (square_module <= BG_FP32_SQUARE_EPSYLON) {
if (square_modulus <= BG_FP32_SQUARE_EPSYLON) {
bg_fp32_vector2_reset(vector);
return 0;
}
bg_fp32_vector2_divide(vector, sqrtf(square_module), vector);
bg_fp32_vector2_divide(vector, sqrtf(square_modulus), vector);
return 1;
}
static inline int bg_fp64_vector2_normalize(BgFP64Vector2* vector)
{
const double square_module = bg_fp64_vector2_get_square_module(vector);
const double square_modulus = bg_fp64_vector2_get_square_modulus(vector);
if (1.0 - BG_FP64_TWO_EPSYLON <= square_module && square_module <= 1.0 + BG_FP64_TWO_EPSYLON) {
if (1.0 - BG_FP64_TWO_EPSYLON <= square_modulus && square_modulus <= 1.0 + BG_FP64_TWO_EPSYLON) {
return 1;
}
if (square_module <= BG_FP64_SQUARE_EPSYLON) {
if (square_modulus <= BG_FP64_SQUARE_EPSYLON) {
bg_fp64_vector2_reset(vector);
return 0;
}
bg_fp64_vector2_divide(vector, sqrt(square_module), vector);
bg_fp64_vector2_divide(vector, sqrt(square_modulus), vector);
return 1;
}
@ -360,38 +360,38 @@ static inline double bg_fp64_vector2_get_distance(const BgFP64Vector2* vector1,
static inline int bg_fp32_vector2_are_equal(const BgFP32Vector2* vector1, const BgFP32Vector2* vector2)
{
const float square_module1 = bg_fp32_vector2_get_square_module(vector1);
const float square_module2 = bg_fp32_vector2_get_square_module(vector2);
const float square_module3 = bg_fp32_vector2_get_square_distance(vector1, vector2);
const float square_modulus1 = bg_fp32_vector2_get_square_modulus(vector1);
const float square_modulus2 = bg_fp32_vector2_get_square_modulus(vector2);
const float square_modulus3 = bg_fp32_vector2_get_square_distance(vector1, vector2);
// 2.0f means dimension amount
if (square_module1 < BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT || square_module2 < BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT) {
return square_module3 < (2.0f * BG_FP32_SQUARE_EPSYLON);
if (square_modulus1 < BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT || square_modulus2 < BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT) {
return square_modulus3 < (2.0f * BG_FP32_SQUARE_EPSYLON);
}
if (square_module1 <= square_module2) {
return square_module3 <= (2.0f * BG_FP32_SQUARE_EPSYLON) * square_module2;
if (square_modulus1 <= square_modulus2) {
return square_modulus3 <= (2.0f * BG_FP32_SQUARE_EPSYLON) * square_modulus2;
}
return square_module3 <= (2.0f * BG_FP32_SQUARE_EPSYLON) * square_module1;
return square_modulus3 <= (2.0f * BG_FP32_SQUARE_EPSYLON) * square_modulus1;
}
static inline int bg_fp64_vector2_are_equal(const BgFP64Vector2* vector1, const BgFP64Vector2* vector2)
{
const double square_module1 = bg_fp64_vector2_get_square_module(vector1);
const double square_module2 = bg_fp64_vector2_get_square_module(vector2);
const double square_module3 = bg_fp64_vector2_get_square_distance(vector1, vector2);
const double square_modulus1 = bg_fp64_vector2_get_square_modulus(vector1);
const double square_modulus2 = bg_fp64_vector2_get_square_modulus(vector2);
const double square_modulus3 = bg_fp64_vector2_get_square_distance(vector1, vector2);
// 2.0 means dimension amount
if (square_module1 < BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT || square_module2 < BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT) {
return square_module3 < (2.0 * BG_FP64_SQUARE_EPSYLON);
if (square_modulus1 < BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT || square_modulus2 < BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT) {
return square_modulus3 < (2.0 * BG_FP64_SQUARE_EPSYLON);
}
if (square_module1 <= square_module2) {
return square_module3 <= (2.0 * BG_FP64_SQUARE_EPSYLON) * square_module2;
if (square_modulus1 <= square_modulus2) {
return square_modulus3 <= (2.0 * BG_FP64_SQUARE_EPSYLON) * square_modulus2;
}
return square_module3 <= (2.0 * BG_FP64_SQUARE_EPSYLON) * square_module1;
return square_modulus3 <= (2.0 * BG_FP64_SQUARE_EPSYLON) * square_modulus1;
}
#endif