commit 11400b6d369abfb5c2ec82180ed987fb967e11dc
parent dc4bb23a2d906fab1acb1159269cfc719c834fa5
Author: Christos Margiolis <christos@margiolis.net>
Date: Sat, 8 Aug 2020 21:43:23 +0300
added some more constants
Diffstat:
2 files changed, 31 insertions(+), 28 deletions(-)
diff --git a/src/main.c b/src/main.c
@@ -2,13 +2,13 @@
#define BUFFSIZE 256
-static void *f = NULL;
+static void *f = NULL;
-static void curses_init(void);
-static void func_get(Plane *p, char *buf);
-static void expression_validate(Plane *p);
-static float expression_evaluate(float x);
-static void keys_handle(Plane *p, int key);
+static void curses_init(void);
+static void func_get(Plane *p, char *buf);
+static void expression_validate(Plane *p);
+static float expression_evaluate(float x);
+static void keys_handle(Plane *p, int key);
int
main(int argc, char **argv)
@@ -95,12 +95,12 @@ keys_handle(Plane *p, int key)
{
switch (key)
{
- case 'k': case KEY_UP: plane_shift(p, 0.0f, 1.0f); break;
- case 'j': case KEY_DOWN: plane_shift(p, 0.0f, -1.0f); break;
- case 'h': case KEY_LEFT: plane_shift(p, -1.0f, 0.0f); break;
- case 'l': case KEY_RIGHT: plane_shift(p, 1.0f, 0.0f); break;
- case '+': zoom_handle(p, 1.0f/1.05f); break;
- case '-': zoom_handle(p, 1.05f); break;
+ case 'k': case KEY_UP: plane_shift(p, 0.0f, SHIFT_STEP); break;
+ case 'j': case KEY_DOWN: plane_shift(p, 0.0f, -SHIFT_STEP); break;
+ case 'h': case KEY_LEFT: plane_shift(p, -SHIFT_STEP, 0.0f); break;
+ case 'l': case KEY_RIGHT: plane_shift(p, SHIFT_STEP, 0.0f); break;
+ case '+': zoom_handle(p, ZOOM_IN_FACTOR); break;
+ case '-': zoom_handle(p, ZOOM_OUT_FACTOR); break;
case 'r': zoom_restore(p); break;
case 'f': expression_validate(p); break;
}
diff --git a/src/plane.h b/src/plane.h
@@ -7,31 +7,34 @@
#include <stdio.h>
#include <stdlib.h>
-#define XMIN_PLANE -2.0f*M_PI;
-#define XMAX_PLANE 2.0f*M_PI;
-#define YMIN_PLANE -M_PI;
-#define YMAX_PLANE M_PI;
-#define XSCALE_PLANE 1.0f;
-#define YSCALE_PLANE 1.0f;
+#define XMIN_PLANE (-2.0f * M_PI)
+#define XMAX_PLANE ( 2.0f * M_PI)
+#define YMIN_PLANE -M_PI
+#define YMAX_PLANE M_PI
+#define XSCALE_PLANE 1.0f
+#define YSCALE_PLANE 1.0f
+#define SHIFT_STEP 1.0f
+#define ZOOM_IN_FACTOR (1.0f / 1.05f)
+#define ZOOM_OUT_FACTOR 1.05f
typedef struct {
float (*yfunc)(float x);
float ymin, ymax;
float xmin, xmax;
float xscale, yscale;
- int ymaxs, xmaxs;
+ int ymaxs, xmaxs;
} Plane;
extern Plane p;
-void plane_init(Plane *p);
-float plane_scale(float val, float omin, float omax, float nmin, float nmax);
-void plane_shift(Plane *p, float xshift, float yshift);
-void zoom_restore(Plane *p);
-void zoom_handle(Plane *p, float factor);
-void get_step(const Plane *p, float *xstep, float *ystep);
-void axes_draw(const Plane *p);
-void graph_draw(const Plane *p);
-void graph_plot(const Plane *p, float x, float y);
+void plane_init(Plane *p);
+float plane_scale(float val, float omin, float omax, float nmin, float nmax);
+void plane_shift(Plane *p, float xshift, float yshift);
+void zoom_restore(Plane *p);
+void zoom_handle(Plane *p, float factor);
+void get_step(const Plane *p, float *xstep, float *ystep);
+void axes_draw(const Plane *p);
+void graph_draw(const Plane *p);
+void graph_plot(const Plane *p, float x, float y);
#endif /* PLANE_H */