Отказ от функций getWeightedSum в пользу appendScaled; оптимизация версоров / Replacing of getWeightedSum onto appendScaled; versor optimization

This commit is contained in:
Andrey Pokidov 2024-11-20 01:21:40 +07:00
parent 7bd9c07f17
commit e354b2425c
13 changed files with 331 additions and 835 deletions

View file

@ -117,16 +117,9 @@ static inline void sp_versor_set(const float s0, const float x1, const float x2,
const float square_module = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3);
if (1.0f - SP_TWO_EPSYLON <= square_module && square_module <= 1.0f + SP_TWO_EPSYLON) {
if (s0 > -1.0f + SP_EPSYLON) {
return;
}
sp_versor_reset(result);
return;
if (square_module < 1.0f - SP_TWO_EPSYLON || 1.0f + SP_TWO_EPSYLON < square_module) {
__sp_versor_normalize(square_module, result);
}
__sp_versor_normalize(square_module, result);
}
static inline void dp_versor_set(const double s0, const double x1, const double x2, const double x3, DPVersor* result)
@ -138,16 +131,9 @@ static inline void dp_versor_set(const double s0, const double x1, const double
const double square_module = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3);
if (1.0 - DP_TWO_EPSYLON <= square_module && square_module <= 1.0 + DP_TWO_EPSYLON) {
if (s0 > -1.0 + DP_EPSYLON) {
return;
}
dp_versor_reset(result);
return;
if (square_module < 1.0 - DP_TWO_EPSYLON || 1.0 + DP_TWO_EPSYLON < square_module) {
__dp_versor_normalize(square_module, result);
}
__dp_versor_normalize(square_module, result);
}
// ==================== Copy ==================== //
@ -268,24 +254,40 @@ static inline void dp_versor_make_inverted(const DPVersor* versor, DPVersor* res
static inline void sp_versor_combine(const SPVersor* second, const SPVersor* first, SPVersor* result)
{
sp_versor_set(
(second->_s0 * first->_s0 - second->_x1 * first->_x1) - (second->_x2 * first->_x2 + second->_x3 * first->_x3),
(second->_x1 * first->_s0 + second->_s0 * first->_x1) - (second->_x3 * first->_x2 - second->_x2 * first->_x3),
(second->_x2 * first->_s0 + second->_s0 * first->_x2) - (second->_x1 * first->_x3 - second->_x3 * first->_x1),
(second->_x3 * first->_s0 + second->_s0 * first->_x3) - (second->_x2 * first->_x1 - second->_x1 * first->_x2),
result
);
const float s0 = (second->_s0 * first->_s0 - second->_x1 * first->_x1) - (second->_x2 * first->_x2 + second->_x3 * first->_x3);
const float x1 = (second->_x1 * first->_s0 + second->_s0 * first->_x1) - (second->_x3 * first->_x2 - second->_x2 * first->_x3);
const float x2 = (second->_x2 * first->_s0 + second->_s0 * first->_x2) - (second->_x1 * first->_x3 - second->_x3 * first->_x1);
const float x3 = (second->_x3 * first->_s0 + second->_s0 * first->_x3) - (second->_x2 * first->_x1 - second->_x1 * first->_x2);
const float square_module = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3);
result->_s0 = s0;
result->_x1 = x1;
result->_x2 = x2;
result->_x3 = x3;
if (square_module < 1.0f - SP_TWO_EPSYLON || 1.0f + SP_TWO_EPSYLON < square_module) {
__sp_versor_normalize(square_module, result);
}
}
static inline void dp_versor_combine(const DPVersor* second, const DPVersor* first, DPVersor* result)
{
dp_versor_set(
(second->_s0 * first->_s0 - second->_x1 * first->_x1) - (second->_x2 * first->_x2 + second->_x3 * first->_x3),
(second->_x1 * first->_s0 + second->_s0 * first->_x1) - (second->_x3 * first->_x2 - second->_x2 * first->_x3),
(second->_x2 * first->_s0 + second->_s0 * first->_x2) - (second->_x1 * first->_x3 - second->_x3 * first->_x1),
(second->_x3 * first->_s0 + second->_s0 * first->_x3) - (second->_x2 * first->_x1 - second->_x1 * first->_x2),
result
);
const double s0 = (second->_s0 * first->_s0 - second->_x1 * first->_x1) - (second->_x2 * first->_x2 + second->_x3 * first->_x3);
const double x1 = (second->_x1 * first->_s0 + second->_s0 * first->_x1) - (second->_x3 * first->_x2 - second->_x2 * first->_x3);
const double x2 = (second->_x2 * first->_s0 + second->_s0 * first->_x2) - (second->_x1 * first->_x3 - second->_x3 * first->_x1);
const double x3 = (second->_x3 * first->_s0 + second->_s0 * first->_x3) - (second->_x2 * first->_x1 - second->_x1 * first->_x2);
const double square_module = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3);
result->_s0 = s0;
result->_x1 = x1;
result->_x2 = x2;
result->_x3 = x3;
if (square_module < 1.0 - DP_TWO_EPSYLON || 1.0 + DP_TWO_EPSYLON < square_module) {
__dp_versor_normalize(square_module, result);
}
}
// ================= Rotation3 ================== //