Debian Codegraph @

texmf-dist/metapost/mp-geom2d/geom2d-rep.mp

raw
1 picture repSavePict;
2 string repSaveW;
3
4 % x and y labels
5 string gddXlabel;
6 gddXlabel := "$x$";
7 string gddYlabel;
8 gddYlabel := "$y$";
9
10 def Repere(expr l,h,ox,oy,ux,uy) =
11 repLargeur := l; repHauteur := h;
12 repOX := ox ; repOY := oy;
13 repXmin := - ox / ux; repXmax := repXmin + l / ux;
14 repYmin := - oy / uy; repYmax := repYmin + h / uy;
15 repUX := ux; repUY := uy;
16 repSaveW := gddW;
17 gddW := "xscaled repUX yscaled repUY shifted (repOX,repOY) scaled gddU";
18 enddef;
19
20 let Frame = Repere;
21
22 def RepereMinMax(expr xmin,xmax,ymin,ymax,ux,uy) =
23 repLargeur := (xmax-xmin)*ux; repHauteur := (ymax-ymin)*uy;
24 repOX := -xmin*ux ; repOY := -ymin*uy;
25 repXmin := xmin; repXmax := xmax;
26 repYmin := ymin; repYmax := ymax;
27 repUX := ux; repUY := uy;
28 repSaveW := gddW;
29 gddW := "xscaled repUX yscaled repUY shifted (repOX,repOY) scaled gddU";
30 enddef;
31
32 let FrameMinMax = RepereMinMax;
33
34 def Debut =
35 repSavePict := currentpicture; currentpicture := nullpicture;
36 enddef;
37
38 let gddBegin = Debut;
39
40 def repClip =
41 clip currentpicture to (%
42 ((0,0)--(repLargeur,0)--(repLargeur,repHauteur)--(0,repHauteur)--cycle)
43 scaled gddU);
44 enddef;
45
46 let frameClip = repClip;
47
48 def repStroke (expr c) =
49 draw ((0,0)--(repLargeur,0)--(repLargeur,repHauteur)--(0,repHauteur)--cycle)
50 scaled gddU withcolor c;
51 enddef;
52
53 let frameStroke = repStroke;
54
55 def Fin =
56 repClip;
57 addto repSavePict also currentpicture; currentpicture := repSavePict;
58 gddW := repSaveW;
59 enddef;
60
61 let gddEnd = Fin;
62
63 def Axes =
64 drawarrow ((repXmin,0)--(repXmax,0)) gddEnPlace;
65 drawarrow ((0,repYmin)--(0,repYmax)) gddEnPlace;
66 label.lrt(textext(gddXlabel),(repXmax,0) gddEnPlace);
67 label.ulft(textext(gddYlabel),(0,repYmax) gddEnPlace);
68 enddef;
69
70 let Axis = Axes;
71
72 def AxesBords =
73 drawarrow ((repXmin,repYmin)--(repXmax,repYmin)) gddEnPlace;
74 drawarrow ((repXmin,repYmin)--(repXmin,repYmax)) gddEnPlace;
75 label.lrt(textext(gddXlabel),(repXmax,repYmin) gddEnPlace);
76 label.ulft(textext(gddYlabel),(repXmin,repYmax) gddEnPlace);
77 enddef;
78
79 let SideAxis = AxesBords;
80
81
82 vardef Graduations =
83 save xmin, xmax, ymin, ymax;
84 xmin = round(repXmin); xmax = round(repXmax) ;
85 ymin = round(repYmin); ymax = round(repYmax) ;
86 SequenceTirets((xmin,0),(1,0),(0,-4),xmax-xmin);
87 SequenceTirets((xmin+0.5,0),(1,0),(0,-2),xmax-xmin);
88 SequenceTirets((0,ymin),(0,1),(-4,0),ymax-ymin+1);
89 SequenceTirets((0,ymin+0.5),(0,1),(-2,0),ymax-ymin);
90 enddef;
91
92
93 vardef GraduationsBords =
94 save xmin, xmax, ymin, ymax;
95 xmin = round(repXmin); xmax = round(repXmax) ;
96 ymin = round(repYmin); ymax = round(repYmax) ;
97 SequenceTirets((xmin,repYmin),(1,0),(0,+4),xmax-xmin);
98 SequenceTirets((xmin+0.5,repYmin),(1,0),(0,+2),xmax-xmin);
99 SequenceTirets((repXmin,ymin),(0,1),(+4,0),ymax-ymin);
100 SequenceTirets((repXmin,ymin+0.5),(0,1),(+2,0),ymax-ymin);
101 enddef;
102
103 vardef SideGraduations = GraduationsBords enddef;
104
105 def ClipRepere =
106 extra_endfig := extra_endfig & "repClip;";
107 enddef;
108
109 let FrameClip = ClipRepere;
110
111 %
112 % SequenceTirets
113 % ------------------------------------------------------------------------------
114 vardef SequenceTirets(expr o,p,t,n) text a=
115 save ot; pair ot; ot := o gddEnPlace;
116 for i:=1 upto n:
117 % tiret
118 draw ot -- (ot shifted t) a;
119 % avancement
120 ot := (o + i*p) gddEnPlace;
121 endfor
122 enddef;
123
124 let DashedSequence = SequenceTirets;
125
126 vardef Unites(expr t) =
127 label.bot(textext("$+"&decimal(t)&"$"),(t,-(3/gddU/repUY)) gddEnPlace);
128 label.lft(textext("$+"&decimal(t)&"$"),(-(3/gddU/repUX),t) gddEnPlace);
129 enddef;
130
131 vardef Units(expr t) = Unites(t) enddef;
132
133 %vardef ValeursGraduations =
134 % label.bot(textext("$+"&decimal(t)&"$"),(t,-(3/gddU/repUY)) gddEnPlace);
135 % label.lft(textext("$+"&decimal(t)&"$"),(-(3/gddU/repUX),t) gddEnPlace);
136 %enddef;
137 %%% ----------------------------------------------------------------------------
138 %%% Grille
139 %%% ----------------------------------------------------------------------------
140
141 def GrilleRepere =
142 save xmin, xmax, ymin, ymax;
143 xmin = floor(repXmin); xmax = floor(repXmax) ;
144 ymin = floor(repYmin); ymax = floor(repYmax) ;
145 for i:=xmin upto xmax:
146 draw ((i,ymin)--(i,ymax)) gddEnPlace;
147 endfor;
148 for i:=ymin upto ymax:
149 draw ((xmin,i)--(xmax,i)) gddEnPlace;
150 endfor;
151 enddef;
152
153 let FrameGrid = GrilleRepere;
154
155 %%% ----------------------------------------------------------------------------
156 %%% CadreRepere
157 %%% ----------------------------------------------------------------------------
158 def CadreRepere =
159 (repXmin,repYmin)--(repXmin,repYmax)--(repXmax,repYmax)--(repXmax,repYmin)--cycle
160 enddef;
161
162 let FrameBox = CadreRepere;
163
164 endinput