Переименование s0 -> s, x1 -> x, x2 -> y, x3 -> z, что должно упростить читаемость кода. Также обновление документации

This commit is contained in:
Andrey Pokidov 2026-03-29 22:06:01 +07:00
parent d83ab7160d
commit b8d383da33
38 changed files with 2104 additions and 2070 deletions

View file

@ -7,8 +7,8 @@ extern inline void bgc_fp64_quaternion_reset(BGC_FP64_Quaternion* const quaterni
extern inline void bgc_fp32_quaternion_make_unit(BGC_FP32_Quaternion* const quaternion);
extern inline void bgc_fp64_quaternion_make_unit(BGC_FP64_Quaternion* const quaternion);
extern inline void bgc_fp32_quaternion_set_values(BGC_FP32_Quaternion* const quaternion, const float s0, const float x1, const float x2, const float x3);
extern inline void bgc_fp64_quaternion_set_values(BGC_FP64_Quaternion* const quaternion, const double s0, const double x1, const double x2, const double x3);
extern inline void bgc_fp32_quaternion_set_values(BGC_FP32_Quaternion* const quaternion, const float s, const float x, const float y, const float z);
extern inline void bgc_fp64_quaternion_set_values(BGC_FP64_Quaternion* const quaternion, const double s, const double x, const double y, const double z);
extern inline float bgc_fp32_quaternion_get_square_magnitude(const BGC_FP32_Quaternion* const quaternion);
extern inline double bgc_fp64_quaternion_get_square_magnitude(const BGC_FP64_Quaternion* const quaternion);
@ -158,13 +158,13 @@ extern inline int bgc_fp64_quaternion_are_close(const BGC_FP64_Quaternion* const
int bgc_fp32_quaternion_get_power(BGC_FP32_Quaternion* const power, const BGC_FP32_Quaternion* const base, const float exponent)
{
const float s0s0 = base->s0 * base->s0;
const float x1x1 = base->x1 * base->x1;
const float x2x2 = base->x2 * base->x2;
const float x3x3 = base->x3 * base->x3;
const float ss = base->s * base->s;
const float xx = base->x * base->x;
const float yy = base->y * base->y;
const float zz = base->z * base->z;
const float square_vector = x1x1 + (x2x2 + x3x3);
const float square_modulus = (s0s0 + x1x1) + (x2x2 + x3x3);
const float square_vector = xx + (yy + zz);
const float square_modulus = (ss + xx) + (yy + zz);
// isnan(square_modulus) means checking for NaN value at square_modulus
if (isnan(square_modulus)) {
@ -172,40 +172,40 @@ int bgc_fp32_quaternion_get_power(BGC_FP32_Quaternion* const power, const BGC_FP
}
if (square_vector <= BGC_FP32_SQUARE_EPSILON) {
if (base->s0 < 0.0f) {
if (base->s < 0.0f) {
return BGC_FAILURE;
}
power->s0 = powf(base->s0, exponent);
power->x1 = 0.0f;
power->x2 = 0.0f;
power->x3 = 0.0f;
power->s = powf(base->s, exponent);
power->x = 0.0f;
power->y = 0.0f;
power->z = 0.0f;
return BGC_SUCCESS;
}
const float vector_modulus = sqrtf(square_vector);
const float power_angle = atan2f(vector_modulus, base->s0) * exponent;
const float power_angle = atan2f(vector_modulus, base->s) * exponent;
const float power_modulus = powf(square_modulus, 0.5f * exponent);
const float multiplier = power_modulus * sinf(power_angle) / vector_modulus;
power->s0 = power_modulus * cosf(power_angle);
power->x1 = base->x1 * multiplier;
power->x2 = base->x2 * multiplier;
power->x3 = base->x3 * multiplier;
power->s = power_modulus * cosf(power_angle);
power->x = base->x * multiplier;
power->y = base->y * multiplier;
power->z = base->z * multiplier;
return BGC_SUCCESS;
}
int bgc_fp64_quaternion_get_power(BGC_FP64_Quaternion* const power, const BGC_FP64_Quaternion* const base, const double exponent)
{
const double s0s0 = base->s0 * base->s0;
const double x1x1 = base->x1 * base->x1;
const double x2x2 = base->x2 * base->x2;
const double x3x3 = base->x3 * base->x3;
const double ss = base->s * base->s;
const double xx = base->x * base->x;
const double yy = base->y * base->y;
const double zz = base->z * base->z;
const double square_vector = x1x1 + (x2x2 + x3x3);
const double square_modulus = (s0s0 + x1x1) + (x2x2 + x3x3);
const double square_vector = xx + (yy + zz);
const double square_modulus = (ss + xx) + (yy + zz);
// isnan(square_modulus) means checking for NaN value at square_modulus
if (isnan(square_modulus)) {
@ -213,27 +213,27 @@ int bgc_fp64_quaternion_get_power(BGC_FP64_Quaternion* const power, const BGC_FP
}
if (square_vector <= BGC_FP64_SQUARE_EPSILON) {
if (base->s0 < 0.0) {
if (base->s < 0.0) {
return BGC_FAILURE;
}
power->s0 = pow(base->s0, exponent);
power->x1 = 0.0;
power->x2 = 0.0;
power->x3 = 0.0;
power->s = pow(base->s, exponent);
power->x = 0.0;
power->y = 0.0;
power->z = 0.0;
return BGC_SUCCESS;
}
const double vector_modulus = sqrt(square_vector);
const double power_angle = atan2(vector_modulus, base->s0) * exponent;
const double power_angle = atan2(vector_modulus, base->s) * exponent;
const double power_modulus = pow(square_modulus, 0.5 * exponent);
const double multiplier = power_modulus * sin(power_angle) / vector_modulus;
power->s0 = power_modulus * cos(power_angle);
power->x1 = base->x1 * multiplier;
power->x2 = base->x2 * multiplier;
power->x3 = base->x3 * multiplier;
power->s = power_modulus * cos(power_angle);
power->x = base->x * multiplier;
power->y = base->y * multiplier;
power->z = base->z * multiplier;
return BGC_SUCCESS;
}