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

Commit9fe649e

Browse files
committed
In geo_ops.c, represent infinite slope as Infinity, not DBL_MAX.
Since we're assuming IEEE floats these days, there seems littlereason not to do this. It has the advantage that when the slope iscomputed as infinite due to the presence of Inf coordinates, we getsaner behavior than before from line_construct(), and thence alsoin some dependent operations such as finding the closest point.Also fix line_construct() to special-case slope zero. The previouscoding got the right answer in most cases, but it could computeC as NaN when the point has Inf coordinates.Discussion:https://postgr.es/m/CAGf+fX70rWFOk5cd00uMfa__0yP+vtQg5ck7c2Onb-Yczp0URA@mail.gmail.com
1 parent8597a48 commit9fe649e

File tree

2 files changed

+140
-133
lines changed

2 files changed

+140
-133
lines changed

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,13 +1055,20 @@ line_send(PG_FUNCTION_ARGS)
10551055
staticinlinevoid
10561056
line_construct(LINE*result,Point*pt,float8m)
10571057
{
1058-
if (m==DBL_MAX)
1058+
if (isinf(m))
10591059
{
10601060
/* vertical - use "x = C" */
10611061
result->A=-1.0;
10621062
result->B=0.0;
10631063
result->C=pt->x;
10641064
}
1065+
elseif (m==0)
1066+
{
1067+
/* horizontal - use "y = C" */
1068+
result->A=0.0;
1069+
result->B=-1.0;
1070+
result->C=pt->y;
1071+
}
10651072
else
10661073
{
10671074
/* use "mx - y + yinter = 0" */
@@ -1201,7 +1208,7 @@ line_sl(LINE *line)
12011208
if (FPzero(line->A))
12021209
return0.0;
12031210
if (FPzero(line->B))
1204-
returnDBL_MAX;
1211+
returnget_float8_infinity();
12051212
returnfloat8_div(line->A,-line->B);
12061213
}
12071214

@@ -1213,7 +1220,7 @@ static inline float8
12131220
line_invsl(LINE*line)
12141221
{
12151222
if (FPzero(line->A))
1216-
returnDBL_MAX;
1223+
returnget_float8_infinity();
12171224
if (FPzero(line->B))
12181225
return0.0;
12191226
returnfloat8_div(line->B,line->A);
@@ -1979,13 +1986,13 @@ point_slope(PG_FUNCTION_ARGS)
19791986
/*
19801987
* Return slope of two points
19811988
*
1982-
* Note that this function returnsDBL_MAX when the points are the same.
1989+
* Note that this function returnsInf when the points are the same.
19831990
*/
19841991
staticinlinefloat8
19851992
point_sl(Point*pt1,Point*pt2)
19861993
{
19871994
if (FPeq(pt1->x,pt2->x))
1988-
returnDBL_MAX;
1995+
returnget_float8_infinity();
19891996
if (FPeq(pt1->y,pt2->y))
19901997
return0.0;
19911998
returnfloat8_div(float8_mi(pt1->y,pt2->y),float8_mi(pt1->x,pt2->x));
@@ -2003,7 +2010,7 @@ point_invsl(Point *pt1, Point *pt2)
20032010
if (FPeq(pt1->x,pt2->x))
20042011
return0.0;
20052012
if (FPeq(pt1->y,pt2->y))
2006-
returnDBL_MAX;
2013+
returnget_float8_infinity();
20072014
returnfloat8_div(float8_mi(pt1->x,pt2->x),float8_mi(pt2->y,pt1->y));
20082015
}
20092016

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp