[%  PROCESS ps/mm   UNLESS global.ps.loaded.mm;
    PROCESS ps/clip UNLESS global.ps.loaded.clip;
    global.ps.loaded.tiles = 1;
-%]
% determines number of page tiles required for path on stack
/tiles {
    gsave
    pathbbox 
    /tiles-try exch def 
    /tiles-trx exch def 
    /tiles-bly exch def 
    /tiles-blx exch def
    /tiles-ysize tiles-try tiles-bly sub abs def
    /tiles-xsize tiles-trx tiles-blx sub abs def
    grestore

    % calculate number of tiles required in X and Y
    /tiles-nx { tiles-xsize clip-xsize div ceiling } def
    /tiles-ny { tiles-ysize clip-ysize div ceiling } def

    % determine X/Y offset required to centre path in tiles
    /tiles-xorg tiles-nx clip-xsize mul 
                tiles-xsize sub 2 div 
                border add 
    def
    /tiles-yorg tiles-ny clip-ysize mul 
                tiles-ysize sub 2 div 
                border add 
    def
[%#
  #  do we need to add border to tiles-orgx/y? 
-%]
} def
