Skip to main content

Module dash

Module dash 

Source
Expand description

Cutting a path into the pieces a dash pattern leaves behind.

§Why this is a path transform rather than a stroke option

A dashed stroke is a stroke of a different path. Cutting first and stroking the pieces gives every dash its own caps and gives the joins that survive the cut the same treatment they would have had, which is what a reader expects and what SVG and PostScript specify. The alternative — teaching the stroker to skip — would have to decide what a join means when one of its two segments is not drawn, and there is no answer to that which is not simply this one arrived at more expensively.

It also means dashing composes with everything already here for free: the result is a path, so it tessellates, transforms, clips and antialiases by the same code as any other.

§What a pattern means

Lengths alternate drawn and skipped, starting drawn, and repeat. An odd number of them repeats to an even one, so [5] is five on and five off — the SVG rule, and the one that makes a single number mean something obvious rather than nothing. The phase advances the starting position into the pattern, which is how a marching-ants animation is made without rebuilding anything.

Measurement is along the flattened path, so a dash on a curve is as accurate as the flattening tolerance makes it. That is the same accuracy the stroke itself has, so a dash cannot be more wrong than the line it lies on.

Structs§

Dash
A dash pattern: alternating drawn and skipped lengths, and where to start.

Functions§

dash_path
Cut path into the drawn pieces of dash.