updated graph lib and created other files

This commit is contained in:
Yann Esposito 2012-11-16 16:18:27 +01:00
parent 8e92c7a6fc
commit 6a764a9562
9 changed files with 96 additions and 19 deletions

View file

@ -0,0 +1,27 @@
pair a,b;
a:=origin;
b:=a shifted (gu,0);
drawState(a,"a");
drawState(b,"b");
drawEdge(a,b,"f");
pair fa,fb;
fa=a shifted (0,-.6gu);
fb=b shifted (0,-.6gu);
drawbox(fa,"F");
drawState(fa,"a");
drawbox(fb,"F");
drawState(fb,"b");
drawEdge(fa,fb,"\mathtt{fmap} f");
pair mf,mff;
path ab,fafb;
ab :=edge(a,b);
fafb:=edge(fa,fb);
mf := midpoint(ab);
mff := midpoint(fafb);
path arr;
arr = subpath (0,.5) of mf -- mff;
drawarrow arr withpen pencircle scaled 1 withcolor yellow;

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View file

@ -6,15 +6,9 @@ z2=z0 shifted (2gu,0);
z3=z1 shifted (2gu,0);
z4=(0.5gu,-.5gu);
z5=(1.5gu,-.5gu);
z5=(1.5gu,0);
z6=(2.5gu,-.5gu);
drawState(z0, "A");
drawState(z1, "B");
drawState(z2, "B");
drawState(z3, "C");
drawState(z4, "A");
drawState(z5, "B");
@ -22,14 +16,12 @@ drawState(z6, "C");
drawoptions(withcolor red);
drawEdge(z0,z1, "f");
drawEdge(z4,z5, "f");
drawEdgeAngle(z4,z5, "f",30);
drawoptions(withcolor blue);
drawEdge(z2,z3, "g");
drawEdge(z5,z6, "g");
drawEdgeAngle(z5,z6, "g",30);
drawoptions(withcolor yellow);
drawEdgeAngle(z4,z6, "g\circ f", -30);
drawEdgeAngle(z4,z6, "g\circ f", 0);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View file

@ -53,6 +53,7 @@ ix := midpoint( lx );
iy := midpoint( ly );
nodesize:= .5u;
nodespace:= .5u;
drawoptions(withcolor blue dashed evenly withpen pencircle scaled 1);
drawarrow edgeAngle(ia,ix,35);
@ -77,11 +78,10 @@ mh := midpoint(h);
mi := midpoint(i);
mk := midpoint(k);
nodesize:= .5u;
drawoptions(withcolor blue dashed evenly withpen pencircle scaled 1);
drawarrow edgeAngle(mf,ix,35);
drawarrow edgeAngle(mf,ix,40);
drawarrow edgeAngle(mg,ix,-15);
drawoptions(withcolor magenta dashed evenly withpen pencircle scaled 1);
drawarrow edgeAngle(mi,mk,15);
drawarrow edgeAngle(mi,mk,30);
drawarrow edgeAngle(mh,mk,15);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 86 KiB

After

Width:  |  Height:  |  Size: 48 KiB

View file

@ -37,13 +37,14 @@ enddef;
% return the middle of a path
vardef midpoint(expr p)=
pair r;
save r; pair r;
r:=point 1/2length(p) of p;
r
enddef;
% shorten a path of length d at the beginning and the end
vardef shorten(expr p,d) =
save q,bcirc,ecirc;
path q,bcirc,ecirc;
bcirc := fullcircle scaled d shifted point 0 of p;
ecirc := fullcircle scaled d shifted point length(p) of p;
@ -53,6 +54,10 @@ enddef;
% Return a rounded box around top left and bottom right point.
vardef block(expr tl,br) =
save p;
save d,shift;
save topleft,bottomright;
save tll,tlt,trt,trr,brr,brb,blb,bll;
path p;
numeric d,shift;
d := 1/3u;
@ -75,12 +80,15 @@ enddef;
% b being the path of the block
vardef blockLabelPosition(expr b)=
save pos;
pair pos;
pos := point 0.5 of b;
pos
enddef;
% draw a block with the right math-mode tex label on top of it
def drawblock(expr topleftpoint, bottomrightpoint, l)=
save b,pos;
path b;
b:=block(topleftpoint,bottomrightpoint);
pair pos;
@ -96,8 +104,8 @@ enddef;
% in angle to B is outan
% nodesize is the size of the node
vardef edgeFull(expr posA,posB,inan,outan) =
path sub;
path s;
save sub,s;
path sub,s;
s := posA {dir inan} .. {dir outan} posB ;
sub := shorten(s,nodespace);
sub
@ -105,6 +113,7 @@ enddef;
% return a picture of the label l for edge e
vardef edgeLabel(expr e,l) =
save ret,mid,an,lab,height,width;
picture ret;
pair mid;
mid := midpoint(e);
@ -135,7 +144,9 @@ enddef;
% return the edge between points A and B.
% out angle from A is an + angle from A to B
vardef edgeAngle(expr posA,posB,an) =
save res,d;
path res;
numeric d;
d := angle(posB-posA);
res := edgeFull(posA,posB,d+an,d-an);
res
@ -147,6 +158,7 @@ enddef;
%% %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
vardef dist(expr a,b)=
save width,height,res;
numeric width,height,res;
width:=xpart b - xpart a;
height:=ypart b - ypart a;
@ -154,6 +166,8 @@ vardef dist(expr a,b)=
enddef;
% return a loop
vardef loopFull(expr a,b,an) =
save ba,ea;
save circ,p,s;
pair ba,ea;
path circ,p,s;
p:=a{1,1}..b..{1,-1}cycle;
@ -178,6 +192,8 @@ enddef;
% return the direct edge between A and B
vardef edge(expr posA,posB) =
save an;
save sub;
numeric an;
path sub;
if (posA = posB):
@ -190,16 +206,22 @@ vardef edge(expr posA,posB) =
enddef;
def drawLoopPoint(expr a,b,l) =
begingroup;
save s;
path s;
s:=loopPoint(a,b);
drawarrow s;
label.top(TEX("$"&l&"$"),midpoint(s));
endgroup;
enddef;
def drawLoop(expr a,l) =
begingroup;
save s;
path s;
s:=loop(a);
drawarrow s;
label.top(TEX("$"&l&"$"),midpoint(s));
endgroup;
enddef;
def drawstate(expr pos) =
@ -208,6 +230,10 @@ enddef;
% draw some state with some label insize
def drawState(expr pos,l) =
begingroup;
save lab,reslab;
save height,width;
save size;
% Draw the circle
draw fullcircle scaled nodesize shifted pos;
@ -227,28 +253,59 @@ def drawState(expr pos,l) =
% help for debug to draw boundaries
% draw ulcorner reslab -- urcorner reslab -- lrcorner reslab -- llcorner reslab -- cycle;
draw reslab;
endgroup;
enddef;
% draw an edge
def drawEdgeFull(expr posA,posB,l,inan,outan) =
begingroup;
save sub;
path sub;
sub := edgeFull(posA,posB,inan,outan);
drawarrow sub;
draw edgeLabel(sub,l);
endgroup;
enddef;
def drawEdgeAngle(expr posA,posB,l,inan) =
begingroup;
save sub;
path sub;
sub := edgeAngle(posA,posB,inan);
drawarrow sub;
draw edgeLabel(sub,l);
endgroup;
enddef;
def drawEdge(expr posA,posB,l) =
begingroup;
save sub;
path sub;
sub := edge(posA,posB);
drawarrow sub;
draw edgeLabel(sub,l);
endgroup;
enddef;
vardef box(expr posA) =
save b,size;
path b;
numeric size;
size:=2nodesize;
b := unitsquare scaled size shifted posA shifted (-.5size,-.5size);
b
enddef;
def drawbox(expr posA,l) =
begingroup;
save b,pos;
path b;
pair pos;
b:=box(posA);
draw b;
pos=point 3 of b;
label.lrt(TEX("$"&l&"$"),pos);
endgroup;
enddef;
prologues:=3;

View file

@ -1,7 +1,8 @@
pair A,B,C,D,E,F;
A:=(0,0); B:=(0,u); C:=(0,2u);
D:=(0,3u); E:=(0,4u); F:=(0,6u);
nodesize:=4bp;
nodespace:=6bp;
drawLoopPoint(A,B,"''");
drawLoopPoint(A,C,"a");
drawLoopPoint(A,D,"b");

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 17 KiB