[Problem] \psgrid with griddots produce wrong results for xunit not equal to yunit

Denis Girou Denis.Girou at idris.fr
Fri Nov 7 22:03:27 CET 1997


-----------------------------------------------------------------------------
This is the PSTricks mailing list, devoted to discussions about computational
graphics in (La)TeX using the PSTricks package from Timothy van Zandt.
For help using this mailing list, see instructions at the end of message.
-----------------------------------------------------------------------------

  There is a typo in pstricks.pro which made \psgrid with griddots to produce
wrong results for xunit not equal to yunit. This bug was introduced in 1994 in
the pstricks.bug file of 0.93 version.

  The patch is trivial (replacing dy by dx).

  P.S. * Take care that I see that there is another problem related to this
example, at least in my installation, with gv (3.5.8) and ghostview (1.5)
which display incorrectly this file. But it's correct with gs (5.03) and on
my printer.

       * Unfortunately, I have always two difficult problems alive (including
the one on fancybox, on which my last adaptation on LaTeX 2e revealed some
pitfall...) and I would prefer to clean all the state before testing all the
up to date distribution on the examples of LGC and transferring all the last
updates on CTAN. 


  Here is my test file:

\documentclass{article}

\usepackage{pstricks}

\pagestyle{empty}

\begin{document}

\begin{pspicture}(6,6)
  \psgrid[xunit=2,griddots=1,gridlabels=0,gridwidth=3mm,subgriddiv=0](2,3)
\end{pspicture}
\begin{pspicture}(6,6)
  \psgrid[yunit=2,griddots=2,gridlabels=0,gridwidth=3mm,
          subgriddiv=4,subgriddots=1,subgridwidth=1mm](3,2)
\end{pspicture}

\makeatletter
\pst at def{Grid}<%
  newpath
  /a 4 string def            % Empty string
  /b ED                      % Label size
  /c ED                      % Label color procedure.
  /n ED                      % Number of grid dots
  cvi dup 1 lt { pop 1 } if /s ED   % Number subdivisions
% Stack: x-unit y-unit
  s div dup 0 eq { pop 1 } if /dy ED  % y-distance between lines.
  s div dup 0 eq { pop 1 } if /dx ED  % x-distance between lines.
% These two are integer multiples of dx and dy:
  dy div round dy mul /y0 ED     % y-origin.
  dx div round dx mul /x0 ED     % x-origin.
% These four are integers, measuring dx and dy units:
  dy div round cvi /y2 ED     % y2
  dx div round cvi /x2 ED     % x2
  dy div round cvi /y1 ED     % y1
  dx div round cvi /x1 ED     % x1
  /h y2 y1 sub 0 gt { 1 } { -1 } ifelse def  % Sign of y2-y1
  /w x2 x1 sub 0 gt { 1 } { -1 } ifelse def  % Sign of x2-x1
% Set up the font and a few parameters for making labels:
  b 0 gt
  { /z1 b 4 div CLW 2 div add def
    /Helvetica findfont b scalefont setfont
    /b b .95 mul CLW 2 div add def }
  if
% If Level 2, use automatic stroke adjustment. Otherwise, do by hand:
  systemdict /setstrokeadjust known  % Level 2
  { true setstrokeadjust /t { } def }
  { /t {
      transform
      0.25 sub round 0.25 add exch
      0.25 sub round 0.25 add exch
      itransform
    } bind def }
  ifelse
% Now make the vertical lines:
  gsave
% Make dotted line, if appropriate
    n 0 gt
    { 1 setlinecap [ 0 dy n div ] dy n div 2 div setdash }
    { 2 setlinecap }
    ifelse
% Initialize index:
    /i x1 def
% Find y-values of endpoints. Adjust these if lines are dotted because
% otherwise rounding errors or stroke adjustment can cause first or
% last dot to be dropped. (Only GhostScript has exhibited problem of
% dropping first dot. This is probably a bug.)
    /f y1 dy mul n 0 gt { dy n div 2 div h mul sub } if def
    /g y2 dy mul n 0 gt { dy n div 2 div h mul add } if def
% Number of lines (Max 1000):
    x2 x1 sub w mul 1 add dup 1000 gt { pop 1000 } if
    {
% Make label:
      i dx mul dup y0 moveto
      b 0 gt
      { gsave
          c                       % Color
          i a cvs dup             % Index, as a string
          stringwidth pop /z2 ED  % Stringwidth
          w 0 gt {z1} {z1 z2 add neg} ifelse
          h 0 gt {b neg} {z1} ifelse
          rmoveto
          show
        grestore
      } if
% Make line ( on stack: i dx mul ):
      dup t f moveto g t L stroke
% Advance index:
      /i i w add def
    } repeat
  grestore
% Now make horizontal lines:
  gsave
    n 0 gt
% DG/SR modification begin - Nov. 7, 1997
%    { 1 setlinecap [ 0 dx n div ] dy n div 2 div setdash }
    { 1 setlinecap [ 0 dx n div ] dx n div 2 div setdash }
% DG/SR modification end
    { 2 setlinecap }
    ifelse
    /i y1 def
    /f x1 dx mul n 0 gt { dx n div 2 div w mul sub } if def
    /g x2 dx mul n 0 gt { dx n div 2 div w mul add } if def
    y2 y1 sub h mul 1 add dup 1000 gt { pop 1000 } if
    { newpath
      i dy mul dup x0 exch moveto
      b 0 gt
      { gsave
          c
          i a cvs dup
          stringwidth pop /z2 ED
          w 0 gt {z1 z2 add neg} {z1} ifelse
          h 0 gt {z1} {b neg} ifelse
          rmoveto
          show
        grestore
      } if
      dup f exch t moveto g exch t L stroke
      /i i h add def
    } repeat
  grestore>
\makeatother

\begin{pspicture}(6,6)
  \psgrid[xunit=2,griddots=1,gridlabels=0,gridwidth=3mm,subgriddiv=0](2,3)
\end{pspicture}
\begin{pspicture}(6,6)
  \psgrid[yunit=2,griddots=2,gridlabels=0,gridwidth=3mm,
          subgriddiv=4,subgriddots=1,subgridwidth=1mm](3,2)
\end{pspicture}

\end{document}

D.G.

-----------------------------------------------------------------------------
The list interface (subscription, information, access to the archives) is on:
http://tug.cs.umb.edu/cgi-bin/lwgate/pstricks
Otherway to unsubscribe, send mail to pstricks-request at tug.cs.umb.edu
with a blank subject and in body the line unsubscribe <email-address>
-----------------------------------------------------------------------------



More information about the PSTricks mailing list