#|is-empty? fails when called on a region produced without an associated dc...|#<br>(define intersection<br> (lambda (region-a region-b)<br> (define new-region (new region%))<br> (send new-region union region-a)<br>
(send new-region intersect region-b)<br> new-region))<br><br>#|-Patrick|#<br><br><div class="gmail_quote">On 2 May 2012 17:55, Patrick Mahoney <span dir="ltr"><<a href="mailto:paddy.mahoney@gmail.com" target="_blank">paddy.mahoney@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">#|Hello All,<br>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.| #<br>
<br>#|Takes two rectangles, and tells whether they overlap as regions.|#<br>
(define overlaps?<br> (lambda (rect-a rect-b)<br> (define region-a (rectangle->region rect-a))<br> (define region-b (rectangle->region rect-b))<br> (define a-intersection-b (intersection dc region-a region-b))<br>
(send a-intersection-b is-empty?)))<br><br>#|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.|#<br>
<br>(define intersection<br> (lambda (region-a region-b)<br> (define new-region (new region% [dc a-dc]))<br> (send new-region union region-a)<br> (send new-region intersect region-b)<br> new-region))<br><br>
#|The region documentation... <a href="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" target="_blank">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</a><br>
<br>I really just don't want to have to rewrite the overlaps? logic for my set of shapes. Thanks all. |#<br><br><br>
</blockquote></div><br>