Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b0f2d68

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 8f742d1 commit b0f2d68

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/backend/utils/adt/geo_ops.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,13 +1072,20 @@ line_construct_pm(Point *pt, double m)
10721072
{
10731073
LINE *result = (LINE *) palloc(sizeof(LINE));
10741074

1075-
/* use "mx - y + yinter = 0" */
1076-
result->A = m;
1077-
result->B = -1.0;
10781075
if (m == DBL_MAX)
1079-
result->C = pt->y;
1076+
{
1077+
/* vertical - use "x = C" */
1078+
result->A = -1;
1079+
result->B = 0;
1080+
result->C = pt->x;
1081+
}
10801082
else
1083+
{
1084+
/* use "mx - y + yinter = 0" */
1085+
result->A = m;
1086+
result->B = -1.0;
10811087
result->C = pt->y - m * pt->x;
1088+
}
10821089

10831090
#ifdef NOT_USED
10841091
result->m = m;

0 commit comments

Comments
 (0)