src/Utils.cpp

changeset 98
1425bf3e18ed
parent 95
ef6048186cb3
child 102
b017001850df
--- a/src/Utils.cpp	Thu Mar 31 23:10:57 2022 +0200
+++ b/src/Utils.cpp	Fri Apr 01 14:58:57 2022 +0200
@@ -35,9 +35,16 @@
 }
 
 
+/**
+ * Often used formulas divide or multiply with 1.97 to convert between EBC and SRM.
+ * Almost all software in the world use this '1.97' formula.
+ * The only alternative I have seen is "srm = (ebc * 0.375 + 0.46)", and that has
+ * almost the same results as the formulas used in this program.
+ * These formulas come from the Dutch 'brouwhulp' program written by Adrie Otten.
+ */
 double Utils::ebc_to_srm(double ebc)
 {
-    double srm = -1.32303E-12 * pow(ebc, 4) - 0.00000000291515 * pow(ebc, 3) + 0.00000818515 * pow(ebc, 2) + 0.372038 * ebc + 0.596351;
+    double srm = -0.00000000000132303 * pow(ebc, 4) - 0.00000000291515 * pow(ebc, 3) + 0.00000818515 * pow(ebc, 2) + 0.372038 * ebc + 0.596351;
     if (ebc < 0 || srm < 0)
 	qDebug() << "ebc_to_srm(" << ebc << ") =" << srm;
     return srm;
@@ -46,7 +53,6 @@
 
 double Utils::srm_to_ebc(double srm)
 {
-    // Formule van Adrie Otten. brouwhulp.
     double ebc = round( 0.000000000176506 * pow(srm, 4) + 0.000000154529 * pow(srm, 3) - 0.000159428 * pow(srm, 2) + 2.68837 * srm - 1.6004 );
     if ((ebc < 0) || (srm < 0))
 	qDebug() << "srm_to_ebc(" << srm << ") =" << ebc;
@@ -54,7 +60,6 @@
 }
 
 
-
 QString Utils::hours_to_string(int hours)
 {
     int dd, hh;
@@ -96,6 +101,7 @@
     if (i > 299)
 	i = 299;
 
+    // A well known table for SRM to RGB conversion, range 0.1 to 30 SRM.
     const int R[] {
  250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, //0
  250, 250, 250, 250, 250, 249, 248, 247, 246, 245, 244, 243, 242, 241, 240, 239, 238, 237, 236, 235, //2
@@ -147,8 +153,8 @@
  15, 14, 14, 14, 13, 13, 13, 12, 12, 12, 11, 11, 11, 10, 10, 10, 9, 9, 9, 8,
  8, 8, 7, 7, 7, 6, 6, 6, 5, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2};
 
- result = QColor::fromRgb(R[i], G[i], B[i]);
- return result;
+    result = QColor::fromRgb(R[i], G[i], B[i]);
+    return result;
 }
 
 
@@ -158,3 +164,15 @@
 }
 
 
+QString Utils::srm_to_style(int srm)
+{
+    QColor color = srm_to_color(srm);
+    return QString("background-color: %1; color: %2;").arg(color.name()).arg((srm > 15) ? "#E0E1E3" : "#19232D");
+}
+
+
+QString Utils::ebc_to_style(int ebc)
+{
+    return srm_to_style(ebc_to_srm(ebc));
+}
+

mercurial