1. rlineto
Appends a straight line segment to the current path using relative coordinates.
1.2. Stack Effects
| Level | Object |
|---|---|
1 |
|
0 |
|
| Level | Object |
|---|---|
(empty) |
Stack cleared of operands |
1.3. Description
rlineto (relative lineto) appends a straight line segment to the current path in the same manner as lineto. However, the number pair is interpreted as a displacement relative to the current point (x, y) rather than as an absolute coordinate. That is, rlineto constructs a line from (x, y) to (x + dx, y + dy) and makes (x + dx, y + dy) the new current point.
If the current point is undefined because the current path is empty, rlineto executes the [nocurrentpoint] error.
1.5. Examples
newpath
100 100 moveto
100 0 rlineto % Right side
0 100 rlineto % Top side
-100 0 rlineto % Left side
closepath % Bottom side
stroke
newpath
50 50 moveto
5 {
20 0 rlineto % Step tread
0 20 rlineto % Step riser
} repeat
stroke
newpath
50 200 moveto
10 {
20 30 rlineto
20 -30 rlineto
} repeat
stroke
1.6. Common Use Cases
1.6.1. Drawing Regular Shapes
/drawPentagon {
% Draws regular pentagon at current point
/size exch def
/angle 72 def
gsave
5 {
size 0 rlineto
angle rotate
} repeat
closepath
grestore
} def
100 100 moveto
50 drawPentagon
1.7. Common Pitfalls
newpath
10 10 rlineto % Error: nocurrentpoint
| Displacements Not Absolute - The arguments are relative displacements (dx, dy). Negative values move in opposite directions. |
100 100 moveto
50 0 rlineto % Moves to (150, 100)
-25 0 rlineto % Moves to (125, 100), not (-25, 100)
Ideal for Regular Patterns - rlineto excels at creating regular, repeating patterns where each segment relates to the previous one.
|
1.8. Error Conditions
| Error | Condition |
|---|---|
[ |
Path becomes too complex for implementation |
[ |
Current path is empty (no current point defined) |
[ |
Fewer than 2 operands on stack |
[ |
Operands are not numbers |
1.9. Implementation Notes
-
Displacements are in user space, transformed by CTM
-
More convenient than calculating absolute coordinates
-
Equivalent to:
currentpoint transform dx dy add transform lineto -
Successive
rlinetocalls build polylines efficiently -
Negative displacements move backward or downward
1.10. Performance Considerations
-
No performance difference from
lineto -
Reduces calculation overhead in code
-
More maintainable for relative patterns
-
Can reduce rounding errors in repetitive patterns
1.11. See Also
-
lineto- Absolute lineto -
rmoveto- Relative moveto -
rcurveto- Relative curveto -
currentpoint- Get current point -
closepath- Close current subpath