DIAG: dump the Object data type, it's useless

This commit is contained in:
hasufell 2014-12-07 04:33:45 +01:00
parent 9c1121d941
commit 70a6dd1766
No known key found for this signature in database
GPG Key ID: 220CD1C5BDEED020
5 changed files with 31 additions and 39 deletions

View File

@ -21,8 +21,8 @@ import Parser.PathParser
polyLines :: Diag polyLines :: Diag
polyLines = Diag pp polyLines = Diag pp
where where
pp _ (Objects []) = mempty pp _ [] = mempty
pp _ (Objects (x:y:_)) = pp _ (x:y:_) =
strokePoly x <> strokePoly y strokePoly x <> strokePoly y
where where
strokePoly x' = (strokeTrail . fromVertices $ x' ++ [head x']) strokePoly x' = (strokeTrail . fromVertices $ x' ++ [head x'])
@ -34,7 +34,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) # fc red # lc red pi' p (x:y:_) = drawP vtpi (dotSize p) # fc red # lc red
where where
vtpi = intersectionPoints . sortLexPolys $ (sortLexPoly x, sortLexPoly y) vtpi = intersectionPoints . sortLexPolys $ (sortLexPoly x, sortLexPoly y)
pi' _ _ = mempty pi' _ _ = mempty
@ -44,7 +44,7 @@ polyIntersection = Diag pi'
polyIntersectionText :: Diag polyIntersectionText :: Diag
polyIntersectionText = Diag pit' polyIntersectionText = Diag pit'
where where
pit' p (Objects (x:y:_)) pit' p (x:y:_)
| showCoordText p = position . zip vtpi $ (pointToTextCoord # fc red <$> vtpi) | showCoordText p = position . zip vtpi $ (pointToTextCoord # fc red <$> vtpi)
# translate (r2 (0, 10)) # translate (r2 (0, 10))
| otherwise = mempty | otherwise = mempty
@ -60,7 +60,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) # fc red # lc red chp p [vt] = drawP (grahamCH vt) (dotSize p) # fc red # lc red
chp _ _ = mempty chp _ _ = mempty
@ -68,7 +68,7 @@ convexHP = Diag chp
convexHPText :: Diag convexHPText :: Diag
convexHPText = Diag chpt convexHPText = Diag chpt
where where
chpt p (Object vt) chpt p [vt]
| showCoordText p = | showCoordText p =
position $ zip vtchf (pointToTextCoord <$> vtchf) # translate (r2 (0, 10)) position $ zip vtchf (pointToTextCoord <$> vtchf) # translate (r2 (0, 10))
| otherwise = mempty | otherwise = mempty
@ -82,8 +82,7 @@ convexHPText = Diag chpt
convexHLs :: Diag convexHLs :: Diag
convexHLs = Diag chl convexHLs = Diag chl
where where
chl _ (Object []) = mempty chl _ [vt] =
chl _ (Object vt) =
(strokeTrail . fromVertices . flip (++) [head $ grahamCH vt] . grahamCH $ vt) (strokeTrail . fromVertices . flip (++) [head $ grahamCH vt] . grahamCH $ vt)
# moveTo (head $ grahamCH vt) # lc red # moveTo (head $ grahamCH vt) # lc red
chl _ _ = mempty chl _ _ = mempty
@ -105,8 +104,7 @@ convexHStepsLs = GifDiag chs
squares :: Diag squares :: Diag
squares = Diag f squares = Diag f
where where
f _ (Object []) = mempty f p [vt] =
f p (Object vt) =
mconcat mconcat
$ (uncurry rectByDiagonal # lw ultraThin) $ (uncurry rectByDiagonal # lw ultraThin)
<$> <$>
@ -120,8 +118,7 @@ squares = Diag f
kdSquares :: Diag kdSquares :: Diag
kdSquares = Diag f kdSquares = Diag f
where where
f _ (Object []) = mempty f p [vt] =
f p (Object vt) =
mconcat mconcat
. fmap (uncurry (~~)) . fmap (uncurry (~~))
$ kdLines (kdTree vt Horizontal) (xDimension p, yDimension p) $ kdLines (kdTree vt Horizontal) (xDimension p, yDimension p)
@ -151,8 +148,7 @@ kdSquares = Diag f
kdRange :: Diag kdRange :: Diag
kdRange = Diag f kdRange = Diag f
where where
f _ (Object []) = mempty f p [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
@ -164,8 +160,7 @@ kdRange = Diag f
kdTreeDiag :: Diag kdTreeDiag :: Diag
kdTreeDiag = Diag f kdTreeDiag = Diag f
where where
f _ (Object []) = mempty f p [vt] =
f p (Object vt) =
-- HACK: in order to give specific nodes a specific color -- HACK: in order to give specific nodes a specific color
renderTree (\n -> case n of renderTree (\n -> case n of
'*':'*':_ -> (text n # fontSizeL 5.0) '*':'*':_ -> (text n # fontSizeL 5.0)
@ -195,8 +190,7 @@ qt vt p = quadTree vt (xDimension p, yDimension p)
quadPathSquare :: Diag quadPathSquare :: Diag
quadPathSquare = Diag f quadPathSquare = Diag f
where where
f _ (Object []) = mempty f p [vt] =
f p (Object vt) =
(uncurry rectByDiagonal # lw thin # lc red) (uncurry rectByDiagonal # lw thin # lc red)
(getSquare (stringToQuads (quadPath p)) (qt vt p, [])) (getSquare (stringToQuads (quadPath p)) (qt vt p, []))
where where
@ -230,8 +224,7 @@ gifQuadPath = GifDiag f
treePretty :: Diag treePretty :: Diag
treePretty = Diag f treePretty = Diag f
where where
f _ (Object []) = mempty f p [vt] =
f p (Object vt) =
prettyRoseTree (quadTreeToRoseTree prettyRoseTree (quadTreeToRoseTree
. flip getCurQT (qt vt p, []) . flip getCurQT (qt vt p, [])
. stringToQuads . stringToQuads

View File

@ -15,7 +15,7 @@ data Diag =
Diag Diag
{ {
mkDiag :: DiagProp mkDiag :: DiagProp
-> Object -> [[PT]]
-> Diagram Cairo R2 -> Diagram Cairo R2
} }
| GifDiag | GifDiag
@ -29,10 +29,6 @@ data Diag =
| EmptyDiag (Diagram Cairo R2) | EmptyDiag (Diagram Cairo R2)
data Object = Object [PT]
| Objects [[PT]]
-- |Holds the properties for a Diagram, like thickness of 2d points etc. -- |Holds the properties for a Diagram, like thickness of 2d points etc.
-- This can also be seen as a context when merging multiple diagrams. -- This can also be seen as a context when merging multiple diagrams.
data DiagProp = MkProp { data DiagProp = MkProp {
@ -68,10 +64,10 @@ instance Monoid Diag where
g p obj = mkDiag d1 p obj <> mkDiag d2 p obj g p obj = mkDiag d1 p obj <> mkDiag d2 p obj
mappend d1@(GifDiag {}) d2@(Diag {}) = GifDiag g mappend d1@(GifDiag {}) d2@(Diag {}) = GifDiag g
where where
g p col f vt = mkGifDiag d1 p col f vt ++ [mkDiag d2 p (Object vt)] g p col f vt = mkGifDiag d1 p col f vt ++ [mkDiag d2 p [vt]]
mappend d1@(Diag {}) d2@(GifDiag {}) = GifDiag g mappend d1@(Diag {}) d2@(GifDiag {}) = GifDiag g
where where
g p col f vt = mkDiag d2 p (Object vt) : mkGifDiag d1 p col f vt g p col f vt = mkDiag d2 p [vt] : mkGifDiag d1 p col f vt
mappend d1@(GifDiag {}) d2@(GifDiag {}) = GifDiag g mappend d1@(GifDiag {}) d2@(GifDiag {}) = GifDiag g
where where
g p col f vt = mkGifDiag d1 p col f vt ++ mkGifDiag d2 p col f vt g p col f vt = mkGifDiag d1 p col f vt ++ mkGifDiag d2 p col f vt

View File

@ -22,14 +22,14 @@ gifDiag p xs =
(upperHullList (upperHullList
<> fmap (<> last upperHullList) lowerHullList <> fmap (<> last upperHullList) lowerHullList
<> [mkDiag (mconcat [convexHPText, convexHP, convexHLs]) <> [mkDiag (mconcat [convexHPText, convexHP, convexHLs])
p{ showCoordText = True } (Object xs)]) p{ showCoordText = True } [xs]])
where where
upperHullList = mkGifDiag convexHStepsLs p purple grahamUHSteps xs upperHullList = mkGifDiag convexHStepsLs p purple grahamUHSteps xs
lowerHullList = mkGifDiag convexHStepsLs p orange grahamLHSteps xs lowerHullList = mkGifDiag convexHStepsLs p orange grahamLHSteps xs
-- add the x-axis and the other default stuff -- add the x-axis and the other default stuff
nonChDiag = nonChDiag =
mconcat . mconcat .
fmap (\x -> mkDiag x p (Object xs)) $ fmap (\x -> mkDiag x p [xs]) $
[coordPoints, plotterBG] [coordPoints, plotterBG]

View File

@ -2,6 +2,7 @@
module Graphics.Diagram.Gtk where module Graphics.Diagram.Gtk where
import Algebra.Vector(PT)
import qualified Data.ByteString.Char8 as B import qualified Data.ByteString.Char8 as B
import Data.List(find) import Data.List(find)
import Diagrams.Backend.Cairo import Diagrams.Backend.Cairo
@ -43,8 +44,8 @@ diagTreAlgos =
-- |Create the Diagram from the points. -- |Create the Diagram from the points.
diag :: DiagProp -> [DiagAlgo] -> Object -> Diagram Cairo R2 diag :: DiagProp -> [DiagAlgo] -> [[PT]] -> Diagram Cairo R2
diag p das obj = maybe mempty (\x -> mkDiag x p obj) diag p das vts = maybe mempty (\x -> mkDiag x p vts)
$ mconcat $ mconcat
<$> getDiags <$> getDiags
<$> find (\(DiagAlgo x _) -> x == algo p) das <$> find (\(DiagAlgo x _) -> x == algo p) das
@ -55,11 +56,11 @@ diag p das obj = maybe mempty (\x -> mkDiag x p obj)
diagS :: DiagProp -> B.ByteString -> Diagram Cairo R2 diagS :: DiagProp -> B.ByteString -> Diagram Cairo R2
diagS p mesh diagS p mesh
| algo p == 2 || algo p == 3 = | algo p == 2 || algo p == 3 =
diag p diagAlgos . Objects . fmap (filterValidPT p) . facesToArr $ mesh diag p diagAlgos . fmap (filterValidPT p) . facesToArr $ mesh
| otherwise = diag p diagAlgos . Object . filterValidPT p . meshToArr $ mesh | otherwise = diag p diagAlgos . (: []) . filterValidPT p . meshToArr $ mesh
-- |Create the tree diagram from a String which is supposed to be the contents -- |Create the tree diagram from a String which is supposed to be the contents
-- of an obj file. -- of an obj file.
diagTreeS :: DiagProp -> B.ByteString -> Diagram Cairo R2 diagTreeS :: DiagProp -> B.ByteString -> Diagram Cairo R2
diagTreeS p = diag p diagTreAlgos . Object . filterValidPT p . meshToArr diagTreeS p = diag p diagTreAlgos . (: []) . filterValidPT p . meshToArr

View File

@ -13,16 +13,18 @@ import Graphics.Diagram.Core
coordPoints :: Diag coordPoints :: Diag
coordPoints = Diag cp coordPoints = Diag cp
where where
cp p (Object vt) = drawP vt (dotSize p) # fc black # lc black cp _ [] = mempty
cp p (Objects vts) = drawP (concat vts) (dotSize p) # fc black # lc black cp p [vt] = drawP vt (dotSize p) # fc black # lc black
cp p vts = drawP (concat vts) (dotSize p) # fc black # lc black
-- |Show coordinates as text above all points. -- |Show coordinates as text above all points.
coordPointsText :: Diag coordPointsText :: Diag
coordPointsText = Diag cpt coordPointsText = Diag f
where where
cpt p (Object vt) = drawT vt p f _ [] = mempty
cpt p (Objects vts) = drawT (concat vts) p f p [vt] = drawT vt p
f p vts = drawT (concat vts) p
drawT [] _ = mempty drawT [] _ = mempty
drawT vt p drawT vt p
| showCoordText p = position $ zip vt (pointToTextCoord <$> vt) | showCoordText p = position $ zip vt (pointToTextCoord <$> vt)