From d7b34e782e2ffe62d725872a2af512ccb68e9bb2 Mon Sep 17 00:00:00 2001 From: Boris Stefanovic <owldev@bluewin.ch> Date: Sun, 22 May 2022 19:39:14 +0200 Subject: [PATCH] save --- Makefile | 3 +++ src/field.c | 9 ++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 25c7843..90338cc 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,9 @@ TESTS:= draw_tests field_tests all: main +exec: main + ./main + main: main.o $(OBJFILES) $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) -lSDL2 diff --git a/src/field.c b/src/field.c index 89afa52..b29131a 100644 --- a/src/field.c +++ b/src/field.c @@ -41,11 +41,7 @@ bool is_in_screen(coordinates_t pos) { bool draw_field_line_point(struct gfx_context_t *ctxt, charge_t *charges, int num_charges, double x0, double x1, double y0, double y1, vec2 pos, vec2 *pos_next, double delta) { vec2 e; compute_total_normalized_e(charges, num_charges, pos, 0.01, &e); - double norm_e = vec2_norm(e); - - // TODO: "Problème ici" ? - pos_next->x = pos.x + delta * (e.x / norm_e); - pos_next->y = pos.y + delta * (e.y / norm_e); + *pos_next = vec2_add(pos, vec2_mul(delta, vec2_normalize(e))); if (pos_next->x <= 0 || pos_next->x >= 1 || pos_next->y <= 0 || pos_next->y >= 1) return false; @@ -61,6 +57,7 @@ bool draw_field_line_point(struct gfx_context_t *ctxt, charge_t *charges, int nu return !is_in_screen(coordinate_pos); } + bool line_reach_charge(vec2 pos, charge_t *charges, int num_charges, double dx) { for (int j = 0; j < num_charges; ++j) { if (vec2_norm(vec2_sub(pos, charges[j].pos)) < dx / HEI) { @@ -103,6 +100,7 @@ static bool draw_field_line(struct gfx_context_t *ctxt, charge_t *charges, int n return !stop_positive || !stop_negative; } + /// Draw all the charges /// A circle with minus sign for negative charges /// A circle with a plus sign for positive charges @@ -129,6 +127,7 @@ static void draw_charges(struct gfx_context_t *context, charge_t *charges, int n } } + void draw_everything( struct gfx_context_t *ctxt, charge_t *charges, -- GitLab