Cleanup warnings
This commit is contained in:
@@ -5,17 +5,16 @@ Description : Concerns carving out of static walls to create the general room pl
|
||||
module Dodge.LevelGen.StaticWalls
|
||||
where
|
||||
import Dodge.Data
|
||||
import Dodge.Base
|
||||
import Dodge.Default
|
||||
--import Dodge.Base
|
||||
--import Dodge.Default
|
||||
import Geometry
|
||||
|
||||
import Control.Lens
|
||||
--import Control.Lens
|
||||
import Data.Function (on)
|
||||
import Data.Graph
|
||||
import Data.List
|
||||
import Data.Maybe
|
||||
import qualified Data.IntMap as IM
|
||||
import qualified Data.Set as S
|
||||
--import qualified Data.IntMap as IM
|
||||
--import qualified Data.Set as S
|
||||
-- | Describe a wall as two points.
|
||||
-- Order is important: the wall face is to the left as you move from 'fst'
|
||||
-- to 'snd'.
|
||||
@@ -48,7 +47,6 @@ cutWalls ps wls = case mapMaybe (`checkWallRight` newWalls) newWalls of
|
||||
_ -> cutWalls (map (rotateV 0.001) $ expandPolyBy 0.01 ps) wls
|
||||
where
|
||||
newWalls = cutWalls' ps wls
|
||||
errsL = mapMaybe (`checkWallLeft` newWalls) newWalls
|
||||
-- | As 'cutWalls', but rotate in the other direction.
|
||||
cutWallsL :: [Point2] -> [WallP] -> [WallP]
|
||||
cutWallsL ps wls = case mapMaybe (`checkWallRight` newWalls) newWalls of
|
||||
@@ -58,7 +56,6 @@ cutWallsL ps wls = case mapMaybe (`checkWallRight` newWalls) newWalls of
|
||||
_ -> cutWalls (map (rotateV (-0.001)) $ expandPolyBy 0.01 ps) wls
|
||||
where
|
||||
newWalls = cutWalls' ps wls
|
||||
errsL = mapMaybe (`checkWallLeft` newWalls) newWalls
|
||||
-- | Cut out a polygon from a set of walls, and check for errors in the
|
||||
-- created walls.
|
||||
-- Give error if created walls are not consistent.
|
||||
@@ -87,8 +84,8 @@ checkWallRight (x,y) wls
|
||||
| length ins == length outs = Nothing
|
||||
| otherwise = Just ((x,y), outs)
|
||||
where
|
||||
ins = filter (\(a,b) -> b == y) wls
|
||||
outs = filter (\(a,b) -> a == y) wls
|
||||
ins = filter (\(_,b) -> b == y) wls
|
||||
outs = filter (\(a,_) -> a == y) wls
|
||||
-- | Given a specific wall and list of walls, checks that the number of walls leaving the
|
||||
-- first point is the same as the number of walls entering the first point of
|
||||
-- the specific wall.
|
||||
@@ -99,8 +96,8 @@ checkWallLeft (x,y) wls
|
||||
| length ins == length outs = Nothing
|
||||
| otherwise = Just ((x,y), outs)
|
||||
where
|
||||
ins = filter (\(a,b) -> a == x) wls
|
||||
outs = filter (\(a,b) -> b == x) wls
|
||||
ins = filter (\(a,_) -> a == x) wls
|
||||
outs = filter (\(_,b) -> b == x) wls
|
||||
-- | Given a polygon of points and collection of walls, cuts out the polygon.
|
||||
-- Ie returns a new set of walls with a hole determined by anticlockwise ordering of the points.
|
||||
-- The overall procedure is:
|
||||
@@ -113,7 +110,7 @@ checkWallLeft (x,y) wls
|
||||
-- 6. remove any duplicate walls
|
||||
-- Unclear behaviour if a line in the polygon is colinear with a wall.
|
||||
cutWalls' :: [Point2] -> [WallP] -> [WallP]
|
||||
cutWalls' qs walls =
|
||||
cutWalls' qs wls =
|
||||
nub
|
||||
. filter (not.wallIsZeroLength)
|
||||
. fuseWallsWith zs
|
||||
@@ -124,7 +121,7 @@ cutWalls' qs walls =
|
||||
$ removeWallsInPolygon ps
|
||||
cwals
|
||||
where
|
||||
(zs,cwals) = cutWallsWithPoints ps walls
|
||||
(zs,cwals) = cutWallsWithPoints ps wls
|
||||
ps = orderPolygon qs
|
||||
rs = orderPolygon $ nub $ zs ++ qs
|
||||
-- | Given a value and a poly, pushes the poly points out from the center by the
|
||||
@@ -145,6 +142,7 @@ cutWallsWithPoints (p:ps) ws = foldr f ([],ws) (zip (p:ps) (ps++[p]))
|
||||
( nub $ as ++ cutWallsPoints p1 p2 ws'
|
||||
, concatMap (cutWall p1 p2) ws'
|
||||
)
|
||||
cutWallsWithPoints _ _ = error "Trying to cut empty polygon"
|
||||
-- | List the points of intersection between a segment and collection of walls.
|
||||
cutWallsPoints :: Point2 -> Point2 -> [WallP] -> [Point2]
|
||||
--cutWallsPoints p1 p2 ws = mapMaybe (\(x:y:_) -> intersectExtendedSegSeg p1 p2 x y)
|
||||
@@ -154,11 +152,13 @@ cutWall :: Point2 -> Point2 -> WallP -> [WallP]
|
||||
cutWall p1 p2 (x,y) = case myIntersectSegSeg p1 p2 x y of
|
||||
Nothing -> [(x,y)]
|
||||
Just cp -> [(x,cp),(cp,y)]
|
||||
-- | Add poly walls?
|
||||
addPolyWalls
|
||||
:: [Point2] -- ^ Multiple walls described as a polygon.
|
||||
-> [WallP]
|
||||
-> [WallP]
|
||||
addPolyWalls (q:qs) walls = foldr addPolyWall walls (zip (q:qs) (qs++[q]))
|
||||
addPolyWalls (q:qs) wls = foldr addPolyWall wls (zip (q:qs) (qs++[q]))
|
||||
addPolyWalls _ _ = error "Trying to add empty poly walls"
|
||||
-- | Add a new wall to a list of walls only if either
|
||||
-- 1. no wall already exists on the normal line from the new wall
|
||||
-- 2. any of the first existing walls hit on the normal line from the new wall
|
||||
@@ -166,12 +166,12 @@ addPolyWalls (q:qs) walls = foldr addPolyWall walls (zip (q:qs) (qs++[q]))
|
||||
-- The normal line is the line from the center point of the new wall outwards
|
||||
-- along the clockwise normal of the new wall (currently 10000 units along)
|
||||
addPolyWall :: WallP -> [WallP] -> [WallP]
|
||||
addPolyWall (p1,p2) walls =
|
||||
addPolyWall (p1,p2) wls =
|
||||
case maybeWs of
|
||||
Just ws -> if all (\(x,y) -> isLHS x y p3) ws
|
||||
then walls
|
||||
else (p1,p2) : walls
|
||||
Nothing -> (p1,p2) : walls
|
||||
then wls
|
||||
else (p1,p2) : wls
|
||||
Nothing -> (p1,p2) : wls
|
||||
where
|
||||
p3 = 0.5 *.* (p1 +.+ p2)
|
||||
p4 = p3 +.+ 10000 *.* vNormal (p2 -.- p1)
|
||||
@@ -182,10 +182,10 @@ addPolyWall (p1,p2) walls =
|
||||
wlsP :: [(WallP, Point2)]
|
||||
wlsP = sortBy (compare `on` (dist p3 . snd))
|
||||
. catMaybes
|
||||
$ zipWith f walls maybes
|
||||
$ zipWith f wls maybes
|
||||
f a (Just b) = Just (a,b)
|
||||
f _ Nothing = Nothing
|
||||
maybes = map (uncurry $ myIntersectSegSeg p3 p4) walls
|
||||
maybes = map (uncurry $ myIntersectSegSeg p3 p4) wls
|
||||
-- | Given a list of points and a point, returns a point in the list if any is close
|
||||
-- to the point.
|
||||
findClosePoint :: [Point2] -> Point2 -> Maybe Point2
|
||||
@@ -212,10 +212,11 @@ fuseWall (ps, (x,y)) = ( nub (x':y':ps) , (x',y') )
|
||||
fuseWallsWith :: [Point2] -> [WallP] -> [WallP]
|
||||
fuseWallsWith zs ws = snd $ foldr fuseWalls' (zs, []) ws
|
||||
where
|
||||
fuseWalls' w (ps, ws) =
|
||||
fuseWalls' w (ps, ws') =
|
||||
let (qs, w') = fuseWall (ps, w)
|
||||
in (qs, w' : ws)
|
||||
in (qs, w' : ws')
|
||||
-- | Test if fst p == snd p.
|
||||
wallIsZeroLength :: Eq a => (a,a) -> Bool
|
||||
wallIsZeroLength (x,y) = x == y
|
||||
-- | Given a polygon and list of walls, removes walls inside the polygon.
|
||||
removeWallsInPolygon :: [Point2] -> [WallP] -> [WallP]
|
||||
|
||||
Reference in New Issue
Block a user