DIAG: improve readability

This commit is contained in:
hasufell 2014-12-03 01:36:12 +01:00
parent 5123abfd99
commit 4a0c9ff58d
No known key found for this signature in database
GPG Key ID: 220CD1C5BDEED020

View File

@ -25,7 +25,7 @@ drawP [] _ = mempty
drawP vt ds = drawP vt ds =
position (zip vt (repeat dot)) position (zip vt (repeat dot))
where where
dot = (circle ds :: Diagram Cairo R2) dot = circle ds :: Diagram Cairo R2
-- |Create a rectangle around a diagonal line, which has sw -- |Create a rectangle around a diagonal line, which has sw
@ -35,7 +35,7 @@ rectByDiagonal :: (Double, Double) -- ^ sw point
-> Diagram Cairo R2 -> Diagram Cairo R2
rectByDiagonal (xmin, xmax) (ymin, ymax) = rectByDiagonal (xmin, xmax) (ymin, ymax) =
rect (xmax - xmin) (ymax - ymin) rect (xmax - xmin) (ymax - ymin)
# moveTo (p2 ((xmax + xmin) / 2, (ymax + ymin) / 2)) # moveTo (p2 ((xmax + xmin) / 2, (ymax + ymin) / 2))
-- |Creates a Diagram that shows the coordinates from the points -- |Creates a Diagram that shows the coordinates from the points
@ -68,9 +68,7 @@ coordPointsText = Diag cpt
cpt p (Objects vts) = drawT (concat vts) p cpt p (Objects vts) = drawT (concat vts) p
drawT [] _ = mempty drawT [] _ = mempty
drawT vt p drawT vt p
| showCoordText p = | showCoordText p = position $ zip vt (pointToTextCoord <$> vt)
position
$ zip vt (pointToTextCoord <$> vt)
# translate (r2 (0, 10)) # translate (r2 (0, 10))
| otherwise = mempty | otherwise = mempty
@ -83,10 +81,7 @@ polyLines = Diag pp
pp _ (Objects (x:y:_)) = pp _ (Objects (x:y:_)) =
strokePoly x <> strokePoly y strokePoly x <> strokePoly y
where where
strokePoly x' = strokePoly x' = (strokeTrail . fromVertices $ x' ++ [head x'])
(strokeTrail
. fromVertices
$ x' ++ [head x'])
# moveTo (head x') # lc black # moveTo (head x') # lc black
pp _ _ = mempty pp _ _ = mempty
@ -97,10 +92,7 @@ polyIntersection = Diag pi'
where where
pi' p (Objects (x:y:_)) = drawP vtpi (dotSize p) # fc red # lc red pi' p (Objects (x:y:_)) = drawP vtpi (dotSize p) # fc red # lc red
where where
vtpi = intersectionPoints vtpi = intersectionPoints . sortLexPolys $ (sortLexPoly x, sortLexPoly y)
. sortLexPolys
$ (sortLexPoly x,
sortLexPoly y)
pi' _ _ = mempty pi' _ _ = mempty
@ -109,10 +101,7 @@ polyIntersectionText :: Diag
polyIntersectionText = Diag pit' polyIntersectionText = Diag pit'
where where
pit' p (Objects (x:y:_)) pit' p (Objects (x:y:_))
| showCoordText p = | showCoordText p = position . zip vtpi $ (pointToTextCoord # fc red <$> vtpi)
position
. zip vtpi
$ (pointToTextCoord # fc red <$> vtpi)
# translate (r2 (0, 10)) # translate (r2 (0, 10))
| otherwise = mempty | otherwise = mempty
where where
@ -137,9 +126,7 @@ convexHPText = Diag chpt
where where
chpt p (Object vt) chpt p (Object vt)
| showCoordText p = | showCoordText p =
position $ position $ zip vtchf (pointToTextCoord <$> vtchf) # translate (r2 (0, 10))
zip vtchf
(pointToTextCoord <$> vtchf) # translate (r2 (0, 10))
| otherwise = mempty | otherwise = mempty
where where
vtchf = grahamCH vt vtchf = grahamCH vt
@ -153,12 +140,8 @@ convexHLs = Diag chl
where where
chl _ (Object []) = mempty chl _ (Object []) = mempty
chl _ (Object vt) = chl _ (Object vt) =
(strokeTrail (strokeTrail . fromVertices . flip (++) [head $ grahamCH vt] . grahamCH $ vt)
. fromVertices # moveTo (head $ grahamCH vt) # lc red
. flip (++) [head $ grahamCH vt]
. grahamCH
$ vt)
# moveTo (head $ grahamCH vt) # lc red
chl _ _ = mempty chl _ _ = mempty
@ -168,11 +151,9 @@ convexHLs = Diag chl
convexHStepsLs :: Diag convexHStepsLs :: Diag
convexHStepsLs = GifDiag chs convexHStepsLs = GifDiag chs
where where
chs _ col f vt = chs _ col f vt = fmap mkChDiag (f vt)
fmap mkChDiag (f vt)
where where
mkChDiag vt' = mkChDiag vt' = (strokeTrail . fromVertices $ vt') # moveTo (head vt') # lc col
(strokeTrail . fromVertices $ vt') # moveTo (head vt') # lc col
-- |Create a diagram that shows all squares of the RangeSearch algorithm -- |Create a diagram that shows all squares of the RangeSearch algorithm
@ -184,10 +165,10 @@ squares = Diag f
f p (Object vt) = f p (Object vt) =
mconcat mconcat
$ (uncurry rectByDiagonal # lw ultraThin) $ (uncurry rectByDiagonal # lw ultraThin)
<$> <$>
(quadTreeSquares (xDimension p, yDimension p) (quadTreeSquares (xDimension p, yDimension p)
. quadTree vt . quadTree vt
$ (xDimension p, yDimension p)) $ (xDimension p, yDimension p))
f _ _ = mempty f _ _ = mempty
@ -229,7 +210,7 @@ kdRange = Diag f
f _ (Object []) = mempty f _ (Object []) = mempty
f p (Object vt) = f p (Object vt) =
(uncurry rectByDiagonal # lc red) (rangeSquare p) (uncurry rectByDiagonal # lc red) (rangeSquare p)
<> drawP ptsInRange (dotSize p) # fc red # lc red <> drawP ptsInRange (dotSize p) # fc red # lc red
where where
ptsInRange = fst . rangeSearch (kdTree vt Vertical) $ rangeSquare p ptsInRange = fst . rangeSearch (kdTree vt Vertical) $ rangeSquare p
f _ _ = mempty f _ _ = mempty
@ -338,13 +319,11 @@ xAxis =
<> Diag segments <> Diag segments
<> Diag labels <> Diag labels
where where
hRule p _ = hRule p _ = arrowAt (p2 (diagXmin p, if diagYmin p <= 0 then 0 else diagYmin p))
arrowAt (p2 (diagXmin p, if diagYmin p <= 0 then 0 else diagYmin p)) (r2 (diagWidth p, 0))
(r2 (diagWidth p, 0)) segments p _ = hcat' (with & sep .~ squareSize p)
segments p _ = (replicate (floor . (/) (diagWidth p) $ squareSize p)
hcat' (with & sep .~ squareSize p) (vrule 10))
(replicate (floor . (/) (diagWidth p) $ squareSize p)
(vrule 10))
# moveTo (p2 (diagXmin p, if diagYmin p <= 0 then 0 else diagYmin p)) # moveTo (p2 (diagXmin p, if diagYmin p <= 0 then 0 else diagYmin p))
labels p _ = labels p _ =
position $ position $
@ -410,17 +389,15 @@ grid :: Diag
grid = Diag xGrid <> Diag yGrid grid = Diag xGrid <> Diag yGrid
where where
yGrid p _ yGrid p _
| haveGrid p = | haveGrid p = hcat' (with & sep .~ squareSize p)
hcat' (with & sep .~ squareSize p) (replicate (floor . (/) (diagWidth p) $ squareSize p)
(replicate (floor . (/) (diagWidth p) $ squareSize p) (vrule $ diagHeight p))
(vrule $ diagHeight p))
# moveTo (p2 (diagXmin p, diagHeightOffset p)) # lw ultraThin # moveTo (p2 (diagXmin p, diagHeightOffset p)) # lw ultraThin
| otherwise = mempty | otherwise = mempty
xGrid p _ xGrid p _
| haveGrid p = | haveGrid p = vcat' (with & sep .~ squareSize p)
vcat' (with & sep .~ squareSize p) (replicate (floor . (/) (diagHeight p) $ squareSize p)
(replicate (floor . (/) (diagHeight p) $ squareSize p) (hrule $ diagWidth p))
(hrule $ diagWidth p))
# alignB # moveTo (p2 (diagWidthOffset p, diagYmin p)) # lw ultraThin # alignB # moveTo (p2 (diagWidthOffset p, diagYmin p)) # lw ultraThin
| otherwise = mempty | otherwise = mempty