Небольшие исправления, а также добавление гомогенного трёхмерного вектора

This commit is contained in:
Andrey Pokidov 2026-02-02 20:44:10 +07:00
parent 03627f4401
commit 043cc72c81
25 changed files with 1686 additions and 1644 deletions

View file

@ -79,7 +79,7 @@ void _bgc_fp32_versor_normalize(BGC_FP32_Versor* versor)
{
const float square_modulus = (versor->_s0 * versor->_s0 + versor->_x1 * versor->_x1) + (versor->_x2 * versor->_x2 + versor->_x3 * versor->_x3);
if (square_modulus <= BGC_FP32_SQUARE_EPSYLON || isnan(square_modulus)) {
if (square_modulus <= BGC_FP32_SQUARE_EPSILON || isnan(square_modulus)) {
versor->_s0 = 1.0f;
versor->_x1 = 0.0f;
versor->_x2 = 0.0f;
@ -99,7 +99,7 @@ void _bgc_fp64_versor_normalize(BGC_FP64_Versor* versor)
{
const double square_modulus = (versor->_s0 * versor->_s0 + versor->_x1 * versor->_x1) + (versor->_x2 * versor->_x2 + versor->_x3 * versor->_x3);
if (square_modulus <= BGC_FP64_SQUARE_EPSYLON || isnan(square_modulus)) {
if (square_modulus <= BGC_FP64_SQUARE_EPSILON || isnan(square_modulus)) {
versor->_s0 = 1.0;
versor->_x1 = 0.0;
versor->_x2 = 0.0;
@ -121,7 +121,7 @@ void bgc_fp32_versor_make_for_turn(BGC_FP32_Versor* versor, const float x1, cons
{
const float square_vector = x1 * x1 + x2 * x2 + x3 * x3;
if (square_vector <= BGC_FP32_SQUARE_EPSYLON) {
if (square_vector <= BGC_FP32_SQUARE_EPSILON) {
bgc_fp32_versor_reset(versor);
return;
}
@ -144,7 +144,7 @@ void bgc_fp64_versor_make_for_turn(BGC_FP64_Versor* versor, const double x1, con
{
const double square_vector = x1 * x1 + x2 * x2 + x3 * x3;
if (square_vector <= BGC_FP64_SQUARE_EPSYLON) {
if (square_vector <= BGC_FP64_SQUARE_EPSILON) {
bgc_fp64_versor_reset(versor);
return;
}
@ -175,7 +175,7 @@ static int _bgc_fp32_versor_make_direction_turn(BGC_FP32_Versor* versor, const B
const float square_modulus = bgc_fp32_vector3_get_square_modulus(&orthogonal_axis);
const float square_sine = square_modulus / square_modulus_product;
if (square_sine > BGC_FP32_SQUARE_EPSYLON) {
if (square_sine > BGC_FP32_SQUARE_EPSILON) {
const float cosine = scalar_product / sqrtf(square_modulus_product);
const float angle = 0.5f * atan2f(sqrtf(square_sine), cosine);
@ -203,7 +203,7 @@ static int _bgc_fp64_versor_make_direction_turn(BGC_FP64_Versor* versor, const B
const double square_modulus = bgc_fp64_vector3_get_square_modulus(&orthogonal_axis);
const double square_sine = square_modulus / square_modulus_product;
if (square_sine > BGC_FP64_SQUARE_EPSYLON) {
if (square_sine > BGC_FP64_SQUARE_EPSILON) {
const double cosine = scalar_product / sqrt(square_modulus_product);
const double angle = 0.5 * atan2(sqrt(square_sine), cosine);
@ -226,7 +226,7 @@ int bgc_fp32_versor_make_direction_difference(BGC_FP32_Versor* versor, const BGC
const float start_square_modulus = bgc_fp32_vector3_get_square_modulus(start);
const float end_square_modulus = bgc_fp32_vector3_get_square_modulus(end);
if (start_square_modulus <= BGC_FP32_SQUARE_EPSYLON || end_square_modulus <= BGC_FP32_SQUARE_EPSYLON) {
if (start_square_modulus <= BGC_FP32_SQUARE_EPSILON || end_square_modulus <= BGC_FP32_SQUARE_EPSILON) {
bgc_fp32_versor_reset(versor);
return BGC_ZERO_TURN;
}
@ -239,7 +239,7 @@ int bgc_fp64_versor_make_direction_difference(BGC_FP64_Versor* versor, const BGC
const double start_square_modulus = bgc_fp64_vector3_get_square_modulus(start);
const double end_square_modulus = bgc_fp64_vector3_get_square_modulus(end);
if (start_square_modulus <= BGC_FP64_SQUARE_EPSYLON || end_square_modulus <= BGC_FP64_SQUARE_EPSYLON) {
if (start_square_modulus <= BGC_FP64_SQUARE_EPSILON || end_square_modulus <= BGC_FP64_SQUARE_EPSILON) {
bgc_fp64_versor_reset(versor);
return BGC_ZERO_TURN;
}
@ -251,17 +251,17 @@ int bgc_fp64_versor_make_direction_difference(BGC_FP64_Versor* versor, const BGC
static int _bgc_fp32_versor_validate_basis(const float primary_square_modulus, const float auxiliary_square_modulus, const float orthogonal_square_modulus)
{
if (primary_square_modulus <= BGC_FP32_SQUARE_EPSYLON) {
if (primary_square_modulus <= BGC_FP32_SQUARE_EPSILON) {
//TODO: add error code for: primary_vector is zero
return BGC_FAILED;
}
if (auxiliary_square_modulus <= BGC_FP32_SQUARE_EPSYLON) {
if (auxiliary_square_modulus <= BGC_FP32_SQUARE_EPSILON) {
//TODO: add error code for: auxiliary_vector is zero
return BGC_FAILED;
}
if (orthogonal_square_modulus <= BGC_FP32_SQUARE_EPSYLON * primary_square_modulus * auxiliary_square_modulus) {
if (orthogonal_square_modulus <= BGC_FP32_SQUARE_EPSILON * primary_square_modulus * auxiliary_square_modulus) {
//TODO: add error code for: primary_vector and auxiliary_vector are parallel
return BGC_FAILED;
}
@ -271,17 +271,17 @@ static int _bgc_fp32_versor_validate_basis(const float primary_square_modulus, c
static int _bgc_fp64_versor_validate_basis(const double primary_square_modulus, const double auxiliary_square_modulus, const double orthogonal_square_modulus)
{
if (primary_square_modulus <= BGC_FP64_SQUARE_EPSYLON) {
if (primary_square_modulus <= BGC_FP64_SQUARE_EPSILON) {
//TODO: add error code for: primary_vector is zero
return BGC_FAILED;
}
if (auxiliary_square_modulus <= BGC_FP64_SQUARE_EPSYLON) {
if (auxiliary_square_modulus <= BGC_FP64_SQUARE_EPSILON) {
//TODO: add error code for: auxiliary_vector is zero
return BGC_FAILED;
}
if (orthogonal_square_modulus <= BGC_FP64_SQUARE_EPSYLON * primary_square_modulus * auxiliary_square_modulus) {
if (orthogonal_square_modulus <= BGC_FP64_SQUARE_EPSILON * primary_square_modulus * auxiliary_square_modulus) {
//TODO: add error code for: primary_vector and auxiliary_vector are parallel
return BGC_FAILED;
}
@ -437,7 +437,7 @@ void bgc_fp32_versor_get_exponation(BGC_FP32_Versor* power, const BGC_FP32_Verso
{
const float square_vector = base->_x1 * base->_x1 + base->_x2 * base->_x2 + base->_x3 * base->_x3;
if (square_vector <= BGC_FP32_SQUARE_EPSYLON || square_vector != square_vector) {
if (square_vector <= BGC_FP32_SQUARE_EPSILON || square_vector != square_vector) {
bgc_fp32_versor_reset(power);
return;
}
@ -455,7 +455,7 @@ void bgc_fp64_versor_get_exponation(BGC_FP64_Versor* power, const BGC_FP64_Verso
{
const double square_vector = base->_x1 * base->_x1 + base->_x2 * base->_x2 + base->_x3 * base->_x3;
if (square_vector <= BGC_FP64_SQUARE_EPSYLON || square_vector != square_vector) {
if (square_vector <= BGC_FP64_SQUARE_EPSILON || square_vector != square_vector) {
bgc_fp64_versor_reset(power);
return;
}
@ -481,7 +481,7 @@ void bgc_fp32_versor_spherically_interpolate(BGC_FP32_Versor* interpolation, con
const float square_vector = delta_x1 * delta_x1 + delta_x2 * delta_x2 + delta_x3 * delta_x3;
// square_vector != square_vector means checking for NaN value at square_vector
if (square_vector <= BGC_FP32_SQUARE_EPSYLON || isnan(square_vector)) {
if (square_vector <= BGC_FP32_SQUARE_EPSILON || isnan(square_vector)) {
bgc_fp32_versor_copy(interpolation, end);
return;
}
@ -516,7 +516,7 @@ void bgc_fp64_versor_spherically_interpolate(BGC_FP64_Versor* interpolation, con
const double square_vector = delta_x1 * delta_x1 + delta_x2 * delta_x2 + delta_x3 * delta_x3;
// square_vector != square_vector means checking for NaN value at square_vector
if (square_vector <= BGC_FP64_SQUARE_EPSYLON || isnan(square_vector)) {
if (square_vector <= BGC_FP64_SQUARE_EPSILON || isnan(square_vector)) {
bgc_fp64_versor_copy(interpolation, end);
return;
}
@ -547,7 +547,7 @@ void bgc_fp32_versor_get_rotation(BGC_FP32_Rotation3* rotation, const BGC_FP32_V
{
const float square_modulus = versor->_x1 * versor->_x1 + versor->_x2 * versor->_x2 + versor->_x3 * versor->_x3;
if (square_modulus <= BGC_FP32_SQUARE_EPSYLON) {
if (square_modulus <= BGC_FP32_SQUARE_EPSILON) {
bgc_fp32_rotation3_reset(rotation);
return;
}
@ -567,7 +567,7 @@ void bgc_fp64_versor_get_rotation(BGC_FP64_Rotation3* rotation, const BGC_FP64_V
{
const double square_modulus = versor->_x1 * versor->_x1 + versor->_x2 * versor->_x2 + versor->_x3 * versor->_x3;
if (square_modulus <= BGC_FP64_SQUARE_EPSYLON) {
if (square_modulus <= BGC_FP64_SQUARE_EPSILON) {
bgc_fp64_rotation3_reset(rotation);
return;
}