Extend last lines to capture extreme edges
This commit is contained in:
@@ -17467,23 +17467,33 @@
|
||||
" lut.writelines(f\" float values[{len(alts_index) + len(ext_alts_index)}][{len(weights_index)}][1000] = {{\\n\")\n",
|
||||
" for alt in ext_alts_index:\n",
|
||||
" lut.writelines(\" {\\n\")\n",
|
||||
" highest_weight = 0\n",
|
||||
" for weight in weights_index:\n",
|
||||
" try:\n",
|
||||
" current_list = ext_curves[tips][alt][weight][0]\n",
|
||||
" mmo = ext_curves[tips][alt][weight][0][999]\n",
|
||||
" lut.writelines(\" {\" + \",\".join(\"{:.3f}f\".format(round(min(x, mmo), 3)) for x in current_list.tolist()) + \"},\\n\")\n",
|
||||
" highest_weight = weight\n",
|
||||
" except IndexError:\n",
|
||||
" lut.writelines(\" {\" + \",\".join([\"-1\".format(x) for x in range(0, 1000)]) + \"},\\n\")\n",
|
||||
" current_list = ext_curves[tips][alt][highest_weight][0]\n",
|
||||
" mmo = ext_curves[tips][alt][highest_weight][0][999]\n",
|
||||
" lut.writelines(\" {\" + \",\".join(\"{:.3f}f\".format(round(min(x, mmo), 3)) for x in current_list.tolist()) + \"},\\n\")\n",
|
||||
" #lut.writelines(\" {\" + \",\".join([\"-1\".format(x) for x in range(0, 1000)]) + \"},\\n\")\n",
|
||||
" lut.writelines(\" },\\n\")\n",
|
||||
" for alt in alts_index:\n",
|
||||
" lut.writelines(\" {\\n\")\n",
|
||||
" highest_weight = 0\n",
|
||||
" for weight in weights_index:\n",
|
||||
" try:\n",
|
||||
" current_list = curves[tips][alt][weight][0]\n",
|
||||
" mmo = curves[tips][alt][weight][0][999]\n",
|
||||
" lut.writelines(\" {\" + \",\".join(\"{:.3f}f\".format(round(min(x, mmo), 3)) for x in current_list.tolist()) + \"},\\n\")\n",
|
||||
" highest_weight = weight\n",
|
||||
" except IndexError:\n",
|
||||
" lut.writelines(\" {\" + \",\".join([\"-1\".format(x) for x in range(0, 1000)]) + \"},\\n\")\n",
|
||||
" current_list = curves[tips][alt][highest_weight][0]\n",
|
||||
" mmo = curves[tips][alt][highest_weight][0][999]\n",
|
||||
" lut.writelines(\" {\" + \",\".join(\"{:.3f}f\".format(round(min(x, mmo), 3)) for x in current_list.tolist()) + \"},\\n\")\n",
|
||||
" # lut.writelines(\" {\" + \",\".join([\"-1\".format(x) for x in range(0, 1000)]) + \"},\\n\")\n",
|
||||
" lut.writelines(\" },\\n\")\n",
|
||||
" lut.writelines(\"};\\n};\\n\\n\")\n",
|
||||
"\n",
|
||||
|
||||
+37
-37
File diff suppressed because one or more lines are too long
+37
-37
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+6
-18
@@ -67,23 +67,23 @@ std::tuple<int, int, float> boundWeight(int weight) {
|
||||
float boundMMO(float totalFuel) {
|
||||
float percent = (int)round(1.57613580e-02 * totalFuel - 1.51221174e+02);
|
||||
|
||||
return percent <= MIN_TIP ? 0 :
|
||||
percent >= MAX_TIP ? 1 :
|
||||
(percent - MIN_TIP) / TIP_STP;
|
||||
return percent <= MIN_TIP ? 0.0f :
|
||||
percent >= MAX_TIP ? 1.0f :
|
||||
(float)std::clamp((percent - MIN_TIP) / TIP_STP, 0.0, 1.0);
|
||||
}
|
||||
|
||||
/// @brief Conversion from FL to index of file
|
||||
/// @param flightLevel FL to convert
|
||||
/// @return Index in file
|
||||
int flightLevel2Index(int flightLevel) {
|
||||
return (flightLevel - MIN_FL) / FL_STP;
|
||||
return std::clamp((flightLevel - MIN_FL) / FL_STP, 0, 21);
|
||||
}
|
||||
|
||||
/// @brief Conversion from tonnes to index of file
|
||||
/// @param weight Weight in tonnes to convert
|
||||
/// @return Index in file
|
||||
int weight2Index(int weight) {
|
||||
return (weight - MIN_WGT) / WGT_STP;
|
||||
return std::clamp((weight - MIN_WGT) / WGT_STP, 0, 15);
|
||||
}
|
||||
|
||||
/// @brief Linear interpolate between lower and upper
|
||||
@@ -100,7 +100,7 @@ float interp(float lower, float upper, float ratio) {
|
||||
/// @param weight Weight in kilogrammes
|
||||
/// @param totalFuel Total fuel in kilogrammes EXCLUDING BALLAST
|
||||
/// @param ci CI
|
||||
/// @return Mach corresponding to CI. Returns -1 if not possible
|
||||
/// @return Mach corresponding to CI
|
||||
float ci2mach(float altitude, float weight, float totalFuel, int ci) {
|
||||
// Some fallback assumptions for extreme cases
|
||||
// Clamp weight, for <140 we use 140
|
||||
@@ -127,12 +127,6 @@ float ci2mach(float altitude, float weight, float totalFuel, int ci) {
|
||||
int lowerWgtIndex = weight2Index(lowerWgt);
|
||||
int upperWgtIndex = weight2Index(upperWgt);
|
||||
|
||||
// Outside of the maximum indicies, safeguard us from out-of-bounds
|
||||
if (lowerFlIndex > 21 || upperFlIndex > 21 || lowerWgtIndex > 15 || upperWgtIndex > 15 ||
|
||||
lowerFlIndex < 0 || upperFlIndex < 0 || lowerWgtIndex < 0 || upperWgtIndex < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
const float* lowerFlLowerWgtCis85 = ci2Mach_85->values[lowerFlIndex][lowerWgtIndex];
|
||||
const float* lowerFlUpperWgtCis85 = ci2Mach_85->values[lowerFlIndex][upperWgtIndex];
|
||||
const float* upperFlLowerWgtCis85 = ci2Mach_85->values[upperFlIndex][lowerWgtIndex];
|
||||
@@ -151,12 +145,6 @@ float ci2mach(float altitude, float weight, float totalFuel, int ci) {
|
||||
float upperFlLowerWgtMach87 = upperFlLowerWgtCis87[ci];
|
||||
float upperFlUpperWgtMach87 = upperFlUpperWgtCis87[ci];
|
||||
|
||||
// Outside operational limits
|
||||
if (upperFlUpperWgtMach87 < 0 || upperFlUpperWgtMach85 < 0 || upperFlLowerWgtMach87 < 0 || upperFlLowerWgtMach85 < 0 ||
|
||||
lowerFlUpperWgtMach87 < 0 || lowerFlUpperWgtMach85 < 0 || lowerFlLowerWgtMach87 < 0 || lowerFlLowerWgtMach85 < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
float ratioedLowerFlMach85 = interp(lowerFlLowerWgtMach85, lowerFlUpperWgtMach85, ratioWgt);
|
||||
float ratioedUpperFlMach85 = interp(upperFlLowerWgtMach85, upperFlUpperWgtMach85, ratioWgt);
|
||||
float ratioedMach85 = interp(ratioedLowerFlMach85, ratioedUpperFlMach85, ratioFl);
|
||||
|
||||
Reference in New Issue
Block a user