From 941c9ed1a922760a2393ae9be0bc2ce04b38b5f5 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sat, 27 Nov 2021 10:28:24 -0800 Subject: [PATCH] tclpkg sgnarea: [nfc] make sign extraction more obvious to the compiler Squashes two -Wfloat-equal warnings. Equivalent of the previous commit, but applied to tclpkg code that looks copy-pasted from neatogen. --- tclpkg/tclpathplan/intersect.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tclpkg/tclpathplan/intersect.c b/tclpkg/tclpathplan/intersect.c index 112fa636b..d72f4d091 100644 --- a/tclpkg/tclpathplan/intersect.c +++ b/tclpkg/tclpathplan/intersect.c @@ -14,6 +14,14 @@ #include "simple.h" #include +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 also find the sign of their product */ @@ -29,9 +37,9 @@ static void sgnarea(struct vertex *l, struct 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