Добавлены функции модуля для версоров и кватернионо / 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

Internal server error - Personal Git Server: Beyond coding. We Forge.

500

Internal server error

Forgejo version: 11.0.1+gitea-1.22.0

@ -116,50 +116,50 @@ static inline void bg_fp64_vector3_set_reverse_fp32(const BgFP32Vector3* from, B
// =================== Module =================== //
static inline float bg_fp32_vector3_get_square_module(const BgFP32Vector3* vector)
static inline float bg_fp32_vector3_get_square_modulus(const BgFP32Vector3* vector)
{
return vector->x1 * vector->x1 + vector->x2 * vector->x2 + vector->x3 * vector->x3;
}
static inline double bg_fp64_vector3_get_square_module(const BgFP64Vector3* vector)
static inline double bg_fp64_vector3_get_square_modulus(const BgFP64Vector3* vector)
{
return vector->x1 * vector->x1 + vector->x2 * vector->x2 + vector->x3 * vector->x3;
}
static inline float bg_fp32_vector3_get_module(const BgFP32Vector3* vector)
static inline float bg_fp32_vector3_get_modulus(const BgFP32Vector3* vector)
{
return sqrtf(bg_fp32_vector3_get_square_module(vector));
return sqrtf(bg_fp32_vector3_get_square_modulus(vector));
}
static inline double bg_fp64_vector3_get_module(const BgFP64Vector3* vector)
static inline double bg_fp64_vector3_get_modulus(const BgFP64Vector3* vector)
{
return sqrt(bg_fp64_vector3_get_square_module(vector));
return sqrt(bg_fp64_vector3_get_square_modulus(vector));
}
// ================= Comparison ================= //
static inline int bg_fp32_vector3_is_zero(const BgFP32Vector3* vector)
{
return bg_fp32_vector3_get_square_module(vector) <= BG_FP32_SQUARE_EPSYLON;
return bg_fp32_vector3_get_square_modulus(vector) <= BG_FP32_SQUARE_EPSYLON;
}
static inline int bg_fp64_vector3_is_zero(const BgFP64Vector3* vector)
{
return bg_fp64_vector3_get_square_module(vector) <= BG_FP64_SQUARE_EPSYLON;
return bg_fp64_vector3_get_square_modulus(vector) <= BG_FP64_SQUARE_EPSYLON;
}
static inline int bg_fp32_vector3_is_unit(const BgFP32Vector3* vector)
{
const float square_module = bg_fp32_vector3_get_square_module(vector);
const float square_modulus = bg_fp32_vector3_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_vector3_is_unit(const BgFP64Vector3* vector)
{
const double square_module = bg_fp64_vector3_get_square_module(vector);
const double square_modulus = bg_fp64_vector3_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 ===================== //
@ -350,35 +350,35 @@ static inline void bg_fp64_vector3_double_cross(const BgFP64Vector3* vector1, co
static inline int bg_fp32_vector3_normalize(BgFP32Vector3* vector)
{
const float square_module = bg_fp32_vector3_get_square_module(vector);
const float square_modulus = bg_fp32_vector3_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_vector3_reset(vector);
return 0;
}
bg_fp32_vector3_divide(vector, sqrtf(square_module), vector);
bg_fp32_vector3_divide(vector, sqrtf(square_modulus), vector);
return 1;
}
static inline int bg_fp64_vector3_normalize(BgFP64Vector3* vector)
{
const double square_module = bg_fp64_vector3_get_square_module(vector);
const double square_modulus = bg_fp64_vector3_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_vector3_reset(vector);
return 0;
}
bg_fp64_vector3_divide(vector, sqrt(square_module), vector);
bg_fp64_vector3_divide(vector, sqrt(square_modulus), vector);
return 1;
}
@ -438,38 +438,38 @@ static inline double bg_fp64_vector3_get_distance(const BgFP64Vector3* vector1,
static inline int bg_fp32_vector3_are_equal(const BgFP32Vector3* vector1, const BgFP32Vector3* vector2)
{
const float square_module1 = bg_fp32_vector3_get_square_module(vector1);
const float square_module2 = bg_fp32_vector3_get_square_module(vector2);