module Dodge.Wall.Zone
    where
import Dodge.Data
import Geometry
import Dodge.Zone
import Dodge.Base

import Control.Lens
import Data.Foldable

zoneOfWall :: Wall -> [(Int,Int)]
zoneOfWall wl 
    | uncurry dist wlline <= 2*zoneSize =  [zoneOfPoint $ uncurry pHalf wlline ]
    | otherwise = map zoneOfPoint $ uncurry (divideLine zoneSize) wlline
  where
    wlline = _wlLine wl

insertWallInZones :: Wall -> World -> World
insertWallInZones wl = wallsZone . znObjects
    %~ flip (foldl' (flip $ \(a,b) -> insertIMInZone a b (_wlID wl) wl)) (zoneOfWall wl)

deleteWallFromZones :: Wall -> World -> World
deleteWallFromZones wl = wallsZone . znObjects 
    %~ flip (foldl' (flip $ \(a,b) -> deleteIMInZone a b (_wlID wl))) (zoneOfWall wl)
