]> granicus.if.org Git - graphviz/commitdiff
tclpathplan between: rephrase to avoid -Wfloat-equal warnings
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 19 Sep 2021 22:46:54 +0000 (15:46 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 25 Sep 2021 17:22:21 +0000 (10:22 -0700)
Similar to commit a420a1a449b23f4be4fb891e1025f20b21c81369. This is intended to
have the same semantics.

tclpkg/tclpathplan/intersect.c

index 6db78650a401b3c65416e6f2c13b26035adfd35b..40e26da990cacc2ac152150df8d8e20a324d126c 100644 (file)
@@ -34,12 +34,38 @@ static void sgnarea(struct vertex *l, struct vertex *m, int i[])
     i[2] = i[0] * i[1];
 }
 
-/* determine if g lies between f and h      */
-static int between(float f, float g, float h)
-{
-    if ((f == g) || (g == h))
-       return (0);
-    return ((f < g) ? (g < h ? 1 : -1) : (h < g ? 1 : -1));
+/** where is `g` relative to the interval delimited by `f` and `h`?
+ *
+ * The order of `f` and `h` is not assumed. That is, the interval defined may be
+ * `(f, h)` or `(h, f)` depending on whether `f` is less than or greater than
+ * `h`.
+ *
+ * \param f First boundary of the interval
+ * \param g Value to test
+ * \param h Second boundary of the interval
+ * \return -1 if g is not in the interval, 1 if g is in the interval, 0 if g is
+ *   on the boundary (that is, equal to f or equal to h)
+ */
+static int between(double f, double g, double h) {
+  if (f < g) {
+    if (g < h) {
+      return 1;
+    }
+    if (g > h) {
+      return -1;
+    }
+    return 0;
+  }
+  if (f > g) {
+    if (g > h) {
+      return 1;
+    }
+    if (g < h) {
+      return -1;
+    }
+    return 0;
+  }
+  return 0;
 }
 
 /* determine if vertex i of line m is on line l     */