| OLD | NEW |
| 1 #ifndef Stats_DEFINED | 1 #ifndef Stats_DEFINED |
| 2 #define Stats_DEFINED | 2 #define Stats_DEFINED |
| 3 | 3 |
| 4 #include <math.h> | |
| 5 | |
| 6 #include "SkString.h" | 4 #include "SkString.h" |
| 7 #include "SkTSort.h" | 5 #include "SkTSort.h" |
| 8 | 6 |
| 9 #ifdef SK_BUILD_FOR_WIN | 7 #ifdef SK_BUILD_FOR_WIN |
| 10 static const char* kBars[] = { ".", "o", "O" }; | 8 static const char* kBars[] = { ".", "o", "O" }; |
| 11 #else | 9 #else |
| 12 static const char* kBars[] = { "▁", "▂", "▃", "▄", "▅", "▆", "▇", "█" }; | 10 static const char* kBars[] = { "▁", "▂", "▃", "▄", "▅", "▆", "▇", "█" }; |
| 13 #endif | 11 #endif |
| 14 | 12 |
| 15 struct Stats { | 13 struct Stats { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 43 if (min == max) { | 41 if (min == max) { |
| 44 // All samples are the same value. Don't divide by zero. | 42 // All samples are the same value. Don't divide by zero. |
| 45 plot.append(kBars[0]); | 43 plot.append(kBars[0]); |
| 46 continue; | 44 continue; |
| 47 } | 45 } |
| 48 | 46 |
| 49 double s = samples[i]; | 47 double s = samples[i]; |
| 50 s -= min; | 48 s -= min; |
| 51 s /= (max - min); | 49 s /= (max - min); |
| 52 s *= (SK_ARRAY_COUNT(kBars) - 1); | 50 s *= (SK_ARRAY_COUNT(kBars) - 1); |
| 53 const size_t bar = (size_t)round(s); | 51 const size_t bar = (size_t)(s + 0.5); |
| 54 SK_ALWAYSBREAK(bar < SK_ARRAY_COUNT(kBars)); | 52 SK_ALWAYSBREAK(bar < SK_ARRAY_COUNT(kBars)); |
| 55 plot.append(kBars[bar]); | 53 plot.append(kBars[bar]); |
| 56 } | 54 } |
| 57 } | 55 } |
| 58 | 56 |
| 59 double min; | 57 double min; |
| 60 double max; | 58 double max; |
| 61 double mean; // Estimate of population mean. | 59 double mean; // Estimate of population mean. |
| 62 double var; // Estimate of population variance. | 60 double var; // Estimate of population variance. |
| 63 double median; | 61 double median; |
| 64 SkString plot; // A single-line bar chart (_not_ histogram) of the samples. | 62 SkString plot; // A single-line bar chart (_not_ histogram) of the samples. |
| 65 }; | 63 }; |
| 66 | 64 |
| 67 #endif//Stats_DEFINED | 65 #endif//Stats_DEFINED |
| OLD | NEW |