From ec6e6abae7629800fec4c715957c4932946f51ed Mon Sep 17 00:00:00 2001 From: Jeremy Attali Date: Sun, 24 May 2020 14:33:50 -0400 Subject: [PATCH] fix(render): fix arrow glitch with 0 ftx MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The use of `acos(θ)` works better than `atan(θ)`. Just need to be careful with the `sign` of `fty`. --- src/render.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/render.c b/src/render.c index c7ce44a..1c8a4c0 100644 --- a/src/render.c +++ b/src/render.c @@ -1,5 +1,6 @@ #include #include +#include #include #include "swappy.h" @@ -105,11 +106,7 @@ static void render_shape_arrow(cairo_t *cr, struct swappy_paint_shape shape) { return; } - double theta = atan(fty / ftx); - - if (ftx < DBL_EPSILON) { - theta = M_PI + theta; - } + double theta = copysign(1.0, fty) * acos(ftx / ftn); // Draw line cairo_save(cr);