PostScript :: CAD Operator - SQUARE
Operator :: X Y L SQUARE
Define :
/SQUARE { 2 index 2 index moveto % X Y rmoveto 0 index 2 div 0 rmoveto % L/2 0 rmoveto 0 index 2 div 0 exch rmoveto % 0 L/2 rmoveto 0 index neg 0 rlineto % -L 0 rlineto 0 index neg 0 exch rlineto % 0 -L rlineto 0 index 0 rlineto % +L 0 rlineto 0 index 0 exch rlineto % 0 +L rlineto clear } def
Detail :
X Y L SQUARE STACK 3 2 1 0 X Y L 2 index X Y L X 2 index 2 index X Y L X Y 2 index 2 index moveto X Y L -> X Y moveto 0 index X Y L L 0 index 2 div X Y L L/2 0 index 2 div 0 X Y L L/2 0 0 index 2 div 0 rmoveto X Y L -> L/2 0 rmoveto 0 index 2 div 0 X Y L L/2 0 0 index 2 div 0 exch X Y L 0 L/2 0 index 2 div 0 exch rmoveto X Y L -> 0 L/2 rmoveto .. 0 index neg 0 rlineto X Y L -> -L 0 rlineto .. 0 index neg 0 exch rlineto X Y L -> 0 -L rlineto .. 0 index 0 rlineto X Y L -> L 0 rlineto .. 0 index 0 exch rlineto X Y L -> 0 L rlineto clear
Example : CAD Operator - SQUARE
%! /inch {72 mul} def /cm {inch 2.54 div } def /mm {cm 10 div } def /SQUARE { 2 index 2 index moveto 0 index 2 div 0 rmoveto 0 index 2 div 0 exch rmoveto 0 index neg 0 rlineto 0 index neg 0 exch rlineto 0 index 0 rlineto 0 index 0 exch rlineto clear } def /HCenterLine { 0 0 moveto -80 mm 10 mm 80 mm { 0 moveto -5 mm 0 rmoveto +1 mm 0 rlineto +1 mm 0 rmoveto +6 mm 0 rlineto } for 0 0 moveto } def /VCenterLine { 0 0 moveto -80 mm 10 mm 80 mm { 0 exch moveto 0 -5 mm rmoveto 0 +1 mm rlineto 0 +1 mm rmoveto 0 +6 mm rlineto } for 0 0 moveto } def /MainView { 0 mm 0 mm 10 mm SQUARE 10 mm 10 mm 40 mm SQUARE } def newpath 320 600 translate 0 0 moveto HCenterLine VCenterLine MainView stroke showpage