DIAG: simplify plotter

This commit is contained in:
hasufell 2014-12-02 19:00:50 +01:00
parent a23842bf82
commit d5d7209039
No known key found for this signature in database
GPG Key ID: 220CD1C5BDEED020
1 changed files with 33 additions and 28 deletions

View File

@ -18,26 +18,36 @@ import Parser.PathParser
import qualified Debug.Trace as D import qualified Debug.Trace as D
-- |Draw a list of points.
drawP :: [PT] -- ^ the points to draw
-> Double -- ^ dot size
-> Diagram Cairo R2 -- ^ the resulting diagram
drawP [] _ = mempty
drawP vt ds =
position (zip vt (repeat dot))
where
dot = (circle ds :: Diagram Cairo R2)
-- |Create a rectangle around a diagonal line, which has sw
-- as startpoint and nw as endpoint.
rectByDiagonal :: (Double, Double) -- ^ sw point
-> (Double, Double) -- ^ nw point
-> Diagram Cairo R2
rectByDiagonal (xmin, xmax) (ymin, ymax) =
rect (xmax - xmin) (ymax - ymin)
# 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
-- as dots. The points and thickness of the dots can be controlled -- as dots. The points and thickness of the dots can be controlled
-- via DiagProp. -- via DiagProp.
coordPoints :: Diag coordPoints :: Diag
coordPoints = Diag cp coordPoints = Diag cp
where where
cp p (Object vt) = drawP vt (dotSize p) black cp p (Object vt) = drawP vt (dotSize p) # fc black # lc black
cp p (Objects vts) = drawP (concat vts) (dotSize p) black cp p (Objects vts) = drawP (concat vts) (dotSize p) # fc black # lc black
-- |Draw a list of points.
drawP :: [PT] -- ^ the points to draw
-> Double -- ^ dot size
-> Colour Double -- ^ fc and lc
-> Diagram Cairo R2 -- ^ the resulting diagram
drawP [] _ _ = mempty
drawP vt ds col =
position (zip vt (repeat dot))
where
dot = (circle ds :: Diagram Cairo R2) # fc col # lc col
-- |Creates a Diagram from a point that shows the coordinates -- |Creates a Diagram from a point that shows the coordinates
@ -87,7 +97,7 @@ polyLines = Diag pp
polyIntersection :: Diag polyIntersection :: Diag
polyIntersection = Diag pi' polyIntersection = Diag pi'
where where
pi' p (Objects (x:y:_)) = drawP vtpi (dotSize p) red pi' p (Objects (x:y:_)) = drawP vtpi (dotSize p) # fc red # lc red
where where
vtpi = intersectionPoints vtpi = intersectionPoints
. sortLexPolys . sortLexPolys
@ -119,7 +129,7 @@ polyIntersectionText = Diag pit'
convexHP :: Diag convexHP :: Diag
convexHP = Diag chp convexHP = Diag chp
where where
chp p (Object vt) = drawP (grahamCH vt) (dotSize p) red chp p (Object vt) = drawP (grahamCH vt) (dotSize p) # fc red # lc red
chp _ _ = mempty chp _ _ = mempty
@ -175,9 +185,9 @@ squares = Diag f
f _ (Object []) = mempty f _ (Object []) = mempty
f p (Object vt) = f p (Object vt) =
mconcat mconcat
$ (\((xmin, xmax), (ymin, ymax)) -> rect (xmax - xmin) (ymax - ymin) $ (uncurry rectByDiagonal # lw ultraThin)
# moveTo (p2 ((xmax + xmin) / 2, (ymax + ymin) / 2)) # 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
@ -220,11 +230,8 @@ kdRange = Diag f
where where
f _ (Object []) = mempty f _ (Object []) = mempty
f p (Object vt) = f p (Object vt) =
(\((xmin, xmax), (ymin, ymax)) -> rect (xmax - xmin) (ymax - ymin) (uncurry rectByDiagonal # lc red) (rangeSquare p)
# moveTo (p2 ((xmax + xmin) / 2, (ymax + ymin) / 2)) <> drawP ptsInRange (dotSize p) # fc red # lc red
# lc red)
(rangeSquare p)
<> drawP ptsInRange (dotSize p) red
where where
ptsInRange = fst . rangeSearch (kdTree vt Vertical) $ rangeSquare p ptsInRange = fst . rangeSearch (kdTree vt Vertical) $ rangeSquare p
f _ _ = mempty f _ _ = mempty
@ -266,8 +273,7 @@ quadPathSquare = Diag f
where where
f _ (Object []) = mempty f _ (Object []) = mempty
f p (Object vt) = f p (Object vt) =
(\((xmin, xmax), (ymin, ymax)) -> rect (xmax - xmin) (ymax - ymin) (uncurry rectByDiagonal # lw thin # lc red)
# moveTo (p2 ((xmax + xmin) / 2,(ymax + ymin) / 2)) # lw thin # lc red)
(getSquare (stringToQuads (quadPath p)) (qt vt p, [])) (getSquare (stringToQuads (quadPath p)) (qt vt p, []))
where where
getSquare :: [Either Quad Orient] -> Zipper PT -> Square getSquare :: [Either Quad Orient] -> Zipper PT -> Square
@ -284,8 +290,7 @@ gifQuadPath :: Diag
gifQuadPath = GifDiag f gifQuadPath = GifDiag f
where where
f p col _ vt = f p col _ vt =
(\((xmin, xmax), (ymin, ymax)) -> rect (xmax - xmin) (ymax - ymin) (uncurry rectByDiagonal # lw thick # lc col)
# moveTo (p2 ((xmax + xmin) / 2,(ymax + ymin) / 2)) # lw thick # lc col)
<$> getSquares (stringToQuads (quadPath p)) (qt vt p, []) <$> getSquares (stringToQuads (quadPath p)) (qt vt p, [])
where where
getSquares :: [Either Quad Orient] -> Zipper PT -> [Square] getSquares :: [Either Quad Orient] -> Zipper PT -> [Square]