]> granicus.if.org Git - graphviz/commitdiff
use C99 bools in triang.c instead of internal constants
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 30 May 2021 17:00:33 +0000 (10:00 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 5 Jun 2021 18:13:03 +0000 (11:13 -0700)
lib/pathplan/triang.c

index 8b9c6ac95afa2488ac82fdfc56dc2851acc02a83..4776186edd945fc0d1fdef2d224b2b53eb7c1548 100644 (file)
@@ -8,7 +8,7 @@
  * Contributors: Details at https://graphviz.org
  *************************************************************************/
 
-
+#include <stdbool.h>
 #include <stdio.h>
 #include <math.h>
 #include <stdlib.h>
 #define ISCW  2
 #define ISON  3
 
-#ifndef TRUE
-#define TRUE 1
-#define FALSE 0
-#endif
-
 static int dpd_ccw(Ppoint_t *, Ppoint_t *, Ppoint_t *);
-static int dpd_isdiagonal(int, int, Ppoint_t **, int);
-static int dpd_intersects(Ppoint_t *, Ppoint_t *, Ppoint_t *, Ppoint_t *);
-static int dpd_between(Ppoint_t *, Ppoint_t *, Ppoint_t *);
+static bool dpd_isdiagonal(int, int, Ppoint_t **, int);
+static bool dpd_intersects(Ppoint_t *, Ppoint_t *, Ppoint_t *, Ppoint_t *);
+static bool dpd_between(Ppoint_t *, Ppoint_t *, Ppoint_t *);
 static int triangulate(Ppoint_t ** pointp, int pointn,
                        void (*fn) (void *, Ppoint_t *), void *vc);
 
@@ -102,7 +97,7 @@ triangulate(Ppoint_t ** pointp, int pointn,
 }
 
 /* check if (i, i + 2) is a diagonal */
-static int dpd_isdiagonal(int i, int ip2, Ppoint_t ** pointp, int pointn)
+static bool dpd_isdiagonal(int i, int ip2, Ppoint_t ** pointp, int pointn)
 {
     int ip1, im1, j, jp1, res;
 
@@ -121,7 +116,7 @@ static int dpd_isdiagonal(int i, int ip2, Ppoint_t ** pointp, int pointn)
                 (dpd_ccw (pointp[ip2], pointp[i], pointp[im1]) != ISCW));
 */
     if (!res) {
-       return FALSE;
+       return false;
     }
 
     /* check against all other edges */
@@ -130,14 +125,14 @@ static int dpd_isdiagonal(int i, int ip2, Ppoint_t ** pointp, int pointn)
        if (!(j == i || jp1 == i || j == ip2 || jp1 == ip2))
            if (dpd_intersects
                (pointp[i], pointp[ip2], pointp[j], pointp[jp1])) {
-               return FALSE;
+               return false;
            }
     }
-    return TRUE;
+    return true;
 }
 
 /* line to line intersection */
-static int dpd_intersects(Ppoint_t * pa, Ppoint_t * pb, Ppoint_t * pc,
+static bool dpd_intersects(Ppoint_t * pa, Ppoint_t * pb, Ppoint_t * pc,
                          Ppoint_t * pd)
 {
     int ccw1, ccw2, ccw3, ccw4;
@@ -146,7 +141,7 @@ static int dpd_intersects(Ppoint_t * pa, Ppoint_t * pb, Ppoint_t * pc,
        dpd_ccw(pc, pd, pa) == ISON || dpd_ccw(pc, pd, pb) == ISON) {
        if (dpd_between(pa, pb, pc) || dpd_between(pa, pb, pd) ||
            dpd_between(pc, pd, pa) || dpd_between(pc, pd, pb))
-           return TRUE;
+           return true;
     } else {
        ccw1 = dpd_ccw(pa, pb, pc) == ISCCW ? 1 : 0;
        ccw2 = dpd_ccw(pa, pb, pd) == ISCCW ? 1 : 0;
@@ -154,17 +149,17 @@ static int dpd_intersects(Ppoint_t * pa, Ppoint_t * pb, Ppoint_t * pc,
        ccw4 = dpd_ccw(pc, pd, pb) == ISCCW ? 1 : 0;
        return (ccw1 ^ ccw2) && (ccw3 ^ ccw4);
     }
-    return FALSE;
+    return false;
 }
 
-static int dpd_between(Ppoint_t * pa, Ppoint_t * pb, Ppoint_t * pc)
+static bool dpd_between(Ppoint_t * pa, Ppoint_t * pb, Ppoint_t * pc)
 {
     Ppoint_t pba, pca;
 
     pba.x = pb->x - pa->x, pba.y = pb->y - pa->y;
     pca.x = pc->x - pa->x, pca.y = pc->y - pa->y;
     if (dpd_ccw(pa, pb, pc) != ISON)
-       return FALSE;
+       return false;
     return pca.x * pba.x + pca.y * pba.y >= 0 &&
        pca.x * pca.x + pca.y * pca.y <= pba.x * pba.x + pba.y * pba.y;
 }