]> granicus.if.org Git - graphviz/commitdiff
tclpkg sgnarea: [nfc] make sign extraction more obvious to the compiler
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 27 Nov 2021 18:28:24 +0000 (10:28 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Fri, 3 Dec 2021 15:44:10 +0000 (07:44 -0800)
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

index 112fa636bc7ab8e1426b7e6221b7a78cdecb6de0..d72f4d091f8f54452ae8b900b4e630259353d2b8 100644 (file)
 #include "simple.h"
 #include <stdlib.h>
 
+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];
 }