aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/geo_ops.c
diff options
context:
space:
mode:
authorPeter Eisentraut <peter_e@gmx.net>2013-07-08 22:42:39 -0400
committerPeter Eisentraut <peter_e@gmx.net>2013-07-08 22:42:39 -0400
commit7888c61238ca082404cf8348a69e2b66bf9f4e96 (patch)
treed9120272a26531323f5f195187bb95c1c66ad775 /src/backend/utils/adt/geo_ops.c
parent12fbe2b3dd9c712532541c6a89cd26b1974c66f2 (diff)
downloadpostgresql-7888c61238ca082404cf8348a69e2b66bf9f4e96.tar.gz
postgresql-7888c61238ca082404cf8348a69e2b66bf9f4e96.zip
Fix bool abuse
path_encode's "closed" argument used to take three values: TRUE, FALSE, or -1, while being of type bool. Replace that with a three-valued enum for more clarity.
Diffstat (limited to 'src/backend/utils/adt/geo_ops.c')
-rw-r--r--src/backend/utils/adt/geo_ops.c34
1 files changed, 18 insertions, 16 deletions
diff --git a/src/backend/utils/adt/geo_ops.c b/src/backend/utils/adt/geo_ops.c
index ad18cf07e7d..5d0b5961061 100644
--- a/src/backend/utils/adt/geo_ops.c
+++ b/src/backend/utils/adt/geo_ops.c
@@ -32,6 +32,8 @@
* Internal routines
*/
+enum path_delim { PATH_NONE, PATH_OPEN, PATH_CLOSED };
+
static int point_inside(Point *p, int npts, Point *plist);
static int lseg_crossing(double x, double y, double px, double py);
static BOX *box_construct(double x1, double x2, double y1, double y2);
@@ -57,7 +59,7 @@ static int pair_decode(char *str, float8 *x, float8 *y, char **s);
static int pair_encode(float8 x, float8 y, char *str);
static int pair_count(char *s, char delim);
static int path_decode(int opentype, int npts, char *str, int *isopen, char **ss, Point *p);
-static char *path_encode(bool closed, int npts, Point *pt);
+static char *path_encode(enum path_delim path_delim, int npts, Point *pt);
static void statlseg_construct(LSEG *lseg, Point *pt1, Point *pt2);
static double box_ar(BOX *box);
static void box_cn(Point *center, BOX *box);
@@ -280,7 +282,7 @@ path_decode(int opentype, int npts, char *str, int *isopen, char **ss, Point *p)
} /* path_decode() */
static char *
-path_encode(bool closed, int npts, Point *pt)
+path_encode(enum path_delim path_delim, int npts, Point *pt)
{
int size = npts * (P_MAXLEN + 3) + 2;
char *result;
@@ -296,15 +298,15 @@ path_encode(bool closed, int npts, Point *pt)
result = palloc(size);
cp = result;
- switch (closed)
+ switch (path_delim)
{
- case TRUE:
+ case PATH_CLOSED:
*cp++ = LDELIM;
break;
- case FALSE:
+ case PATH_OPEN:
*cp++ = LDELIM_EP;
break;
- default:
+ case PATH_NONE:
break;
}
@@ -322,15 +324,15 @@ path_encode(bool closed, int npts, Point *pt)
pt++;
}
cp--;
- switch (closed)
+ switch (path_delim)
{
- case TRUE:
+ case PATH_CLOSED:
*cp++ = RDELIM;
break;
- case FALSE:
+ case PATH_OPEN:
*cp++ = RDELIM_EP;
break;
- default:
+ case PATH_NONE:
break;
}
*cp = '\0';
@@ -415,7 +417,7 @@ box_out(PG_FUNCTION_ARGS)
{
BOX *box = PG_GETARG_BOX_P(0);
- PG_RETURN_CSTRING(path_encode(-1, 2, &(box->high)));
+ PG_RETURN_CSTRING(path_encode(PATH_NONE, 2, &(box->high)));
}
/*
@@ -1018,7 +1020,7 @@ line_out(PG_FUNCTION_ARGS)
{
}
- return path_encode(TRUE, 2, (Point *) &(ls->p[0]));
+ return path_encode(PATH_CLOSED, 2, (Point *) &(ls->p[0]));
#else
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
@@ -1441,7 +1443,7 @@ path_out(PG_FUNCTION_ARGS)
{
PATH *path = PG_GETARG_PATH_P(0);
- PG_RETURN_CSTRING(path_encode(path->closed, path->npts, path->p));
+ PG_RETURN_CSTRING(path_encode(path->closed ? PATH_CLOSED : PATH_OPEN, path->npts, path->p));
}
/*
@@ -1823,7 +1825,7 @@ point_out(PG_FUNCTION_ARGS)
{
Point *pt = PG_GETARG_POINT_P(0);
- PG_RETURN_CSTRING(path_encode(-1, 1, pt));
+ PG_RETURN_CSTRING(path_encode(PATH_NONE, 1, pt));
}
/*
@@ -2051,7 +2053,7 @@ lseg_out(PG_FUNCTION_ARGS)
{
LSEG *ls = PG_GETARG_LSEG_P(0);
- PG_RETURN_CSTRING(path_encode(FALSE, 2, (Point *) &(ls->p[0])));
+ PG_RETURN_CSTRING(path_encode(PATH_OPEN, 2, (Point *) &(ls->p[0])));
}
/*
@@ -3494,7 +3496,7 @@ poly_out(PG_FUNCTION_ARGS)
{
POLYGON *poly = PG_GETARG_POLYGON_P(0);
- PG_RETURN_CSTRING(path_encode(TRUE, poly->npts, poly->p));
+ PG_RETURN_CSTRING(path_encode(PATH_CLOSED, poly->npts, poly->p));
}
/*