PARSER: use 'Either' from Prelude instead of custom QuadOrOrient
This commit is contained in:
parent
068ea04d56
commit
d5741d3839
@ -197,11 +197,11 @@ quadPathSquare = Diag f
|
||||
# moveTo (p2 ((xmax + xmin) / 2,(ymax + ymin) / 2)) # lw thin # lc red)
|
||||
(getSquare (stringToQuads (pQt p)) (qt, []))
|
||||
where
|
||||
getSquare :: [QuadOrOrient] -> Zipper PT -> Square
|
||||
getSquare :: [Either Quad Orient] -> Zipper PT -> Square
|
||||
getSquare [] z = getSquareByZipper (dX p, dY p) z
|
||||
getSquare (q:qs) z = case q of
|
||||
Orient x -> getSquare qs (fromMaybe z (findNeighbor x z))
|
||||
Quad x -> getSquare qs (fromMaybe z (goQuad x z))
|
||||
Right x -> getSquare qs (fromMaybe z (findNeighbor x z))
|
||||
Left x -> getSquare qs (fromMaybe z (goQuad x z))
|
||||
qt :: QuadTree PT
|
||||
qt = quadTree vtf (dX p, dY p)
|
||||
vtf :: [PT]
|
||||
@ -218,13 +218,13 @@ gifQuadPath = GifDiag f
|
||||
# moveTo (p2 ((xmax + xmin) / 2,(ymax + ymin) / 2)) # lw thick # lc col)
|
||||
<$> (getSquares (stringToQuads (pQt p)) (qt, []))
|
||||
where
|
||||
getSquares :: [QuadOrOrient] -> Zipper PT -> [Square]
|
||||
getSquares :: [Either Quad Orient] -> Zipper PT -> [Square]
|
||||
getSquares [] z = [getSquareByZipper (dX p, dY p) z]
|
||||
getSquares (q:qs) z = case q of
|
||||
Orient x -> getSquareByZipper (dX p, dY p) z :
|
||||
getSquares qs (fromMaybe z (findNeighbor x z))
|
||||
Quad x -> getSquareByZipper (dX p, dY p) z :
|
||||
getSquares qs (fromMaybe z (goQuad x z))
|
||||
Right x -> getSquareByZipper (dX p, dY p) z :
|
||||
getSquares qs (fromMaybe z (findNeighbor x z))
|
||||
Left x -> getSquareByZipper (dX p, dY p) z :
|
||||
getSquares qs (fromMaybe z (goQuad x z))
|
||||
qt :: QuadTree PT
|
||||
qt = quadTree vtf (dX p, dY p)
|
||||
vtf :: [PT]
|
||||
|
@ -7,16 +7,9 @@ import Parser.Core
|
||||
import Algorithms.RangeSearch.Core (Quad(NW, NE, SW, SE), Orient(North, South, West, East))
|
||||
|
||||
|
||||
-- |Can either be an Orientation or a Quad, corresponding to the
|
||||
-- Algorithms.RangeSearch module.
|
||||
data QuadOrOrient = Orient Orient
|
||||
| Quad Quad
|
||||
deriving (Show)
|
||||
|
||||
|
||||
-- |Parse a string such as "ne, n, sw, e" into
|
||||
-- [Quad NE, Orient North, Quad SW, Orient East].
|
||||
stringToQuads :: String -> [QuadOrOrient]
|
||||
stringToQuads :: String -> [Either Quad Orient]
|
||||
stringToQuads str = case runParser parsePath str of
|
||||
Nothing -> []
|
||||
Just xs -> fst xs
|
||||
@ -28,19 +21,19 @@ stringToQuads str = case runParser parsePath str of
|
||||
|
||||
-- |Parses a string that represents a single squad into the
|
||||
-- QuadOrOrient ADT.
|
||||
parseQuad :: Parser QuadOrOrient
|
||||
parseQuad :: Parser (Either Quad Orient)
|
||||
parseQuad =
|
||||
const (Quad NW) <$> (string "nw" <|> string "NW")
|
||||
<|> const (Quad NE) <$> (string "ne" <|> string "NE")
|
||||
<|> const (Quad SW) <$> (string "sw" <|> string "SW")
|
||||
<|> const (Quad SE) <$> (string "se" <|> string "SE")
|
||||
const (Left NW) <$> (string "nw" <|> string "NW")
|
||||
<|> const (Left NE) <$> (string "ne" <|> string "NE")
|
||||
<|> const (Left SW) <$> (string "sw" <|> string "SW")
|
||||
<|> const (Left SE) <$> (string "se" <|> string "SE")
|
||||
|
||||
|
||||
-- |Parses a string that represents a single Orientation into the
|
||||
-- QuadOrOrient ADT.
|
||||
parseOrient :: Parser QuadOrOrient
|
||||
parseOrient :: Parser (Either Quad Orient)
|
||||
parseOrient =
|
||||
const (Orient North) <$> (string "n" <|> string "N")
|
||||
<|> const (Orient South) <$> (string "s" <|> string "S")
|
||||
<|> const (Orient West) <$> (string "w" <|> string "W")
|
||||
<|> const (Orient East) <$> (string "e" <|> string "E")
|
||||
const (Right North) <$> (string "n" <|> string "N")
|
||||
<|> const (Right South) <$> (string "s" <|> string "S")
|
||||
<|> const (Right West) <$> (string "w" <|> string "W")
|
||||
<|> const (Right East) <$> (string "e" <|> string "E")
|
||||
|
Loading…
Reference in New Issue
Block a user