Skip to content

Instantly share code, notes, and snippets.

@glguy
Last active December 29, 2021 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glguy/c51bb1e01e964f780e9255eaad77ca69 to your computer and use it in GitHub Desktop.
Save glguy/c51bb1e01e964f780e9255eaad77ca69 to your computer and use it in GitHub Desktop.
subtractBox1 :: Box n -> Box n -> [Box n]
subtractBox1 b1 b2 =
case intersectBox b1 b2 of
Nothing -> [b2]
Just i -> subtractBox' i b2
-- | Worker for 'subtractBox'
subtractBox' :: Box n -> Box n -> [Box n]
subtractBox' Pt Pt = []
subtractBox' (i@(Seg x y) :* is) (Seg c d :* ys)
= [Seg c x :* ys | c < x] ++
[Seg y d :* ys | y < d] ++
map (i :*) (subtractBox' is ys)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment