From 64c3f12b3279a77bd8976548bcb4757d1b8685c9 Mon Sep 17 00:00:00 2001 From: Piotr Justyna Date: Thu, 28 Mar 2024 16:51:45 +0000 Subject: [PATCH] rendering with collision avoidance --- HelloWorld.hs | 30 ++++++++++++++++-------------- hello-world.svg | 2 +- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/HelloWorld.hs b/HelloWorld.hs index 3358437..737afa3 100644 --- a/HelloWorld.hs +++ b/HelloWorld.hs @@ -106,26 +106,28 @@ nextAvailableCoordinatesForBranchingStep x y takenCoordinates = then nextAvailableCoordinatesForBranchingStep x (y - cellHeight) takenCoordinates else y -uniqueCoordinates :: Tree Step -> Double -> Double -> [OriginCoordinates] -> [OriginCoordinates] -uniqueCoordinates (Leaf _) currentWidth currentDepth takenCoordinates = - [newCoordinates] +uniqueCoordinates :: Tree Step -> Double -> Double -> [OriginCoordinates] -> [(OriginCoordinates, Diagram B)] +uniqueCoordinates (Leaf x) currentWidth currentDepth takenCoordinates = + [(newCoordinates, Main.render x currentWidth newDepth)] where newDepth = nextAvailableCoordinates currentWidth currentDepth takenCoordinates newCoordinates = p2 (currentWidth, newDepth) -uniqueCoordinates (Node1 _ x) currentWidth currentDepth takenCoordinates = - [newCoordinates] - ++ uniqueCoordinates x currentWidth (newDepth - cellHeight) (newCoordinates : takenCoordinates) +uniqueCoordinates (Node1 x y) currentWidth currentDepth takenCoordinates = + [(newCoordinates, Main.render x currentWidth newDepth)] + ++ uniqueCoordinates y currentWidth (newDepth - cellHeight) (newCoordinates : takenCoordinates) where newDepth = nextAvailableCoordinates currentWidth currentDepth takenCoordinates newCoordinates = p2 (currentWidth, newDepth) -uniqueCoordinates (Node2 x _ z) currentWidth currentDepth takenCoordinates = - [newCoordinates] +uniqueCoordinates (Node2 x y z) currentWidth currentDepth takenCoordinates = + [(newCoordinates, Main.render y currentWidth newDepth)] ++ right - ++ uniqueCoordinates x currentWidth (newDepth - cellHeight) (right ++ takenCoordinates) + ++ uniqueCoordinates x currentWidth (newDepth - cellHeight) (allTaken ++ takenCoordinates) where newDepth = nextAvailableCoordinatesForBranchingStep currentWidth currentDepth takenCoordinates newCoordinates = p2 (currentWidth, newDepth) right = uniqueCoordinates z (currentWidth + cellWidth) (newDepth - cellHeight) (newCoordinates : takenCoordinates) + --very inefficient + allTaken = [coordinate | (coordinate, diagram) <- right] flattenSteps :: Tree Step -> Double -> Double -> [(OriginCoordinates, Diagram B)] flattenSteps (Leaf x) currentWidth currentDepth = @@ -144,9 +146,9 @@ render Main.End x y = endShape $ uniqueName x y render Main.Decision x y = decisionShape $ uniqueName x y render Main.Command x y = commandShape $ uniqueName x y -main = do - putStrLn . show $ uniqueCoordinates steps 0.0 0.0 [] +-- main = do +-- putStrLn . show $ uniqueCoordinates steps 0.0 0.0 [] --- main = mainWith $ --- position (flattenSteps steps 0.0 0.0) --- # lw veryThin +main = mainWith $ + position (uniqueCoordinates steps 0.0 0.0 []) + # lw veryThin diff --git a/hello-world.svg b/hello-world.svg index 44b28ce..60dc521 100644 --- a/hello-world.svg +++ b/hello-world.svg @@ -1,3 +1,3 @@ "x4.0y-3.0": end"x2.0y-2.0""x2.0y-4.0": end"x2.0y-3.0""x0.0y-1.0""x0.0y-5.0": end"x0.0y-4.0""x0.0y-3.0""x0.0y-2.0""x0.0y0.0": start \ No newline at end of file + "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">"x0.0y-7.0": end"x0.0y-6.0""x2.0y-7.0": end"x2.0y-6.0""x0.0y-5.0""x0.0y-2.0""x2.0y-4.0": end"x2.0y-3.0""x4.0y-3.0": end"x2.0y-2.0""x0.0y-1.0""x0.0y0.0": start \ No newline at end of file