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

Commitb087b01

Browse files
committed
Fix an ancient error in dist_ps (distance from point to line segment), which
a number of other geometric operators also depend on. It miscalculated theslope of the perpendicular to the given line segment anytime that slope wasother than 0, infinite, or +/-1. In some cases the error would be maskedbecause the true closest point on the line segment was one of its endpointsrather than the intersection point, but in other cases it could give anarbitrarily bad answer. Per bug #4872 from Nick Roosevelt.Bug goes clear back to Berkeley days, so patch all supported branches.Make a couple of cosmetic adjustments while at it.
1 parent8d355d7 commitb087b01

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

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

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/geo_ops.c,v 1.101 2009/01/01 17:23:49 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/geo_ops.c,v 1.102 2009/06/23 16:25:02 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -2449,18 +2449,16 @@ dist_ps_internal(Point *pt, LSEG *lseg)
24492449
tmpdist;
24502450
Point*ip;
24512451

2452-
/*
2453-
* Construct a line perpendicular to the input segment
2454-
* and through the input point
2455-
*/
2452+
/*
2453+
* Construct a line perpendicular to the input segment
2454+
* and through the input point
2455+
*/
24562456
if (lseg->p[1].x==lseg->p[0].x)
24572457
m=0;
24582458
elseif (lseg->p[1].y==lseg->p[0].y)
2459-
{/* slope is infinite */
2460-
m= (double)DBL_MAX;
2461-
}
2459+
m= (double)DBL_MAX;/* slope is infinite */
24622460
else
2463-
m= ((lseg->p[0].y-lseg->p[1].y) / (lseg->p[1].x-lseg->p[0].x));
2461+
m= (lseg->p[0].x-lseg->p[1].x) / (lseg->p[1].y-lseg->p[0].y);
24642462
ln=line_construct_pm(pt,m);
24652463

24662464
#ifdefGEODEBUG
@@ -2469,13 +2467,14 @@ dist_ps_internal(Point *pt, LSEG *lseg)
24692467
#endif
24702468

24712469
/*
2472-
* Calculate distance to the line segment or to theendpoints of the
2473-
* segment.
2470+
* Calculate distance to the line segment or to thenearest endpoint of
2471+
*thesegment.
24742472
*/
24752473

24762474
/* intersection is on the line segment? */
24772475
if ((ip=interpt_sl(lseg,ln))!=NULL)
24782476
{
2477+
/* yes, so use distance to the intersection point */
24792478
result=point_dt(pt,ip);
24802479
#ifdefGEODEBUG
24812480
printf("dist_ps- distance is %f to intersection point is (%f,%f)\n",
@@ -2484,7 +2483,7 @@ dist_ps_internal(Point *pt, LSEG *lseg)
24842483
}
24852484
else
24862485
{
2487-
/*intersection is not on line segment */
2486+
/*no, so use distance to the nearer endpoint */
24882487
result=point_dt(pt,&lseg->p[0]);
24892488
tmpdist=point_dt(pt,&lseg->p[1]);
24902489
if (tmpdist<result)
@@ -3790,7 +3789,7 @@ poly_contain(PG_FUNCTION_ARGS)
37903789
{
37913790
if (point_inside(&(polyb->p[i]),polya->npts,&(polya->p[0]))==0)
37923791
{
3793-
#ifGEODEBUG
3792+
#ifdefGEODEBUG
37943793
printf("poly_contain- point (%f,%f) not in polygon\n",polyb->p[i].x,polyb->p[i].y);
37953794
#endif
37963795
result= false;
@@ -3803,7 +3802,7 @@ poly_contain(PG_FUNCTION_ARGS)
38033802
{
38043803
if (point_inside(&(polya->p[i]),polyb->npts,&(polyb->p[0]))==1)
38053804
{
3806-
#ifGEODEBUG
3805+
#ifdefGEODEBUG
38073806
printf("poly_contain- point (%f,%f) in polygon\n",polya->p[i].x,polya->p[i].y);
38083807
#endif
38093808
result= false;
@@ -3814,7 +3813,7 @@ poly_contain(PG_FUNCTION_ARGS)
38143813
}
38153814
else
38163815
{
3817-
#ifGEODEBUG
3816+
#ifdefGEODEBUG
38183817
printf("poly_contain- bound box ((%f,%f),(%f,%f)) not inside ((%f,%f),(%f,%f))\n",
38193818
polyb->boundbox.low.x,polyb->boundbox.low.y,polyb->boundbox.high.x,polyb->boundbox.high.y,
38203819
polya->boundbox.low.x,polya->boundbox.low.y,polya->boundbox.high.x,polya->boundbox.high.y);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp