Apart from introducing a bounding box check, I would<br>suggest converting each scanline into a single exact integer<br>with 1 bits corresponding to alpha unequal 0. Then for each scanline,<br>you can use arithmetic-shift and bitwise-and, and then check the result for<br>
being non-zero.<br><br>Stephan<br><div class="gmail_extra"><br><br><div class="gmail_quote">2012/11/28 Stephen Bloch <span dir="ltr">&lt;<a href="mailto:bloch@adelphi.edu" target="_blank">bloch@adelphi.edu</a>&gt;</span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
On Nov 28, 2012, at 3:10 AM, John Clements wrote:<br>
<br>
&gt; Okay, the totally-dumb collision detection implementation was shorter than expected; only 73 lines, including (light) testing.  Here&#39;s a link to that code:<br>
&gt;<br>
&gt; <a href="https://gist.github.com/4159778" target="_blank">https://gist.github.com/4159778</a><br>
<br>
Simple, straightforward.  I notice that your test cases use &quot;empty-scene&quot;, which raises another thought in my mind.<br>
<br>
At SIGCSE a year or two ago, somebody (I think it was either Anne Mulhern or Emmanuel Schanzer) suggested that students be taught to build complex images not with the idiom<br>
        (place-image ... (place-image ... (place-image ...)))<br>
but rather<br>
        (overlay        (place-image ...)<br>
                        (place-image ...)<br>
                        (place-image ...))<br>
This imposes less of an ordering on the images -- in fact, if they don&#39;t overlap, the order is completely irrelevant.  And it&#39;s easy to insert or remove individual images from the stack of slides, because that doesn&#39;t change the parenthesis nesting.  And it allows students to decide where each image belongs, then forget about this decision rather than keeping the location information around separately until we do the place-image.<br>

<br>
But for the latter to work, the various slides we&#39;re stacking up need to be mostly transparent.<br>
<br>
What would break if empty-scene defaulted to the color (make-color 0 0 0 0) rather than &#39;white (i.e. (make-color 255 255 255 255))?<br>
<br>
I guess if people did this routinely, the bounding-box computation John proposes adding to the collision-detection algorithm wouldn&#39;t help.  And the implementation of overlay might need to be revised to optimize for this case.<br>

<br>
&gt; It&#39;s observed to be darn slow: it took 4ms for collision detection between the two 65x65 images. This could be acceptable for a game with one or two collision detections per frame.<br>
&gt;<br>
&gt; You could improve this *hugely* just by doing some bounding-box computation.<br>
&gt;<br>
&gt; Should I put this code in 2htdp/private/image-more.rkt somewhere?<br>
<br>
Sounds useful to me.<br>
<br>
<br>
<br>
<br>
Stephen Bloch<br>
<a href="mailto:sbloch@adelphi.edu">sbloch@adelphi.edu</a><br>
<br>
<br>
____________________<br>
  Racket Users list:<br>
  <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
</blockquote></div><br></div>