Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7888c61

Browse files
committed
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 enumfor more clarity.
1 parent12fbe2b commit7888c61

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

‎src/backend/utils/adt/geo_ops.c

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
* Internal routines
3333
*/
3434

35+
enumpath_delim {PATH_NONE,PATH_OPEN,PATH_CLOSED };
36+
3537
staticintpoint_inside(Point*p,intnpts,Point*plist);
3638
staticintlseg_crossing(doublex,doubley,doublepx,doublepy);
3739
staticBOX*box_construct(doublex1,doublex2,doubley1,doubley2);
@@ -57,7 +59,7 @@ static intpair_decode(char *str, float8 *x, float8 *y, char **s);
5759
staticintpair_encode(float8x,float8y,char*str);
5860
staticintpair_count(char*s,chardelim);
5961
staticintpath_decode(intopentype,intnpts,char*str,int*isopen,char**ss,Point*p);
60-
staticchar*path_encode(boolclosed,intnpts,Point*pt);
62+
staticchar*path_encode(enumpath_delimpath_delim,intnpts,Point*pt);
6163
staticvoidstatlseg_construct(LSEG*lseg,Point*pt1,Point*pt2);
6264
staticdoublebox_ar(BOX*box);
6365
staticvoidbox_cn(Point*center,BOX*box);
@@ -280,7 +282,7 @@ path_decode(int opentype, int npts, char *str, int *isopen, char **ss, Point *p)
280282
}/* path_decode() */
281283

282284
staticchar*
283-
path_encode(boolclosed,intnpts,Point*pt)
285+
path_encode(enumpath_delimpath_delim,intnpts,Point*pt)
284286
{
285287
intsize=npts* (P_MAXLEN+3)+2;
286288
char*result;
@@ -296,15 +298,15 @@ path_encode(bool closed, int npts, Point *pt)
296298
result=palloc(size);
297299

298300
cp=result;
299-
switch (closed)
301+
switch (path_delim)
300302
{
301-
caseTRUE:
303+
casePATH_CLOSED:
302304
*cp++=LDELIM;
303305
break;
304-
caseFALSE:
306+
casePATH_OPEN:
305307
*cp++=LDELIM_EP;
306308
break;
307-
default:
309+
casePATH_NONE:
308310
break;
309311
}
310312

@@ -322,15 +324,15 @@ path_encode(bool closed, int npts, Point *pt)
322324
pt++;
323325
}
324326
cp--;
325-
switch (closed)
327+
switch (path_delim)
326328
{
327-
caseTRUE:
329+
casePATH_CLOSED:
328330
*cp++=RDELIM;
329331
break;
330-
caseFALSE:
332+
casePATH_OPEN:
331333
*cp++=RDELIM_EP;
332334
break;
333-
default:
335+
casePATH_NONE:
334336
break;
335337
}
336338
*cp='\0';
@@ -415,7 +417,7 @@ box_out(PG_FUNCTION_ARGS)
415417
{
416418
BOX*box=PG_GETARG_BOX_P(0);
417419

418-
PG_RETURN_CSTRING(path_encode(-1,2,&(box->high)));
420+
PG_RETURN_CSTRING(path_encode(PATH_NONE,2,&(box->high)));
419421
}
420422

421423
/*
@@ -1018,7 +1020,7 @@ line_out(PG_FUNCTION_ARGS)
10181020
{
10191021
}
10201022

1021-
returnpath_encode(TRUE,2, (Point*)&(ls->p[0]));
1023+
returnpath_encode(PATH_CLOSED,2, (Point*)&(ls->p[0]));
10221024
#else
10231025
ereport(ERROR,
10241026
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
@@ -1441,7 +1443,7 @@ path_out(PG_FUNCTION_ARGS)
14411443
{
14421444
PATH*path=PG_GETARG_PATH_P(0);
14431445

1444-
PG_RETURN_CSTRING(path_encode(path->closed,path->npts,path->p));
1446+
PG_RETURN_CSTRING(path_encode(path->closed ?PATH_CLOSED :PATH_OPEN,path->npts,path->p));
14451447
}
14461448

14471449
/*
@@ -1823,7 +1825,7 @@ point_out(PG_FUNCTION_ARGS)
18231825
{
18241826
Point*pt=PG_GETARG_POINT_P(0);
18251827

1826-
PG_RETURN_CSTRING(path_encode(-1,1,pt));
1828+
PG_RETURN_CSTRING(path_encode(PATH_NONE,1,pt));
18271829
}
18281830

18291831
/*
@@ -2051,7 +2053,7 @@ lseg_out(PG_FUNCTION_ARGS)
20512053
{
20522054
LSEG*ls=PG_GETARG_LSEG_P(0);
20532055

2054-
PG_RETURN_CSTRING(path_encode(FALSE,2, (Point*)&(ls->p[0])));
2056+
PG_RETURN_CSTRING(path_encode(PATH_OPEN,2, (Point*)&(ls->p[0])));
20552057
}
20562058

20572059
/*
@@ -3494,7 +3496,7 @@ poly_out(PG_FUNCTION_ARGS)
34943496
{
34953497
POLYGON*poly=PG_GETARG_POLYGON_P(0);
34963498

3497-
PG_RETURN_CSTRING(path_encode(TRUE,poly->npts,poly->p));
3499+
PG_RETURN_CSTRING(path_encode(PATH_CLOSED,poly->npts,poly->p));
34983500
}
34993501

35003502
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp