[racket] is-empty? on region% with no device-context.

From: Patrick Mahoney (paddy.mahoney at gmail.com)
Date: Wed May 2 17:55:49 EDT 2012

#|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

(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)

#|The region documentation...

I really just don't want to have to rewrite the overlaps? logic for my set
of shapes. Thanks all. |#
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120502/011b3807/attachment-0001.html>

Posted on the users mailing list.