%! %find bounding box of polygon %find a bounding box of polygon %arguments: array of points %return: array of [Xmin Ymin Xmax Ymax] /FindBounding { 10 dict begin %store whole array /A exch store %number of point /NPoint A length 2 idiv store %first point /Xmin A 0 get store /Xmax Xmin store /Ymin A 1 get store /Ymax Ymin store 1 1 NPoint 1 sub { /Index exch 2 mul store /X A Index get store /Y A Index 1 add get store Xmin X gt {/Xmin X store} if Xmax X lt {/Xmax X store} if Ymin Y gt {/Ymin Y store} if Ymax Y lt {/Ymax Y store} if } for /Return [Xmin Ymin Xmax Ymax] store Return end } def %draw a polygon %arguments: array of points /Polygon { 10 dict begin %store whole array /A exch store %number of point /NPoint A length 2 idiv store %first point A 0 get A 1 get moveto 1 1 NPoint 1 sub { /Index exch 2 mul store A Index get % x A Index 1 add get %y lineto } for closepath stroke end } def %draw a square. %arg: [xmin ymin xmax ymax] /Square { newpath dup dup 0 get exch 1 get moveto dup dup 2 get exch 1 get lineto dup dup 2 get exch 3 get lineto dup dup 0 get exch 3 get lineto dup dup 0 get exch 1 get lineto closepath stroke } def /Points [2 3 40 50 10 100 220 20 20 60 60 10] store Points Polygon Points FindBounding Square showpage