Добавлены функции модуля для версоров и кватернионо / Functions of modulus have been added for versors and quaternions
This commit is contained in:
parent
bef7ab98f4
commit
03e390c1d0
12 changed files with 246 additions and 211 deletions
|
@ -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);
|
||||
const float square_module3 = bg_fp32_vector3_get_square_distance(vector1, vector2);
|
||||
const float square_modulus1 = bg_fp32_vector3_get_square_modulus(vector1);
|
||||
const float square_modulus2 = bg_fp32_vector3_get_square_modulus(vector2);
|
||||
const float square_modulus3 = bg_fp32_vector3_get_square_distance(vector1, vector2);
|
||||
|
||||
// 3.0f means dimension amount
|
||||
if (square_module1 < BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT || square_module2 < BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT) {
|
||||
return square_module3 < (3.0f * BG_FP32_SQUARE_EPSYLON);
|
||||
if (square_modulus1 < BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT || square_modulus2 < BG_FP32_EPSYLON_EFFECTIVENESS_LIMIT) {
|
||||
return square_modulus3 < (3.0f * BG_FP32_SQUARE_EPSYLON);
|
||||
}
|
||||
|
||||
if (square_module1 <= square_module2) {
|
||||
return square_module3 <= (3.0f * BG_FP32_SQUARE_EPSYLON) * square_module2;
|
||||
if (square_modulus1 <= square_modulus2) {
|
||||
return square_modulus3 <= (3.0f * BG_FP32_SQUARE_EPSYLON) * square_modulus2;
|
||||
}
|
||||
|
||||
return square_module3 <= (3.0f * BG_FP32_SQUARE_EPSYLON) * square_module1;
|
||||
return square_modulus3 <= (3.0f * BG_FP32_SQUARE_EPSYLON) * square_modulus1;
|
||||
}
|
||||
|
||||
static inline int bg_fp64_vector3_are_equal(const BgFP64Vector3* vector1, const BgFP64Vector3* vector2)
|
||||
{
|
||||
const double square_module1 = bg_fp64_vector3_get_square_module(vector1);
|
||||
const double square_module2 = bg_fp64_vector3_get_square_module(vector2);
|
||||
const double square_module3 = bg_fp64_vector3_get_square_distance(vector1, vector2);
|
||||
const double square_modulus1 = bg_fp64_vector3_get_square_modulus(vector1);
|
||||
const double square_modulus2 = bg_fp64_vector3_get_square_modulus(vector2);
|
||||
const double square_modulus3 = bg_fp64_vector3_get_square_distance(vector1, vector2);
|
||||
|
||||
// 3.0 means dimension amount
|
||||
if (square_module1 < BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT || square_module2 < BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT) {
|
||||
return square_module3 < (3.0 * BG_FP64_SQUARE_EPSYLON);
|
||||
if (square_modulus1 < BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT || square_modulus2 < BG_FP64_EPSYLON_EFFECTIVENESS_LIMIT) {
|
||||
return square_modulus3 < (3.0 * BG_FP64_SQUARE_EPSYLON);
|
||||
}
|
||||
|
||||
if (square_module1 <= square_module2) {
|
||||
return square_module3 <= (3.0 * BG_FP64_SQUARE_EPSYLON) * square_module2;
|
||||
if (square_modulus1 <= square_modulus2) {
|
||||
return square_modulus3 <= (3.0 * BG_FP64_SQUARE_EPSYLON) * square_modulus2;
|
||||
}
|
||||
|
||||
return square_module3 <= (3.0 * BG_FP64_SQUARE_EPSYLON) * square_module1;
|
||||
return square_modulus3 <= (3.0 * BG_FP64_SQUARE_EPSYLON) * square_modulus1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue