From: Matthew Fernandez Date: Sat, 27 Nov 2021 18:28:24 +0000 (-0800) Subject: tclpkg sgnarea: [nfc] make sign extraction more obvious to the compiler X-Git-Tag: 2.50.0~5^2~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=941c9ed1a922760a2393ae9be0bc2ce04b38b5f5;p=graphviz 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. --- 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]; }