[Gimp-developer] gimp-python: checking if point is in selection

saulgoode at brickfilms.com saulgoode at brickfilms.com
Fri Jun 2 10:44:33 PDT 2006


Quoting Sebastian Breuers <sebbreuers at gmx.de>:
> i wondered if there is a possibility to check, if a point is in a given
> selection by using an internal gimp function.
> If it's not, could someone give me a hint, how to achieve this in creating an
> own function?

I don't use Python-fu but the following Script-fu function should be  
easily ported (or perhaps you can find a better way):

(define (point-in-selection image x y)
   (let* (
       (saved (car (gimp-selection-save image)))
       (return-value)
       )
     (gimp-rect-select image x y 1 1 CHANNEL-OP-INTERSECT 0 0)
     (set! return-value (car (gimp-selection-is-empty image)))
     (gimp-selection-load saved)
     (if (= return-value 0)
       1
       0
       )
     )
   )

Note that the selection does not include the points at the rightmost  
and bottommost edges. For example, if the selection is from (0,0) to  
(10,10) then the point (10,10) is *not* "in" the selection but (9,9)  
is. You may need to adjust things to account for this.


More information about the Gimp-developer mailing list