#|is-empty? fails when called on a region produced without an associated dc...|# (define intersection (lambda (region-a region-b) (define new-region (new region%)) (send new-region union region-a) (send new-region intersect region-b) new-region))
#|-Patrick|# On 2 May 2012 17:55, Patrick Mahoney <paddy.maho...@gmail.com> wrote: > #|Hello All, > I'm attempting to ensure that shapes drawn onto a canvas don't overlap. In > order to do so, I attempted to use region% objects.| # > > #|Takes two rectangles, and tells whether they overlap as regions.|# > (define overlaps? > (lambda (rect-a rect-b) > (define region-a (rectangle->region rect-a)) > (define region-b (rectangle->region rect-b)) > (define a-intersection-b (intersection dc region-a region-b)) > (send a-intersection-b is-empty?))) > > #|Unfortunately this doesn't work-the is-empty? method only works on a > region% with an associated drawing context. Is there any way to salvage > this such that is-empty? can be used on region% objects unassociated with a > dc object? I'm not sure why they would require one, as otherwise the > region% interface seems fairly decoupled from the notion of > device-contexts. However, I'm sure that there is a reason that I don't yet > understand.|# > > (define intersection > (lambda (region-a region-b) > (define new-region (new region% [dc a-dc])) > (send new-region union region-a) > (send new-region intersect region-b) > new-region)) > > #|The region documentation... > http://docs.racket-lang.org/draw/region_.html?q=region&q=any-of%3F#%28meth._%28%28%28lib._racket/draw..rkt%29._region~25%29._in-region~3f%29%29<http://docs.racket-lang.org/draw/region_.html?q=region&q=any-of%3F#%28meth._%28%28%28lib._racket/draw..rkt%29._region%7E25%29._in-region%7E3f%29%29> > > I really just don't want to have to rewrite the overlaps? logic for my set > of shapes. Thanks all. |# > > >
____________________ Racket Users list: http://lists.racket-lang.org/users