1. newpath
Initializes the current path to empty, making the current point undefined.
1.2. Stack Effects
| Level | Object |
|---|---|
(empty) |
No operands required |
| Level | Object |
|---|---|
(empty) |
No results |
1.3. Description
newpath initializes the current path to be empty, causing the current point to become undefined.
This operator is typically used at the beginning of a path construction sequence to ensure that no leftover path segments from previous operations interfere with the new path being constructed.
1.5. Examples
newpath
100 100 moveto
200 200 lineto
stroke
% First path
newpath
100 100 moveto
200 100 lineto
stroke
% Second path (independent)
newpath
100 200 moveto
200 200 lineto
stroke
newpath
100 100 moveto
200 200 lineto
% Decide not to use this path
newpath % Discard it
% Start fresh
150 150 moveto
250 250 lineto
stroke
1.6. Common Use Cases
1.6.1. Starting Every Drawing Operation
/drawCircle {
% x y radius
/r exch def
/y exch def
/x exch def
newpath
x y r 0 360 arc
closepath
fill
} def
100 100 50 drawCircle
200 200 75 drawCircle
1.7. Common Pitfalls
newpath
200 200 lineto % Error: nocurrentpoint
Painting Operators Don’t Clear Path - Unlike painting operators in some graphics systems, PostScript’s stroke and fill do not automatically clear the path. Use newpath explicitly.
|
newpath
100 100 moveto
200 200 lineto
stroke
% Path still exists!
fill % Fills the same path again
% Better practice:
newpath
100 100 moveto
200 200 lineto
stroke
newpath % Explicitly clear
Use at Start of Path Procedures - Always begin path construction procedures with newpath to ensure a clean slate.
|
1.8. Error Conditions
None. newpath cannot generate errors.
1.9. Implementation Notes
-
Clears all subpaths from the current path
-
Makes the current point undefined
-
Does not affect the graphics state otherwise
-
Very lightweight operation
-
Does not consume or produce any stack values
-
Idempotent: calling
newpathmultiple times has same effect as calling once
1.10. Interaction with Graphics State
newpath only affects the current path. It does not change:
-
Current transformation matrix (CTM)
-
Current color
-
Line width or dash pattern
-
Clipping path
-
Current font
-
Any other graphics state parameters
1.11. Best Practices
1.11.1. Always Start with newpath
% Good practice
/drawShape {
newpath
% ... path construction ...
stroke
} def
1.12. Performance Considerations
-
Extremely fast operation
-
No memory allocation involved
-
No computational overhead
-
Should be used liberally for code clarity
-
Does not affect rendering performance
1.13. See Also
-
moveto- Set current point -
closepath- Close current subpath -
currentpoint- Get current point