Skip to content

Commit 90e8efa

Browse files
committed
Fix line_construct_pm() for the case of "infinite" (DBL_MAX) slope.
This code was just plain wrong: what you got was not a line through the given point but a line almost indistinguishable from the Y-axis, although not truly vertical. The only caller that tries to use this function with m == DBL_MAX is dist_ps_internal for the case where the lseg is horizontal; it would end up producing the distance from the given point to the place where the lseg's line crosses the Y-axis. That function is used by other operators too, so there are several operators that could compute wrong distances from a line segment to something else. Per bug #5745 from jindiax. Back-patch to all supported branches.
1 parent 55425d3 commit 90e8efa

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/backend/utils/adt/geo_ops.c

+11-4
Original file line numberDiff line numberDiff line change
@@ -1070,13 +1070,20 @@ line_construct_pm(Point *pt, double m)
10701070
{
10711071
LINE *result = (LINE *) palloc(sizeof(LINE));
10721072

1073-
/* use "mx - y + yinter = 0" */
1074-
result->A = m;
1075-
result->B = -1.0;
10761073
if (m == DBL_MAX)
1077-
result->C = pt->y;
1074+
{
1075+
/* vertical - use "x = C" */
1076+
result->A = -1;
1077+
result->B = 0;
1078+
result->C = pt->x;
1079+
}
10781080
else
1081+
{
1082+
/* use "mx - y + yinter = 0" */
1083+
result->A = m;
1084+
result->B = -1.0;
10791085
result->C = pt->y - m * pt->x;
1086+
}
10801087

10811088
#ifdef NOT_USED
10821089
result->m = m;

0 commit comments

Comments
 (0)