Source PostScript (cpath.pps)

Retour Texte non formaté
%% %% version 1 %% %% syntaxe : path drawpath %% /drawpath { %% 1 dict begin %% dup isstring { %% /option exch def %% } { %% /option () def %% } ifelse %% pathpointstable option ligne %% end %% } def %% %% %% syntaxe : path ppathtopath --> path, transforme un chemin a %% %% coordonnees dans le repere postscript en un chemin a coordonnees dans %% %% le repere jps %% /ppathtopath { %% 1 dict begin %% /path exch def %% [ %% path cvx exec %% {ptojpoint} papply %% ] %% end %% } def %% %% %% syntaxe : path pathtopath --> path, transforme un chemin a %% %% coordonnees dans le repere jps en un chemin a coordonnees dans %% %% le repere postscript %% /pathtoppath { %% 1 dict begin %% /path exch def %% [ %% path cvx exec %% {jtoppoint} papply %% ] %% end %% } def %% %% %% t path pathelongueur -> longueur du chemin entre le point de %% %% parametre t et le point de parametre tn %% /pathelongueur { %% pathlongueurs exch pop %% } def %% %% %% syntaxe : path pathendpoint --> A, le dernier point du chemin %% /pathendpoint { %% 2 dict begin %% pathpointstable /table exch def %% /n table length 2 div 1 sub cvi def %% table 2 n mul get %% table 2 n mul 1 add get %% end %% } def %% %% %% syntaxe : path pathlongueur --> l %% /pathlongueur { %% pathpointstable longueur %% } def %% %% %% t path pathlongueurs -> l1 l2 %% /pathlongueurs { %% splitpath %% exch %% pathpointstable longueur %% exch %% pathpointstable longueur %% } def %% %% %% syntaxe : path pathparamtable --> array, tableau des parametres du chemin %% /pathparamtable { %% cvx exec %% pop %% } def %% %% %% syntaxe : t path pathpoint --> A, le point de parametre t du chemin %% /pathpoint { %% cvx exec %% interpolparamfunct %% } def %% %% %% syntaxe : path pathpointstable --> array, tableau des points du chemin %% /pathpointstable { %% cvx exec %% exch pop %% } def %% %% %% t path pathslongueur -> longueur du chemin entre le point de %% %% parametre t0 et le point de parametre t %% /pathslongueur { %% pathlongueurs pop %% } def %% %% %% syntaxe : path pathstartpoint --> A, le 1er point du chemin %% /pathstartpoint { %% pathpointstable dup 0 get exch 1 get %% } def %% %% %% syntaxe : lastpath --> path_object, l'objet path associe au dernier %% %% chemin dessine %% /lastpath { %% pathdict /the_lastpath get exec %% } def %% %% %% syntaxe : lastpath --> path_object, l'objet path associe au dernier %% %% chemin dessine %% /lastppath { %% pathdict /the_lastppath get exec %% } def %% %% /stockcurrentpath { %% pathdict /the_lastppath currentppathobj put %% pathdict /the_lastpath currentpathobj put %% } def %% %% %% syntaxe : currentpathobj --> path_object soit [array1 array2] %% %% parametrage du chemin courant ou array1 est un tableau des valeurs %% %% du parametre t (entre 0 et 100), et array 2 est un tableau des points %% %% (x, y) correspondants %% /currentpathobj { %% 3 dict begin %% currentpathpointstable %% /table exch def %% /n table length 2 div cvi def %% nb de points dans "table" %% [ %% [ %% /i 0 def %% n { %% i n 1 sub div 100 mul %% /i i 1 add def %% } repeat %% ] %% table %% ] %% end %% } def %% %% %% syntaxe : currentpathpointstable --> array, tableau de points definis %% %% par le chemin courant (ds le repere jps) %% /currentpathpointstable { %% currentppathpointstable {ptojpoint} papply %% } def %% %% %% syntaxe : currentppathobj --> path_object soit [array1 array2] %% %% parametrage du chemin courant ou array1 est un tableau des valeurs %% %% du parametre t (entre 0 et 100), et array 2 est un tableau des points %% %% (x, y) correspondants (dans le repere postscript) %% /currentppathobj { %% 3 dict begin %% currentppathpointstable %% /table exch def %% /n table length 2 div cvi def %% nb de points dans "table" %% [ %% [ %% /i 0 def %% n { %% i n 1 sub div 100 mul %% /i i 1 add def %% } repeat %% ] %% table %% ] %% end %% } def %% %% %% syntaxe : currentppathpointstable --> array, tableau de points definis %% %% par le chemin courant (ds le repere postscript) %% /currentppathpointstable { %% 1 dict begin %% gsave %% flattenpath %% [ %% {} {} {} {} pathforall %% % {mymoveto /mymoveto {} def} {} {} {} pathforall %% ] %% grestore %% end %% } def %% %% %mymoveto {pop pop} def %% %% syntaxe : path reversepathobj %% /reversepathobj { %% 2 dict begin %% /path exch def %% [ %% path cvx exec reversep %% ] %% end %% } def %% %% %% syntaxe : t path_object splitpath --> subpath1 subpath2 %% %% soit [array1' array2'] [array1" array2"] %% %% le chemin est defini a partir des tableaux array1 (parametre) et array2 %% %% (les points). dim array2 = 2 * dim array1, et array1 trie par ordre %% %% croissant. Attention, t est dans ]t0 ; tn[. depose sur la pile les %% %% 2 sous chemins. Le point de parametre t appartient a chacun des 2 %% %% sous chemins %% /splitpath { %% 10 dict begin %% cvx exec %% /table_xy exch def %% /table_t exch def %% /t exch def %% /n table_t length 1 sub def %% %% %% (interpolparamfunct) == %% %% (t) == t == %% %% (t0) == table_t 0 get == %% %% (tn) == table_t n get == %% %% %% t0 < t < tn %% /i 0 def %% /ti 0 def %% { %% /i i 1 add store %% /ti table_t i get store %% t ti le { %% %% ti-1 < t =< ti %% /xi table_xy 2 i mul get def %% /yi table_xy 2 i mul 1 add get def %% /xi-1 table_xy 2 i 1 sub mul get def %% /yi-1 table_xy 2 i 1 sub mul 1 add get def %% /ti-1 table_t i 1 sub get def %% xi xi-1 sub ti ti-1 sub div t ti-1 sub mul xi-1 add /x exch def %% yi yi-1 sub ti ti-1 sub div t ti-1 sub mul yi-1 add /y exch def %% %% %% (sortie) == %% %% (i) == i == %% %% (xi-1 -> ) == xi-1 == %% %% (xi -> ) == xi == %% %% (x -> ) == 1 index == %% %% (y -> ) == 0 index == %% %% exit %% } if %% } loop %% [ %% [table_t 0 i getinterval aload pop t] %% [table_xy 0 2 i mul getinterval aload pop x y] %% ] %% [ %% [t table_t i n 1 add i sub getinterval aload pop] %% [x y table_xy 2 i mul n 1 add i sub 2 mul getinterval aload pop] %% ] %% end %% } def %% %% %% syntaxe : pathobj1 normalizepath --> pathobj2, reaffecte le tableau %% %% des parametres, de telle facon que ceux-ci soient dans l'intervalle %% %% [0; 100], et qu'ils soient repartis de facon proportionnelle a la %% %% longueur du chemin %% /normalizepath { %% 4 dict begin %% /path1 exch def %% /tabpoints path1 pathpointstable def %% /tabparam path1 pathparamtable def %% /l path1 pathlongueur def %% [ %% tabparam {path1 pathslongueur 100 mul l div} apply %% tabpoints %% ] %% end %% } def %% %% syntaxe : path1 u translatepath --> path2, image de path1 par la %% %% translation de vecteur u %% /translatepath { %% 2 dict begin %% /u defpoint %% /path1 exch def %% [ %% path1 pathparamtable {} apply %% path1 pathpointstable {u translatepoint} papply %% ] %% end %% } def %% %% syntaxe : path1 projypath --> path2, projete orthogonal de path1 %% %% sur l'axe Oy %% /projypath { %% 1 dict begin %% /path1 exch def %% [ %% path1 pathparamtable {} apply %% path1 pathpointstable {projy} papply %% ] %% end %% } def %% %% syntaxe : path1 projxpath --> path2, projete orthogonal de path1 %% %% sur l'axe Ox %% /projxpath { %% 1 dict begin %% /path1 exch def %% [ %% path1 pathparamtable {} apply %% path1 pathpointstable {projx} papply %% ] %% end %% } def %% %% syntaxe : path1 D orthoprojpath --> path2, projete orthogonal de path1 %% %% sur la droite D %% /orthoprojpath { %% 2 dict begin %% /D defdroite %% /path1 exch def %% [ %% path1 pathparamtable {} apply %% path1 pathpointstable {D orthoproj} papply %% ] %% end %% } def %% %% syntaxe : path1 I alpha rotatepath --> path2, image de path1 par la %% %% rotation de centre I et d'angle alpha %% /rotatepath { %% 3 dict begin %% /alpha exch def %% /I defpoint %% /path1 exch def %% [ %% path1 pathparamtable {} apply %% path1 pathpointstable {I alpha rotatepoint} papply %% ] %% end %% } def %% %% syntaxe : path1 I alpha rotatepath --> path2, image de path1 par %% %% l'homothetie de centre I et de rapport alpha %% /hompath { %% 3 dict begin %% /alpha exch def %% /I defpoint %% /path1 exch def %% [ %% path1 pathparamtable {} apply %% path1 pathpointstable {I alpha hompoint} papply %% ] %% end %% } def %% %% syntaxe : path1 I sympath --> path2, symétrique de path1 %% %% par rapport au point I %% /sympath { %% 2 dict begin %% /I defpoint %% /path1 exch def %% [ %% path1 pathparamtable {} apply %% path1 pathpointstable {I sympoint} papply %% ] %% end %% } def %% %% syntaxe : path1 I sym path --> path2, symétrique de path1 %% %% par rapport a la droite D %% /axesympath { %% 2 dict begin %% /D defsroite %% /path1 exch def %% [ %% path1 pathparamtable {} apply %% path1 pathpointstable {D axesympoint} papply %% ] %% end %% } def %% %% %% version 2 %% syntaxe : array1 uniqp --> array2 /uniqp { 3 dict begin /table exch def /n table length 2 idiv 1 sub def table 0 getp /old defpoint [ old 1 1 n { /i exch def table i getp /new defpoint old new eqp { } { new new /old defpoint } ifelse } for ] end } def %% syntaxe : path drawcpath /drawcpath { 1 dict begin dup isstring { /option exch def } { /option () def } ifelse cpathpointstable option ligne end } def %% syntaxe : cpath cppathtocpath --> cpath, transforme un chemin a %% coordonnees dans le repere postscript en un chemin a coordonnees dans %% le repere jps /cppathtocpath { 1 dict begin /cpath exch def [ cpath cvx exec {ptojpoint} papply ] end } def %% syntaxe : cpath cpathtocpath --> cpath, transforme un chemin a %% coordonnees dans le repere jps en un chemin a coordonnees dans %% le repere postscript /cpathtocppath { 1 dict begin /cpath exch def [ cpath cvx exec {jtoppoint} papply ] end } def %% t cpath cpathelongueur -> longueur du chemin entre le point de %% parametre t et le point de parametre tn /cpathelongueur { cpathlongueurs exch pop } def %% syntaxe : cpath cpathendpoint --> A, le dernier point du chemin /cpathendpoint { 2 dict begin cpathpointstable /table exch def /n table length 2 div 1 sub cvi def table 2 n mul get table 2 n mul 1 add get end } def %% syntaxe : cpath cpathlongueur --> l /cpathlongueur { cpathpointstable longueur } def %% t cpath cpathlongueurs -> l1 l2 /cpathlongueurs { splitcpath exch cpathpointstable longueur exch cpathpointstable longueur } def %% syntaxe : cpath cpathparamtable --> array, tableau des parametres du chemin /cpathparamtable { cvx exec pop } def %% syntaxe : t cpath cpathpoint --> A, le point de parametre t du chemin /cpathpoint { cvx exec interpolparamfunct } def %% syntaxe : cpath cpathpointstable --> array, tableau des points du chemin /cpathpointstable { cvx exec exch pop } def %% t cpath cpathslongueur -> longueur du chemin entre le point de %% parametre t0 et le point de parametre t /cpathslongueur { cpathlongueurs pop } def %% syntaxe : cpath cpathstartpoint --> A, le 1er point du chemin /cpathstartpoint { cpathpointstable dup 0 get exch 1 get } def %% syntaxe : lastcpath --> cpath_object, l'objet cpath associe au dernier %% chemin dessine /lastcpath { pathdict /the_lastcpath get exec } def %% syntaxe : lastcpath --> cpath_object, l'objet cpath associe au dernier %% chemin dessine /lastcppath { pathdict /the_lastcppath get exec } def /stockcurrentcpath { pathdict /the_lastcppath currentcppathobj put pathdict /the_lastcpath currentcpathobj put } def %% syntaxe : currentcpathobj --> cpath_object soit [array1 array2] %% parametrage du chemin courant ou array1 est un tableau des valeurs %% du parametre t (entre 0 et 100), et array 2 est un tableau des points %% (x, y) correspondants /currentcpathobj { 3 dict begin currentcpathpointstable /table exch def /n table length 2 div cvi def %% nb de points dans "table" [ [ /i 0 def n { i n 1 sub div 100 mul /i i 1 add def } repeat ] table ] end } def %% syntaxe : currentcpathpointstable --> array, tableau de points definis %% par le chemin courant (ds le repere jps) /currentcpathpointstable { currentcppathpointstable {ptojpoint} papply } def %% syntaxe : currentcppathobj --> cpath_object soit [array1 array2] %% parametrage du chemin courant ou array1 est un tableau des valeurs %% du parametre t (entre 0 et 100), et array 2 est un tableau des points %% (x, y) correspondants (dans le repere postscript) /currentcppathobj { 3 dict begin currentcppathpointstable /table exch def /n table length 2 div cvi def %% nb de points dans "table" [ [ /i 0 def n { i n 1 sub div 100 mul /i i 1 add def } repeat ] table ] end } def %% syntaxe : currentcppathpointstable --> array, tableau de points definis %% par le chemin courant (ds le repere postscript) /currentcppathpointstable { 1 dict begin gsave flattenpath [ {} {} {} {} pathforall % {mymoveto /mymoveto {} def} {} {} {} pathforall ] % uniqp grestore end } def %mymoveto {pop pop} def %% syntaxe : cpath reversecpathobj /reversecpathobj { 2 dict begin /cpath exch def [ cpath cvx exec reversep ] end } def %% syntaxe : t cpath_object splitcpath --> subcpath1 subcpath2 %% soit [array1' array2'] [array1" array2"] %% le chemin est defini a partir des tableaux array1 (parametre) et array2 %% (les points). dim array2 = 2 * dim array1, et array1 trie par ordre %% croissant. Attention, t est dans ]t0 ; tn[. depose sur la pile les %% 2 sous chemins. Le point de parametre t appartient a chacun des 2 %% sous chemins /splitcpath { 10 dict begin cvx exec /table_xy exch def /table_t exch def /t exch def /n table_t length 1 sub def %% (interpolparamfunct) == %% (t) == t == %% (t0) == table_t 0 get == %% (tn) == table_t n get == %% t0 < t < tn /i 0 def /ti 0 def { /i i 1 add store /ti table_t i get store t ti le { %% ti-1 < t =< ti /xi table_xy 2 i mul get def /yi table_xy 2 i mul 1 add get def /xi-1 table_xy 2 i 1 sub mul get def /yi-1 table_xy 2 i 1 sub mul 1 add get def /ti-1 table_t i 1 sub get def xi xi-1 sub ti ti-1 sub div t ti-1 sub mul xi-1 add /x exch def yi yi-1 sub ti ti-1 sub div t ti-1 sub mul yi-1 add /y exch def %% (sortie) == %% (i) == i == %% (xi-1 -> ) == xi-1 == %% (xi -> ) == xi == %% (x -> ) == 1 index == %% (y -> ) == 0 index == exit } if } loop [ [table_t 0 i getinterval aload pop t] [table_xy 0 2 i mul getinterval aload pop x y] ] [ [t table_t i n 1 add i sub getinterval aload pop] [x y table_xy 2 i mul n 1 add i sub 2 mul getinterval aload pop] ] end } def %% syntaxe : cpathobj1 normalizecpath --> cpathobj2, reaffecte le tableau %% des parametres, de telle facon que ceux-ci soient dans l'intervalle %% [0; 100], et qu'ils soient repartis de facon proportionnelle a la %% longueur du chemin /normalizecpath { 4 dict begin /cpath1 exch def /tabpoints cpath1 cpathpointstable def /tabparam cpath1 cpathparamtable def /l cpath1 cpathlongueur def [ tabparam {cpath1 cpathslongueur 100 mul l div} apply tabpoints ] end } def %% syntaxe : cpath1 u translatecpath --> cpath2, image de cpath1 par la %% translation de vecteur u /translatecpath { 2 dict begin /u defpoint /cpath1 exch def [ cpath1 cpathparamtable {} apply cpath1 cpathpointstable {u translatepoint} papply ] end } def %% syntaxe : cpath1 projycpath --> cpath2, projete orthogonal de cpath1 %% sur l'axe Oy /projycpath { 1 dict begin /cpath1 exch def [ cpath1 cpathparamtable {} apply cpath1 cpathpointstable {projy} papply ] end } def %% syntaxe : cpath1 projxcpath --> cpath2, projete orthogonal de cpath1 %% sur l'axe Ox /projxcpath { 1 dict begin /cpath1 exch def [ cpath1 cpathparamtable {} apply cpath1 cpathpointstable {projx} papply ] end } def %% syntaxe : cpath1 D orthoprojcpath --> cpath2, projete orthogonal de cpath1 %% sur la droite D /orthoprojcpath { 2 dict begin /D defdroite /cpath1 exch def [ cpath1 cpathparamtable {} apply cpath1 cpathpointstable {D orthoproj} papply ] end } def %% syntaxe : cpath1 I alpha rotatecpath --> cpath2, image de cpath1 par la %% rotation de centre I et d'angle alpha /rotatecpath { 3 dict begin /alpha exch def /I defpoint /cpath1 exch def [ cpath1 cpathparamtable {} apply cpath1 cpathpointstable {I alpha rotatepoint} papply ] end } def %% syntaxe : cpath1 I alpha rotatecpath --> cpath2, image de cpath1 par %% l'homothetie de centre I et de rapport alpha /homcpath { 3 dict begin /alpha exch def /I defpoint /cpath1 exch def [ cpath1 cpathparamtable {} apply cpath1 cpathpointstable {I alpha hompoint} papply ] end } def %% syntaxe : cpath1 I symcpath --> cpath2, symétrique de cpath1 %% par rapport au point I /symcpath { 2 dict begin /I defpoint /cpath1 exch def [ cpath1 cpathparamtable {} apply cpath1 cpathpointstable {I sympoint} papply ] end } def %% syntaxe : cpath1 I sym cpath --> cpath2, symétrique de cpath1 %% par rapport a la droite D /axesymcpath { 2 dict begin /D defsroite /cpath1 exch def [ cpath1 cpathparamtable {} apply cpath1 cpathpointstable {D axesympoint} papply ] end } def