Simplify curve fitting code a bit

This commit is contained in:
korenkonder
2023-04-15 14:05:57 +03:00
parent be9ec19fa1
commit 9129da5b2d
3 changed files with 12 additions and 25 deletions
+3 -3
View File
@@ -306,12 +306,12 @@ namespace Glitter {
double_t t1_accum = 0.0;
double_t t2_accum = 0.0;
for (size_t j = 1; j < i - 1; j++) {
float_t _t1 = (float_t)(j * step) / (float_t)(i * step);
float_t _t2 = (float_t)((j + 1) * step) / (float_t)(i * step);
float_t _t1 = (float_t)(int32_t)((j + 0) * step) / (float_t)(int32_t)(i * step);
float_t _t2 = (float_t)(int32_t)((j + 1) * step) / (float_t)(int32_t)(i * step);
float_t t1_1 = _t1 - 1.0f;
float_t t2_1 = _t2 - 1.0f;
float_t t1_t2_1 = a[j] - a[0] - (_t1 * 2.0f - 3.0f) * (_t1 * _t1) * (a[0] - a[i]);
float_t t1_t2_1 = a[j + 0] - a[0] - (_t1 * 2.0f - 3.0f) * (_t1 * _t1) * (a[0] - a[i]);
float_t t1_t2_2 = a[j + 1] - a[0] - (_t2 * 2.0f - 3.0f) * (_t2 * _t2) * (a[0] - a[i]);
t1_t2_1 /= t1_1 * _t1;
t1_t2_2 /= t2_1 * _t2;
+4 -11
View File
@@ -7,14 +7,8 @@
void interpolate_chs_reverse_value(float_t* arr, size_t length,
float_t& t1, float_t& t2, size_t f1, size_t f2, size_t f) {
t1 = 0.0f;
t2 = 0.0f;
if (!arr || length < 2 || f - f1 + 1 >= length || f < 1 || f < f1 || f + 2 > f2)
return;
float_t _t1 = (float_t)(f - f1) / (float_t)(f2 - f1);
float_t _t2 = (float_t)(f - f1 + 1) / (float_t)(f2 - f1);
float_t _t1 = (float_t)(int32_t)(f - f1 + 0) / (float_t)(int32_t)(f2 - f1);
float_t _t2 = (float_t)(int32_t)(f - f1 + 1) / (float_t)(int32_t)(f2 - f1);
float_t t1_2 = _t1 * _t1;
float_t t2_2 = _t2 * _t2;
float_t t1_3 = t1_2 * _t1;
@@ -33,9 +27,8 @@ void interpolate_chs_reverse_value(float_t* arr, size_t length,
float_t h11_1 = t1_3 - t1_2;
float_t h11_2 = t2_3 - t2_2;
float_t t1_t2_1 = (arr[f] - h00_1 * arr[f1] - h01_1 * arr[f2]);
float_t t1_t2_2 = (arr[f + 1] - h00_2 * arr[f1] - h01_2 * arr[f2]);
float_t t1_t2_1 = arr[f + 0] - h00_1 * arr[f1] - h01_1 * arr[f2];
float_t t1_t2_2 = arr[f + 1] - h00_2 * arr[f1] - h01_2 * arr[f2];
t1_t2_1 /= (t1_2 - _t1) * (t2_2 - _t2);
t1_t2_2 /= (t1_2 - _t1) * (t2_2 - _t2);
+5 -11
View File
@@ -111,7 +111,7 @@ void mot_set::unpack_file(prj::shared_ptr<prj::stack_allocator> alloc, const voi
mot_modern_read_inner(this, alloc, s);
}
inline static float_t interpolate_mot_value(float_t p1, float_t p2,
static float_t interpolate_mot_value(float_t p1, float_t p2,
float_t t1, float_t t2, float_t f1, float_t f2, float_t f) {
float_t df = f - f1;
float_t t = df / (f2 - f1);
@@ -120,20 +120,14 @@ inline static float_t interpolate_mot_value(float_t p1, float_t p2,
+ (t * 2.0f - 3.0f) * (t * t) * (p1 - p2) + p1;
}
inline static void interpolate_mot_reverse_value(float_t* arr, size_t length,
static void interpolate_mot_reverse_value(float_t* arr, size_t length,
float_t& t1, float_t& t2, size_t f1, size_t f2, size_t f) {
t1 = 0.0f;
t2 = 0.0f;
if (!arr || length < 2 || f - f1 + 1 >= length || f < 1 || f < f1 || f + 2 > f2)
return;
float_t _t1 = (float_t)(f - f1) / (float_t)(f2 - f1);
float_t _t2 = (float_t)(f - f1 + 1) / (float_t)(f2 - f1);
float_t _t1 = (float_t)(int32_t)(f - f1 + 0) / (float_t)(int32_t)(f2 - f1);
float_t _t2 = (float_t)(int32_t)(f - f1 + 1) / (float_t)(int32_t)(f2 - f1);
float_t t1_1 = _t1 - 1.0f;
float_t t2_1 = _t2 - 1.0f;
float_t t1_t2_1 = arr[f] - arr[f1] - (_t1 * 2.0f - 3.0f) * (_t1 * _t1) * (arr[f1] - arr[f2]);
float_t t1_t2_1 = arr[f + 0] - arr[f1] - (_t1 * 2.0f - 3.0f) * (_t1 * _t1) * (arr[f1] - arr[f2]);
float_t t1_t2_2 = arr[f + 1] - arr[f1] - (_t2 * 2.0f - 3.0f) * (_t2 * _t2) * (arr[f1] - arr[f2]);
t1_t2_1 /= t1_1 * _t1;
t1_t2_2 /= t2_1 * _t2;