TransWikia.com

PGF equivalent of PostScript relative movement (`rlineto` and `rmoveto`)

TeX - LaTeX Asked on July 1, 2021

Like PostScript (with its rmoveto and rlineto), TikZ makes it trivial to produce relative movement of the current point. I’m not seeing anything equivalent in PGF. Is it missing? If so, is it easy to say why? (And what is the intended replacement in PFG?) Even if relative movement is not low-level enough for the system layer (hard to believe?), it seems low level enough for the base layer.

Edit (Related Queries): Is pgfrelative deprecated (it’s not in the current manual)? And, what PGF command produces the current point?

One Answer

In the following example, two new macros pgfpathrlineto{<coord>} and pgfpathrmoveto{<coord>} are provided. They are not fully tested, so be careful.

Actually, we need to keep track of the original (un-transformed) coordinates of last point, but here pgf@x and pgf@y store transformed coordinates.

The point is, in (x, y) -- ++(2, 3), the expected line before transforming is (x, y) -- (x+2, y+3), while what I implemented in the following example is (x, y) -- ($ (x, y) + T'(2, 3) $), where T' is the inversion of transformation.

documentclass{article}
usepackage{pgf}

makeatletter
defpgf@path@last@point{%
  pgfpoint{pgf@path@lastx}{pgf@path@lasty}}

% rlineto
defpgfpathrlineto#1{%
  pgf@process{#1}%
  globaladvancepgf@xpgf@path@lastx
  globaladvancepgf@ypgf@path@lasty
  % similar to pgfpathlineto, but without applying transformation
  pgf@nlt@lineto{pgf@x}{pgf@y}%
  globalpgf@path@lastx=pgf@x
  globalpgf@path@lasty=pgf@y
}

% rmoveto
defpgfpathrmoveto#1{%
  pgf@process{#1}%
  globaladvancepgf@xpgf@path@lastx
  globaladvancepgf@ypgf@path@lasty
  % similar to pgfpathlineto, but without applying transformation
  pgf@nlt@moveto{pgf@x}{pgf@y}%
  globalpgf@path@lastx=pgf@x
  globalpgf@path@lasty=pgf@y
}
makeatother

begin{document}
begin{pgfpicture}
  pgfpathmoveto{pgfpointorigin}
  pgfpathlineto{pgfpoint{20pt}{0pt}}
  pgfpathmoveto{pgfpoint{40pt}{0pt}}
  pgfpathlineto{pgfpoint{60pt}{0pt}}
  pgfusepath{draw}
  
  pgftransformshift{pgfpoint{10pt}{10pt}}
  pgfsetcolor{red}
  pgfpathmoveto{pgfpointorigin}
  pgfpathlineto{pgfpoint{20pt}{0pt}}
  pgfpathmoveto{pgfpoint{40pt}{0pt}}
  pgfpathlineto{pgfpoint{60pt}{0pt}}
  pgfusepath{draw}
end{pgfpicture}
qquad
% use r(line|move)to
begin{pgfpicture}
  pgfpathmoveto{pgfpointorigin}
  pgfpathrlineto{pgfpoint{20pt}{0pt}}
  pgfpathrmoveto{pgfpoint{20pt}{0pt}}
  pgfpathrlineto{pgfpoint{20pt}{0pt}}
  pgfusepath{draw}
  
  pgftransformshift{pgfpoint{10pt}{10pt}}
  pgfsetcolor{red}
  pgfpathmoveto{pgfpointorigin}
  pgfpathrlineto{pgfpoint{20pt}{0pt}}
  pgfpathrmoveto{pgfpoint{20pt}{0pt}}
  pgfpathrlineto{pgfpoint{20pt}{0pt}}
  pgfusepath{draw}
end{pgfpicture}
end{document}

enter image description here

Answered by muzimuzhi Z on July 1, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP