From d8608689f4fc6f0f3737e6fc5110f0797af7d6f0 Mon Sep 17 00:00:00 2001 From: nick black Date: Sun, 1 Aug 2021 23:41:50 -0400 Subject: [PATCH] unmacroize update_domain_T #1976 --- src/info/main.c | 2 +- src/lib/plot.c | 64 ++++++++++++++++++++++++++++++++----------------- 2 files changed, 43 insertions(+), 23 deletions(-) diff --git a/src/info/main.c b/src/info/main.c index 57ba07e3e..41e1d4add 100644 --- a/src/info/main.c +++ b/src/info/main.c @@ -100,7 +100,7 @@ finish_line(struct ncplane* n){ static int emoji_viz(struct ncplane* n){ - static const char emoji[] = "ðŸ‘ūðŸīðŸĪ˜ðŸšŽðŸŒðŸŒŽðŸŒðŸĨ†ðŸ’ĢðŸ—ĄðŸ”Ŧ⚗ïļâš›ïļâ˜Ēïļâ˜ĢïļðŸŒŋðŸŽąðŸ§ðŸ’‰ðŸ’ŠðŸ“ĄðŸĶ‘ðŸ‡ŪðŸ‡ąðŸ‡ĶðŸ‡ķðŸšąðŸŠĪ🧎🔎ðŸī‍☠ïļ"; + static const char emoji[] = "ðŸ‘ūðŸīðŸĪ˜ðŸšŽðŸŒðŸŒŽðŸŒðŸĨ†ðŸ’ĢðŸ—ĄðŸ”Ŧ⚗ïļâš›ïļâ˜Ēïļâ˜ĢïļðŸŒŋðŸŽąðŸ§ðŸ’‰ðŸ’ŠðŸ“ĄðŸĪŧðŸĶ‘ðŸ‡ŪðŸ‡ąðŸ‡ĶðŸ‡ķðŸšąðŸŠĪ🧎🔎ðŸī‍☠ïļ"; ncplane_set_bg_rgb(n, 0); int bytes; for(const char* e = emoji ; *e ; e += bytes){ diff --git a/src/lib/plot.c b/src/lib/plot.c index 461a70935..5ee429174 100644 --- a/src/lib/plot.c +++ b/src/lib/plot.c @@ -348,28 +348,7 @@ int window_slide_##T(nc##X##plot* ncp, int64_t x){ \ return 0; \ } \ \ -/* if we're doing domain detection, update the domain to reflect the value we \ - just set. if we're not, check the result against the known ranges, and \ - return -1 if the value is outside of that range. */ \ -int update_domain_##T(nc##X##plot* ncp, uint64_t x){ \ - const T val = ncp->slots[x % ncp->plot.slotcount]; \ - if(ncp->plot.detectdomain){ \ - if(val > ncp->maxy){ \ - ncp->maxy = val; \ - } \ - if(!ncp->plot.detectonlymax){ \ - if(val < ncp->miny){ \ - ncp->miny = val; \ - } \ - } \ - return 0; \ - } \ - if(val > ncp->maxy || val < ncp->miny){ \ - return -1; \ - } \ - return 0; \ -} \ -\ +static int update_domain_##T(nc##X##plot* ncp, uint64_t x); \ static void update_sample_##T(nc##X##plot* ncp, int64_t x, T y, bool reset); \ \ int set_sample_##T(nc##X##plot* ncpp, uint64_t x, T y){ \ @@ -414,6 +393,47 @@ void destroy_##T(nc##X##plot* ncpp){ \ CREATE(uint64_t, u) CREATE(double, d) +/* if we're doing domain detection, update the domain to reflect the value we + just set. if we're not, check the result against the known ranges, and + return -1 if the value is outside of that range. */ +int update_domain_uint64_t(ncuplot* ncp, uint64_t x){ + const uint64_t val = ncp->slots[x % ncp->plot.slotcount]; + if(ncp->plot.detectdomain){ + if(val > ncp->maxy){ + ncp->maxy = val; + } + if(!ncp->plot.detectonlymax){ + if(val < ncp->miny){ + ncp->miny = val; + } + } + return 0; + } + if(val > ncp->maxy || val < ncp->miny){ + return -1; + } + return 0; +} + +int update_domain_double(ncdplot* ncp, uint64_t x){ + const double val = ncp->slots[x % ncp->plot.slotcount]; + if(ncp->plot.detectdomain){ + if(val > ncp->maxy){ + ncp->maxy = val; + } + if(!ncp->plot.detectonlymax){ + if(val < ncp->miny){ + ncp->miny = val; + } + } + return 0; + } + if(val > ncp->maxy || val < ncp->miny){ + return -1; + } + return 0; +} + /* x must be within n's window at this point */ static void update_sample_uint64_t(ncuplot* ncp, int64_t x, uint64_t y, bool reset){