Commit 3ba9dddf authored by Thorsten Wißmann's avatar Thorsten Wißmann 🐧
Browse files

Proper rails

parent b970d078
......@@ -9,3 +9,13 @@ $ make
When running this the first time, you need to confirm some questions by "Yes".
In order to get a repl, run:
```
$ elm repl
---- elm-repl 0.17.1 -----------------------------------------------------------
:help for help, :exit to exit, more at <https://github.com/elm-lang/elm-repl>
--------------------------------------------------------------------------------
> import Main
>
```
module RailTree exposing (..)
import List
import String
import Svg
import Svg.Attributes as SvgAttr
......@@ -72,25 +73,33 @@ enumerate =
--snd . List.foldl (\el (idx,tl) -> (idx+1,(idx,el)::tl)) (0,[])
-- /////////////////////////////////////////
-- /// Rail Layouting Algorithm ///
-- /////////////////////////////////////////
type alias TrackA t = (t,Float,P2D,Float,P2D) -- annotated tracks
type alias JunctionA j = (j,Float,P2D) -- annotated junctions
layoutRailTree : RailTree t j -> RailTree (t,P2D,P2D) (j,Float,P2D)
layoutRailTree : RailTree t j -> RailTree (TrackA t) (JunctionA j)
layoutRailTree =
let
config =
{ junctionRadius = 20.0
, trackLength = 90.0
}
helper : Float -> P2D -> RailTree t j -> RailTree (t,P2D,P2D) (j,Float,P2D)
helper : Float -> P2D -> RailTree t j -> RailTree (TrackA t) (JunctionA j)
helper left_angle left_point =
\x -> case x of
Track t rt ->
let right_point =
config.trackLength -- go that far
|> rad left_angle -- in that direction
|> shift left_point -- starting at this point
in
Track (t,left_point,right_point) $ helper left_angle right_point rt
helper left_angle right_point rt
|> Track (t,left_angle,left_point,left_angle,right_point)
Junction j rts ->
let
center =
......@@ -102,7 +111,7 @@ layoutRailTree =
then (left_angle, left_angle)
else
if List.length rts == 2
-- in svg, the lower point has a higher y-coordinate, so
-- in svg, the lower point has a higher y-coordinate, so
-- so the 'begin' angle is lower
then (left_angle - 20.0, left_angle + 20.0)
else (left_angle - 30.0, left_angle + 30.0)
......@@ -125,13 +134,26 @@ layoutRailTree =
in helper 0.0 {x = 0, y = 0}
renderRailTree : RailTree (t,P2D,P2D) (j,Float,P2D) -> List (Svg.Svg msg)
renderRailTree : RailTree (TrackA t) (JunctionA j) -> List (Svg.Svg msg)
renderRailTree =
let
track (t,p1,p2) =
let mypoints = (showPoint p1) ++ " " ++ (showPoint p2)
config =
{ trackW = 10.0
}
track (t,a1,p1,a2,p2) =
let mypoints angle =
[ p1, p2 ]
|> List.map (shift (rad angle (config.trackW / 2.0)))
|> List.map showPoint
|> List.intersperse " "
|> List.foldl String.append ""
in
(::) (Svg.polyline [ SvgAttr.stroke "red", SvgAttr.points mypoints ] [])
\x ->
(Svg.polyline [ SvgAttr.stroke "red", SvgAttr.points (mypoints (a1+90.0)) ] [])
:: (Svg.polyline [ SvgAttr.stroke "blue", SvgAttr.points (mypoints (a1-90.0)) ] [])
:: x
junction (t,r,c) results =
(Svg.circle
[ SvgAttr.cx (toString c.x)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment