[PATCH] DIX/ConfineTo: Improve algorithm to jump to the nearest point inside

Egbert Eich eich at freedesktop.org
Fri Feb 7 09:56:30 PST 2014


On Fri, Feb 07, 2014 at 11:38:25AM +0100, Egbert Eich wrote:
> > 
> > commit d8a52a3a3b5bc4a1ff0a986e87dd6c36366e531b
> > Author: Keith Packard <keithp at keithp.com>
> > Date:   Fri Oct 4 16:00:49 2013 -0700
> > 
> >     Improved ConfineToShape
> >     
> >     Find the box within the region which is closest to the point and move
> >     there.
> >     
> >     Signed-off-by: Keith Packard <keithp at keithp.com>
> > 
> >  
> > +static uint32_t
> > +ConfineToBox(int x, int y, BoxPtr box, int *px, int16_t *py)
> 
>                                                     ^^^^^^
>    You probably want to use an int here or fix the other types
>    as well. As it is it will produce a big compiler warning.
>    I see your point here, you wanted to make sure that the 
>    distance ^ 2 still fits into an int. But this is already
>    done by clamping dx and dy to 32767.
> 
[..]

> > +    BoxPtr box;
> > +    int nbox;
> >      int x = *px, y = *py;
> > -    int incx = 1, incy = 1;
> > +    int bx, by;
> > +    uint32_t box_dist_2;
> > +    int best_x, best_y;
> > -                return;         /* should never get here! */
> > +    box = REGION_RECTS(shape);
> 
> You probably intended to do:
> 
>        nbox = REGION_NUM_RECTS(shape);
>        for (i = 0; i < nbox; i++) {
>        ....
> 
> > +    for (i = 0; i < REGION_NUM_RECTS(shape); i++) {
> > +        box_dist_2 = ConfineToBox(x, y, &box[i], &bx, &by);
> 
> 
> [..]
> 

And, BTW, with the two points addressed,

Reviewed-By: Egbert Eich <eich at freedesktop.org>


More information about the xorg-devel mailing list