From 4496e007a15b9e077b3fa83ebcdecd413077baa1 Mon Sep 17 00:00:00 2001 From: Bill Kendrick Date: Sat, 20 Jan 2024 11:15:53 -0800 Subject: [PATCH] Trochoids: Mend freeze bug I had updated the guide circle drawing routine to draw points every 360 / radius steps (so smaller circles had fewer XOR'd points), but obviously this will cause a divide by zero if either circle's radius = 360, since I'm using an integer, it will cause a frozen for()-loop if radius > 360. h/t Pere for pointing out the freeze! --- magic/src/trochoids.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/magic/src/trochoids.c b/magic/src/trochoids.c index 609a979fe..a8b9bf321 100644 --- a/magic/src/trochoids.c +++ b/magic/src/trochoids.c @@ -382,7 +382,6 @@ void trochoids_work(magic_api * api, int which, /* Erase old before drawing new */ - /* FIXME */ update_rect->x = 0; update_rect->y = 0; update_rect->w = canvas->w; @@ -393,6 +392,7 @@ void trochoids_work(magic_api * api, int which, /* Draw the lines */ LCM = calc_lcm(r, R); + for (a = 0; a < 360.0 * (float) (LCM / R); a++) { float a2 = (a + 1); @@ -417,12 +417,19 @@ void trochoids_work(magic_api * api, int which, } if (guides) { + int guide_spacing; + /* When still dragging (before release), draw some "guides", showing the mechanism that would be used to generate the pattern */ rotator_anim_a = (int) (atan2(y - trochoids_y, x - trochoids_x) / M_PI * 180.0); /* Stator (fixed circle) */ - for (a = 0; a < 360; a = a + 360 / R) { + guide_spacing = 360 / R; + if (guide_spacing < 2) { + guide_spacing = 2; + } + + for (a = 0; a < 360; a = a + guide_spacing) { px = (int) ((float) trochoids_x + ((float) R * deg_cos(a))); py = (int) ((float) trochoids_y - ((float) R * deg_sin(a))); api->putpixel(canvas, px, py, 0); @@ -432,7 +439,12 @@ void trochoids_work(magic_api * api, int which, } /* Rotator (rolling circle) */ - for (a = 0; a < 360; a = a + 360 / r) { + guide_spacing = 360 / r; + if (guide_spacing < 2) { + guide_spacing = 2; + } + + for (a = 0; a < 360; a = a + guide_spacing) { if (which == TOOL_HYPOTROCHOID_SIZES || which == TOOL_HYPOTROCHOID_NOSIZES_1 || which == TOOL_HYPOTROCHOID_NOSIZES_2 ||