Auto-Closing Paths
Background
Paths in SVG are closed with the 'z' or 'Z' closepath commands.
This works OK for paths consisting of straight lines but is problematic
for paths which begin and end with curved lines:
But using the closepath command is problematic for
paths which begin and end with curved lines:
The particular example above results in a zero length path
segment. In the more general case, rounding errors can lead
to the closepath segment having a small non-zero
length. This can effect how many markers are drawn and how
they are aligned.
Note that at the
Tokyo
F2F meeting we resolved that on a closed path, the marker
orientation at the beginning/ending of the path is derived
from the end of the last path and the start of the first path.
We also resolved that zero length path segments are ignored in
determining marker orientation.
There appears to be a descrepancy between how the browsers render
the middle marker when a path is closed. Firefox uses
the direction of the path before the 'z' segment, Chrome uses
the direction of the path at the start of the path.
Possible Solutions
New commands
It has been pointed out that the 'z' command is essentially an
'l' command where the point is starting point of the path
segment. We could extend this concept by adding new path
commands with one less point than normal. The missing point
would be the first point in the path segment:
- 'z_a': arc
- 'z_c': bezier curve
- etc.
First point token
Use a non-numerical parameter to indicate the first point in the
path segement should be used:
- 'a 50,50 0 0 1 #'
- 'c 100,100 200,200 #'
- etc.
First point 'z' token
Use a 'z' to "replace" a missing point:
- 'a 50,50 0 0 1 z'
- 'c 100,100 200,200 z'
- etc.
Bonus topic
What should be drawn at the start/end of a closed path?
Proposal: to match shapes, a mid-marker should be drawn by
default. If either a start-marker or end-marker is specified,
it overrides the mid-marker.