actual patch for close_ps() [file: geo_ops.c]

Started by Gautam H Thakerover 27 years ago2 messages
#1Gautam H Thaker
gthaker@atl.lmco.com
1 attachment(s)

Opps, did not include the actual patch in my last email:

Attached is my patch that fixes the routine close_ps().
I can try to fix other as I run into them, esp. for
line when line can be input. I tested my fix with:

-- try vertical lseg.
select '(1,1)'::point ## '((0,0),(0,2))'::lseg;
?column?
--------
(0,1)
(1 row)

-- try horizontal lseg.
select '(1,1)'::point ## '((0,2),(2,2))'::lseg;
?column?
--------
(1,2)
(1 row)

(both of above were returning wrong answers before.)

--
Gautam H. Thaker
Distributed Processing Lab; Lockheed Martin Adv. Tech. Labs
A&E 3W; 1 Federal Street; Camden, NJ 08102
609-338-3907, fax 609-338-4144 email: gthaker@atl.lmco.com

Attachments:

geo_ops.c.patchtext/plain; charset=us-ascii; name=geo_ops.c.patchDownload
*** geo_ops.c	Fri May  1 14:41:47 1998
--- geo_ops.c.last	Fri May  1 13:43:36 1998
***************
*** 2354,2360 ****
   *
   * Some tricky code here, relying on boolean expressions
   *	evaluating to only zero or one to use as an array index.
-  *      bug fixes by gthaker@atl.lmco.com; May 1, 98 
   */
  Point *
  close_ps(Point *pt, LSEG *lseg)
--- 2354,2359 ----
***************
*** 2368,2374 ****
  	result = NULL;
  	xh = lseg->p[0].x < lseg->p[1].x;
  	yh = lseg->p[0].y < lseg->p[1].y;
! 	/* !xh (or !yh) is the index of lower x( or y) end point of lseg */
  
  	/* vertical segment? */
  	if (lseg_vertical(lseg))
--- 2367,2382 ----
  	result = NULL;
  	xh = lseg->p[0].x < lseg->p[1].x;
  	yh = lseg->p[0].y < lseg->p[1].y;
! 	if (pt->x < lseg->p[!xh].x)
! 		result = point_copy(&lseg->p[!xh]);
! 	else if (pt->x > lseg->p[xh].x)
! 		result = point_copy(&lseg->p[xh]);
! 	else if (pt->y < lseg->p[!yh].y)
! 		result = point_copy(&lseg->p[!yh]);
! 	else if (pt->y > lseg->p[yh].y)
! 		result = point_copy(&lseg->p[yh]);
! 	if (result != NULL)
! 		return (result);
  
  	/* vertical segment? */
  	if (lseg_vertical(lseg))
***************
*** 2376,2391 ****
  #ifdef GEODEBUG
  		printf("close_ps- segment is vertical\n");
  #endif
- 		/* first check if point is below or above the entire lseg. */
- 		if (pt->y < lseg->p[!yh].y)
- 		  result = point_copy(&lseg->p[!yh]); /* below the lseg */
- 		else if (pt->y > lseg->p[yh].y)
- 		  result = point_copy(&lseg->p[yh]); /* above the lseg */
- 		if (result != NULL)
- 		  return (result);
- 
- 		/* point lines along (to left or right) of the vertical lseg. */
- 		
  		result = palloc(sizeof(*result));
  		result->x = lseg->p[0].x;
  		result->y = pt->y;
--- 2384,2389 ----
***************
*** 2396,2410 ****
  #ifdef GEODEBUG
  		printf("close_ps- segment is horizontal\n");
  #endif
- 		/* first check if point is left or right of the entire lseg. */
- 		if (pt->x < lseg->p[!xh].x)
- 		  result = point_copy(&lseg->p[!xh]); /* left of the lseg */
- 		else if (pt->x > lseg->p[xh].x)
- 		  result = point_copy(&lseg->p[xh]); /* right of the lseg */
- 		if (result != NULL)
- 		  return (result);
- 
- 		/* point lines along (at top or below) the horiz. lseg. */
  		result = palloc(sizeof(*result));
  		result->x = pt->x;
  		result->y = lseg->p[0].y;
--- 2394,2399 ----
#2Thomas G. Lockhart
lockhart@alumni.caltech.edu
In reply to: Gautam H Thaker (#1)
Re: [HACKERS] actual patch for close_ps() [file: geo_ops.c]

Attached is my patch that fixes the routine close_ps().

Hi Gautam. The patch seems "backwards". Can you next time run the diff
as

  diff -c geo_ops.c.last geo_ops.c > geo_ops.c.patch

to make it a bit easier to apply? Haven't tried testing yet, but should
get to it sometime soon...

- Tom