graphcurses

Curses 2D graph generator
git clone git://git.christosmarg.xyz/graphcurses.git
Log | Files | Refs | README | LICENSE

commit 06df6154ed6dafa80a57bc0121a7a3afe27268b1
parent 54361dc6f04ce4894fc672e1913030cac4701390
Author: Christos Margiolis <christos@margiolis.net>
Date:   Sun, 10 May 2020 16:41:28 +0300

added return types above function names

Diffstat:
Msrc/main.cpp | 15++++++++++-----
Msrc/plane.cpp | 24++++++++++++++++--------
2 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/src/main.cpp b/src/main.cpp @@ -7,7 +7,8 @@ static void getfunc(char *buffer, Plane& plane); static void validate_expression(Plane& plane); static void handle_key(int key, Plane& plane); -int main(int argc, char **argv) +int +main(int argc, char **argv) { init_curses(); Plane plane; @@ -41,7 +42,8 @@ int main(int argc, char **argv) return 0; } -static void init_curses() +static void +init_curses() { initscr(); cbreak(); @@ -53,7 +55,8 @@ static void init_curses() init_pair(2, COLOR_YELLOW, COLOR_BLACK); } -static void getfunc(char *buffer, Plane& plane) +static void +getfunc(char *buffer, Plane& plane) { move(0, 0); clrtoeol(); @@ -66,7 +69,8 @@ static void getfunc(char *buffer, Plane& plane) noecho(); } -static void validate_expression(Plane& plane) +static void +validate_expression(Plane& plane) { char *buffer = new char[256]; getfunc(buffer, plane); @@ -79,7 +83,8 @@ static void validate_expression(Plane& plane) delete[] buffer; } -static void handle_key(int key, Plane& plane) +static void +handle_key(int key, Plane& plane) { switch (key) { diff --git a/src/plane.cpp b/src/plane.cpp @@ -5,7 +5,8 @@ Plane::Plane() xscale(XSCALE_PLANE), yscale(YSCALE_PLANE), ymaxs(getmaxy(stdscr)), xmaxs(getmaxx(stdscr)) {} -void Plane::restore_zoom() +void +Plane::restore_zoom() { xmin = XMIN_PLANE; xmax = XMAX_PLANE; @@ -15,7 +16,8 @@ void Plane::restore_zoom() yscale = YSCALE_PLANE; } -void Plane::draw_axes() +void +Plane::draw_axes() { float x0 = scale(0.0f, xmin, xmax, 0.0f, xmaxs); float y0 = scale(0.0f, ymin, ymax, ymaxs, 0.0f); @@ -37,7 +39,8 @@ void Plane::draw_axes() } } -void Plane::draw_graph(const std::function<float(float)>& yfunc) +void +Plane::draw_graph(const std::function<float(float)>& yfunc) { float xstep; float ystep; @@ -51,19 +54,22 @@ void Plane::draw_graph(const std::function<float(float)>& yfunc) attroff(COLOR_PAIR(2)); } -float Plane::scale(float val, float omin, float omax, float nmin, float nmax) +float +Plane::scale(float val, float omin, float omax, float nmin, float nmax) { float s = (val - omin) / (omax - omin); return s * (nmax - nmin) + nmin; } -void Plane::getstep(float &xstep, float &ystep) +void +Plane::getstep(float &xstep, float &ystep) { if (xstep) xstep = (xmax - xmin) / (xmaxs + 1.0f); if (ystep) ystep = (ymax - ymin) / (ymaxs + 1.0f); } -void Plane::plot(float x, float y) +void +Plane::plot(float x, float y) { float xp = scale(x, xmin, xmax, 0.0f, xmaxs); float yp = scale(y, ymin, ymax, ymaxs, 0.0f); @@ -71,7 +77,8 @@ void Plane::plot(float x, float y) } -void Plane::handle_zoom(float factor) +void +Plane::handle_zoom(float factor) { float centerX = (xmin + ymax) / 2.0f; float centerY = (ymin + ymax) / 2.0f; @@ -81,7 +88,8 @@ void Plane::handle_zoom(float factor) ymax = scale(factor, 1.0f, 0.0f, ymax, centerY); } -void Plane::shift(float xshift, float yshift) +void +Plane::shift(float xshift, float yshift) { xshift *= (xmax - xmin) / 16.0f; yshift *= (ymax - ymin) / 16.0f;