From c6ab869d5312cf2abc3c477c082997f37df2fa74 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sat, 27 Nov 2021 10:25:40 -0800 Subject: [PATCH] neaotgen sgnarea: [nfc] make sign extraction more obvious to the compiler Squashes two -Wfloat-equal warnings. --- lib/neatogen/legal.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/neatogen/legal.c b/lib/neatogen/legal.c index adedeaf4a..2fbeaeef3 100644 --- a/lib/neatogen/legal.c +++ b/lib/neatogen/legal.c @@ -56,6 +56,13 @@ typedef struct polygon polygon; int nvertices, npolygons, ninters; } data ; +static int sign(double v) { + if (v < 0) + return -1; + if (v > 0) + return 1; + return 0; +} /* find the sign of the area of each of the triangles formed by adding a vertex of m to l @@ -72,9 +79,9 @@ static void sgnarea(vertex *l, vertex *m, int i[]) g = after(m)->pos.x - a; h = after(m)->pos.y - b; t = c * f - d * e; - i[0] = t == 0 ? 0 : (t > 0 ? 1 : -1); + i[0] = sign(t); t = c * h - d * g; - i[1] = t == 0 ? 0 : (t > 0 ? 1 : -1); + i[1] = sign(t); i[2] = i[0] * i[1]; } -- 2.40.0