Refactor function names, split out some functions

This commit is contained in:
hasufell 2014-10-13 20:14:50 +02:00
parent d87dc25d26
commit 09eeaeda27
No known key found for this signature in database
GPG Key ID: 220CD1C5BDEED020
3 changed files with 33 additions and 28 deletions

View File

@ -16,14 +16,14 @@ gifDiag :: DiagProp -> [PT] -> [(Diagram Cairo R2, GifDelay)]
gifDiag p xs = gifDiag p xs =
fmap ((\x -> (x, 100)) . (<> nonChDiag)) . fmap ((\x -> (x, 100)) . (<> nonChDiag)) .
flip (++) flip (++)
[mkDiag (convexHullPointsText `mappend` [mkDiag (convexHPText `mappend`
convexHullPoints) convexHP)
p xs <> lastUpperHull <> lastLowerHull] $ p xs <> lastUpperHull <> lastLowerHull] $
(lowerHullList ++ ((<> lastLowerHull) <$> upperHullList)) (lowerHullList ++ ((<> lastLowerHull) <$> upperHullList))
where where
upperHullList = convexHullLinesIntervalUpper p xs upperHullList = convexUHStepsLs p xs
lastUpperHull = last upperHullList lastUpperHull = last upperHullList
lowerHullList = convexHullLinesIntervalLower p xs lowerHullList = convexLHStepsLs p xs
lastLowerHull = last lowerHullList lastLowerHull = last lowerHullList
-- add the x-axis and the other default stuff -- add the x-axis and the other default stuff
nonChDiag = nonChDiag =

View File

@ -22,8 +22,8 @@ diag p = case alg p of
1 -> 1 ->
mkDiag mkDiag
(mconcat (mconcat
[maybeDiag (ct p) convexHullPointsText, [maybeDiag (ct p) convexHPText,
convexHullPoints, convexHullLines, convexHP, convexHLs,
coordPoints, xAxis, yAxis, coordPoints, xAxis, yAxis,
maybeDiag (gd p) grid, whiteRectB]) maybeDiag (gd p) grid, whiteRectB])
p p

View File

@ -44,8 +44,8 @@ coordPointsText = Diag cpt
-- |Create a diagram which shows the points of the convex hull. -- |Create a diagram which shows the points of the convex hull.
convexHullPoints :: Diag convexHP :: Diag
convexHullPoints = Diag chp convexHP = Diag chp
where where
chp p vt = chp p vt =
position (zip (filter (inRange (dX p) (dY p)) vtch) position (zip (filter (inRange (dX p) (dY p)) vtch)
@ -56,8 +56,8 @@ convexHullPoints = Diag chp
-- |Show coordinates as text above the convex hull points. -- |Show coordinates as text above the convex hull points.
convexHullPointsText :: Diag convexHPText :: Diag
convexHullPointsText = Diag chpt convexHPText = Diag chpt
where where
chpt p vt = chpt p vt =
position $ position $
@ -69,8 +69,8 @@ convexHullPointsText = Diag chpt
-- |Create a diagram which shows the lines along the convex hull -- |Create a diagram which shows the lines along the convex hull
-- points. -- points.
convexHullLines :: Diag convexHLs :: Diag
convexHullLines = Diag chl convexHLs = Diag chl
where where
chl _ [] = mempty chl _ [] = mempty
chl p vt = chl p vt =
@ -85,32 +85,37 @@ convexHullLines = Diag chl
vtf = filter (inRange (dX p) (dY p)) vt vtf = filter (inRange (dX p) (dY p)) vt
convexHullLinesIntervalLower :: DiagProp -> [PT] -> [Diagram Cairo R2] -- |Create list of diagrama which describe the lines along points of a half
convexHullLinesIntervalLower p xs = -- convex hull, for each iteration of the algorithm. Which half is chosen
fmap mkChDiag (grahamLHSteps xs) -- depends on the input.
convexHStepsLs :: Colour Double
-> ([PT] -> [[PT]])
-> DiagProp
-> [PT]
-> [Diagram Cairo R2]
convexHStepsLs col f p xs =
fmap mkChDiag (f xs)
where where
mkChDiag vt = mkChDiag vt =
(strokeTrail . (strokeTrail .
fromVertices $ fromVertices $
vtf) # vtf) #
moveTo (head vtf) # moveTo (head vtf) #
lc orange lc col
where where
vtf = filter (inRange (dX p) (dY p)) vt vtf = filter (inRange (dX p) (dY p)) vt
convexHullLinesIntervalUpper :: DiagProp -> [PT] -> [Diagram Cairo R2] -- |Create list of diagrama which describe the lines along the lower
convexHullLinesIntervalUpper p xs = -- convex hull points, for each iteration of the algorithm.
fmap mkChDiag (grahamUHSteps xs) convexLHStepsLs :: DiagProp -> [PT] -> [Diagram Cairo R2]
where convexLHStepsLs = convexHStepsLs orange grahamLHSteps
mkChDiag vt =
(strokeTrail .
fromVertices $ -- |Create list of diagrama which describe the lines along the upper
vtf) # -- convex hull points, for each iteration of the algorithm.
moveTo (head vtf) # convexUHStepsLs :: DiagProp -> [PT] -> [Diagram Cairo R2]
lc purple convexUHStepsLs = convexHStepsLs purple grahamUHSteps
where
vtf = filter (inRange (dX p) (dY p)) vt
-- |Creates a Diagram that shows an XAxis which is bound -- |Creates a Diagram that shows an XAxis which is bound