DIAGRAM: abstract point to text conversion out a little

This commit is contained in:
hasufell 2014-10-10 15:34:18 +02:00
parent 01e2dd7802
commit 1540bf443e
No known key found for this signature in database
GPG Key ID: 220CD1C5BDEED020

View File

@ -105,17 +105,21 @@ coordPoints = Diag cp
dot = (circle $ t p :: Diagram Cairo R2) # fc black dot = (circle $ t p :: Diagram Cairo R2) # fc black
-- |Creates a Diagram from a point that shows the coordinates
-- in text format, such as "(1.0, 2.0)".
pointToTextCoord :: PT -> Diagram Cairo R2
pointToTextCoord pt =
text ("(" ++ show x ++ ", " ++ show y ++ ")") # scale 10
where
(x, y) = unp2 pt
coordPointsText :: Diag coordPointsText :: Diag
coordPointsText = Diag cpt coordPointsText = Diag cpt
where where
cpt _ vt = cpt _ vt =
position $ position $
zip vt zip vt (pointToTextCoord <$> vt) # translate (r2 (0, 10))
((\(x, y) -> (flip (<>) (square 1 # lw none) .
text $ ("(" ++ show x ++ ", " ++ show y ++ ")")) #
scale 10 # translate (r2 (0, 10))) <$>
unp2 <$>
vt)
-- |Create a diagram which shows the points of the convex hull. -- |Create a diagram which shows the points of the convex hull.
@ -137,11 +141,7 @@ convexHullPointsText = Diag chpt
chpt _ vt = chpt _ vt =
position $ position $
zip vtch zip vtch
((\(x, y) -> (flip (<>) (square 1 # lw none) . (pointToTextCoord <$> vtch) # translate (r2 (0, 10))
text $ ("(" ++ show x ++ ", " ++ show y ++ ")")) #
scale 10 # translate (r2 (0, 10))) <$>
unp2 <$>
vtch)
where where
vtch = grahamGetCH vt vtch = grahamGetCH vt