From 686ce639a0f259bbe10aab898d4adb71a7dcbc6e Mon Sep 17 00:00:00 2001 From: Timothy Stack Date: Tue, 2 Oct 2018 22:01:18 -0700 Subject: [PATCH] [build] use cmath instead of math.h Defect Number: Reviewed By: Testing Done: --- src/hist_source.cc | 5 ----- src/hist_source.hh | 5 ++--- src/listview_curses.cc | 3 ++- src/lnav.cc | 1 - src/lnav_util.hh | 1 - src/log_accel.hh | 6 +++--- src/log_format.cc | 1 - src/spectro_source.hh | 1 - src/textview_curses.cc | 2 +- src/view_curses.cc | 44 ++++++++++++++++++++++++++++++++++++++++++ src/view_curses.hh | 42 ++-------------------------------------- 11 files changed, 54 insertions(+), 57 deletions(-) diff --git a/src/hist_source.cc b/src/hist_source.cc index bc7e4860..d797573f 100644 --- a/src/hist_source.cc +++ b/src/hist_source.cc @@ -29,11 +29,6 @@ #include "config.h" -#include -#include - -#include - #include "lnav_util.hh" #include "hist_source.hh" diff --git a/src/hist_source.hh b/src/hist_source.hh index 701fd565..d32fdf49 100644 --- a/src/hist_source.hh +++ b/src/hist_source.hh @@ -32,9 +32,8 @@ #ifndef __hist_source_hh #define __hist_source_hh -#include - #include +#include #include #include #include @@ -269,7 +268,7 @@ public: }; double width() const { - return fabs(this->bs_max_value - this->bs_min_value); + return std::fabs(this->bs_max_value - this->bs_min_value); }; void update(double value) { diff --git a/src/listview_curses.cc b/src/listview_curses.cc index cc696b88..2caee147 100644 --- a/src/listview_curses.cc +++ b/src/listview_curses.cc @@ -32,9 +32,10 @@ #include "config.h" #include -#include #include +#include + #include "lnav_log.hh" #include "listview_curses.hh" diff --git a/src/lnav.cc b/src/lnav.cc index 02e3dbdb..c7b10bed 100644 --- a/src/lnav.cc +++ b/src/lnav.cc @@ -37,7 +37,6 @@ #include #include -#include #include #include #include diff --git a/src/lnav_util.hh b/src/lnav_util.hh index f7afe54b..c05c11fd 100644 --- a/src/lnav_util.hh +++ b/src/lnav_util.hh @@ -34,7 +34,6 @@ #ifndef __lnav_util_hh #define __lnav_util_hh -#include #include #include #include diff --git a/src/log_accel.hh b/src/log_accel.hh index af59296b..0b2d8df5 100644 --- a/src/log_accel.hh +++ b/src/log_accel.hh @@ -10,7 +10,7 @@ * list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. + * and/or otherlist materials provided with the distribution. * * Neither the name of Timothy Stack nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -32,9 +32,9 @@ #ifndef __log_accel_h #define __log_accel_h -#include #include +#include #include #include "lnav_log.hh" @@ -131,7 +131,7 @@ public: double avg_accel = this->get_avg_accel(); direction_t retval; - if (::fabs(avg_accel) <= THRESHOLD) { + if (std::fabs(avg_accel) <= THRESHOLD) { retval = A_STEADY; } else if (avg_accel < 0.0) { diff --git a/src/log_format.cc b/src/log_format.cc index bc0617ef..2652b42d 100644 --- a/src/log_format.cc +++ b/src/log_format.cc @@ -29,7 +29,6 @@ #include "config.h" -#include #include #include #include diff --git a/src/spectro_source.hh b/src/spectro_source.hh index 69712d8b..28aa958c 100644 --- a/src/spectro_source.hh +++ b/src/spectro_source.hh @@ -32,7 +32,6 @@ #ifndef __spectro_source_hh #define __spectro_source_hh -#include #include #include diff --git a/src/textview_curses.cc b/src/textview_curses.cc index a73bb682..27d104fd 100644 --- a/src/textview_curses.cc +++ b/src/textview_curses.cc @@ -84,7 +84,7 @@ void textview_curses::reload_data(void) if (this->tc_sub_source != nullptr) { this->tc_sub_source->text_update_marks(this->tc_bookmarks); } - this->listview_curses::reload_data(); + listview_curses::reload_data(); } void textview_curses::grep_begin(grep_proc &gp, vis_line_t start, vis_line_t stop) diff --git a/src/view_curses.cc b/src/view_curses.cc index 83b30866..55c910d5 100644 --- a/src/view_curses.cc +++ b/src/view_curses.cc @@ -31,6 +31,7 @@ #include "config.h" +#include #include #include "auto_mem.hh" @@ -718,3 +719,46 @@ int view_colors::ensure_color_pair(const rgb_color &rgb_fg, const rgb_color &rgb xterm_colors.match_color(rgb_fg), rgb_bg.empty() ? (short) COLOR_BLACK : xterm_colors.match_color(rgb_bg)); } + +lab_color::lab_color(const rgb_color &rgb) +{ + double r = rgb.rc_r / 255.0, + g = rgb.rc_g / 255.0, + b = rgb.rc_b / 255.0, + x, y, z; + + r = (r > 0.04045) ? pow((r + 0.055) / 1.055, 2.4) : r / 12.92; + g = (g > 0.04045) ? pow((g + 0.055) / 1.055, 2.4) : g / 12.92; + b = (b > 0.04045) ? pow((b + 0.055) / 1.055, 2.4) : b / 12.92; + + x = (r * 0.4124 + g * 0.3576 + b * 0.1805) / 0.95047; + y = (r * 0.2126 + g * 0.7152 + b * 0.0722) / 1.00000; + z = (r * 0.0193 + g * 0.1192 + b * 0.9505) / 1.08883; + + x = (x > 0.008856) ? pow(x, 1.0/3.0) : (7.787 * x) + 16.0/116.0; + y = (y > 0.008856) ? pow(y, 1.0/3.0) : (7.787 * y) + 16.0/116.0; + z = (z > 0.008856) ? pow(z, 1.0/3.0) : (7.787 * z) + 16.0/116.0; + + this->lc_l = (116.0 * y) - 16; + this->lc_a = 500.0 * (x - y); + this->lc_b = 200.0 * (y - z); +} + +double lab_color::deltaE(const lab_color &other) const +{ + double deltaL = this->lc_l - other.lc_l; + double deltaA = this->lc_a - other.lc_a; + double deltaB = this->lc_b - other.lc_b; + double c1 = sqrt(this->lc_a * this->lc_a + this->lc_b * this->lc_b); + double c2 = sqrt(other.lc_a * other.lc_a + other.lc_b * other.lc_b); + double deltaC = c1 - c2; + double deltaH = deltaA * deltaA + deltaB * deltaB - deltaC * deltaC; + deltaH = deltaH < 0.0 ? 0.0 : sqrt(deltaH); + double sc = 1.0 + 0.045 * c1; + double sh = 1.0 + 0.015 * c1; + double deltaLKlsl = deltaL / (1.0); + double deltaCkcsc = deltaC / (sc); + double deltaHkhsh = deltaH / (sh); + double i = deltaLKlsl * deltaLKlsl + deltaCkcsc * deltaCkcsc + deltaHkhsh * deltaHkhsh; + return i < 0.0 ? 0.0 : sqrt(i); +} diff --git a/src/view_curses.hh b/src/view_curses.hh index 4f7656e9..e9fc9023 100644 --- a/src/view_curses.hh +++ b/src/view_curses.hh @@ -35,7 +35,6 @@ #include "config.h" #include -#include #include #include #include @@ -309,46 +308,9 @@ struct lab_color { lab_color() : lc_l(0), lc_a(0), lc_b(0) { }; - lab_color(const rgb_color &rgb) { - double r = rgb.rc_r / 255.0, - g = rgb.rc_g / 255.0, - b = rgb.rc_b / 255.0, - x, y, z; + lab_color(const rgb_color &rgb); - r = (r > 0.04045) ? pow((r + 0.055) / 1.055, 2.4) : r / 12.92; - g = (g > 0.04045) ? pow((g + 0.055) / 1.055, 2.4) : g / 12.92; - b = (b > 0.04045) ? pow((b + 0.055) / 1.055, 2.4) : b / 12.92; - - x = (r * 0.4124 + g * 0.3576 + b * 0.1805) / 0.95047; - y = (r * 0.2126 + g * 0.7152 + b * 0.0722) / 1.00000; - z = (r * 0.0193 + g * 0.1192 + b * 0.9505) / 1.08883; - - x = (x > 0.008856) ? pow(x, 1.0/3.0) : (7.787 * x) + 16.0/116.0; - y = (y > 0.008856) ? pow(y, 1.0/3.0) : (7.787 * y) + 16.0/116.0; - z = (z > 0.008856) ? pow(z, 1.0/3.0) : (7.787 * z) + 16.0/116.0; - - this->lc_l = (116.0 * y) - 16; - this->lc_a = 500.0 * (x - y); - this->lc_b = 200.0 * (y - z); - } - - double deltaE(const lab_color &other) const { - double deltaL = this->lc_l - other.lc_l; - double deltaA = this->lc_a - other.lc_a; - double deltaB = this->lc_b - other.lc_b; - double c1 = sqrt(this->lc_a * this->lc_a + this->lc_b * this->lc_b); - double c2 = sqrt(other.lc_a * other.lc_a + other.lc_b * other.lc_b); - double deltaC = c1 - c2; - double deltaH = deltaA * deltaA + deltaB * deltaB - deltaC * deltaC; - deltaH = deltaH < 0.0 ? 0.0 : sqrt(deltaH); - double sc = 1.0 + 0.045 * c1; - double sh = 1.0 + 0.015 * c1; - double deltaLKlsl = deltaL / (1.0); - double deltaCkcsc = deltaC / (sc); - double deltaHkhsh = deltaH / (sh); - double i = deltaLKlsl * deltaLKlsl + deltaCkcsc * deltaCkcsc + deltaHkhsh * deltaHkhsh; - return i < 0.0 ? 0.0 : sqrt(i); - } + double deltaE(const lab_color &other) const; lab_color& operator=(const lab_color &other) { this->lc_l = other.lc_l;