1 | |
---|
2 | open Mlpost |
---|
3 | |
---|
4 | |
---|
5 | (* Helpers *) |
---|
6 | |
---|
7 | let tex = Box.tex ~dx:(Num.cm 0.2) ~dy:(Num.cm 0.1) ~stroke:(Some Color.black) |
---|
8 | |
---|
9 | let texttt name s = tex ~name ("\\texttt{" ^ s ^ "}") |
---|
10 | |
---|
11 | let middle p1 p2 = |
---|
12 | let p = Point.add p1 p2 in |
---|
13 | Point.mult (Num.of_float 0.5) p |
---|
14 | |
---|
15 | let pathp = Path.pathp ~style:Path.jLine |
---|
16 | |
---|
17 | |
---|
18 | (* Boxes *) |
---|
19 | |
---|
20 | let cond = texttt "cond" "x?" |
---|
21 | let res1 = texttt "res1" "y+2*z" |
---|
22 | let res2 = texttt "res2" "z" |
---|
23 | |
---|
24 | let boxes = |
---|
25 | let res = Box.vbox ~padding:(Num.cm 0.1) [res1 ; res2] in |
---|
26 | Box.hbox ~padding:(Num.cm 1.) [cond ; res] |
---|
27 | |
---|
28 | |
---|
29 | (* Arrows *) |
---|
30 | |
---|
31 | let edge = 0.5 |
---|
32 | |
---|
33 | let get s = Box.get s boxes |
---|
34 | |
---|
35 | let entry = |
---|
36 | let p2 = Box.west (get "cond") in |
---|
37 | let p1 = Point.shift (Point.pt (Num.cm (-.edge), Num.zero)) p2 in |
---|
38 | [Arrow.simple ~dashed:Dash.evenly (pathp [p1 ; p2])] |
---|
39 | |
---|
40 | let exits = |
---|
41 | let p1 = Box.east (get "res1") in |
---|
42 | let p2 = Point.shift (Point.pt (Num.cm edge, Num.zero)) p1 in |
---|
43 | let p3 = Box.east (get "res2") in |
---|
44 | let p4 = Point.pt (Point.xpart p2, Point.ypart p3) in |
---|
45 | [Arrow.simple ~dashed:Dash.evenly (pathp [p1 ; p2]) ; |
---|
46 | Arrow.simple ~dashed:Dash.evenly (pathp [p3 ; p4])] |
---|
47 | |
---|
48 | let branch = |
---|
49 | let p1 = Box.east (get "cond") in |
---|
50 | let p3 = Box.west (get "res1") in |
---|
51 | let p2 = Point.pt (Point.xpart (middle p1 p3), Point.ypart p1) in |
---|
52 | let p4 = Box.west (get "res2") in |
---|
53 | let ptmp1 = Point.pt (Point.xpart p2, Point.ypart p3) in |
---|
54 | let ptmp2 = Point.pt (Point.xpart p2, Point.ypart p4) in |
---|
55 | [Path.draw (pathp [p1 ; p2]) ; |
---|
56 | Arrow.simple (pathp [p2 ; ptmp1 ; p3]) ; |
---|
57 | Arrow.simple (pathp [p2 ; ptmp2 ; p4])] |
---|
58 | |
---|
59 | let arrows = Box.group (List.map Box.pic (entry @ exits @ branch)) |
---|
60 | |
---|
61 | |
---|
62 | (* Ternary *) |
---|
63 | |
---|
64 | let ternary = Box.group [boxes ; arrows] |
---|
65 | |
---|
66 | |
---|
67 | (* Output pictures *) |
---|
68 | |
---|
69 | let result = ternary |
---|
70 | let result = Box.draw result |
---|
71 | |
---|
72 | let _ = Metapost.emit "ternary1" result |
---|