From a81b00b60192cde6eceb35cca61ea7f3e08898a5 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Mon, 13 Sep 2010 23:54:13 +0000 Subject: automata update (13sep10) git-svn-id: svn://tug.org/texlive/trunk@19717 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/metapost/automata/automata.mp | 157 ++++++++++++++++++------ 1 file changed, 122 insertions(+), 35 deletions(-) (limited to 'Master/texmf-dist/metapost') diff --git a/Master/texmf-dist/metapost/automata/automata.mp b/Master/texmf-dist/metapost/automata/automata.mp index 35ed9e6ae73..f3e1e24c4e6 100644 --- a/Master/texmf-dist/metapost/automata/automata.mp +++ b/Master/texmf-dist/metapost/automata/automata.mp @@ -1,5 +1,4 @@ % PACKAGE FOR METAPOST TO DRAW FINITE STATE MACHINES, GRAPHS, TREES, ETC. -% Version 0.2 % Author: gabriele puppis % declares a grid of equally-spaced nodes @@ -104,8 +103,8 @@ enddef; % % syntax: movepos.(x,y); % -% example: movepos.a(100,100); -% movepos.b[0][0](100,100); +% example: movepos.a(10,10); +% movepos.b[0][0](10,10); vardef movepos@# expr p = @#.c := @#.c shifted p; @#.h := @#.h shifted p; @@ -121,13 +120,13 @@ enddef; % parameters: size = 7 | ... % nodemargin = 1.5 | ... % shape = circle | utriangle | ltriangle | btriangle | rtriangle | -% box | fixedbox | rbox | rfixedbox | none +% boxed | fixedbox | roundbox | roundfixedbox | diamond | none % boxmargin = 5 | ... -% fixedboxwidth = 7 | ... -% fixedboxheight = 7 | ... +% fixedboxwidth = 14 | ... +% fixedboxheight = 14 | ... % border = solid | bold | dash | double | none % bordercolor = black | white | ... -% filling = none | solid | left | right +% filling = none | solid | lefthalf | righthalf % fillingcolor = black | white | ... % nodelabel = yes | no % nodelabelcolor = black | white | ... @@ -171,7 +170,7 @@ vardef node@#(expr l) = @#.h := @#.c shifted (0.5xpart(@#.s),0); fs := (size,size); fm := 4solidsize; - elseif (shape=box): + elseif (shape=boxed): @#.s := urcorner pic - llcorner pic + (boxmargin,boxmargin); @#.f := squarepath; @#.h := @#.c; @@ -183,18 +182,24 @@ vardef node@#(expr l) = @#.h := @#.c; fs := @#.s; fm := 0; - elseif (shape=rbox): + elseif (shape=roundbox): @#.s := urcorner pic - llcorner pic; @#.f := rrectangle(xpart(@#.s),ypart(@#.s)); @#.h := @#.c; fs := @#.s; fm := 0; - elseif (shape=rfixedbox): + elseif (shape=roundfixedbox): @#.s := (fixedboxwidth,fixedboxheight); @#.f := rrectangle(xpart(@#.s),ypart(@#.s)); @#.h := @#.c; fs := @#.s; fm := 0; + elseif (shape=diamond): + @#.s := (size,size); + @#.f := diamondpath; + @#.h := @#.c; + fs := (size,size); + fm := 0; elseif (shape=none): @#.s := (0,0); @#.f := (0,0)..(0,0); @@ -216,7 +221,7 @@ vardef node@#(expr l) = fill @#.f xscaled xpart(fs) yscaled ypart(fs) shifted @#.c withcolor fillingcolor; fi - elseif (filling=left): + elseif (filling=lefthalf): if (border=double): fill buildcycle(@#.f,(0,-1)--(0,1)) xscaled (xpart(fs)-2doublesize) yscaled (ypart(fs)-2doublesize) @@ -226,7 +231,7 @@ vardef node@#(expr l) = xscaled xpart(fs) yscaled ypart(fs) shifted @#.c withcolor fillingcolor; fi - elseif (filling=right): + elseif (filling=righthalf): if (border=double): fill buildcycle(@#.f,(0,-1)--(0,1)) rotated 180 xscaled (xpart(fs)-2doublesize) yscaled (ypart(fs)-2doublesize) @@ -282,10 +287,11 @@ enddef; % % example: arrow.top(0.5, btex $a$ etex)(a[0][0],a[0][1]) a[0][0].c{dir90}..a[0][1].c; % -% parameters: style = solid | bold | dash | bolddash +% parameters: style = solid | bold | dash | bolddash | invisible % arrowcolor = black | white | ... % arrowlabel = yes | no % unfillonarrowlabel = yes | no +% unfillcolor = white | black | ... % arrowlabelcolor = black | white | ... % tipangle = 25 | ...; % tipsharpness = 10 | ...; @@ -335,6 +341,7 @@ vardef arrow@#(expr o,l)(suffix a,b) expr p = elseif (style=bolddash): draw cutp withpen pencircle scaled boldsize dashed evenly scaled dashsize withcolor arrowcolor; draw tip withpen pencircle scaled boldsize withcolor arrowcolor; + elseif (style=invisible): else: errmessage("Arrow style not defined"); fi @@ -344,7 +351,7 @@ vardef arrow@#(expr o,l)(suffix a,b) expr p = picture lab; lab := thelabel.@#(l, point o*length(cutp) of cutp); if (unfillonarrowlabel=yes): - unfill (bbox lab); + fill (bbox lab) withcolor unfillcolor; fi draw lab withcolor arrowlabelcolor; %label.@#(l, point o*length(cutp) of cutp) withcolor arrowlabelcolor; @@ -363,8 +370,8 @@ enddef; % example: loop.top(0.5, btex $a$ etex)(a[0][0]) 90; % % parameters: loopsize = 15 | ... -% looporientation = counterclockwise | clockwise -% style = solid | bold | dash | bolddash +% looporientation = counterclockwiseorientation | clockwiseorientation +% style = solid | bold | dash | bolddash | invisible % arrowcolor = black | white | ... % arrowlabel = yes | no % tipangle = 25 | ...; @@ -376,9 +383,9 @@ enddef; vardef loop@#(expr o,l)(suffix a) expr d = save p; path p; - if (looporientation=clockwise): + if (looporientation=clockwiseorientation): p := (-0.5*loopsize,0)..(0,0.5*loopsize)..(0.5*loopsize,0)..(0,-0.5*loopsize)..cycle; - elseif (looporientation=counterclockwise): + elseif (looporientation=counterclockwiseorientation): p := (-0.5*loopsize,0)..(0,-0.5*loopsize)..(0.5*loopsize,0)..(0,0.5*loopsize)..cycle; else: errmessage("Loop orientation not defined"); @@ -445,44 +452,82 @@ vardef outgoing@#(expr o,l)(suffix a) expr d = enddef; +% this function can be used to enclose a sequence of points inside a bounding area +% +% syntax: enclose ; +% where is a closed path, whose points are listed in clockwise order +% +% example: enclose a[0][0].c--a[0][1].c--a[1][1].c--cycle; +% +% parameters: style = solid | bold | dash | bolddash +% enclosurecolor = black | white | ... +% enclosuremargin = 5 | ... +% solidsize = 0.9 | ... +% boldsize = 1.5 | ... +% dashsize = 0.75 | ... +vardef enclose expr p = + if (style=solid): + draw enclosure(p) withpen pencircle scaled solidsize withcolor enclosurecolor; + elseif (style=bold): + draw enclosure(p) withpen pencircle scaled boldsize withcolor enclosurecolor; + elseif (style=dash): + draw enclosure(p) withpen pencircle scaled solidsize dashed evenly scaled dashsize withcolor enclosurecolor; + elseif (style=bolddash): + draw enclosure(p) withpen pencircle scaled boldsize dashed evenly scaled dashsize withcolor enclosurecolor; + else: + errmessage("Arrow style not defined"); + fi +enddef; + + % shorthand macros def node_circle = with shape(circle) node enddef; def node_utriangle = with shape(utriangle) node enddef; def node_ltriangle = with shape(ltriangle) node enddef; def node_dtriangle = with shape(dtriangle) node enddef; def node_rtriangle = with shape(rtriangle) node enddef; +def node_diamond = with shape(diamond) node enddef; def node_unfilled = with filling(none) node enddef; def node_filled = with filling(solid) node enddef; -def node_filledleft = with filling(left) node enddef; -def node_filledright = with filling(right) node enddef; +def node_filledleft = with filling(lefthalf) node enddef; +def node_filledright = with filling(righthalf) node enddef; def node_solid = with border(solid) node enddef; def node_bold = with border(bold) node enddef; def node_dash = with border(dash) node enddef; def node_double = with border(double) node enddef; def node_hidden = with border(none) node enddef; -def node_box = with shape(box) node enddef; +def node_boxed = with shape(boxed) node enddef; def node_fixed = with shape(fixedbox) node enddef; -def node_rbox = with shape(rbox) node enddef; -def node_rfixed = with shape(rfixedbox) node enddef; +def node_roundbox = with shape(roundbox) node enddef; +def node_roundfixed = with shape(roundfixedbox) node enddef; def node_marker = with shape(none) node enddef; def arrow_solid = with style(solid) arrow enddef; def arrow_bold = with style(bold) arrow enddef; def arrow_dash = with style(dash) arrow enddef; def arrow_bolddash = with style(bolddash) arrow enddef; +def arrow_invisible = with style(invisible) arrow enddef; def loop_solid = with style(solid) loop enddef; def loop_bold = with style(bold) loop enddef; def loop_dash = with style(dash) loop enddef; def loop_bolddash = with style(bolddash) loop enddef; -def loop_cw = with looporientation(clockwise) loop enddef; -def loop_ccw = with looporientation(counterclockwise) loop enddef; +def loop_invisible = with style(invisible) loop enddef; +def loop_cw = with looporientation(clockwiseorientation) loop enddef; +def loop_ccw = with looporientation(counterclockwiseorientation) loop enddef; def incoming_solid = with style(solid) incoming enddef; def incoming_bold = with style(bold) incoming enddef; def incoming_dash = with style(dash) incoming enddef; def incoming_bolddash = with style(bolddash) incoming enddef; +def incoming_invisible = with style(invisible) incoming enddef; def outgoing_solid = with style(solid) outgoing enddef; def outgoing_bold = with style(bold) outgoing enddef; def outgoing_dash = with style(dash) outgoing enddef; def outgoing_bolddash = with style(bolddash) outgoing enddef; +def outgoing_invisible = with style(invisible) outgoing enddef; +def enclose_solid = with style(solid) enclose enddef; +def enclose_bold = with style(bold) enclose enddef; +def enclose_dash = with style(dash) enclose enddef; +def enclose_bolddash = with style(bolddash) enclose enddef; +def enclose_thin = with style(dash) dashsize(0.5) enclose enddef; % e.g. with fillingcolor(black) node ... vardef with@#(expr v) text e = push.@#; @# := v; e; pop.@# enddef; % e.g. light.gray, light.light.gray, ... @@ -502,9 +547,34 @@ def ltrianglepath = (trianglepath rotated 90) enddef; def btrianglepath = (trianglepath rotated 180) enddef; def rtrianglepath = (trianglepath rotated 270) enddef; def squarepath = ((0.5,-0.5)--(-0.5,-0.5)--(-0.5,0.5)--(0.5,0.5)--cycle) enddef; +def diamondpath = ((0.5,0)--(0,0.5)--(-0.5,0)--(0,-0.5)--cycle) enddef; +def urdiamondpath = ((0,0.5)--(0.5,0)--(0,0)--cycle) enddef; +def uldiamondpath = ((-0.5,0)--(0,0.5)--(0,0)--cycle) enddef; +def lrdiamondpath = ((0.5,0)--(0,-0.5)--(0,0)--cycle) enddef; +def lldiamondpath = ((0,0)--(0,-0.5)--(-0.5,0)--cycle) enddef; vardef rrectangle(expr w,h) = (((0.5w-0.25h,-0.5h)---(-0.5w+0.25h,-0.5h).. (-0.5w+0.25h,0.5h)---(0.5w-0.25h,0.5h)..cycle) xscaled (1/w) yscaled (1/h)) enddef; +vardef sqr(expr x) = ((x)*(x)) enddef; +vardef firstenclosurepoint(expr p,q) = ((ypart(p)-ypart(q)) * sqrt(sqr(enclosuremargin) / (sqr(xpart(p)-xpart(q)) + sqr(ypart(p)-ypart(q)))) + xpart(p), + (xpart(q)-xpart(p)) * sqrt(sqr(enclosuremargin) / (sqr(xpart(p)-xpart(q)) + sqr(ypart(p)-ypart(q)))) + ypart(p)) enddef; +vardef secondenclosurepoint(expr p,q) = ((ypart(p)-ypart(q)) * sqrt(sqr(enclosuremargin) / (sqr(xpart(p)-xpart(q)) + sqr(ypart(p)-ypart(q)))) + xpart(q), + (xpart(q)-xpart(p)) * sqrt(sqr(enclosuremargin) / (sqr(xpart(p)-xpart(q)) + sqr(ypart(p)-ypart(q)))) + ypart(q)) enddef; vardef enclosuresegment(expr p,q) = firstenclosurepoint(p,q)---secondenclosurepoint(p,q) enddef; +vardef enclosure(expr p) = + save enc; + save i; + path enc; + if (pair p): + enc := circlepath scaled (2*enclosuremargin) shifted point 1 of p; + else: + enc := enclosuresegment(point 0 of p, point 1 of p); + for i=1 upto length(p)-1: + enc := enc..enclosuresegment(point i of p, point i+1 of p); + endfor; + enc := enc..cycle; + fi + enc +enddef; % general appearence constants and variables @@ -516,19 +586,21 @@ def utriangle = 11 enddef; def ltriangle = 12 enddef; def btriangle = 13 enddef; def rtriangle = 14 enddef; -def box = 15 enddef; +def boxed = 15 enddef; def fixedbox = 16 enddef; -def rbox = 17 enddef; -def rfixedbox = 18 enddef; +def roundbox = 17 enddef; +def roundfixedbox = 18 enddef; +def diamond = 19 enddef; def solid = 20 enddef; -def left = 21 enddef; -def right = 22 enddef; +def lefthalf = 21 enddef; +def righthalf = 22 enddef; def bold = 30 enddef; def dash = 31 enddef; def bolddash = 32 enddef; def double = 33 enddef; -def clockwise = 40 enddef; -def counterclockwise = 41 enddef; +def invisible = 34 enddef; +def clockwiseorientation = 40 enddef; +def counterclockwiseorientation = 41 enddef; pair spacing; pair offset; @@ -557,11 +629,14 @@ numeric dashsize; numeric doublesize; numeric nodemargin; numeric arrowmargin; +numeric enclosuremargin; color bordercolor; color fillingcolor; color nodelabelcolor; color arrowcolor; color arrowlabelcolor; +color unfillcolor; +color enclosurecolor; spacing = (60,30); offset = (0,0); @@ -569,19 +644,20 @@ numbering = (0,0); size := 5; shape := circle; boxmargin := 5; -fixedboxwidth := 7; -fixedboxheight := 7; +fixedboxwidth := 14; +fixedboxheight := 14; border := solid; filling := none; style := solid; nodelabel := yes; arrowlabel := yes; unfillonarrowlabel := no; +unfillcolor := white; tipangle := 20; tipsharpness := 15; tipsize := 4; loopsize := 14; -looporientation := counterclockwise; +looporientation := counterclockwiseorientation; incominglength := 20; outgoinglength := 20; solidsize := 0.7; @@ -590,11 +666,13 @@ dashsize := 0.7; doublesize := 1.3; nodemargin := 1.5; arrowmargin := 3.8; +enclosuremargin := 5; bordercolor = black; fillingcolor = black; nodelabelcolor = black; arrowcolor = black; arrowlabelcolor = black; +enclosurecolor = gray; linecap := butt; linejoin := mitered; @@ -627,11 +705,14 @@ numeric dashsize.back[]; numeric doublesize.back[]; numeric nodemargin.back[]; numeric arrowmargin.back[]; +numeric enclosuremargin.back[]; color bordercolor.back[]; color fillingcolor.back[]; color nodelabelcolor.back[]; color arrowcolor.back[]; color arrowlabelcolor.back[]; +color unfillcolor.back[]; +color enclosurecolor.back[]; numeric spacing.count; numeric offset.count; @@ -647,6 +728,7 @@ numeric style.count; numeric nodelabel.count; numeric arrowlabel.count; numeric unfillonarrowlabel.count; +numeric unfillcolor.count; numeric tipangle.count; numeric tipsharpness.count; numeric tipsize.count; @@ -660,11 +742,13 @@ numeric dashsize.count; numeric doublesize.count; numeric nodemargin.count; numeric arrowmargin.count; +numeric enclosuremargin.count; numeric bordercolor.count; numeric fillingcolor.count; numeric nodelabelcolor.count; numeric arrowcolor.count; numeric arrowlabelcolor.count; +numeric enclosurecolor.count; spacing.count := 0; offset.count := 0; @@ -680,6 +764,7 @@ style.count := 0; nodelabel.count := 0; arrowlabel.count := 0; unfillonarrowlabel.count := 0; +unfillcolor.count := 0; tipangle.count := 0; tipsharpness.count := 0; tipsize.count := 0; @@ -693,8 +778,10 @@ dashsize.count := 0; doublesize.count := 0; nodemargin.count := 0; arrowmargin.count := 0; +enclosuremargin.count := 0; bordercolor.count := 0; fillingcolor.count := 0; nodelabelcolor.count := 0; arrowcolor.count := 0; arrowlabelcolor.count := 0; +enclosurecolor.count := 0; -- cgit v1.2.3