Skip to content

Commit

Permalink
fix(render): fix arrow glitch with 0 ftx
Browse files Browse the repository at this point in the history
The use of `acos(θ)` works better than `atan(θ)`. Just need to be
careful with the `sign` of `fty`.
  • Loading branch information
jtheoof committed May 24, 2020
1 parent 2adcf94 commit ec6e6ab
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/render.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <gdk/gdk.h>
#include <gtk/gtk.h>
#include <math.h>
#include <pango/pangocairo.h>

#include "swappy.h"
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ec6e6ab

Please sign in to comment.