From 8808ec3f923b8be9a27c398c4ca34fc7fd91396e Mon Sep 17 00:00:00 2001
From: Florian Burgener <florian.burgener@etu.hesge.ch>
Date: Mon, 9 May 2022 13:26:22 +0200
Subject: [PATCH] Add more constants

---
 src/Simulation.c | 12 ++++++------
 src/constants.c  |  3 +++
 src/constants.h  |  1 +
 3 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/Simulation.c b/src/Simulation.c
index 3eb8282..7f463be 100644
--- a/src/Simulation.c
+++ b/src/Simulation.c
@@ -1,5 +1,6 @@
 #include "Simulation.h"
 
+#include <math.h>
 #include <stdlib.h>
 
 #include "Charge.h"
@@ -25,7 +26,7 @@ static Charge *generate_random_charges(Rectangle *universe, int *charges_length)
             Charge charge = generate_random_charge();
 
             Vector2 position = charge.position;
-            double eps = (double)CHARGE_CIRCLE_RADIUS / SCREEN_WIDTH;
+            double eps = RADIUS_TRESHOLD;
             if (is_out_of_bounds(universe, vector2_add(position, vector2_init(0, -eps)))) {
                 continue;
             }
@@ -106,13 +107,10 @@ static bool compute_next_point(Simulation *simulation, int direction, Vector2 cu
 
 static void draw_field_line_with_direction(Simulation *simulation, Graphics *graphics, Vector2 starting_point, int direction) {
     Vector2 current_point = starting_point;
-    // Represents the acceptable distance between the last point and the charge, this distance is calculated with
-    // the radius of the charge display circle and the width of the window.
-    double eps = (double)CHARGE_CIRCLE_RADIUS / SCREEN_WIDTH;
 
     while (true) {
         Vector2 next_point;
-        if (!compute_next_point(simulation, direction, current_point, eps, &next_point)) {
+        if (!compute_next_point(simulation, direction, current_point, RADIUS_TRESHOLD, &next_point)) {
             break;
         }
 
@@ -159,7 +157,9 @@ void simulation_draw(Simulation *simulation, Graphics *graphics) {
         double angle = 0;
         while (angle < 2 * M_PI) {
             angle += 2 * M_PI / 64;
-            Vector2 starting_point = vector2_add(position, vector2_init(cos(angle) * 0.1, sin(angle) * 0.1));
+            double x = cos(angle) * RADIUS_TRESHOLD * 1.1;
+            double y = sin(angle) * RADIUS_TRESHOLD * 1.1;
+            Vector2 starting_point = vector2_add(position, vector2_init(x, y));
             draw_field_line(simulation, graphics, starting_point);
         }
     }
diff --git a/src/constants.c b/src/constants.c
index 328ccca..03ffa9d 100644
--- a/src/constants.c
+++ b/src/constants.c
@@ -15,3 +15,6 @@ const int MAX_CHARGES = 5;
 
 const double K = 8.988e9;
 const double ELEMENTARY_CHARGE = 1.602e-19;
+// Represents the acceptable distance between the last point and the charge, this distance is calculated with
+// the radius of the charge display circle and the width of the window.
+const double RADIUS_TRESHOLD = (double)CHARGE_CIRCLE_RADIUS / SCREEN_WIDTH;
diff --git a/src/constants.h b/src/constants.h
index 4f8d25e..d39f078 100644
--- a/src/constants.h
+++ b/src/constants.h
@@ -16,5 +16,6 @@ extern const int MAX_CHARGES;
 
 extern const double K;
 extern const double ELEMENTARY_CHARGE;
+extern const double RADIUS_TRESHOLD;
 
 #endif
-- 
GitLab