Commit f59d3f60 authored by Huw Davies's avatar Huw Davies Committed by Alexandre Julliard

gdi32: Use a binary search for PtInRegion() and RectInRegion().

parent 7fd44a51
...@@ -1038,15 +1038,7 @@ BOOL WINAPI PtInRegion( HRGN hrgn, INT x, INT y ) ...@@ -1038,15 +1038,7 @@ BOOL WINAPI PtInRegion( HRGN hrgn, INT x, INT y )
if ((obj = GDI_GetObjPtr( hrgn, OBJ_REGION ))) if ((obj = GDI_GetObjPtr( hrgn, OBJ_REGION )))
{ {
int i; region_find_pt( obj, x, y, &ret );
if (obj->numRects > 0 && is_in_rect(&obj->extents, x, y))
for (i = 0; i < obj->numRects; i++)
if (is_in_rect(&obj->rects[i], x, y))
{
ret = TRUE;
break;
}
GDI_ReleaseObj( hrgn ); GDI_ReleaseObj( hrgn );
} }
return ret; return ret;
...@@ -1071,6 +1063,7 @@ BOOL WINAPI RectInRegion( HRGN hrgn, const RECT *rect ) ...@@ -1071,6 +1063,7 @@ BOOL WINAPI RectInRegion( HRGN hrgn, const RECT *rect )
WINEREGION *obj; WINEREGION *obj;
BOOL ret = FALSE; BOOL ret = FALSE;
RECT rc; RECT rc;
int i;
/* swap the coordinates to make right >= left and bottom >= top */ /* swap the coordinates to make right >= left and bottom >= top */
/* (region building rectangles are normalized the same way) */ /* (region building rectangles are normalized the same way) */
...@@ -1079,29 +1072,23 @@ BOOL WINAPI RectInRegion( HRGN hrgn, const RECT *rect ) ...@@ -1079,29 +1072,23 @@ BOOL WINAPI RectInRegion( HRGN hrgn, const RECT *rect )
if ((obj = GDI_GetObjPtr( hrgn, OBJ_REGION ))) if ((obj = GDI_GetObjPtr( hrgn, OBJ_REGION )))
{ {
RECT *pCurRect, *pRectEnd;
/* this is (just) a useful optimization */
if ((obj->numRects > 0) && overlapping(&obj->extents, &rc)) if ((obj->numRects > 0) && overlapping(&obj->extents, &rc))
{ {
for (pCurRect = obj->rects, pRectEnd = pCurRect + for (i = region_find_pt( obj, rc.left, rc.top, &ret ); !ret && i < obj->numRects; i++ )
obj->numRects; pCurRect < pRectEnd; pCurRect++)
{ {
if (pCurRect->bottom <= rc.top) if (obj->rects[i].bottom <= rc.top)
continue; /* not far enough down yet */ continue; /* not far enough down yet */
if (pCurRect->top >= rc.bottom) if (obj->rects[i].top >= rc.bottom)
break; /* too far down */ break; /* too far down */
if (pCurRect->right <= rc.left) if (obj->rects[i].right <= rc.left)
continue; /* not far enough over yet */ continue; /* not far enough over yet */
if (pCurRect->left >= rc.right) { if (obj->rects[i].left >= rc.right)
continue; continue;
}
ret = TRUE; ret = TRUE;
break;
} }
} }
GDI_ReleaseObj(hrgn); GDI_ReleaseObj(hrgn);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment