#|Hello All,<br>I&#39;m attempting to ensure that shapes drawn onto a canvas don&#39;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-&gt;region rect-a))<br>    (define region-b (rectangle-&gt;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&#39;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&#39;m not sure why they would require one, as otherwise the region% interface seems fairly decoupled from the notion of device-contexts. However, I&#39;m sure that there is a reason that I don&#39;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&amp;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&amp;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&#39;t want to have to rewrite the overlaps? logic for my set of shapes. Thanks all. |#<br><br><br>