From 0a0f4093618074e4be59e4108404fd1369d71eda Mon Sep 17 00:00:00 2001 From: "S. Gilles" Date: Thu, 26 Jan 2017 02:00:31 -0500 Subject: [PATCH] Fix up trig constants o Remove useless sine/cosine precalculations o Add M_PI, since GCC (or glibc?) is inconsistent on whether the default options in the Makefile bring it in. --- ui-sdl.c | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/ui-sdl.c b/ui-sdl.c index 7e8cfc8..a9c82c2 100644 --- a/ui-sdl.c +++ b/ui-sdl.c @@ -31,7 +31,9 @@ #define TICKS_PER_FRAME (1000 / 60) -#define TRIG_PRECALC_NUM 4 +#ifndef M_PI +#define M_PI (3.14159265358979323846) +#endif /* What clicking does */ static enum ui_action { @@ -242,29 +244,6 @@ static uint_fast8_t save_load_delay; /* If something needs to be freed next frame, but not before */ static void *free_this; -/* sine tables */ -static double precalc_sins[TRIG_PRECALC_NUM]; - -/* cosine tables */ -static double precalc_coss[TRIG_PRECALC_NUM]; - -/* Precalculate sines and cosines */ -static void precalc_trig(void) -{ - precalc_coss[0] = 0.0; - precalc_sins[0] = 1.0; - - for (size_t j = 1; j < TRIG_PRECALC_NUM - 1; ++j) { - double theta = (M_PI * j) / (2 * (TRIG_PRECALC_NUM - 1)); - - precalc_sins[j] = sin(theta); - precalc_coss[j] = cos(theta); - } - - precalc_coss[TRIG_PRECALC_NUM - 1] = 0.0; - precalc_sins[TRIG_PRECALC_NUM - 1] = 1.0; -} - /* GCD */ static int gcd(uint_fast8_t x, uint_fast8_t y) { @@ -840,9 +819,6 @@ int ui_init(struct quiver *i_q) eq_len = 2; eq_head = 0; eq_tail = 0; - - /* Sines and cosines for drawing circles */ - precalc_trig(); done: return ret; -- 2.11.4.GIT