summaryrefslogtreecommitdiff
path: root/metapost
diff options
context:
space:
mode:
authorMarius <mariausol@gmail.com>2011-10-06 00:40:15 +0300
committerMarius <mariausol@gmail.com>2011-10-06 00:40:15 +0300
commitbc8667da1c26a3ca8db3fe379e6a00544fa02e8a (patch)
treeecb7249faae4e8f0f63f68aa44f933e5d0e673a0 /metapost
parent070e1ac9465175c8b3674540c243882a3b3900b5 (diff)
downloadcontext-bc8667da1c26a3ca8db3fe379e6a00544fa02e8a.tar.gz
beta 2011.10.05 23:32
Diffstat (limited to 'metapost')
-rw-r--r--metapost/context/base/metafun.mpiv26
-rw-r--r--metapost/context/base/mp-butt.mp108
-rw-r--r--metapost/context/base/mp-char.mp21
-rw-r--r--metapost/context/base/mp-flow.mpiv1020
-rw-r--r--metapost/context/base/mp-shap.mp471
5 files changed, 1291 insertions, 355 deletions
diff --git a/metapost/context/base/metafun.mpiv b/metapost/context/base/metafun.mpiv
index 89a7c3935..c58d5dc15 100644
--- a/metapost/context/base/metafun.mpiv
+++ b/metapost/context/base/metafun.mpiv
@@ -17,21 +17,21 @@
%D copy.
input mp-base.mpiv ;
-input mp-tool.mp ;
+input mp-tool.mp ;
input mp-core.mpiv ;
-input mp-page.mp ;
-input mp-text.mp ;
-input mp-txts.mp ;
-input mp-shap.mp ;
-input mp-butt.mp ;
-input mp-char.mp ;
-input mp-step.mp ;
-input mp-grph.mp ;
-input mp-figs.mp ;
+input mp-page.mp ;
+input mp-text.mp ;
+input mp-txts.mp ;
+input mp-butt.mp ;
+% mp-shap.mp ; % there no need to always load this
+% mp-char.mp ; % there no need to always load this
+input mp-step.mp ; % there no need to always load this (todo)
+input mp-grph.mp ;
+input mp-figs.mp ;
input mp-mlib.mpiv ;
-input mp-chem.mpiv ;
-input mp-grid.mp ;
-input mp-func.mp ;
+input mp-chem.mpiv ; % there no need to always load this (todo)
+input mp-grid.mp ;
+input mp-func.mp ;
string metafunversion ;
diff --git a/metapost/context/base/mp-butt.mp b/metapost/context/base/mp-butt.mp
index cf580211e..3ae3dc983 100644
--- a/metapost/context/base/mp-butt.mp
+++ b/metapost/context/base/mp-butt.mp
@@ -1,6 +1,6 @@
%D \module
%D [ file=mp-butt.mp,
-%D version=2000.05.31,
+%D version=2000.05.31,
%D title=\CONTEXT\ \METAPOST\ graphics,
%D subtitle=buttons,
%D author=Hans Hagen,
@@ -8,68 +8,64 @@
%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See licen-en.pdf for
-%C details.
+%C therefore copyrighted by \PRAGMA. See licen-en.pdf for
+%C details.
-if unknown context_tool : input mp-tool ; fi ;
-if known context_butt : endinput ; fi ;
+if unknown context_tool : input mp-tool ; fi ;
+if known context_butt : endinput ; fi ;
-boolean context_butt ; context_butt := true ;
+boolean context_butt ; context_butt := true ;
-def some_button (expr button_type ,
- button_size ,
- button_linecolor ,
- button_fillcolor ) =
+def some_button (expr button_type, button_size, button_linecolor, button_fillcolor) =
- numeric button_linewidth ; button_linewidth := button_size/10 ;
+ numeric button_linewidth ; button_linewidth := button_size/10 ;
- drawoptions (withpen pencircle scaled button_linewidth
- withcolor button_linecolor) ;
+ drawoptions (withpen pencircle scaled button_linewidth withcolor button_linecolor) ;
- path p ; p := unitsquare scaled button_size ;
- numeric d ; d := button_size ;
- numeric l ; l := button_linewidth ;
+ path p ; p := unitsquare scaled button_size ;
+ numeric d ; d := button_size ;
+ numeric l ; l := button_linewidth ;
- fill p withcolor button_fillcolor ; draw p ;
+ fill p withcolor button_fillcolor ; draw p ;
- if button_type=101 :
- draw (d-2l,2l)--(2l,.5d)--(d-2l,d-2l)--cycle ;
- elseif button_type=102 :
- draw (2l,2l)--(d-2l,.5d)--(2l,d-2l)--cycle ;
- elseif button_type=103 :
- for i=2l step 2l until d-2l :
- draw (2l,i)--(2l ,i) ;
- draw (4l,i)--(d-2l,i) ;
- endfor ;
- elseif button_type=104 :
- for i=2l step 2l until d-2l :
- draw (2l ,i)--(d/2-l,i) ;
- draw (d/2+l,i)--(d-2l ,i) ;
- endfor ;
- elseif button_type=105 :
- fill fullcircle scaled (.2d) shifted (.5d,.7d) ;
- fill fullcircle xscaled (.6d) yscaled d shifted (.5d,0) ;
- clip currentpicture to p ;
- draw p ;
- elseif button_type=106 :
- draw (2l,2l)--(d-2l,d-2l) ;
- draw (d-2l,2l)--(2l,d-2l) ;
- elseif button_type=107 :
- p := (3l,d-2l)--(d-3l,d-2l)--(.5d,4l)--cycle ;
- fill p ; draw p ;
- draw (.5d,2l) ;
- elseif button_type=108 :
- draw (.5d,2l)--(d-2l,d-2l)--(2l,d-2l)--cycle ;
- elseif button_type=109 :
- draw (.5d,d-2l)--(d-2l,2l)--(2l,2l)--cycle ;
- elseif button_type=110 :
- button_linewidth := button_linewidth/2 ;
- draw p enlarged (-2l,-l) ;
- for i=2l step l until d-2l :
- draw (3l,i)--(d-3l,i) ;
- endfor ;
- fi ;
+ if button_type = 101 :
+ draw (d-2l,2l)--(2l,.5d)--(d-2l,d-2l)--cycle ;
+ elseif button_type = 102 :
+ draw (2l,2l)--(d-2l,.5d)--(2l,d-2l)--cycle ;
+ elseif button_type = 103 :
+ for i=2l step 2l until d-2l :
+ draw (2l,i)--(2l ,i) ;
+ draw (4l,i)--(d-2l,i) ;
+ endfor ;
+ elseif button_type = 104 :
+ for i=2l step 2l until d-2l :
+ draw (2l ,i)--(d/2-l,i) ;
+ draw (d/2+l,i)--(d-2l ,i) ;
+ endfor ;
+ elseif button_type = 105 :
+ fill fullcircle scaled (.2d) shifted (.5d,.7d) ;
+ fill fullcircle xscaled (.6d) yscaled d shifted (.5d,0) ;
+ clip currentpicture to p ;
+ draw p ;
+ elseif button_type = 106 :
+ draw (2l,2l)--(d-2l,d-2l) ;
+ draw (d-2l,2l)--(2l,d-2l) ;
+ elseif button_type = 107 :
+ p := (3l,d-2l)--(d-3l,d-2l)--(.5d,4l)--cycle ;
+ fill p ; draw p ;
+ draw (.5d,2l) ;
+ elseif button_type = 108 :
+ draw (.5d,2l)--(d-2l,d-2l)--(2l,d-2l)--cycle ;
+ elseif button_type = 109 :
+ draw (.5d,d-2l)--(d-2l,2l)--(2l,2l)--cycle ;
+ elseif button_type = 110 :
+ button_linewidth := button_linewidth/2 ;
+ draw p enlarged (-2l,-l) ;
+ for i=2l step l until d-2l :
+ draw (3l,i)--(d-3l,i) ;
+ endfor ;
+ fi ;
-enddef ;
+enddef ;
-endinput ;
+endinput ;
diff --git a/metapost/context/base/mp-char.mp b/metapost/context/base/mp-char.mp
index fd9e33848..3a7a1d939 100644
--- a/metapost/context/base/mp-char.mp
+++ b/metapost/context/base/mp-char.mp
@@ -111,6 +111,7 @@ def new_chart =
color xydraw [][] ;
numeric xyline [][] ;
boolean xypeep [][] ;
+ picture xypicture[][] ;
numeric cpath ; cpath := 0 ;
path cpaths [] ;
@@ -233,6 +234,15 @@ def flush_shapes =
endfor ;
enddef ;
+def flush_pictures =
+ for x=1 upto max_x :
+ for y=1 upto max_y :
+ flush_picture (x, y) ;
+ endfor ;
+ endfor ;
+enddef ;
+
+
def draw_connection_point (expr x, y, z) =
pickup pencircle scaled if (z=0): 2 fi xyline[x][y] ;
drawdot xy_bottom(x,y,z,false) scaled_to_grid withcolor (1,0,0) ;
@@ -450,6 +460,16 @@ def draw_midpoint (expr n) =
endgroup ;
enddef ;
+def flush_picture(expr x, y) =
+ if known xypicture[x][y]:
+ draw xypicture[x][y] shifted xy_offset((x+0.5)*grid_width,(max_y-y+1.5)*grid_height) ;
+ fi ;
+enddef ;
+
+def chart_draw_picture(expr x, y, p) =
+ xypicture[x][y] := p ;
+enddef ;
+
boolean reverse_connection ; reverse_connection := false ;
vardef up_on_grid (expr n) =
@@ -911,6 +931,7 @@ enddef ;
def end_chart =
flush_shapes ;
flush_connections ;
+ flush_pictures ;
cmin_x := cmin_x ;
cmax_x := cmin_x+cmax_x ;
cmin_y := cmin_y-1 ;
diff --git a/metapost/context/base/mp-flow.mpiv b/metapost/context/base/mp-flow.mpiv
new file mode 100644
index 000000000..c134f28d8
--- /dev/null
+++ b/metapost/context/base/mp-flow.mpiv
@@ -0,0 +1,1020 @@
+%D \module
+%D [ file=mp-char.mp,
+%D version=2011.10.1, % 1998.10.10,
+%D title=\CONTEXT\ \METAPOST\ graphics,
+%D subtitle=charts,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See licen-en.pdf for
+%C details.
+
+%D This is ancient code .. but I see no need to rewrite it.
+
+if unknown context_tool : input mp-tool ; fi ;
+if unknown context_shap : input mp-shap ; fi ;
+if known context_flow : endinput ; fi ;
+
+boolean context_flow ; context_flow := true ;
+
+%D settings
+
+numeric flow_grid_width ; flow_grid_width := 60pt ;
+numeric flow_shape_width ; flow_shape_width := 45pt ;
+numeric flow_grid_height ; flow_grid_height := 40pt ;
+numeric flow_shape_height ; flow_shape_height := 30pt ;
+numeric flow_chart_offset ; flow_chart_offset := 2pt ;
+color flow_chart_background_color ; flow_chart_background_color := white ;
+boolean flow_show_mid_points ; flow_show_mid_points := false ;
+boolean flow_show_con_points ; flow_show_con_points := false ;
+boolean flow_show_all_points ; flow_show_all_points := false ;
+numeric flow_shape_line_width ; flow_shape_line_width := 2pt ;
+color flow_shape_line_color ; flow_shape_line_color := .5white ;
+color flow_shape_fill_color ; flow_shape_fill_color := .9white ;
+color flow_connection_line_color ; flow_connection_line_color := .2white ;
+
+numeric flow_connection_line_width ; flow_connection_line_width := flow_shape_line_width ;
+
+numeric flow_connection_smooth_size ; flow_connection_smooth_size := 5pt ;
+numeric flow_connection_arrow_size ; flow_connection_arrow_size := 4pt ;
+numeric flow_connection_dash_size ; flow_connection_dash_size := 3pt ;
+
+numeric flow_max_x ; flow_max_x := 6 ;
+numeric flow_max_y ; flow_max_y := 4 ;
+
+boolean flow_smooth ; flow_smooth := true ;
+boolean flow_peepshape ; flow_peepshape := false ;
+boolean flow_arrowtip ; flow_arrowtip := true ;
+boolean flow_dashline ; flow_dashline := false ;
+boolean flow_forcevalid ; flow_forcevalid := false ;
+boolean flow_touchshape ; flow_touchshape := false ;
+boolean flow_showcrossing ; flow_showcrossing := false ;
+boolean flow_reverse_y ; flow_reverse_y := true ;
+
+picture flow_dash_pattern ; flow_dash_pattern := nullpicture ;
+
+numeric flow_shape_node ; flow_shape_node := 0 ;
+numeric flow_shape_action ; flow_shape_action := 24 ;
+numeric flow_shape_procedure ; flow_shape_procedure := 5 ;
+numeric flow_shape_product ; flow_shape_product := 12 ;
+numeric flow_shape_decision ; flow_shape_decision := 14 ;
+numeric flow_shape_archive ; flow_shape_archive := 19 ;
+numeric flow_shape_loop ; flow_shape_loop := 35 ;
+numeric flow_shape_wait ; flow_shape_wait := 6 ;
+numeric flow_shape_subprocedure ; flow_shape_subprocedure := 20 ;
+numeric flow_shape_singledocument ; flow_shape_singledocument := 32 ;
+numeric flow_shape_multidocument ; flow_shape_multidocument := 33 ;
+numeric flow_shape_right ; flow_shape_right := 66 ;
+numeric flow_shape_left ; flow_shape_left := 67 ;
+numeric flow_shape_up ; flow_shape_up := 68 ;
+numeric flow_shape_down ; flow_shape_down := 69 ;
+
+% vardef some_shape_path (expr type) == imported from mp-shap
+
+def flow_show_shapes(expr n) =
+ flow_begin_chart(n,8,10) ;
+ flow_show_con_points := true ;
+ for i=0 upto 7 :
+ for j=0 upto 9 :
+ flow_new_shape(i+1,j+1,i*10+j);
+ endfor ;
+ endfor ;
+ flow_end_chart ;
+enddef ;
+
+%D connections
+
+def flow_new_chart =
+
+ flow_grid_width := 60pt ;
+ flow_shape_width := 45pt ;
+ flow_grid_height := 40pt ;
+ flow_shape_height := 30pt ;
+ flow_chart_offset := 2pt ;
+ flow_chart_background_color := white ;
+ flow_show_mid_points := false ;
+ flow_show_con_points := false ;
+ flow_show_all_points := false ;
+ flow_shape_line_width := 2pt ;
+ flow_shape_line_color := .5white ;
+ flow_shape_fill_color := .9white ;
+ flow_connection_line_color := .2white ;
+ flow_connection_line_width := flow_shape_line_width ;
+ flow_connection_smooth_size := 5pt ;
+ flow_connection_arrow_size := 4pt ;
+ flow_connection_dash_size := 3pt ;
+
+ flow_max_x := 6 ;
+ flow_max_y := 4 ;
+
+ flow_smooth := true ;
+ flow_peepshape := false ;
+ flow_arrowtip := true ;
+ flow_dashline := false ;
+ flow_forcevalid := false ;
+ flow_touchshape := false ;
+ flow_showcrossing := false ;
+ flow_reverse_y := true ;
+
+ flow_dash_pattern := nullpicture ;
+
+ numeric flow_xypoint ; flow_xypoint := 0 ;
+ numeric flow_cpath ; flow_cpath := 0 ;
+
+ pair flow_xypoints [] ;
+ boolean flow_xyfree [][] ;
+ path flow_xypath [][] ;
+ numeric flow_xysx [][] ;
+ numeric flow_xysy [][] ;
+ color flow_xyfill [][] ;
+ color flow_xydraw [][] ;
+ numeric flow_xyline [][] ;
+ boolean flow_xypeep [][] ;
+ picture flow_xytext [][] ;
+ picture flow_xylabel_l[][] ;
+ picture flow_xylabel_r[][] ;
+ picture flow_xylabel_t[][] ;
+ picture flow_xylabel_b[][] ;
+ picture flow_xyexit_l [][] ;
+ picture flow_xyexit_r [][] ;
+ picture flow_xyexit_t [][] ;
+ picture flow_xyexit_b [][] ;
+ path flow_cpaths [] ;
+ numeric flow_cline [] ;
+ color flow_ccolor [] ;
+ boolean flow_carrow [] ;
+ boolean flow_cdash [] ;
+ boolean flow_ccross [] ;
+
+ picture flow_tpicture[][] ;
+ picture flow_bpicture[][] ;
+ picture flow_lpicture[][] ;
+ picture flow_rpicture[][] ;
+
+ predefined_shapes[61] := (fullcircle scaled (1.5*predefined_shapes_yradius) xscaled (flow_grid_height/flow_grid_width)) ;
+ predefined_shapes[62] := (fullcircle scaled (2.0*predefined_shapes_yradius) xscaled (flow_grid_height/flow_grid_width)) ;
+
+enddef ;
+
+flow_new_chart ;
+
+def flow_y_pos(expr y) =
+ if flow_reverse_y :
+ flow_max_y + 1 - y
+ else :
+ y
+ fi
+enddef ;
+
+def flow_initialize_grid(expr maxx, maxy) =
+ flow_max_x := maxx ;
+ flow_max_y := maxy ;
+ flow_dsp_x := 0 ;
+ flow_dsp_y := 0 ;
+ for x=1 upto flow_max_x :
+ for y=1 upto flow_max_y :
+ flow_xyfree[x][y] := true ;
+ flow_xyfill[x][y] := flow_shape_fill_color ;
+ flow_xydraw[x][y] := flow_shape_line_color ;
+ flow_xyline[x][y] := flow_shape_line_width ;
+ endfor ;
+ endfor ;
+enddef ;
+
+def flow_scaled_to_grid =
+ xscaled flow_grid_width yscaled flow_grid_height
+enddef ;
+
+def flow_xy_offset(expr x, y) =
+ (x+.5,y+.5)
+enddef ;
+
+def flow_draw_shape(expr x, yy, p, sx, sy) =
+ begingroup ;
+ save y ; numeric y ;
+ y := flow_y_pos(yy) ;
+ flow_xypath [x][y] := (p xscaled sx yscaled sy) shifted flow_xy_offset(x,y) ;
+ flow_xyfree [x][y] := false ;
+ flow_xysx [x][y] := sx ;
+ flow_xysy [x][y] := sy ;
+ flow_xyfill [x][y] := flow_shape_fill_color ;
+ flow_xydraw [x][y] := flow_shape_line_color ;
+ flow_xyline [x][y] := flow_shape_line_width ;
+ flow_xypeep [x][y] := flow_peepshape ;
+ endgroup ;
+enddef ;
+
+vardef flow_i_point (expr x, y, p, t) =
+ begingroup ;
+ save q, ok ; pair q ; boolean ok ;
+ q := flow_xypath[x][y] intersection_point ((p) shifted flow_xy_offset(x,y)) ;
+ ok := true ;
+ if not ok :
+ message (t & " of shape (" & decimal x & "," & decimal y & ") limited") ;
+ fi ;
+ q
+ endgroup
+enddef ;
+
+vardef flow_trimmed (expr x, y, z, t) =
+ if flow_touchshape and t :
+ flow_xyline[x][y]/z
+ else :
+ epsilon
+ fi
+enddef ;
+
+numeric flow_zfactor ; flow_zfactor := 1/3 ;
+
+vardef flow_xy_bottom (expr x, y, z, t) =
+ flow_i_point(x, y, ((0,0)--(0,-2)) shifted (flow_zfactor*z*flow_xysx[x][y],0), "bottom")
+ shifted(0,-flow_trimmed(x,y,flow_grid_height,t))
+enddef ;
+
+vardef flow_xy_top (expr x, y, z, t) =
+ flow_i_point (x, y, ((0,0)--(0,2)) shifted (flow_zfactor*z*flow_xysx[x][y],0), "top")
+ shifted(0,flow_trimmed(x,y,flow_grid_height,t))
+enddef ;
+
+vardef flow_xy_left (expr x, y, z, t) =
+ flow_i_point (x, y, ((0,0)--(-2,0)) shifted (0,flow_zfactor*z*flow_xysy[x][y]), "left")
+ shifted(-flow_trimmed(x,y,flow_grid_width,t),0)
+enddef ;
+
+vardef flow_xy_right (expr x, y, z, t) =
+ flow_i_point (x, y, ((0,0)--(2,0)) shifted (0,flow_zfactor*z*flow_xysy[x][y]), "right")
+ shifted(flow_trimmed(x,y,flow_grid_width,t),0)
+enddef ;
+
+def flow_flush_shapes =
+ for x=1 upto flow_max_x :
+ for y=1 upto flow_max_y :
+ flow_flush_shape(x, y) ;
+ endfor ;
+ endfor ;
+enddef ;
+
+def flow_flush_pictures =
+ for x=1 upto flow_max_x :
+ for y=1 upto flow_max_y :
+ flow_flush_picture(x, y) ;
+ endfor ;
+ endfor ;
+enddef ;
+
+def flow_draw_connection_point(expr x, y, z) =
+ pickup pencircle scaled if (z=0): 2 fi flow_xyline[x][y] ;
+ drawdot flow_xy_bottom(x,y,z,false) flow_scaled_to_grid withcolor (1,0,0) ;
+ drawdot flow_xy_top (x,y,z,false) flow_scaled_to_grid withcolor (0,1,0) ;
+ drawdot flow_xy_left (x,y,z,false) flow_scaled_to_grid withcolor (0,0,1) ;
+ drawdot flow_xy_right (x,y,z,false) flow_scaled_to_grid withcolor (1,1,0) ;
+enddef ;
+
+def flow_flush_shape(expr x, yy) =
+ begingroup ;
+ save y ; numeric y ;
+ y := flow_y_pos(yy) ;
+ if not flow_xyfree[x][y] :
+ pickup pencircle scaled flow_xyline[x][y] ;
+ if flow_xypeep[x][y] :
+ fill (flow_xypath[x][y] peepholed (unitsquare shifted (x,y)))
+ flow_scaled_to_grid withpen pencircle scaled 0
+ withcolor flow_chart_background_color ;
+ else :
+ fill flow_xypath[x][y] flow_scaled_to_grid withcolor flow_xyfill[x][y] ;
+ fi ;
+ draw flow_xypath[x][y] flow_scaled_to_grid withcolor flow_xydraw[x][y] ;
+ if flow_show_con_points or flow_show_all_points :
+ flow_draw_connection_point(x, y, 0) ;
+ fi ;
+ if flow_show_all_points :
+ for i=-1 upto 1 :
+ flow_draw_connection_point(x, y, i) ;
+ endfor ;
+ fi ;
+ fi ;
+ endgroup ;
+enddef ;
+
+vardef flow_points_initialized(expr xfrom, yfrom, xto, yto, n) =
+ if not flow_xyfree[xfrom][yfrom] and not flow_xyfree[xto][yto] :
+ flow_xypoint := n ; true
+ else :
+ flow_xypoint := 0 ; false
+ fi
+enddef ;
+
+def flow_collapse_points = % this is now an mp-tool macro
+ begingroup ;
+ % remove redundant points
+ save n ; numeric n ;
+ n := 1 ;
+ for i=2 upto flow_xypoint :
+ if not (flow_xypoints[i] = flow_xypoints[n]) :
+ n := n + 1 ;
+ flow_xypoints[n] := flow_xypoints[i]
+ fi ;
+ endfor ;
+ flow_xypoint := n ;
+ % make straight lines
+ if flow_xypoints[2] = flow_xypoints[flow_xypoint-1] :
+ flow_xypoints[3] := flow_xypoints[flow_xypoint] ;
+ flow_xypoint := 3 ;
+ fi ;
+ endgroup ;
+enddef ;
+
+vardef flow_smooth_connection(expr a,b) =
+ if ypart a = ypart b :
+ a shifted ( if xpart a >= xpart b : - fi (flow_connection_smooth_size/flow_grid_width ),0)
+ else :
+ a shifted (0,if ypart a >= ypart b : - fi (flow_connection_smooth_size/flow_grid_height) )
+ fi
+enddef ;
+
+vardef flow_trim_points =
+ begingroup
+ save p, a, b, d, i ; numeric a, b ; path p ; pair d ;
+ p := for i=1 upto flow_xypoint-1 : flow_xypoints[i]-- endfor flow_xypoints[flow_xypoint] ;
+ if flow_touchshape :
+ a := flow_shape_line_width/flow_grid_width ;
+ b := flow_shape_line_width/flow_grid_height ;
+ else :
+ a := epsilon ;
+ b := epsilon ;
+ fi ;
+ d := direction infinity of p ;
+ flow_xypoints[flow_xypoint] := flow_xypoints[flow_xypoint] shifted
+ if xpart d < 0 : (+a,0) ;
+ elseif xpart d > 0 : (-a,0) ;
+ elseif ypart d < 0 : (0,+b) ;
+ elseif ypart d > 0 : (0,-b) ;
+ else : origin ;
+ fi ;
+ d := direction 0 of p ;
+ flow_xypoints[1] := flow_xypoints[1] shifted
+ if xpart d < 0 : (-a,0) ;
+ elseif xpart d > 0 : (+a,0) ;
+ elseif ypart d < 0 : (0,-b) ;
+ elseif ypart d > 0 : (0,+b) ;
+ else : origin ;
+ fi ;
+ endgroup
+enddef ;
+
+vardef flow_trim_points = enddef ;
+
+vardef flow_connection_path =
+ if flow_reverse_connection : reverse fi (flow_xypoints[1] --
+ for i=2 upto flow_xypoint-1 :
+ if flow_smooth :
+ flow_smooth_connection(flow_xypoints[i],flow_xypoints[i-1]) ..
+ controls flow_xypoints[i] and flow_xypoints[i] ..
+ flow_smooth_connection(flow_xypoints[i],flow_xypoints[i+1]) --
+ else :
+ flow_xypoints[i] --
+ fi
+ endfor
+ flow_xypoints[flow_xypoint])
+enddef ;
+
+def flow_draw_connection =
+ if flow_xypoint > 0 :
+ flow_collapse_points ;
+ flow_trim_points ;
+ flow_cpath := flow_cpath + 1 ;
+ flow_cpaths[flow_cpath] := flow_connection_path flow_scaled_to_grid ;
+ flow_cline[flow_cpath] := flow_connection_line_width ;
+ flow_ccolor[flow_cpath] := flow_connection_line_color ;
+ flow_carrow[flow_cpath] := flow_arrowtip ;
+ flow_cdash[flow_cpath] := flow_dashline ;
+ flow_ccross[flow_cpath] := flow_showcrossing ;
+ else :
+ message("no connection defined") ;
+ fi ;
+ flow_reverse_connection := false ;
+enddef ;
+
+def flow_flush_connections = % protect locals
+ begingroup ;
+ save ip, crossing, cp ; numeric ip ; boolean crossing ; path cp ;
+ ahlength := flow_connection_arrow_size ;
+ flow_dash_pattern := dashpattern(on flow_connection_dash_size off flow_connection_dash_size) ;
+ for i=1 upto flow_cpath :
+ if flow_ccross[i] :
+ crossing := false ;
+ for j=1 upto i :
+ if not (point infinity of flow_cpaths[i] = point infinity of flow_cpaths[j]) :
+ ip := flow_cpaths[i] intersection_point flow_cpaths[j] ;
+ if intersection_found : crossing := true fi ;
+ fi ;
+ endfor ;
+ if crossing :
+ pickup pencircle scaled 2flow_cline[i] ;
+ cp := flow_cpaths[i] ;
+ cp := cp cutbefore point .05 length cp of cp ;
+ cp := cp cutafter point .95 length cp of cp ;
+ draw cp withcolor flow_chart_background_color ;
+ fi ;
+ fi ;
+ pickup pencircle scaled flow_cline[i] ;
+ if flow_carrow[i] :
+ if flow_cdash[i] :
+ drawarrow flow_cpaths[i] withcolor flow_ccolor[i] dashed flow_dash_pattern ;
+ else :
+ drawarrow flow_cpaths[i] withcolor flow_ccolor[i] ;
+ fi ;
+ else :
+ if flow_cdash[i] :
+ draw flow_cpaths[i] withcolor flow_ccolor[i] dashed flow_dash_pattern ;
+ else :
+ draw flow_cpaths[i] withcolor flow_ccolor[i] ;
+ fi ;
+ fi ;
+ flow_draw_midpoint(i) ;
+ endfor ;
+ endgroup ;
+enddef ;
+
+def flow_draw_midpoint (expr n) =
+ begingroup
+ save p ; pair p ;
+ p := point .5*length(flow_cpaths[n]) of flow_cpaths[n];
+ pickup pencircle scaled 2flow_cline[n] ;
+ if flow_show_mid_points :
+ drawdot p withcolor .7white ;
+ fi ;
+ endgroup ;
+enddef ;
+
+def flow_flush_picture(expr x, yy) =
+ begingroup ; save y ; numeric y ;
+ y := flow_y_pos(yy) ;
+ if known flow_xytext[x][y] :
+ begingroup ;
+ % flow_xypath[x][y]
+ save p, offset ; path p ; pair offset ;
+ offset := flow_xy_offset((x+0.5)*flow_grid_width,(flow_max_y-y+1.5)*flow_grid_height) ;
+ offset := offset shifted (-flow_xyline[x][y]/4,-flow_xyline[x][y]/4) ; % terrible hack (some compensation)
+ p := fullsquare
+ xscaled flow_grid_width
+ yscaled flow_grid_height
+ shifted offset ;
+ if known flow_xytext[x][y]:
+ draw flow_xytext[x][y] shifted offset ;
+ fi ;
+ if known flow_xylabel_t[x][y] :
+ label.urt(flow_xylabel_t[x][y],0.5[ulcorner p,urcorner p]) ;
+ fi ;
+ if known flow_xylabel_b[x][y] :
+ label.lrt(flow_xylabel_b[x][y],0.5[llcorner p,lrcorner p]) ;
+ fi ;
+ if known flow_xylabel_l[x][y] :
+ label.ulft(flow_xylabel_l[x][y],0.5[ulcorner p,llcorner p]) ;
+ fi ;
+ if known flow_xylabel_r[x][y] :
+ label.urt (flow_xylabel_r[x][y],0.5[urcorner p,lrcorner p]) ;
+ fi ;
+ if known flow_xyexit_t[x][y] :
+ label.top(flow_xyexit_t[x][y],0.5[ulcorner p,urcorner p] shifted (0, flow_grid_height/2)) ;
+ fi ;
+ if known flow_xyexit_b[x][y] :
+ label.bot(flow_xyexit_b[x][y],0.5[llcorner p,lrcorner p] shifted (0,-flow_grid_height/2)) ;
+ fi ;
+ if known flow_xyexit_l[x][y] :
+ label.lft(flow_xyexit_l[x][y],0.5[ulcorner p,llcorner p] shifted (-flow_grid_width/2,0)) ;
+ fi ;
+ if known flow_xyexit_r[x][y] :
+ label.rt (flow_xyexit_r[x][y],0.5[urcorner p,lrcorner p] shifted ( flow_grid_width/2,0)) ;
+ fi ;
+ endgroup ;
+ fi ;
+ endgroup ;
+enddef ;
+
+def flow_chart_draw_text(expr x, y, p) =
+ flow_xytext[x][y] := p ;
+enddef ;
+
+def flow_chart_draw_label_t(expr x, y, p) = flow_xylabel_t[x][y] := p ; enddef ;
+def flow_chart_draw_label_b(expr x, y, p) = flow_xylabel_b[x][y] := p ; enddef ;
+def flow_chart_draw_label_l(expr x, y, p) = flow_xylabel_l[x][y] := p ; enddef ;
+def flow_chart_draw_label_r(expr x, y, p) = flow_xylabel_r[x][y] := p ; enddef ;
+
+def flow_chart_draw_exit_t (expr x, y, p) = flow_xyexit_t [x][y] := p ; enddef ;
+def flow_chart_draw_exit_b (expr x, y, p) = flow_xyexit_b [x][y] := p ; enddef ;
+def flow_chart_draw_exit_l (expr x, y, p) = flow_xyexit_l [x][y] := p ; enddef ;
+def flow_chart_draw_exit_r (expr x, y, p) = flow_xyexit_r [x][y] := p ; enddef ;
+
+boolean flow_reverse_connection ; flow_reverse_connection := false ;
+
+vardef flow_up_on_grid (expr n) =
+ (xpart flow_xypoints[n],(ypart flow_xypoints[n]+1) div 1)
+enddef ;
+
+vardef flow_down_on_grid (expr n) =
+ (xpart flow_xypoints[n],(ypart flow_xypoints[n]) div 1)
+enddef ;
+
+vardef flow_left_on_grid (expr n) =
+ ((xpart flow_xypoints[n]) div 1, ypart flow_xypoints[n])
+enddef ;
+
+vardef flow_right_on_grid (expr n) =
+ ((xpart flow_xypoints[n]+1) div 1, ypart flow_xypoints[n])
+enddef ;
+
+vardef flow_x_on_grid (expr n, xfrom, xto, zfrom) =
+ if (xfrom = xto) and not (zfrom = 0) :
+ if (zfrom=1) : flow_right_on_grid(2) else : flow_left_on_grid(2) fi
+ elseif xpart flow_xypoints[1] < xpart flow_xypoints[6] :
+ flow_right_on_grid(n)
+ else :
+ flow_left_on_grid(n)
+ fi
+enddef ;
+
+vardef y_on_grid (expr n, yfrom, yto, zfrom) =
+ if (yfrom = yto) and not (zfrom = 0) :
+ if (zfrom = 1) : flow_up_on_grid(2) else : flow_down_on_grid(2) fi
+ elseif ypart flow_xypoints[1] < ypart flow_xypoints[6] :
+ flow_up_on_grid(n)
+ else :
+ flow_down_on_grid(n)
+ fi
+enddef ;
+
+vardef flow_xy_on_grid (expr n, m) =
+ (xpart flow_xypoints[n], ypart flow_xypoints[m])
+enddef ;
+
+vardef flow_down_to_grid (expr a,b) =
+ (xpart flow_xypoints[a], ypart flow_xypoints[if ypart flow_xypoints[a]<ypart flow_xypoints[b] : a else : b fi])
+enddef ;
+
+vardef flow_up_to_grid (expr a,b) =
+ (xpart flow_xypoints[a], ypart flow_xypoints[if ypart flow_xypoints[a]>ypart flow_xypoints[b] : a else : b fi])
+enddef ;
+
+vardef flow_left_to_grid (expr a,b) =
+ (xpart flow_xypoints[if xpart flow_xypoints[a]<xpart flow_xypoints[b] : a else : b fi], ypart flow_xypoints[a])
+enddef ;
+
+vardef flow_right_to_grid (expr a,b) =
+ (xpart flow_xypoints[if xpart flow_xypoints[a]>xpart flow_xypoints[b] : a else : b fi], ypart flow_xypoints[a])
+enddef ;
+
+vardef flow_valid_connection (expr xfrom, yfrom, xto, yto) =
+ begingroup ;
+ save ok, vc, pp ; boolean ok ; pair vc ; path pp ;
+ save flow_xyfirst, flow_xylast ; pair flow_xyfirst, flow_xylast ;
+ % check for slanted lines
+ ok := true ;
+ for i=1 upto flow_xypoint-1 :
+ if not ((xpart flow_xypoints[i]=xpart flow_xypoints[i+1]) or (ypart flow_xypoints[i]=ypart flow_xypoints[i+1])) :
+ ok := false ;
+ fi ;
+ endfor ;
+ if not ok :
+ % message("slanted");
+ false
+ elseif flow_forcevalid :
+ % message("force");
+ true
+ elseif (xfrom=xto) and (yfrom=yto) :
+ % message("self");
+ false
+ else :
+ % check for crossing shapes
+ flow_xyfirst := flow_xypoints[1] ;
+ flow_xylast := flow_xypoints[flow_xypoint] ;
+ flow_trim_points ;
+ pp := for i=1 upto flow_xypoint-1 : flow_xypoints[i]-- endfor flow_xypoints[flow_xypoint] ;
+ flow_xypoints[1] := flow_xyfirst ;
+ flow_xypoints[flow_xypoint] := flow_xylast ;
+ for i=1 upto flow_max_x :
+ for j=1 upto flow_max_y : % was bug: xfrom,yto
+ if not ( ( (i,j)=(xfrom,yfrom) ) or ( (i,j)=(xto,yto) ) ) :
+ if not flow_xyfree[i][j] :
+ vc := pp intersection_point flow_xypath[i][j] ;
+ if intersection_found :
+ ok := false
+ fi ;
+ fi ;
+ fi ;
+ endfor ;
+ endfor ;
+ % if not ok: message("crossing") ; fi ;
+ ok
+ fi
+ endgroup
+enddef ;
+
+def flow_connect_top_bottom (expr xfrom, yyfrom, zfrom) (expr xto, yyto, zto) =
+ yfrom := flow_y_pos(yyfrom) ;
+ yto := flow_y_pos(yyto) ;
+ if flow_points_initialized(xfrom,yfrom,xto,yto,6) :
+ flow_xypoints[1] := flow_xy_top(xfrom,yfrom,zfrom,true) ;
+ flow_xypoints[6] := flow_xy_bottom(xto,yto,zto,true) ;
+ flow_xypoints[2] := flow_up_on_grid(1) ;
+ flow_xypoints[5] := flow_down_on_grid(6) ;
+ flow_xypoints[3] := flow_up_to_grid(2,5) ;
+ flow_xypoints[4] := flow_up_to_grid(2,5) ;
+ if not flow_valid_connection(xfrom,yfrom,xto,yto) :
+ flow_xypoints[3] := flow_x_on_grid(2,xfrom,xto,zfrom) ;
+ flow_xypoints[4] := flow_xy_on_grid(3,5) ;
+ fi ;
+ %%%% begin experiment
+ flow_xypoints[3] := flow_xypoints[3] shifted (flow_dsp_x,0) ;
+ flow_xypoints[4] := flow_xypoints[4] shifted (flow_dsp_x,0) ;
+ if flow_dsp_y>0 :
+ flow_xypoints[2] := flow_xypoints[2] shifted (0,flow_dsp_y) ;
+ flow_xypoints[3] := flow_xypoints[3] shifted (0,flow_dsp_y) ;
+ elseif flow_dsp_y<0 :
+ flow_xypoints[4] := flow_xypoints[4] shifted (0,flow_dsp_y) ;
+ flow_xypoints[5] := flow_xypoints[5] shifted (0,flow_dsp_y) ;
+ fi
+ %%%% end experiment
+ flow_draw_connection ;
+ fi ;
+enddef ;
+
+def flow_connect_left_right (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) =
+ yfrom := flow_y_pos(yyfrom) ;
+ yto := flow_y_pos(yyto) ;
+ if flow_points_initialized(xfrom,yfrom,xto,yto,6) :
+ flow_xypoints[1] := flow_xy_left(xfrom,yfrom,zfrom,true) ;
+ flow_xypoints[6] := flow_xy_right(xto,yto,zto,true) ;
+ flow_xypoints[2] := flow_left_on_grid(1) ;
+ flow_xypoints[5] := flow_right_on_grid(6) ;
+ flow_xypoints[3] := flow_left_to_grid(2,5) ;
+ flow_xypoints[4] := flow_left_to_grid(2,5) ;
+ if not flow_valid_connection(xfrom,yfrom,xto,yto) :
+ flow_xypoints[3] := flow_y_on_grid(2,yfrom,yto,zfrom) ;
+ flow_xypoints[4] := flow_xy_on_grid(5,3) ;
+ fi ;
+ flow_draw_connection ;
+ fi ;
+enddef ;
+
+def flow_connect_left_top (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) =
+ yfrom := flow_y_pos(yyfrom) ;
+ yto := flow_y_pos(yyto) ;
+ if flow_points_initialized(xfrom,yfrom,xto,yto,5) :
+ flow_xypoints[1] := flow_xy_left(xfrom,yfrom,zfrom,true) ;
+ flow_xypoints[5] := flow_xy_top(xto,yto,zto,true) ;
+ flow_xypoints[2] := flow_left_on_grid(1) ;
+ flow_xypoints[4] := flow_up_on_grid(5) ;
+ flow_xypoints[3] := flow_left_to_grid(2,5) ;
+ if not flow_valid_connection(xfrom,yfrom,xto,yto) :
+ flow_xypoints[3] := flow_xy_on_grid(2,4) ;
+ fi ;
+ flow_draw_connection ;
+ fi ;
+enddef ;
+
+def flow_connect_left_bottom (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) =
+ yfrom := flow_y_pos(yyfrom) ;
+ yto := flow_y_pos(yyto) ;
+ if flow_points_initialized(xfrom,yfrom,xto,yto,5) :
+ flow_xypoints[1] := flow_xy_left(xfrom,yfrom,zfrom,true) ;
+ flow_xypoints[5] := flow_xy_bottom(xto,yto,zto,true) ;
+ flow_xypoints[2] := flow_left_on_grid(1) ;
+ flow_xypoints[4] := flow_down_on_grid(5) ;
+ flow_xypoints[3] := flow_left_to_grid(2,5) ;
+ if not flow_valid_connection(xfrom,yfrom,xto,yto) :
+ flow_xypoints[3] := flow_xy_on_grid(2,4) ;
+ fi ;
+ flow_draw_connection ;
+ fi ;
+enddef ;
+
+def flow_connect_right_top (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) =
+ yfrom := flow_y_pos(yyfrom) ;
+ yto := flow_y_pos(yyto) ;
+ if flow_points_initialized(xfrom,yfrom,xto,yto,5) :
+ flow_xypoints[1] := flow_xy_right(xfrom,yfrom,zfrom,true) ;
+ flow_xypoints[5] := flow_xy_top(xto,yto,zto,true) ;
+ flow_xypoints[2] := flow_right_on_grid(1) ;
+ flow_xypoints[4] := flow_up_on_grid(5) ;
+ flow_xypoints[3] := flow_right_to_grid(2,5) ;
+ if not flow_valid_connection(xfrom,yfrom,xto,yto) :
+ flow_xypoints[3] := flow_xy_on_grid(2,4) ;
+ fi ;
+ flow_draw_connection ;
+ fi ;
+enddef ;
+
+def flow_connect_right_bottom (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) =
+ yfrom := flow_y_pos(yyfrom) ;
+ yto := flow_y_pos(yyto) ;
+ if flow_points_initialized(xfrom,yfrom,xto,yto,5) :
+ flow_xypoints[1] := flow_xy_right(xfrom,yfrom,zfrom,true) ;
+ flow_xypoints[5] := flow_xy_bottom(xto,yto,zto,true) ;
+ flow_xypoints[2] := flow_right_on_grid(1) ;
+ flow_xypoints[4] := flow_down_on_grid(5) ;
+ flow_xypoints[3] := flow_right_to_grid(2,5) ;
+ if not flow_valid_connection(xfrom,yfrom,xto,yto) :
+ flow_xypoints[3] := flow_xy_on_grid(2,4) ;
+ fi ;
+ %%%% begin experiment
+ flow_xypoints[2] := flow_xypoints[2] shifted (flow_dsp_x,0) ;
+ flow_xypoints[3] := flow_xypoints[3] shifted (flow_dsp_x,0) ;
+ if flow_dsp_y>0 :
+ flow_xypoints[3] := flow_xypoints[3] shifted (0,-flow_dsp_y) ;
+ flow_xypoints[4] := flow_xypoints[4] shifted (0,-flow_dsp_y) ;
+ elseif flow_dsp_y<0 :
+ flow_xypoints[3] := flow_xypoints[3] shifted (0,flow_dsp_y) ;
+ flow_xypoints[4] := flow_xypoints[4] shifted (0,flow_dsp_y) ;
+ fi
+ %%%% end experiment
+ flow_draw_connection ;
+ fi ;
+enddef ;
+
+def flow_connect_left_left (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) =
+ yfrom := flow_y_pos(yyfrom) ;
+ yto := flow_y_pos(yyto) ;
+ if flow_points_initialized(xfrom,yfrom,xto,yto,6) :
+ flow_xypoints[1] := flow_xy_left(xfrom,yfrom,zfrom,true) ;
+ flow_xypoints[6] := flow_xy_left(xto,yto,zto,true) ;
+ flow_xypoints[2] := flow_left_on_grid(1) ;
+ flow_xypoints[5] := flow_left_on_grid(6) ;
+ flow_xypoints[3] := flow_left_to_grid(2,5) ;
+ flow_xypoints[4] := flow_left_to_grid(5,2) ;
+ if not flow_valid_connection(xfrom,yfrom,xto,yto) :
+ flow_xypoints[3] := flow_y_on_grid(2,yfrom,yto,zfrom) ;
+ flow_xypoints[4] := flow_xy_on_grid(5,3) ;
+ fi ;
+ flow_draw_connection ;
+ fi ;
+enddef ;
+
+def flow_connect_right_right (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) =
+ yfrom := flow_y_pos(yyfrom) ;
+ yto := flow_y_pos(yyto) ;
+ if flow_points_initialized(xfrom,yfrom,xto,yto,6) :
+ flow_xypoints[1] := flow_xy_right(xfrom,yfrom,zfrom,true) ;
+ flow_xypoints[6] := flow_xy_right(xto,yto,zto,true) ;
+ flow_xypoints[2] := flow_right_on_grid(1) ;
+ flow_xypoints[5] := flow_right_on_grid(6) ;
+ flow_xypoints[3] := flow_right_to_grid(2,5) ;
+ flow_xypoints[4] := flow_right_to_grid(5,2) ;
+ if not flow_valid_connection(xfrom,yfrom,xto,yto) :
+ flow_xypoints[3] := flow_y_on_grid(2,yfrom,yto,zfrom) ;
+ flow_xypoints[4] := flow_xy_on_grid(5,3) ;
+ fi ;
+ flow_draw_connection ;
+ fi ;
+enddef ;
+
+def flow_connect_top_top (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) =
+ yfrom := flow_y_pos(yyfrom) ;
+ yto := flow_y_pos(yyto) ;
+ if flow_points_initialized(xfrom,yfrom,xto,yto,6) :
+ flow_xypoints[1] := flow_xy_top(xfrom,yfrom,zfrom,true) ;
+ flow_xypoints[6] := flow_xy_top(xto,yto,zto,true) ;
+ flow_xypoints[2] := flow_up_on_grid(1) ;
+ flow_xypoints[5] := flow_up_on_grid(6) ;
+ flow_xypoints[3] := flow_up_to_grid(2,5) ;
+ flow_xypoints[4] := flow_up_to_grid(5,2) ;
+ if not flow_valid_connection(xfrom,yfrom,xto,yto) :
+ flow_xypoints[3] := flow_x_on_grid(2,xfrom,xto,zfrom) ;
+ flow_xypoints[4] := flow_xy_on_grid(3,5) ;
+ fi ;
+ flow_draw_connection ;
+ fi ;
+enddef ;
+
+def flow_connect_bottom_bottom (expr xfrom,yyfrom,zfrom) (expr xto,yyto,zto) =
+ yfrom := flow_y_pos(yyfrom) ;
+ yto := flow_y_pos(yyto) ;
+ if flow_points_initialized(xfrom,yfrom,xto,yto,6) :
+ flow_xypoints[1] := flow_xy_bottom(xfrom,yfrom,zfrom,true) ;
+ flow_xypoints[6] := flow_xy_bottom(xto,yto,zto,true) ;
+ flow_xypoints[2] := flow_down_on_grid(1) ;
+ flow_xypoints[5] := flow_down_on_grid(6) ;
+ flow_xypoints[3] := flow_down_to_grid(2,5) ;
+ flow_xypoints[4] := flow_down_to_grid(5,2) ;
+ if not flow_valid_connection(xfrom,yfrom,xto,yto) :
+ flow_xypoints[3] := flow_x_on_grid(2,xfrom,xto,zfrom) ;
+ flow_xypoints[4] := flow_xy_on_grid(3,5) ;
+ fi ;
+ %%%% begin experiment
+ flow_xypoints[3] := flow_xypoints[3] shifted (flow_dsp_x,0) ;
+ flow_xypoints[4] := flow_xypoints[4] shifted (flow_dsp_x,0) ;
+ if flow_dsp_y<0 :
+ flow_xypoints[2] := flow_xypoints[2] shifted (0,-flow_dsp_y) ;
+ flow_xypoints[3] := flow_xypoints[3] shifted (0,-flow_dsp_y) ;
+ elseif flow_dsp_y>0 :
+ flow_xypoints[4] := flow_xypoints[4] shifted (0,flow_dsp_y) ;
+ flow_xypoints[5] := flow_xypoints[5] shifted (0,flow_dsp_y) ;
+ fi
+ %%%% end experiment
+ flow_draw_connection ;
+ fi ;
+enddef ;
+
+def flow_connect_bottom_top (expr xfrom,yfrom,zfrom) (expr xto,yto,zto) =
+ flow_reverse_connection := true ;
+ flow_connect_top_bottom (xto,yto,zto) (xfrom,yfrom,zfrom) ;
+enddef ;
+
+def flow_connect_right_left (expr xfrom,yfrom,zfrom) (expr xto,yto,zto) =
+ flow_reverse_connection := true ;
+ flow_connect_left_right (xto,yto,zto) (xfrom,yfrom,zfrom) ;
+enddef ;
+
+def flow_connect_top_left (expr xfrom,yfrom,zfrom) (expr xto,yto,zto) =
+ flow_reverse_connection := true ;
+ flow_connect_left_top(xto,yto,zto) (xfrom,yfrom,zfrom) ;
+enddef ;
+
+def flow_connect_bottom_left (expr xfrom,yfrom,zfrom) (expr xto,yto,zto) =
+ flow_reverse_connection := true ;
+ flow_connect_left_bottom (xto,yto,zto) (xfrom,yfrom,zfrom) ;
+enddef ;
+
+def flow_connect_top_right (expr xfrom,yfrom,zfrom) (expr xto,yto,zto) =
+ flow_reverse_connection := true ;
+ flow_connect_right_top (xto,yto,zto) (xfrom,yfrom,zfrom) ;
+enddef ;
+
+def flow_connect_bottom_right (expr xfrom,yfrom,zfrom) (expr xto,yto,zto) =
+ flow_reverse_connection := true ;
+ flow_connect_right_bottom (xto,yto,zto) (xfrom,yfrom,zfrom) ;
+enddef ;
+
+def flow_draw_test_shape(expr x, y) =
+ flow_draw_shape(x,y,fullcircle, .7, .7) ;
+enddef ;
+
+def flow_draw_test_shapes =
+ for i=1 upto flow_max_x :
+ for j=1 upto flow_max_y :
+ flow_draw_test_shape(i,j) ;
+ endfor ;
+ endfor ;
+enddef;
+
+def flow_draw_test_area =
+ pickup pencircle scaled .5flow_shape_line_width ;
+ draw (unitsquare xscaled flow_max_x yscaled flow_max_y shifted (1,1)) flow_scaled_to_grid withcolor blue ;
+enddef ;
+
+def flow_show_connection(expr n, m) =
+
+ flow_begin_chart(100+n,6,6) ;
+
+ flow_draw_test_area ;
+
+ flow_smooth := true ;
+ flow_arrowtip := true ;
+ flow_dashline := true ;
+
+ flow_draw_test_shape(2,2) ; flow_draw_test_shape(4,5) ;
+ flow_draw_test_shape(3,3) ; flow_draw_test_shape(5,1) ;
+ flow_draw_test_shape(2,5) ; flow_draw_test_shape(1,3) ;
+ flow_draw_test_shape(6,2) ; flow_draw_test_shape(4,6) ;
+
+ if (m=1) :
+ flow_connect_top_bottom (2,2,0) (4,5,0) ;
+ flow_connect_top_bottom (3,3,0) (5,1,0) ;
+ flow_connect_top_bottom (2,5,0) (1,3,0) ;
+ flow_connect_top_bottom (6,2,0) (4,6,0) ;
+ elseif (m=2) :
+ flow_connect_top_top (2,2,0) (4,5,0) ;
+ flow_connect_top_top (3,3,0) (5,1,0) ;
+ flow_connect_top_top (2,5,0) (1,3,0) ;
+ flow_connect_top_top (6,2,0) (4,6,0) ;
+ elseif (m=3) :
+ flow_connect_bottom_bottom (2,2,0) (4,5,0) ;
+ flow_connect_bottom_bottom (3,3,0) (5,1,0) ;
+ flow_connect_bottom_bottom (2,5,0) (1,3,0) ;
+ flow_connect_bottom_bottom (6,2,0) (4,6,0) ;
+ elseif (m=4) :
+ flow_connect_left_right (2,2,0) (4,5,0) ;
+ flow_connect_left_right (3,3,0) (5,1,0) ;
+ flow_connect_left_right (2,5,0) (1,3,0) ;
+ flow_connect_left_right (6,2,0) (4,6,0) ;
+ elseif (m=5) :
+ flow_connect_left_left (2,2,0) (4,5,0) ;
+ flow_connect_left_left (3,3,0) (5,1,0) ;
+ flow_connect_left_left (2,5,0) (1,3,0) ;
+ flow_connect_left_left (6,2,0) (4,6,0) ;
+ elseif (m=6) :
+ flow_connect_right_right (2,2,0) (4,5,0) ;
+ flow_connect_right_right (3,3,0) (5,1,0) ;
+ flow_connect_right_right (2,5,0) (1,3,0) ;
+ flow_connect_right_right (6,2,0) (4,6,0) ;
+ elseif (m=7) :
+ flow_connect_left_top (2,2,0) (4,5,0) ;
+ flow_connect_left_top (3,3,0) (5,1,0) ;
+ flow_connect_left_top (2,5,0) (1,3,0) ;
+ flow_connect_left_top (6,2,0) (4,6,0) ;
+ elseif (m=8) :
+ flow_connect_left_bottom (2,2,0) (4,5,0) ;
+ flow_connect_left_bottom (3,3,0) (5,1,0) ;
+ flow_connect_left_bottom (2,5,0) (1,3,0) ;
+ flow_connect_left_bottom (6,2,0) (4,6,0) ;
+ elseif (m=9) :
+ flow_connect_right_top (2,2,0) (4,5,0) ;
+ flow_connect_right_top (3,3,0) (5,1,0) ;
+ flow_connect_right_top (2,5,0) (1,3,0) ;
+ flow_connect_right_top (6,2,0) (4,6,0) ;
+ else :
+ flow_connect_right_bottom (2,2,0) (4,5,0) ;
+ flow_connect_right_bottom (3,3,0) (5,1,0) ;
+ flow_connect_right_bottom (2,5,0) (1,3,0) ;
+ flow_connect_right_bottom (6,2,0) (4,6,0) ;
+ fi ;
+
+ flow_end_chart ;
+
+enddef ;
+
+def flow_show_connections =
+ for f=1 upto 10 :
+ flow_show_connection(f,f) ;
+ endfor ;
+enddef ;
+
+%D charts
+
+def flow_clip_chart(expr minx, miny, maxx, maxy) =
+ flow_cmin_x := minx ;
+ flow_cmax_x := maxx ;
+ flow_cmin_y := miny ;
+ flow_cmax_y := maxy ;
+enddef ;
+
+def flow_begin_chart(expr n, maxx, maxy) =
+ flow_new_chart ;
+ flow_chart_figure := n ;
+ flow_chart_scale := 1 ;
+ if flow_chart_figure>0:
+ beginfig(flow_chart_figure) ;
+ fi ;
+ flow_initialize_grid (maxx, maxy) ;
+ bboxmargin := 0 ;
+ flow_cmin_x := 1 ;
+ flow_cmax_x := maxx ;
+ flow_cmin_y := 1 ;
+ flow_cmax_y := maxy ;
+enddef ;
+
+def flow_end_chart =
+ begingroup ;
+ save p ; path p ;
+ flow_flush_shapes ;
+ flow_flush_connections ;
+ flow_flush_pictures ;
+ flow_cmin_x := flow_cmin_x ;
+ flow_cmax_x := flow_cmin_x+flow_cmax_x ;
+ flow_cmin_y := flow_cmin_y-1 ;
+ flow_cmax_y := flow_cmin_y+flow_cmax_y ;
+ if flow_reverse_y :
+ flow_cmin_y := flow_y_pos(flow_cmin_y) ;
+ flow_cmax_y := flow_y_pos(flow_cmax_y) ;
+ fi ;
+ p := (((flow_cmin_x,flow_cmin_y)--(flow_cmax_x,flow_cmin_y)--
+ (flow_cmax_x,flow_cmax_y)--(flow_cmin_x,flow_cmax_y)--cycle))
+ flow_scaled_to_grid ;
+ %draw p withcolor red ;
+ p := p enlarged flow_chart_offset ;
+ clip currentpicture to p ;
+ setbounds currentpicture to p ;
+ endgroup ;
+ currentpicture := currentpicture scaled flow_chart_scale ;
+ if flow_chart_figure>0:
+ endfig ;
+ fi ;
+enddef ;
+
+def flow_new_shape(expr x, y, n) =
+ if known n :
+ if (x>0) and (x<=flow_max_x) and (y>0) and (y<=flow_max_y) :
+ flow_draw_shape(x,y,some_shape_path(n), flow_shape_width/flow_grid_width, flow_shape_height/flow_grid_height) ;
+ else :
+ message ("shape outside grid ignored") ;
+ fi ;
+ else :
+ message ("shape not known" ) ;
+ fi ;
+enddef ;
+
+def flow_begin_sub_chart =
+ begingroup ;
+ save flow_shape_line_width, flow_connection_line_width ;
+ save flow_shape_line_color, flow_shape_fill_color, flow_connection_line_color ;
+ color flow_shape_line_color, flow_shape_fill_color, flow_connection_line_color ;
+ save flow_smooth, flow_arrowtip, flow_dashline, flow_peepshape ;
+ boolean flow_smooth, flow_arrowtip, flow_dashline, flow_peepshape ;
+enddef ;
+
+def flow_end_sub_chart =
+ endgroup ;
+enddef ;
+
diff --git a/metapost/context/base/mp-shap.mp b/metapost/context/base/mp-shap.mp
index 0f5fe431d..785231278 100644
--- a/metapost/context/base/mp-shap.mp
+++ b/metapost/context/base/mp-shap.mp
@@ -1,6 +1,6 @@
%D \module
%D [ file=mp-shap.mp,
-%D version=2000.05.31,
+%D version=2000.05.31,
%D title=\CONTEXT\ \METAPOST\ graphics,
%D subtitle=shapes,
%D author=Hans Hagen,
@@ -8,300 +8,199 @@
%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See licen-en.pdf for
-%C details.
-
-if unknown context_tool : input mp-tool ; fi ;
-if known context_shap : endinput ; fi ;
-
-boolean context_shap ; context_shap := true ;
+%C therefore copyrighted by \PRAGMA. See licen-en.pdf for
+%C details.
+
+if unknown context_tool : input mp-tool ; fi ;
+if known context_shap : endinput ; fi ;
+
+boolean context_shap ; context_shap := true ;
+
+path predefined_shapes[] ;
+
+begingroup ;
+
+save xradius, yradius, xxradius, yyradius ;
+save ll, lr, ur, ul, llx, lly, lrx, lry, urx, ury, ulx, uly, llxx, llyy, lrxx, lryy, urxx, uryy, ulxx, ulyy, lc, rc, tc, bc ;
+
+numeric xradius, yradius, xxradius, yyradius ;
+pair ll, lr, ur, ul, llx, lly, lrx, lry, urx, ury, ulx, uly, llxx, llyy, lrxx, lryy, urxx, uryy, ulxx, ulyy, lc, rc, tc, bc ;
+
+xradius := .15 ;
+yradius := .15 ;
+xxradius := .10 ;
+yyradius := .10 ;
+
+ll := llcorner (unitsquare shifted (-.5,-.5)) ;
+lr := lrcorner (unitsquare shifted (-.5,-.5)) ;
+ur := urcorner (unitsquare shifted (-.5,-.5)) ;
+ul := ulcorner (unitsquare shifted (-.5,-.5)) ;
+
+llx := ll shifted (xradius,0) ;
+lly := ll shifted (0,yradius) ;
+
+lrx := lr shifted (-xradius,0) ;
+lry := lr shifted (0,yradius) ;
+
+urx := ur shifted (-xradius,0) ;
+ury := ur shifted (0,-yradius) ;
+
+ulx := ul shifted (xradius,0) ;
+uly := ul shifted (0,-yradius) ;
+
+llxx := ll shifted (xxradius,0) ;
+llyy := ll shifted (0,yyradius) ;
+
+lrxx := lr shifted (-xxradius,0) ;
+lryy := lr shifted (0,yyradius) ;
+
+urxx := ur shifted (-xxradius,0) ;
+uryy := ur shifted (0,-yyradius) ;
+
+ulxx := ul shifted (xxradius,0) ;
+ulyy := ul shifted (0,-yyradius) ;
+
+lc := ll shifted (0,.5) ;
+rc := lr shifted (0,.5) ;
+tc := ul shifted (.5,0) ;
+bc := ll shifted (.5,0) ;
+
+predefined_shapes[ 0] := (origin--cycle) ;
+predefined_shapes[ 5] := (llx--lrx{right}...rc...{left}urx--ulx{left}...lc...{right}cycle) ;
+predefined_shapes[ 6] := (ll--lrx{right}...rc...{left}urx--ul--cycle) ;
+predefined_shapes[ 7] := (ll--lrx{right}...rc...{left}urx--ul--cycle) rotatedaround(origin,180) ;
+predefined_shapes[ 8] := (lr--ury{up}...tc...{down}uly--ll--cycle) ;
+predefined_shapes[ 9] := (lr--ury{up}...tc...{down}uly--ll--cycle) rotatedaround(origin,180) ;
+predefined_shapes[10] := (ll--lr--ur--ul--ll--ur--ul--ll--cycle) ;
+predefined_shapes[11] := (ll--lr--ur--ul--ll--lr--ul--ll--cycle) ;
+predefined_shapes[12] := (ll--lrx--ur--ulx--cycle) ;
+predefined_shapes[13] := (llx--lr--urx--ul--cycle) ;
+predefined_shapes[14] := (lly--bc--lry--ury--tc--uly--cycle) ;
+predefined_shapes[15] := (llx--lrx--rc--urx--ulx--lc--cycle) ;
+predefined_shapes[16] := (ll--lrx--rc--urx--ul--cycle) ;
+predefined_shapes[17] := (ll--lrx--rc--urx--ul--cycle) rotatedaround(origin,180) ;
+predefined_shapes[18] := (lr--ury--tc--uly--ll--cycle) ;
+predefined_shapes[19] := (lr--ury--tc--uly--ll--cycle) rotatedaround(origin,180) ;
+predefined_shapes[20] := (ll--lr--ur--ul--ll--llxx--ulxx--ul--ll--lr--ur--urxx--lrxx--cycle) ;
+predefined_shapes[21] := (ul--ll--lr--ur--ul--ulyy--uryy--ur--ul--ll--lr--lryy--llyy--cycle) ;
+predefined_shapes[22] := (ll--lrx--lry--ur--ulx--uly--cycle) ;
+predefined_shapes[23] := (llx--lr--ury--urx--ul--lly--cycle) ;
+predefined_shapes[24] := (ll--lr--ur--ul--cycle) ;
+predefined_shapes[25] := (llx--lrx--lry--ury--urx--ulx--uly--lly--cycle) ;
+predefined_shapes[26] := (ll--lrx--lry--ur--ul--cycle) ;
+predefined_shapes[27] := (ll--lr--ury--urx--ul--cycle) rotatedaround(origin,180) ;
+predefined_shapes[28] := (ll--lr--ury--urx--ul--cycle) ;
+predefined_shapes[29] := (ll--lrx--lry--ur--ul--cycle) rotatedaround(origin,180) ;
+predefined_shapes[30] := (bc{right}...{up}rc...tc{left}...{down}lc...{right}bc & bc--tc & tc{left}..{down}lc & lc--rc & rc{up}..tc{left}...{down}lc...{right}bc & cycle) rotated 45;
+predefined_shapes[31] := (bc{right}...{up}rc...tc{left}...{down}lc...{right}bc & bc--tc & tc{left}..{down}lc & lc--rc & rc{up}..tc{left}...{down}lc...{right}bc & cycle) ;
+predefined_shapes[32] := (ll{right}...{right}lry--ur--ul--ll--cycle) ;
+predefined_shapes[33] := (ll{right}...{right}lry--ur--ul--ll--cycle--ul--ulx--ulx shifted(0,yyradius)--ur shifted(yyradius,yyradius)--lry shifted(yyradius,yyradius)--lry shifted(0,yyradius)--ur--ul--cycle ) ;
+predefined_shapes[34] := (uly..tc..ury & ury..tc shifted (0,-2yradius)..uly & uly--lly & lly..bc..lry & lry--ury & ury..tc shifted (0,-2yradius)..uly & cycle ) ;
+predefined_shapes[35] := (bc{right}...rc{up}...tc{left}...lc{down}...cycle) ;
+predefined_shapes[36] := (ul--tc{right}..rc{down}..{left}bc--ll & ll..(xpart llx, ypart lc)..ul & cycle) ;
+predefined_shapes[37] := (ul--tc{right}..rc{down}..{left}bc--ll & ll..(xpart llx, ypart lc)..ul & cycle) rotatedaround(origin,180) ;
+predefined_shapes[38] := (ll--lc{up}..tc{right}..{down}rc--lr & lr..(xpart bc, ypart lly)..ll & cycle) ;
+predefined_shapes[39] := (ll--lc{up}..tc{right}..{down}rc--lr & lr..(xpart bc, ypart lly)..ll & cycle) rotatedaround(origin,180) ;
+predefined_shapes[40] := (ll--lr--ur--ul--ll--ur--ul--ll--lr--ul--ll--cycle) ;
+predefined_shapes[41] := (ll--lr--ur--ul--ll--lr--rc--lc--ll--bc--tc--ul--ll & cycle) ;
+predefined_shapes[42] := (ll--lr--origin shifted (+epsilon,0)--ur--ul--origin shifted (-epsilon,0)--cycle) ;
+predefined_shapes[43] := (ll--ul--origin shifted (0,+epsilon)--ur--lr--origin shifted (0,-epsilon)--cycle) ;
+predefined_shapes[45] := (bc--rc--tc--lc--cycle) ;
+predefined_shapes[46] := (ll--ul--rc--cycle) ;
+predefined_shapes[47] := (ll--ul--rc--cycle) rotatedaround(origin,180) ;
+predefined_shapes[48] := (ul--ur--bc--cycle) rotatedaround(origin,180) ;
+predefined_shapes[49] := (ul--ur--bc--cycle) ;
+predefined_shapes[56] := (ll--lry--ury--ul--cycle) ;
+predefined_shapes[57] := (ll--lry--ury--ul--cycle) rotatedaround(origin,180) ;
+predefined_shapes[58] := (ll--ulx--urx--lr--cycle) ;
+predefined_shapes[59] := (ll--ulx--urx--lr--cycle) rotatedaround(origin,180);
+predefined_shapes[66] := (rc--origin shifted ( epsilon,0) --cycle & rc--origin--cycle ) ;
+predefined_shapes[67] := (lc--origin shifted (-epsilon,0) --cycle & lc--origin--cycle ) ;
+predefined_shapes[68] := (tc--origin shifted (0, epsilon) --cycle & tc--origin--cycle ) ;
+predefined_shapes[69] := (bc--origin shifted (0,-epsilon) --cycle & bc--origin--cycle ) ;
+predefined_shapes[75] := (lly--lry--ury--uly--cycle) rotatedaround(origin,180) ;
+predefined_shapes[76] := (ll--lr--ur--uly--cycle) rotatedaround(origin,180) ;
+predefined_shapes[77] := (ll--lr--ury--ul--cycle) rotatedaround(origin,180) ;
+predefined_shapes[78] := (lly--lr--ur--ul--cycle) rotatedaround(origin,180) ;
+predefined_shapes[79] := (ll--lry--ur--ul--cycle) rotatedaround(origin,180) ;
+
+numeric predefined_shapes_xradius ; predefined_shapes_xradius := xradius ;
+numeric predefined_shapes_yradius ; predefined_shapes_yradius := yradius ;
+numeric predefined_shapes_xxradius ; predefined_shapes_xxradius := xxradius ;
+numeric predefined_shapes_yyradius ; predefined_shapes_yyradius := yyradius ;
+
+endgroup ;
vardef some_shape_path (expr type) =
+ if known predefined_shapes[type] : predefined_shapes[type] else : predefined_shapes[0] fi
+enddef ;
+def some_shape (expr shape_type, shape_width, shape_height, shape_linewidth, shape_linecolor, shape_fillcolor) =
begingroup ;
-
- save border, xradius, yradius,
- normal, mirror, rotate,
- lc, rc, tc, bc, ll, lr, ur, ul,
- llx, lrx, urx, ulx, lly, lry, ury, uly ;
-
- path border ;
-
- xradius := .15 ; xxradius := .10 ;
- yradius := .15 ; yyradius := .10 ;
-
- pair ll ; ll := llcorner (unitsquare shifted (-.5,-.5)) ;
- pair lr ; lr := lrcorner (unitsquare shifted (-.5,-.5)) ;
- pair ur ; ur := urcorner (unitsquare shifted (-.5,-.5)) ;
- pair ul ; ul := ulcorner (unitsquare shifted (-.5,-.5)) ;
-
- pair llx ; llx := ll shifted (xradius,0) ;
- pair lly ; lly := ll shifted (0,yradius) ;
-
- pair lrx ; lrx := lr shifted (-xradius,0) ;
- pair lry ; lry := lr shifted (0,yradius) ;
-
- pair urx ; urx := ur shifted (-xradius,0) ;
- pair ury ; ury := ur shifted (0,-yradius) ;
-
- pair ulx ; ulx := ul shifted (xradius,0) ;
- pair uly ; uly := ul shifted (0,-yradius) ;
-
- pair llxx ; llxx := ll shifted (xxradius,0) ;
- pair llyy ; llyy := ll shifted (0,yyradius) ;
-
- pair lrxx ; lrxx := lr shifted (-xxradius,0) ;
- pair lryy ; lryy := lr shifted (0,yyradius) ;
-
- pair urxx ; urxx := ur shifted (-xxradius,0) ;
- pair uryy ; uryy := ur shifted (0,-yyradius) ;
-
- pair ulxx ; ulxx := ul shifted (xxradius,0) ;
- pair ulyy ; ulyy := ul shifted (0,-yyradius) ;
-
- pair lc ; lc := ll shifted (0,.5) ;
- pair rc ; rc := lr shifted (0,.5) ;
- pair tc ; tc := ul shifted (.5,0) ;
- pair bc ; bc := ll shifted (.5,0) ;
-
- def mirror (expr p) =
- p rotatedaround(origin,180)
- enddef ;
-
- def normal (expr p ) =
- p
- enddef ;
-
- def rotate (expr p) =
- p rotated 45
- enddef ;
-
- if type= 0 :
- border := normal (origin--cycle) ;
-
- elseif type= 5 :
- border := normal (llx--lrx{right}...rc...{left}urx--ulx{left}...lc...{right}cycle) ;
- elseif type= 6 :
- border := normal (ll--lrx{right}...rc...{left}urx--ul--cycle) ;
- elseif type= 7 :
- border := mirror (ll--lrx{right}...rc...{left}urx--ul--cycle) ;
- elseif type= 8 :
- border := normal (lr--ury{up}...tc...{down}uly--ll--cycle) ;
- elseif type= 9 :
- border := mirror (lr--ury{up}...tc...{down}uly--ll--cycle) ;
- elseif type=10 :
- border := normal (ll--lr--ur--ul--ll--ur--ul--ll--cycle) ;
- elseif type=11 :
- border := normal (ll--lr--ur--ul--ll--lr--ul--ll--cycle) ;
- elseif type=12 :
- border := normal (ll--lrx--ur--ulx--cycle) ;
- elseif type=13 :
- border := normal (llx--lr--urx--ul--cycle) ;
- elseif type=14 :
- border := normal (lly--bc--lry--ury--tc--uly--cycle) ;
- elseif type=15 :
- border := normal (llx--lrx--rc--urx--ulx--lc--cycle) ;
- elseif type=16 :
- border := normal (ll--lrx--rc--urx--ul--cycle) ;
- elseif type=17 :
- border := mirror (ll--lrx--rc--urx--ul--cycle) ;
- elseif type=18 :
- border := normal (lr--ury--tc--uly--ll--cycle) ;
- elseif type=19 :
- border := mirror (lr--ury--tc--uly--ll--cycle) ;
- elseif type=20 :
- border := normal (ll--lr--ur--ul--ll--llxx--ulxx--ul--ll--
- lr--ur--urxx--lrxx--cycle) ;
- elseif type=21 :
- border := normal (ul--ll--lr--ur--ul--ulyy--uryy--ur--ul--
- ll--lr--lryy--llyy--cycle) ;
- elseif type=22 :
- border := normal (ll--lrx--lry--ur--ulx--uly--cycle) ;
- elseif type=23 :
- border := normal (llx--lr--ury--urx--ul--lly--cycle) ;
- elseif type=24 :
- border := normal (ll--lr--ur--ul--cycle) ;
- elseif type=25 :
- border := normal (llx--lrx--lry--ury--urx--ulx--uly--lly--cycle) ;
- elseif type=26 :
- border := normal (ll--lrx--lry--ur--ul--cycle) ;
- elseif type=27 :
- border := mirror (ll--lr--ury--urx--ul--cycle) ;
- elseif type=28 :
- border := normal (ll--lr--ury--urx--ul--cycle) ;
- elseif type=29 :
- border := mirror (ll--lrx--lry--ur--ul--cycle) ;
- elseif type=30 :
- border := rotate (bc{right}...{up}rc...tc{left}...{down}lc...{right}bc &
- bc--tc & tc{left}..{down}lc & lc--rc &
- rc{up}..tc{left}...{down}lc...{right}bc & cycle) ;
- elseif type=31 :
- border := normal (bc{right}...{up}rc...tc{left}...{down}lc...{right}bc &
- bc--tc & tc{left}..{down}lc & lc--rc &
- rc{up}..tc{left}...{down}lc...{right}bc & cycle) ;
- elseif type=32 :
- border := normal (ll{right}...{right}lry--ur--ul--ll--cycle) ;
- elseif type=33 :
- border := normal (ll{right}...{right}lry--ur--ul--ll--cycle
- --ul--ulx--ulx shifted(0,yyradius)
- --ur shifted(yyradius,yyradius)
- --lry shifted(yyradius,yyradius)
- --lry shifted(0,yyradius)
- --ur--ul--cycle ) ;
- elseif type=34 :
- border := normal (uly..tc..ury &
- ury..tc shifted (0,-2yradius)..uly &
- uly--lly &
- lly..bc..lry &
- lry--ury &
- ury..tc shifted (0,-2yradius)..uly & cycle ) ;
- elseif type=35 :
- border := normal (bc{right}...rc{up}...tc{left}...lc{down}...cycle) ;
- elseif type=36 :
- border := normal (ul--tc{right}..rc{down}..{left}bc--ll &
- ll..(xpart llx, ypart lc)..ul & cycle) ;
- elseif type=37 :
- border := mirror (ul--tc{right}..rc{down}..{left}bc--ll &
- ll..(xpart llx, ypart lc)..ul & cycle) ;
- elseif type=38 :
- border := normal (ll--lc{up}..tc{right}..{down}rc--lr &
- lr..(xpart bc, ypart lly)..ll & cycle) ;
- elseif type=39 :
- border := mirror (ll--lc{up}..tc{right}..{down}rc--lr &
- lr..(xpart bc, ypart lly)..ll & cycle) ;
- elseif type=40 :
- border := normal (ll--lr--ur--ul--ll--ur--ul--ll--lr--ul--ll--cycle) ;
- elseif type=41 :
- border := normal (ll--lr--ur--ul--ll--lr--rc--lc--ll--bc--tc--ul--ll & cycle) ;
- elseif type=42 :
- border := normal (ll--lr--origin shifted (+epsilon,0)--
- ur--ul--origin shifted (-epsilon,0)--cycle) ;
- elseif type=43 :
- border := normal (ll--ul--origin shifted (0,+epsilon)--
- ur--lr--origin shifted (0,-epsilon)--cycle) ;
- elseif type=45 :
- border := normal (bc--rc--tc--lc--cycle) ;
- elseif type=46 :
- border := normal (ll--ul--rc--cycle) ;
- elseif type=47 :
- border := mirror (ll--ul--rc--cycle) ;
- elseif type=48 :
- border := mirror (ul--ur--bc--cycle) ;
- elseif type=49 :
- border := normal (ul--ur--bc--cycle) ;
-
- elseif type=56 :
- border := normal (ll--lry--ury--ul--cycle) ;
- elseif type=57 :
- border := mirror (ll--lry--ury--ul--cycle) ;
- elseif type=58 :
- border := normal (ll--ulx--urx--lr--cycle) ;
- elseif type=59 :
- border := mirror (ll--ulx--urx--lr--cycle) ;
-
- elseif type=61 :
- border := normal (fullcircle scaled (1.5*yradius) xscaled (grid_height/grid_width)) ;
- elseif type=62 :
- border := normal (fullcircle scaled (2.0*yradius) xscaled (grid_height/grid_width)) ;
-
- elseif type=66 :
- border := normal (rc--origin shifted ( epsilon,0) --cycle &
- rc--origin --cycle ) ;
- elseif type=67 :
- border := normal (lc--origin shifted (-epsilon,0) --cycle &
- lc--origin --cycle ) ;
- elseif type=68 :
- border := normal (tc--origin shifted (0, epsilon) --cycle &
- tc--origin --cycle ) ;
- elseif type=69 :
- border := normal (bc--origin shifted (0,-epsilon) --cycle &
- bc--origin --cycle ) ;
-
- elseif type=75 :
- border := mirror (lly--lry--ury--uly--cycle) ;
- elseif type=76 :
- border := mirror (ll--lr--ur--uly--cycle) ;
- elseif type=77 :
- border := mirror (ll--lr--ury--ul--cycle) ;
- elseif type=78 :
- border := mirror (lly--lr--ur--ul--cycle) ;
- elseif type=79 :
- border := mirror (ll--lry--ur--ul--cycle) ;
-
- else :
- border := normal (origin--cycle) ;
- %border := normal (ll--lr--ur--ul--cycle) ;
- fi ;
-
- border
-
- endgroup
-
-enddef;
-
-def some_shape ( expr shape_type ,
- shape_width ,
- shape_height ,
- shape_linewidth ,
- shape_linecolor ,
- shape_fillcolor ) =
-
- path p ; p :=
- some_shape_path (shape_type)
- xscaled shape_width
- yscaled shape_height ;
-
- pickup pencircle scaled shape_linewidth ;
-
- fill p withcolor shape_fillcolor ;
- draw p withcolor shape_linecolor ;
-
-enddef ;
+ save p ; path p ;
+ p := some_shape_path (shape_type) xscaled shape_width yscaled shape_height ;
+ pickup pencircle scaled shape_linewidth ;
+ fill p withcolor shape_fillcolor ;
+ draw p withcolor shape_linecolor ;
+ endgroup ;
+enddef ;
vardef drawshape (expr t, p, lw, lc, fc) =
- save pp ;
- if t>1 : % normal shape
- path pp ;
- pp := some_shape_path(t) xyscaled(bbwidth(p), bbheight(p)) shifted center p ;
- fill pp withcolor fc ;
- draw pp withpen pencircle scaled lw withcolor lc ;
- elseif t=1 : % background only
- path pp ;
- pp := fullsquare xyscaled(bbwidth(p), bbheight(p)) shifted center p ;
- fill pp withcolor fc ;
- else : % dimensions only
- picture pp ; pp := nullpicture ;
- setbounds pp to fullsquare xyscaled(bbwidth(p), bbheight(p)) shifted center p ;
- draw pp ;
- fi ;
+ save pp ;
+ if t>1 : % normal shape
+ path pp ;
+ pp := some_shape_path(t) xyscaled(bbwidth(p), bbheight(p)) shifted center p ;
+ fill pp withcolor fc ;
+ draw pp withpen pencircle scaled lw withcolor lc ;
+ elseif t=1 : % background only
+ path pp ;
+ pp := fullsquare xyscaled(bbwidth(p), bbheight(p)) shifted center p ;
+ fill pp withcolor fc ;
+ else : % dimensions only
+ picture pp ; pp := nullpicture ;
+ setbounds pp to fullsquare xyscaled(bbwidth(p), bbheight(p)) shifted center p ;
+ draw pp ;
+ fi ;
enddef ;
vardef drawline (expr t, p, lw, lc) =
- if (t>0) and (length(p)>1) :
- saveoptions ;
- drawoptions(withpen pencircle scaled lw withcolor lc) ;
- draw p ;
- if t = 1 :
- draw arrowheadonpath(p,1) ;
- elseif t = 2 :
- draw arrowheadonpath(reverse p,1) ;
- elseif t = 3 :
- for $ = p,reverse p : draw arrowheadonpath($,1) ; endfor ;
- elseif t = 11 :
- draw arrowheadonpath(p,1/2) ;
- elseif t = 12 :
- draw arrowheadonpath(reverse p,1/2) ;
- elseif t = 13 :
- for $=p,reverse p : draw arrowheadonpath($,1) ; endfor ;
- for $=p,reverse p : draw arrowheadonpath($,3/4) ; endfor ;
- elseif t = 21 :
- for $=1/5,1/2,4/5 : draw arrowheadonpath(p,$) ; endfor ;
- elseif t = 22 :
- for $=1/5,1/2,4/5 : draw arrowheadonpath(reverse p,$) ; endfor ;
- elseif t = 23 :
- for $=p,reverse p : draw arrowheadonpath($,1/4) ; endfor ;
+ if (t>0) and (length(p)>1) :
+ saveoptions ;
+ drawoptions(withpen pencircle scaled lw withcolor lc) ;
+ draw p ;
+ if t = 1 :
+ draw arrowheadonpath(p,1) ;
+ elseif t = 2 :
+ draw arrowheadonpath(reverse p,1) ;
+ elseif t = 3 :
+ for $ = p,reverse p :
+ draw arrowheadonpath($,1) ;
+ endfor ;
+ elseif t = 11 :
+ draw arrowheadonpath(p,1/2) ;
+ elseif t = 12 :
+ draw arrowheadonpath(reverse p,1/2) ;
+ elseif t = 13 :
+ for $=p,reverse p :
+ draw arrowheadonpath($,1) ;
+ endfor ;
+ for $=p,reverse p :
+ draw arrowheadonpath($,3/4) ;
+ endfor ;
+ elseif t = 21 :
+ for $=1/5,1/2,4/5 :
+ draw arrowheadonpath(p,$) ;
+ endfor ;
+ elseif t = 22 :
+ for $=1/5,1/2,4/5 :
+ draw arrowheadonpath(reverse p,$) ;
+ endfor ;
+ elseif t = 23 :
+ for $=p,reverse p :
+ draw arrowheadonpath($,1/4) ;
+ endfor ;
+ fi ;
fi ;
- fi ;
enddef ;
-endinput ;
+endinput ;