36 #include "utils/fmgrprotos.h"
136 const char *type_name,
const char *orig_string,
140 const char *type_name,
const char *orig_string,
145 bool *isopen,
char **endptr_p,
146 const char *type_name,
const char *orig_string,
160 #define LDELIM_EP '['
161 #define RDELIM_EP ']'
195 const char *type_name,
const char *orig_string,
213 const char *type_name,
const char *orig_string,
218 while (isspace((
unsigned char) *
str))
236 while (isspace((
unsigned char) *
str))
243 else if (*
str !=
'\0')
249 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
250 errmsg(
"invalid input syntax for type %s: \"%s\"",
251 type_name, orig_string)));
267 bool *isopen,
char **endptr_p,
268 const char *type_name,
const char *orig_string,
275 while (isspace((
unsigned char) *
str))
288 while (isspace((
unsigned char) *cp))
302 for (
i = 0;
i < npts;
i++)
318 while (isspace((
unsigned char) *
str))
328 else if (*
str !=
'\0')
334 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
335 errmsg(
"invalid input syntax for type %s: \"%s\"",
336 type_name, orig_string)));
359 for (
i = 0;
i < npts;
i++)
396 while ((s = strchr(s, delim)) != NULL)
401 return (ndelim % 2) ? ((ndelim + 1) / 2) : -1;
425 Node *escontext = fcinfo->context;
523 result->
low.
x = pt2->
x;
528 result->
low.
x = pt1->
x;
533 result->
low.
y = pt2->
y;
538 result->
low.
y = pt1->
y;
965 while (isspace((
unsigned char) *s))
973 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
974 errmsg(
"invalid input syntax for type %s: \"%s\"",
982 Node *escontext = fcinfo->context;
989 while (isspace((
unsigned char) *s))
997 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
998 errmsg(
"invalid line specification: A and B cannot both be zero")));
1007 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
1008 errmsg(
"invalid line specification: must be two distinct points")));
1051 (
errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
1052 errmsg(
"invalid line specification: A and B cannot both be zero")));
1106 if (result->
C == 0.0)
1123 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1124 errmsg(
"invalid line specification: must be two distinct points")));
1201 if (
unlikely(isnan(l1->
A) || isnan(l1->
B) || isnan(l1->
C) ||
1202 isnan(l2->
A) || isnan(l2->
B) || isnan(l2->
C)))
1272 else if (!
FPzero(l1->
B) && !isnan(l1->
B) && !
FPzero(l2->
B) && !isnan(l2->
B))
1390 for (
i = 0;
i < path->
npts;
i++)
1392 j = (
i + 1) % path->
npts;
1405 Node *escontext = fcinfo->context;
1416 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
1417 errmsg(
"invalid input syntax for type %s: \"%s\"",
1421 while (isspace((
unsigned char) *s))
1431 base_size =
sizeof(path->
p[0]) * npts;
1432 size = offsetof(
PATH, p) + base_size;
1435 if (base_size / npts !=
sizeof(path->
p[0]) || size <= base_size)
1437 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
1438 errmsg(
"too many points requested")));
1445 if (!
path_decode(s,
true, npts, &(path->
p[0]), &isopen, &s,
"path",
str,
1453 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
1454 errmsg(
"invalid input syntax for type %s: \"%s\"",
1456 while (isspace((
unsigned char) *s))
1461 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
1462 errmsg(
"invalid input syntax for type %s: \"%s\"",
1465 path->
closed = (!isopen);
1499 if (npts <= 0 || npts >= (
int32) ((INT_MAX - offsetof(
PATH, p)) /
sizeof(
Point)))
1501 (
errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
1502 errmsg(
"invalid number of points in external \"path\" value")));
1504 size = offsetof(
PATH, p) +
sizeof(path->
p[0]) * npts;
1509 path->
closed = (closed ? 1 : 0);
1513 for (
i = 0;
i < npts;
i++)
1535 for (
i = 0;
i < path->
npts;
i++)
1668 for (
i = 1;
i < p1->
npts;
i++)
1677 for (
i = 1;
i <
p2->npts;
i++)
1688 for (
i = 0;
i < p1->
npts;
i++)
1698 iprev = p1->
npts - 1;
1701 for (
j = 0;
j <
p2->npts;
j++)
1711 jprev =
p2->npts - 1;
1735 bool have_min =
false;
1742 for (
i = 0;
i < p1->
npts;
i++)
1752 iprev = p1->
npts - 1;
1755 for (
j = 0;
j <
p2->npts;
j++)
1765 jprev =
p2->npts - 1;
1798 for (
i = 0;
i < path->
npts;
i++)
1808 iprev = path->
npts - 1;
1980 if (
unlikely(isnan(pt1->
x) || isnan(pt1->
y) ||
1981 isnan(pt2->
x) || isnan(pt2->
y)))
2025 if (
FPeq(pt1->
x, pt2->
x))
2027 if (
FPeq(pt1->
y, pt2->
y))
2041 if (
FPeq(pt1->
x, pt2->
x))
2043 if (
FPeq(pt1->
y, pt2->
y))
2068 Node *escontext = fcinfo->context;
2144 lseg->
p[0].
x = pt1->
x;
2145 lseg->
p[0].
y = pt1->
y;
2146 lseg->
p[1].
x = pt2->
x;
2147 lseg->
p[1].
y = pt2->
y;
2438 bool have_min =
false;
2449 for (
i = 0;
i < path->
npts;
i++)
2459 iprev = path->
npts - 1;
2464 if (!have_min ||
float8_lt(tmp, result))
2641 seg.
p[0].
x = poly->
p[0].
x;
2642 seg.
p[0].
y = poly->
p[0].
y;
2643 seg.
p[1].
x = poly->
p[poly->
npts - 1].
x;
2644 seg.
p[1].
y = poly->
p[poly->
npts - 1].
y;
2648 for (
i = 0;
i < poly->
npts - 1;
i++)
2650 seg.
p[0].
x = poly->
p[
i].
x;
2651 seg.
p[0].
y = poly->
p[
i].
y;
2652 seg.
p[1].
x = poly->
p[
i + 1].
x;
2653 seg.
p[1].
y = poly->
p[
i + 1].
y;
2703 *result = lseg->
p[0];
2705 *result = lseg->
p[1];
2839 *result = on_lseg->
p[0];
2846 *result = on_lseg->
p[1];
2895 point.
x = box->
low.
x;
2910 point.
y = box->
low.
y;
2974 *result = lseg->
p[0];
2981 *result = lseg->
p[1];
3025 point.
x = box->
low.
x;
3040 point.
y = box->
low.
y;
3132 return box->
high.
x >= point->
x && box->
low.
x <= point->
x &&
3133 box->
high.
y >= point->
y && box->
low.
y <= point->
y;
3180 for (
i = 0;
i < n;
i++)
3290 point.
x = box->
low.
x;
3301 point.
y = box->
low.
y;
3386 x1 = x2 = poly->
p[0].
x;
3387 y2 = y1 = poly->
p[0].
y;
3388 for (
i = 1;
i < poly->
npts;
i++)
3418 Node *escontext = fcinfo->context;
3427 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
3428 errmsg(
"invalid input syntax for type %s: \"%s\"",
3431 base_size =
sizeof(poly->
p[0]) * npts;
3432 size = offsetof(
POLYGON, p) + base_size;
3435 if (base_size / npts !=
sizeof(poly->
p[0]) || size <= base_size)
3437 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
3438 errmsg(
"too many points requested")));
3445 if (!
path_decode(
str,
false, npts, &(poly->
p[0]), &isopen, NULL,
"polygon",
3484 if (npts <= 0 || npts >= (
int32) ((INT_MAX - offsetof(
POLYGON, p)) /
sizeof(
Point)))
3486 (
errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
3487 errmsg(
"invalid number of points in external \"polygon\" value")));
3489 size = offsetof(
POLYGON, p) +
sizeof(poly->
p[0]) * npts;
3495 for (
i = 0;
i < npts;
i++)
3518 for (
i = 0;
i < poly->
npts;
i++)
3766 sa.p[0] = polya->
p[polya->
npts - 1];
3769 for (ia = 0; ia < polya->
npts && !result; ia++)
3772 sa.p[1] = polya->
p[ia];
3775 sb.
p[0] = polyb->
p[polyb->
npts - 1];
3777 for (ib = 0; ib < polyb->
npts && !result; ib++)
3779 sb.
p[1] = polyb->
p[ib];
3872 intersection =
false;
3879 s.
p[0] = poly->
p[(start == 0) ? (poly->
npts - 1) : (start - 1)];
3887 s.
p[1] = poly->
p[
i];
3908 intersection =
true;
3917 if (
res && !intersection)
3952 s.
p[0] = contained_poly->
p[contained_poly->
npts - 1];
3954 for (
i = 0;
i < contained_poly->
npts;
i++)
3956 s.
p[1] = contained_poly->
p[
i];
4032 bool have_min =
false;
4052 for (
i = 0;
i < polya->
npts;
i++)
4059 iprev = polya->
npts - 1;
4061 for (
j = 0;
j < polyb->
npts;
j++)
4068 jprev = polyb->
npts - 1;
4360 base_size =
sizeof(p1->
p[0]) * (p1->
npts +
p2->npts);
4361 size = offsetof(
PATH, p) + base_size;
4364 if (base_size /
sizeof(p1->
p[0]) != (p1->
npts +
p2->npts) ||
4367 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
4368 errmsg(
"too many points requested")));
4378 for (
i = 0;
i < p1->
npts;
i++)
4380 result->
p[
i].
x = p1->
p[
i].
x;
4381 result->
p[
i].
y = p1->
p[
i].
y;
4383 for (
i = 0;
i <
p2->npts;
i++)
4402 for (
i = 0;
i < path->
npts;
i++)
4415 for (
i = 0;
i < path->
npts;
i++)
4431 for (
i = 0;
i < path->
npts;
i++)
4444 for (
i = 0;
i < path->
npts;
i++)
4462 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4463 errmsg(
"open path cannot be converted to polygon")));
4469 size = offsetof(
POLYGON, p) +
sizeof(poly->
p[0]) * path->
npts;
4475 for (
i = 0;
i < path->
npts;
i++)
4477 poly->
p[
i].
x = path->
p[
i].
x;
4478 poly->
p[
i].
y = path->
p[
i].
y;
4542 size = offsetof(
POLYGON, p) +
sizeof(poly->
p[0]) * 4;
4548 poly->
p[0].
x = box->
low.
x;
4549 poly->
p[0].
y = box->
low.
y;
4550 poly->
p[1].
x = box->
low.
x;
4555 poly->
p[3].
y = box->
low.
y;
4575 size = offsetof(
PATH, p) +
sizeof(path->
p[0]) * poly->
npts;
4584 for (
i = 0;
i < poly->
npts;
i++)
4586 path->
p[
i].
x = poly->
p[
i].
x;
4587 path->
p[
i].
y = poly->
p[
i].
y;
4614 Node *escontext = fcinfo->context;
4621 while (isspace((
unsigned char) *s))
4629 while (isspace((
unsigned char) *cp))
4647 if (circle->
radius < 0.0)
4649 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
4650 errmsg(
"invalid input syntax for type %s: \"%s\"",
4659 while (isspace((
unsigned char) *s))
4664 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
4665 errmsg(
"invalid input syntax for type %s: \"%s\"",
4671 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
4672 errmsg(
"invalid input syntax for type %s: \"%s\"",
4715 if (circle->
radius < 0.0)
4717 (
errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
4718 errmsg(
"invalid radius in external \"circle\" value")));
5238 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5239 errmsg(
"cannot convert circle with radius zero to polygon")));
5243 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5244 errmsg(
"must request at least 2 points")));
5246 base_size =
sizeof(poly->
p[0]) * npts;
5247 size = offsetof(
POLYGON, p) + base_size;
5250 if (base_size / npts !=
sizeof(poly->
p[0]) || size <= base_size)
5252 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
5253 errmsg(
"too many points requested")));
5261 for (
i = 0;
i < npts;
i++)
5295 for (
i = 0;
i < poly->
npts;
i++)
5300 for (
i = 0;
i < poly->
npts;
i++)
5337 #define POINT_ON_POLYGON INT_MAX