From c35a8302c6275a1ba71dcdff15f58310d064a909 Mon Sep 17 00:00:00 2001 From: rodri Date: Mon, 8 Mar 2021 21:01:40 +0000 Subject: refactor statistics code to make it more general purpose. --- main.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 106b31f..c7ae3a3 100644 --- a/main.c +++ b/main.c @@ -13,9 +13,6 @@ State state; double t, Δt; -double min(double a, double b) { return a < b? a: b; } -double max(double a, double b) { return a > b? a: b; } - /* * Dynamics stepper * @@ -153,7 +150,7 @@ redraw(void) draw(screen, screen->r, display->black, nil, ZP); drawtimestep(t); - drawbar(state.min); drawbar(state.max); drawbar(state.avg); + drawbar(state.stats.min); drawbar(state.stats.max); drawbar(state.stats.avg); fillellipse(screen, toscreen(Pt2(0,state.x,1)), 2, 2, display->white, ZP); flushimage(display, 1); @@ -176,6 +173,7 @@ resetsim(void) { memset(&state, 0, sizeof(State)); state.x = 100; + state.stats.update = statsupdate; t = 0; } @@ -275,10 +273,7 @@ threadmain(int argc, char *argv[]) integrate(&state, t, Δt); - state.acc += state.x; - state.avg = state.acc/++state.nsteps; - state.min = min(state.min, state.x); - state.max = max(state.max, state.x); + state.stats.update(&state.stats, state.x); redraw(); -- cgit v1.2.3