Задача 0000002: змена методов get_weighted_sum на append_scaled для векторов / Task 0000002: replacement of get_weighted_sum methods on append_scaled for vectors

This commit is contained in:
Andrey Pokidov 2024-11-19 14:38:57 +07:00
parent 791557fb94
commit 7bd9c07f17
4 changed files with 22 additions and 332 deletions

View file

@ -204,7 +204,7 @@ static inline void dp_quaternion_subtract(const DPQuaternion * minuend, const DP
result->x3 = minuend->x3 - subtrahend->x3;
}
// ================ Combination ================= //
// =============== Multiplication =============== //
static inline void sp_quaternion_multiply(const SPQuaternion* left, const SPQuaternion* right, SPQuaternion* result)
{

View file

@ -204,104 +204,18 @@ static inline void dp_vector2_divide(const DPVector2* dividend, const double div
result->x2 = dividend->x2 / divisor;
}
// ============= Weighed Sum of two ============= //
// ================ Append scaled =============== //
static inline void sp_vector2_get_weighted_sum2(
const float weight1, const SPVector2* vector1,
const float weight2, const SPVector2* vector2,
SPVector2* result
)
static inline void sp_vector2_append_scaled(SPVector2* basic_vector, const SPVector2* scalable_summand, const float scale)
{
result->x1 = vector1->x1 * weight1 + vector2->x1 * weight2;
result->x2 = vector1->x2 * weight1 + vector2->x2 * weight2;
basic_vector->x1 += scalable_summand->x1 * scale;
basic_vector->x2 += scalable_summand->x2 * scale;
}
static inline void dp_vector2_get_weighted_sum2(
const double weight1, const DPVector2* vector1,
const double weight2, const DPVector2* vector2,
DPVector2* result
)
static inline void dp_vector2_append_scaled(DPVector2* basic_vector, const DPVector2* scalable_summand, const double scale)
{
result->x1 = vector1->x1 * weight1 + vector2->x1 * weight2;
result->x2 = vector1->x2 * weight1 + vector2->x2 * weight2;
}
// ============ Weighed Sum of three ============ //
static inline void sp_vector2_get_weighted_sum3(
const float weight1, const SPVector2* vector1,
const float weight2, const SPVector2* vector2,
const float weight3, const SPVector2* vector3,
SPVector2* result
)
{
result->x1 = vector1->x1 * weight1 + vector2->x1 * weight2 + vector3->x1 * weight3;
result->x2 = vector1->x2 * weight1 + vector2->x2 * weight2 + vector3->x2 * weight3;
}
static inline void dp_vector2_get_weighted_sum3(
const double weight1, const DPVector2* vector1,
const double weight2, const DPVector2* vector2,
const double weight3, const DPVector2* vector3,
DPVector2* result
)
{
result->x1 = vector1->x1 * weight1 + vector2->x1 * weight2 + vector3->x1 * weight3;
result->x2 = vector1->x2 * weight1 + vector2->x2 * weight2 + vector3->x2 * weight3;
}
// ============ Weighed Sum of four ============= //
static inline void sp_vector2_get_weighted_sum4(
const float weight1, const SPVector2* vector1,
const float weight2, const SPVector2* vector2,
const float weight3, const SPVector2* vector3,
const float weight4, const SPVector2* vector4,
SPVector2* result
)
{
result->x1 = (vector1->x1 * weight1 + vector2->x1 * weight2) + (vector3->x1 * weight3 + vector4->x1 * weight4);
result->x2 = (vector1->x2 * weight1 + vector2->x2 * weight2) + (vector3->x2 * weight3 + vector4->x2 * weight4);
}
static inline void dp_vector2_get_weighted_sum4(
const double weight1, const DPVector2* vector1,
const double weight2, const DPVector2* vector2,
const double weight3, const DPVector2* vector3,
const double weight4, const DPVector2* vector4,
DPVector2* result
)
{
result->x1 = (vector1->x1 * weight1 + vector2->x1 * weight2) + (vector3->x1 * weight3 + vector4->x1 * weight4);
result->x2 = (vector1->x2 * weight1 + vector2->x2 * weight2) + (vector3->x2 * weight3 + vector4->x2 * weight4);
}
// ============ Weighed Sum of five ============= //
static inline void sp_vector2_get_weighted_sum5(
const float weight1, const SPVector2* vector1,
const float weight2, const SPVector2* vector2,
const float weight3, const SPVector2* vector3,
const float weight4, const SPVector2* vector4,
const float weight5, const SPVector2* vector5,
SPVector2* result
)
{
result->x1 = (vector1->x1 * weight1 + vector2->x1 * weight2) + (vector3->x1 * weight3 + vector4->x1 * weight4) + vector5->x1 * weight5;
result->x2 = (vector1->x2 * weight1 + vector2->x2 * weight2) + (vector3->x2 * weight3 + vector4->x2 * weight4) + vector5->x2 * weight5;
}
static inline void dp_vector2_get_weighted_sum5(
const double weight1, const DPVector2* vector1,
const double weight2, const DPVector2* vector2,
const double weight3, const DPVector2* vector3,
const double weight4, const DPVector2* vector4,
const double weight5, const DPVector2* vector5,
DPVector2* result
)
{
result->x1 = (vector1->x1 * weight1 + vector2->x1 * weight2) + (vector3->x1 * weight3 + vector4->x1 * weight4) + vector5->x1 * weight5;
result->x2 = (vector1->x2 * weight1 + vector2->x2 * weight2) + (vector3->x2 * weight3 + vector4->x2 * weight4) + vector5->x2 * weight5;
basic_vector->x1 += scalable_summand->x1 * scale;
basic_vector->x2 += scalable_summand->x2 * scale;
}
// ================== Average2 ================== //
@ -320,82 +234,18 @@ static inline void dp_vector2_get_mean2(const DPVector2* vector1, const DPVector
// ================== Average3 ================== //
static inline void sp_vector2_get_mean3(
const SPVector2* vector1,
const SPVector2* vector2,
const SPVector2* vector3,
SPVector2* result
)
static inline void sp_vector2_get_mean3(const SPVector2* vector1, const SPVector2* vector2, const SPVector2* vector3, SPVector2* result)
{
result->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * SP_ONE_THIRD;
result->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * SP_ONE_THIRD;
}
static inline void dp_vector2_get_mean3(
const DPVector2* vector1,
const DPVector2* vector2,
const DPVector2* vector3,
DPVector2* result
)
static inline void dp_vector2_get_mean3(const DPVector2* vector1, const DPVector2* vector2, const DPVector2* vector3, DPVector2* result)
{
result->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * DP_ONE_THIRD;
result->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * DP_ONE_THIRD;
}
// ================== Average4 ================== //
static inline void sp_vector2_get_mean4(
const SPVector2* vector1,
const SPVector2* vector2,
const SPVector2* vector3,
const SPVector2* vector4,
SPVector2* result
)
{
result->x1 = ((vector1->x1 + vector2->x1) + (vector3->x1 + vector4->x1)) * 0.25f;
result->x2 = ((vector1->x2 + vector2->x2) + (vector3->x2 + vector4->x2)) * 0.25f;
}
static inline void dp_vector2_get_mean4(
const DPVector2* vector1,
const DPVector2* vector2,
const DPVector2* vector3,
const DPVector2* vector4,
DPVector2* result
)
{
result->x1 = ((vector1->x1 + vector2->x1) + (vector3->x1 + vector4->x1)) * 0.25;
result->x2 = ((vector1->x2 + vector2->x2) + (vector3->x2 + vector4->x2)) * 0.25;
}
// ================== Average5 ================== //
static inline void sp_vector2_get_mean5(
const SPVector2* vector1,
const SPVector2* vector2,
const SPVector2* vector3,
const SPVector2* vector4,
const SPVector2* vector5,
SPVector2* result
)
{
result->x1 = ((vector1->x1 + vector2->x1) + (vector3->x1 + vector4->x1) + vector5->x1) * 0.2f;
result->x2 = ((vector1->x2 + vector2->x2) + (vector3->x2 + vector4->x2) + vector5->x2) * 0.2f;
}
static inline void dp_vector2_get_mean5(
const DPVector2* vector1,
const DPVector2* vector2,
const DPVector2* vector3,
const DPVector2* vector4,
const DPVector2* vector5,
DPVector2* result
)
{
result->x1 = ((vector1->x1 + vector2->x1) + (vector3->x1 + vector4->x1) + vector5->x1) * 0.2;
result->x2 = ((vector1->x2 + vector2->x2) + (vector3->x2 + vector4->x2) + vector5->x2) * 0.2;
}
// =============== Scalar Product =============== //
static inline float sp_vector2_scalar(const SPVector2* vector1, const SPVector2* vector2)

View file

@ -226,112 +226,20 @@ static inline void dp_vector3_divide(const DPVector3* dividend, const double div
result->x3 = dividend->x3 / divisor;
}
// ============= Weighed Sum of two ============= //
// ================ Append scaled =============== //
static inline void sp_vector3_get_weighted_sum2(
const float weight1, const SPVector3* vector1,
const float weight2, const SPVector3* vector2,
SPVector3* result
)
static inline void sp_vector3_append_scaled(SPVector3* basic_vector, const SPVector3* scalable_summand, const float scale)
{
result->x1 = vector1->x1 * weight1 + vector2->x1 * weight2;
result->x2 = vector1->x2 * weight1 + vector2->x2 * weight2;
result->x3 = vector1->x3 * weight1 + vector2->x3 * weight2;
basic_vector->x1 += scalable_summand->x1 * scale;
basic_vector->x2 += scalable_summand->x2 * scale;
basic_vector->x3 += scalable_summand->x3 * scale;
}
static inline void dp_vector3_get_weighted_sum2(
const double weight1, const DPVector3* vector1,
const double weight2, const DPVector3* vector2,
DPVector3* result
)
static inline void dp_vector3_append_scaled(DPVector3* basic_vector, const DPVector3* scalable_summand, const double scale)
{
result->x1 = vector1->x1 * weight1 + vector2->x1 * weight2;
result->x2 = vector1->x2 * weight1 + vector2->x2 * weight2;
result->x3 = vector1->x3 * weight1 + vector2->x3 * weight2;
}
// ============ Weighed Sum of three ============ //
static inline void sp_vector3_get_weighted_sum3(
const float weight1, const SPVector3* vector1,
const float weight2, const SPVector3* vector2,
const float weight3, const SPVector3* vector3,
SPVector3* result
)
{
result->x1 = vector1->x1 * weight1 + vector2->x1 * weight2 + vector3->x1 * weight3;
result->x2 = vector1->x2 * weight1 + vector2->x2 * weight2 + vector3->x2 * weight3;
result->x3 = vector1->x3 * weight1 + vector2->x3 * weight2 + vector3->x3 * weight3;
}
static inline void dp_vector3_get_weighted_sum3(
const double weight1, const DPVector3* vector1,
const double weight2, const DPVector3* vector2,
const double weight3, const DPVector3* vector3,
DPVector3* result
)
{
result->x1 = vector1->x1 * weight1 + vector2->x1 * weight2 + vector3->x1 * weight3;
result->x2 = vector1->x2 * weight1 + vector2->x2 * weight2 + vector3->x2 * weight3;
result->x3 = vector1->x3 * weight1 + vector2->x3 * weight2 + vector3->x3 * weight3;
}
// ============ Weighed Sum of four ============= //
static inline void sp_vector3_get_weighted_sum4(
const float weight1, const SPVector3* vector1,
const float weight2, const SPVector3* vector2,
const float weight3, const SPVector3* vector3,
const float weight4, const SPVector3* vector4,
SPVector3* result
)
{
result->x1 = (vector1->x1 * weight1 + vector2->x1 * weight2) + (vector3->x1 * weight3 + vector4->x1 * weight4);
result->x2 = (vector1->x2 * weight1 + vector2->x2 * weight2) + (vector3->x2 * weight3 + vector4->x2 * weight4);
result->x3 = (vector1->x3 * weight1 + vector2->x3 * weight2) + (vector3->x3 * weight3 + vector4->x3 * weight4);
}
static inline void dp_vector3_get_weighted_sum4(
const double weight1, const DPVector3* vector1,
const double weight2, const DPVector3* vector2,
const double weight3, const DPVector3* vector3,
const double weight4, const DPVector3* vector4,
DPVector3* result
)
{
result->x1 = (vector1->x1 * weight1 + vector2->x1 * weight2) + (vector3->x1 * weight3 + vector4->x1 * weight4);
result->x2 = (vector1->x2 * weight1 + vector2->x2 * weight2) + (vector3->x2 * weight3 + vector4->x2 * weight4);
result->x3 = (vector1->x3 * weight1 + vector2->x3 * weight2) + (vector3->x3 * weight3 + vector4->x3 * weight4);
}
// ============ Weighed Sum of five ============= //
static inline void sp_vector3_get_weighted_sum5(
const float weight1, const SPVector3* vector1,
const float weight2, const SPVector3* vector2,
const float weight3, const SPVector3* vector3,
const float weight4, const SPVector3* vector4,
const float weight5, const SPVector3* vector5,
SPVector3* result
)
{
result->x1 = (vector1->x1 * weight1 + vector2->x1 * weight2) + (vector3->x1 * weight3 + vector4->x1 * weight4) + vector5->x1 * weight5;
result->x2 = (vector1->x2 * weight1 + vector2->x2 * weight2) + (vector3->x2 * weight3 + vector4->x2 * weight4) + vector5->x2 * weight5;
result->x3 = (vector1->x3 * weight1 + vector2->x3 * weight2) + (vector3->x3 * weight3 + vector4->x3 * weight4) + vector5->x3 * weight5;
}
static inline void dp_vector3_get_weighted_sum5(
const double weight1, const DPVector3* vector1,
const double weight2, const DPVector3* vector2,
const double weight3, const DPVector3* vector3,
const double weight4, const DPVector3* vector4,
const double weight5, const DPVector3* vector5,
DPVector3* result
)
{
result->x1 = (vector1->x1 * weight1 + vector2->x1 * weight2) + (vector3->x1 * weight3 + vector4->x1 * weight4) + vector5->x1 * weight5;
result->x2 = (vector1->x2 * weight1 + vector2->x2 * weight2) + (vector3->x2 * weight3 + vector4->x2 * weight4) + vector5->x2 * weight5;
result->x3 = (vector1->x3 * weight1 + vector2->x3 * weight2) + (vector3->x3 * weight3 + vector4->x3 * weight4) + vector5->x3 * weight5;
basic_vector->x1 += scalable_summand->x1 * scale;
basic_vector->x2 += scalable_summand->x2 * scale;
basic_vector->x3 += scalable_summand->x3 * scale;
}
// ================== Average2 ================== //
@ -352,88 +260,20 @@ static inline void dp_vector3_get_mean2(const DPVector3* vector1, const DPVector
// ================== Average3 ================== //
static inline void sp_vector3_get_mean3(
const SPVector3* vector1,
const SPVector3* vector2,
const SPVector3* vector3,
SPVector3* result
)
static inline void sp_vector3_get_mean3(const SPVector3* vector1, const SPVector3* vector2, const SPVector3* vector3, SPVector3* result)
{
result->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * SP_ONE_THIRD;
result->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * SP_ONE_THIRD;
result->x3 = (vector1->x3 + vector2->x3 + vector3->x3) * SP_ONE_THIRD;
}
static inline void dp_vector3_get_mean3(
const DPVector3* vector1,
const DPVector3* vector2,
const DPVector3* vector3,
DPVector3* result
)
static inline void dp_vector3_get_mean3(const DPVector3* vector1, const DPVector3* vector2, const DPVector3* vector3, DPVector3* result)
{
result->x1 = (vector1->x1 + vector2->x1 + vector3->x1) * DP_ONE_THIRD;
result->x2 = (vector1->x2 + vector2->x2 + vector3->x2) * DP_ONE_THIRD;
result->x3 = (vector1->x3 + vector2->x3 + vector3->x3) * DP_ONE_THIRD;
}
// ================== Average4 ================== //
static inline void sp_vector3_get_mean4(
const SPVector3* vector1,
const SPVector3* vector2,
const SPVector3* vector3,
const SPVector3* vector4,
SPVector3* result
)
{
result->x1 = ((vector1->x1 + vector2->x1) + (vector3->x1 + vector4->x1)) * 0.25f;
result->x2 = ((vector1->x2 + vector2->x2) + (vector3->x2 + vector4->x2)) * 0.25f;
result->x3 = ((vector1->x3 + vector2->x3) + (vector3->x3 + vector4->x3)) * 0.25f;
}
static inline void dp_vector3_get_mean4(
const DPVector3* vector1,
const DPVector3* vector2,
const DPVector3* vector3,
const DPVector3* vector4,
DPVector3* result
)
{
result->x1 = ((vector1->x1 + vector2->x1) + (vector3->x1 + vector4->x1)) * 0.25;
result->x2 = ((vector1->x2 + vector2->x2) + (vector3->x2 + vector4->x2)) * 0.25;
result->x3 = ((vector1->x3 + vector2->x3) + (vector3->x3 + vector4->x3)) * 0.25;
}
// ================== Average5 ================== //
static inline void sp_vector3_get_mean5(
const SPVector3* vector1,
const SPVector3* vector2,
const SPVector3* vector3,
const SPVector3* vector4,
const SPVector3* vector5,
SPVector3* result
)
{
result->x1 = ((vector1->x1 + vector2->x1) + (vector3->x1 + vector4->x1) + vector5->x1) * 0.2f;
result->x2 = ((vector1->x2 + vector2->x2) + (vector3->x2 + vector4->x2) + vector5->x2) * 0.2f;
result->x3 = ((vector1->x3 + vector2->x3) + (vector3->x3 + vector4->x3) + vector5->x3) * 0.2f;
}
static inline void dp_vector3_get_mean5(
const DPVector3* vector1,
const DPVector3* vector2,
const DPVector3* vector3,
const DPVector3* vector4,
const DPVector3* vector5,
DPVector3* result
)
{
result->x1 = ((vector1->x1 + vector2->x1) + (vector3->x1 + vector4->x1) + vector5->x1) * 0.2;
result->x2 = ((vector1->x2 + vector2->x2) + (vector3->x2 + vector4->x2) + vector5->x2) * 0.2;
result->x3 = ((vector1->x3 + vector2->x3) + (vector3->x3 + vector4->x3) + vector5->x3) * 0.2;
}
// =============== Scalar Product =============== //
static inline float sp_vector3_scalar(const SPVector3* vector1, const SPVector3* vector2)

View file

@ -147,7 +147,7 @@ static inline void dp_versor_set(const double s0, const double x1, const double
return;
}
__sp_versor_normalize(square_module, result);
__dp_versor_normalize(square_module, result);
}
// ==================== Copy ==================== //