summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/profcollege/latex/PfCGeometrie.tex
blob: ad7e495f044e0a0800856e081ed2c3750a7e7052 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
%%%
% Geometrie
%%%
\setKVdefault[Geometrie]{CoinBG={(0,0)},CoinHD={(10u,10u)},TypeTrace="Instruments",Clip,Cadres=false,Epaisseur=1,Pointilles=false,Ombre=false,Couleur=black,Ecart=2,ModeleCouleur=5}%
\defKV[Geometrie]{Cadre=\setKV[Geometrie]{Cadres}\setKV[Geometrie]{Clip=false}}%

\ifluatex%
\NewDocumentEnvironment{Geometrie}{o +b}{%
  \useKVdefault[Geometrie]%
  \setKV[Geometrie]{#1}%
  \mplibforcehmode%
  \begin{mplibcode}
    defaultcolormodel := \useKV[Geometrie]{ModeleCouleur};
    
     vardef rounded_corners expr p =
     for i=1 upto length p:
     subpath (i-15/16, i-1/16) of p ..
     endfor cycle
     enddef;
    %
    boolean Clip,Cadres,Pointilles,Ombre;
    Clip=\useKV[Geometrie]{Clip};
    Cadres=\useKV[Geometrie]{Cadres};
    Pointilles=\useKV[Geometrie]{Pointilles};
    Ombre=\useKV[Geometrie]{Ombre};
    Epaisseur=\useKV[Geometrie]{Epaisseur};
    bboxmargin:=\useKV[Geometrie]{Ecart};
    color CouleurCadre;
    CouleurCadre=\useKV[Geometrie]{Couleur};
    pair Coinbg,Coinhd;
    if Clip:
    Coinbg=\useKV[Geometrie]{CoinBG};
    Coinhd=\useKV[Geometrie]{CoinHD};
    else:
    Coinbg=(-1000,-1000);
    Coinhd=(1000,1000);
    fi;
    if \useKV[Geometrie]{TypeTrace}="Instruments":
    typetrace:="normal";
    elseif \useKV[Geometrie]{TypeTrace}="MainLevee":
    typetrace:="mainlevee";
    elseif \useKV[Geometrie]{TypeTrace}="Espace":
    typetrace:="3D";
    typerepre:="persp";
    fi;
    xa:=xpart(Coinbg);
    xb:=xpart(Coinhd);
    ya:=ypart(Coinbg);
    yb:=ypart(Coinhd);
    feuille(xa,ya,xb,yb);
    _tfig:=if (xb-xa)>(yb-ya): (xb-xa) else: (yb-ya) fi;
    _tfig:=2*_tfig;
    #2%
    %%
    if Cadres:
    string Cadre;
    Cadre=\useKV[Geometrie]{Cadre};

    picture P; P = currentpicture;

    if Cadre<>"aucun":
    if Cadre="rectangle":
      if Ombre:
        fill bbox P shifted (3,-3) withcolor 3/4[CouleurCadre,white];
        unfill bbox P;
      fi;
      if Pointilles:
        drawoptions(dashed evenly withpen pencircle scaled Epaisseur withcolor CouleurCadre;);
      else:
        drawoptions(withpen pencircle scaled Epaisseur withcolor CouleurCadre;);
      fi;
      draw bbox P;
      drawoptions();
      draw P;
    else:
      if Ombre:
        fill rounded_corners bbox P shifted (3,-3) withcolor 3/4[CouleurCadre,white];
        unfill rounded_corners bbox P;
      fi;
      if Pointilles:
        drawoptions(dashed evenly withpen pencircle scaled Epaisseur withcolor CouleurCadre;);
      else:
        drawoptions(withpen pencircle scaled Epaisseur withcolor CouleurCadre;);
      fi;
      draw rounded_corners bbox P;
      drawoptions();
      draw P;
      fi;
      fi;
      fi;
  \end{mplibcode}
}{}%
\else
\NewDocumentEnvironment{Geometrie}{o +b}{%
  \useKVdefault[Geometrie]%
  \setKV[Geometrie]{#1}%
  \begin{mpost}[mpsettings={%
      vardef rounded_corners expr p =
     for i=1 upto length p:
     subpath (i-15/16, i-1/16) of p ..
     endfor cycle
     enddef;
    %
    boolean Clip,Cadres,Pointilles,Ombre;
    Clip=\useKV[Geometrie]{Clip};
    Cadres=\useKV[Geometrie]{Cadres};
    Pointilles=\useKV[Geometrie]{Pointilles};
    Ombre=\useKV[Geometrie]{Ombre};
    Epaisseur=\useKV[Geometrie]{Epaisseur};
    bboxmargin:=\useKV[Geometrie]{Ecart};
    color CouleurCadre;
    CouleurCadre=\useKV[Geometrie]{Couleur};
      pair Coinbg,Coinhd;
      Coinbg=\useKV[Geometrie]{CoinBG};
      Coinhd=\useKV[Geometrie]{CoinHD};
      if \useKV[Geometrie]{TypeTrace}="Instruments":
      typetrace:="normal";
      elseif \useKV[Geometrie]{TypeTrace}="MainLevee":
      typetrace:="mainlevee";
      elseif \useKV[Geometrie]{TypeTrace}="Espace":
      typetrace:="3D";
      typerepre:="persp";
      fi;}
    ]%
    xa:=xpart(Coinbg);
    xb:=xpart(Coinhd);;
    ya:=ypart(Coinbg);
    yb:=ypart(Coinhd);
    feuille(xa,ya,xb,yb);
    _tfig:=if (xb-xa)>(yb-ya): (xb-xa) else: (yb-ya) fi;
    _tfig:=2*_tfig;
    #2%
        %%
    if Cadres:
    string Cadre;
    Cadre=\useKV[Geometrie]{Cadre};

    picture P; P = currentpicture;

    if Cadre<>"aucun":
    if Cadre="rectangle":
      if Ombre:
        fill bbox P shifted (3,-3) withcolor 3/4[CouleurCadre,white];
        unfill bbox P;
      fi;
      if Pointilles:
        drawoptions(dashed evenly withpen pencircle scaled Epaisseur withcolor CouleurCadre;);
      else:
        drawoptions(withpen pencircle scaled Epaisseur withcolor CouleurCadre;);
      fi;
      draw bbox P;
      drawoptions();
      draw P;
    else:
      if Ombre:
        fill rounded_corners bbox P shifted (3,-3) withcolor 3/4[CouleurCadre,white];
        unfill rounded_corners bbox P;
      fi;
      if Pointilles:
        drawoptions(dashed evenly withpen pencircle scaled Epaisseur withcolor CouleurCadre;);
      else:
        drawoptions(withpen pencircle scaled Epaisseur withcolor CouleurCadre;);
      fi;
      draw rounded_corners bbox P;
      drawoptions();
      draw P;
      fi;
      fi;
      fi;
  \end{mpost}
}{}%
\fi%