The code takes a quadtree and inserts a rectangle. However I get a parse error on the let statment. I want to call the function newExtent without having to add all the arguments. So newExtent TopLeft
instead of having to call newExtent TopLeft extent rectangle
. How do I make it work?
insert :: QuadTree -> Rectangle -> QuadTree
insert (Qt extent horizontal vertical qTL qTR qBL qBR) rectangle
| quadPart extent rectangle == VerLine = Qt extent horizontal (rectangle:vertical) qTL qTR qBL qBR
| quadPart extent rectangle == HorLine = Qt extent (rectangle:horizontal) vertical qTL qTR qBL qBR
| quadPart extent rectangle == TopLeft && qTL == EmptyQuadTree = Qt extent horizontal vertical (newExtent TopLeft) qTR qBL qBR
| quadPart extent rectangle == TopLeft = Qt extent horizontal vertical (insert qTL rectangle) qTR qBL qBR
| quadPart extent rectangle == TopRight && qTR == EmptyQuadTree = Qt extent horizontal vertical qTL (newExtent TopRight) qBL qBR
| quadPart extent rectangle == TopRight = Qt extent horizontal vertical qTL (insert qTR rectangle) qBL qBR
| quadPart extent rectangle == BottomLeft && qBL == EmptyQuadTree = Qt extent horizontal vertical qTL qTR (newExtent BottomLeft) qBR
| quadPart extent rectangle == BottomLeft = Qt extent horizontal vertical qTL qTR (insert qBL rectangle) qBR
| quadPart extent rectangle == BottomRight && qBR == EmptyQuadTree = Qt extent horizontal vertical qTL qTR qBL (newExtent BottomRight)
| otherwise = Qt extent horizontal vertical qTL qTR qBL (insert qBR rectangle)
let (Rect eL eT eR eB) = extent
in newExtent :: TreeParts -> Rectangle -> Rectangle -> QuadTree
newExtent part (Rect eL eT eR eB) rectangle
| part == TopLeft = insert (emptyQtree (Rect eL eT ((eL + eR) `div` 2) ((eT + eB) `div` 2))) rectangle
| part == TopRight = insert (emptyQtree (Rect ((eL + eR) `div` 2) eT eR ((eT + eB) `div` 2))) rectangle
| part == BottomLeft = insert (emptyQtree (Rect eL ((eT + eB) `div` 2) ((eL + eR) `div` 2) eB)) rectangle
| part == BottomRight = insert (emptyQtree (Rect ((eL + eR) `div` 2) ((eT + eB) `div` 2) eR eB)) rectangle