|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * IDENTIFICATION
|
11 |
| - * $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.66 2002/09/05 00:43:07 tgl Exp $ |
| 11 | + * $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.67 2002/11/08 17:37:52 tgl Exp $ |
12 | 12 | *
|
13 | 13 | *-------------------------------------------------------------------------
|
14 | 14 | */
|
|
19 | 19 | #include<float.h>
|
20 | 20 | #include<ctype.h>
|
21 | 21 |
|
| 22 | +#include"utils/builtins.h" |
22 | 23 | #include"utils/geo_decls.h"
|
23 | 24 |
|
24 | 25 | #ifndefPI
|
@@ -79,11 +80,9 @@ static Point *line_interpt_internal(LINE *l1, LINE *l2);
|
79 | 80 | #defineLDELIM_C'<'
|
80 | 81 | #defineRDELIM_C'>'
|
81 | 82 |
|
82 |
| -/* Maximum number of output digits printed */ |
83 |
| -#defineP_MAXDIG DBL_DIG |
84 |
| -#defineP_MAXLEN (2*(P_MAXDIG+7)+1) |
85 |
| - |
86 |
| -staticintdigits8=P_MAXDIG; |
| 83 | +/* Maximum number of characters printed by pair_encode() */ |
| 84 | +/* ...+2+7 : 2 accounts for extra_float_digits max value */ |
| 85 | +#defineP_MAXLEN (2*(DBL_DIG+2+7)+1) |
87 | 86 |
|
88 | 87 |
|
89 | 88 | /*
|
@@ -139,7 +138,12 @@ single_decode(char *str, float8 *x, char **s)
|
139 | 138 | staticint
|
140 | 139 | single_encode(float8x,char*str)
|
141 | 140 | {
|
142 |
| -sprintf(str,"%.*g",digits8,x); |
| 141 | +intndig=DBL_DIG+extra_float_digits; |
| 142 | + |
| 143 | +if (ndig<1) |
| 144 | +ndig=1; |
| 145 | + |
| 146 | +sprintf(str,"%.*g",ndig,x); |
143 | 147 | return TRUE;
|
144 | 148 | }/* single_encode() */
|
145 | 149 |
|
@@ -190,7 +194,12 @@ pair_decode(char *str, float8 *x, float8 *y, char **s)
|
190 | 194 | staticint
|
191 | 195 | pair_encode(float8x,float8y,char*str)
|
192 | 196 | {
|
193 |
| -sprintf(str,"%.*g,%.*g",digits8,x,digits8,y); |
| 197 | +intndig=DBL_DIG+extra_float_digits; |
| 198 | + |
| 199 | +if (ndig<1) |
| 200 | +ndig=1; |
| 201 | + |
| 202 | +sprintf(str,"%.*g,%.*g",ndig,x,ndig,y); |
194 | 203 | return TRUE;
|
195 | 204 | }
|
196 | 205 |
|
@@ -976,7 +985,7 @@ line_construct_pts(LINE *line, Point *pt1, Point *pt2)
|
976 | 985 | #endif
|
977 | 986 | #ifdefGEODEBUG
|
978 | 987 | printf("line_construct_pts- line is neither vertical nor horizontal (diffs x=%.*g, y=%.*g\n",
|
979 |
| -digits8, (pt2->x-pt1->x),digits8, (pt2->y-pt1->y)); |
| 988 | +DBL_DIG, (pt2->x-pt1->x),DBL_DIG, (pt2->y-pt1->y)); |
980 | 989 | #endif
|
981 | 990 | }
|
982 | 991 | }
|
@@ -1181,8 +1190,8 @@ line_interpt_internal(LINE *l1, LINE *l2)
|
1181 | 1190 |
|
1182 | 1191 | #ifdefGEODEBUG
|
1183 | 1192 | printf("line_interpt- lines are A=%.*g, B=%.*g, C=%.*g, A=%.*g, B=%.*g, C=%.*g\n",
|
1184 |
| -digits8,l1->A,digits8,l1->B,digits8,l1->C,digits8,l2->A,digits8,l2->B,digits8,l2->C); |
1185 |
| -printf("line_interpt- lines intersect at (%.*g,%.*g)\n",digits8,x,digits8,y); |
| 1193 | +DBL_DIG,l1->A,DBL_DIG,l1->B,DBL_DIG,l1->C,DBL_DIG,l2->A,DBL_DIG,l2->B,DBL_DIG,l2->C); |
| 1194 | +printf("line_interpt- lines intersect at (%.*g,%.*g)\n",DBL_DIG,x,DBL_DIG,y); |
1186 | 1195 | #endif
|
1187 | 1196 |
|
1188 | 1197 | returnresult;
|
@@ -2381,14 +2390,14 @@ interpt_sl(LSEG *lseg, LINE *line)
|
2381 | 2390 | p=line_interpt_internal(&tmp,line);
|
2382 | 2391 | #ifdefGEODEBUG
|
2383 | 2392 | printf("interpt_sl- segment is (%.*g %.*g) (%.*g %.*g)\n",
|
2384 |
| -digits8,lseg->p[0].x,digits8,lseg->p[0].y,digits8,lseg->p[1].x,digits8,lseg->p[1].y); |
| 2393 | +DBL_DIG,lseg->p[0].x,DBL_DIG,lseg->p[0].y,DBL_DIG,lseg->p[1].x,DBL_DIG,lseg->p[1].y); |
2385 | 2394 | printf("interpt_sl- segment becomes line A=%.*g B=%.*g C=%.*g\n",
|
2386 |
| -digits8,tmp.A,digits8,tmp.B,digits8,tmp.C); |
| 2395 | +DBL_DIG,tmp.A,DBL_DIG,tmp.B,DBL_DIG,tmp.C); |
2387 | 2396 | #endif
|
2388 | 2397 | if (PointerIsValid(p))
|
2389 | 2398 | {
|
2390 | 2399 | #ifdefGEODEBUG
|
2391 |
| -printf("interpt_sl- intersection point is (%.*g %.*g)\n",digits8,p->x,digits8,p->y); |
| 2400 | +printf("interpt_sl- intersection point is (%.*g %.*g)\n",DBL_DIG,p->x,DBL_DIG,p->y); |
2392 | 2401 | #endif
|
2393 | 2402 | if (on_ps_internal(p,lseg))
|
2394 | 2403 | {
|
@@ -3940,7 +3949,7 @@ circle_out(PG_FUNCTION_ARGS)
|
3940 | 3949 | char*result;
|
3941 | 3950 | char*cp;
|
3942 | 3951 |
|
3943 |
| -result=palloc(3*(P_MAXLEN+1)+3); |
| 3952 | +result=palloc(2*P_MAXLEN+6); |
3944 | 3953 |
|
3945 | 3954 | cp=result;
|
3946 | 3955 | *cp++=LDELIM_C;
|
|