Contact/support | Changelog

Good use of continuations?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
overlap :: MonadIO m => (Surface,(Int,Int)) -> Maybe Rect -> (Surface,(Int,Int)) -> Maybe Rect -> m Bool
overlap (lhs,(lx,ly)) lrect (rhs,(rx,ry)) rrect =
    withLock lhs $ withLock rhs $
        runContT' return $ callCC $ \exit -> do
            forM_ [(i,j) | i <- [xStart..xEnd], j <- [yStart..yEnd]] $ \(px, py) -> do
                Pixel p1 <- getPixel32 lhs (lxOffset + px) (lyOffset + py)
                Pixel p2 <- getPixel32 rhs (rxOffset + (px-xStart)) (ryOffset + (py-yStart))
                when (p1 /= black && p2 /= black) $ exit True
            return False

 where runContT' = flip runContT
       black = 0x00000000
       -- more definitions I haven't copied here...
       ...
       ...
       ...