artemp/mapnik — Issue #628: Fit dashed lines to endpoints
Author: artemp
Created: 2011-10-11 16:30:00+00:00
State: open
Labels: Symbolizers

Dashed lines should be able to be "fit" or extended to endpoints. Reason being: some times, it is more important to define the shape of the line than to maintain the dashing pattern.

The algorithm is not trivial because the dashing pattern might be complex (e.g. --- -+- --- - --- -+- --- - ---) . Let's suppose we'd like to extend the larger portion of the dashing pattern, or let the user specify which part (or even parts) of the dashing pattern should have priority to be extended.

A basic algorithm should be: take the line, calculate its middlepoint and (half) lenght, check if:
a) if started drawing the dashed line from the middlepoint from the extension point of the dashing pattern, the dashing pattern should end properly (i.e. the line half-lenght is a multiple of the lenght of the dashing pattern, plus/minus half the lenght of the part of the pattern that can be extended.
b) if not, try starting from the middlepoint, but from the opposite part of the dashing pattern (i.e. add or substract half the lenght of the dashing pattern)
c) if not (only happening when the dash-to-invisible ratio is less than 0.5), test which of the two options come closer to the edge. Then extend.

The algorithm should be able to be simplifued to just calculating some points along the dashing pattern, calculating line_lenght modulo pattern_lenght, and finding minimum distances to the options along the dashing pattern.

Questions to be resolved:
* Whether to apply this algorithm to points in a line (or polygon outline) where the line changes inclination by more than N degrees (22.5?)
* Whether to apply this algorithm to polygons, forcing at least one point (the one with the largest inclination variation?), so the dashing looks good on the polygon closure.
* How the dashing shift and extension can be saved for other lineSymbolizers along the same line. For example, think about a railway pattern (black-white), or a pattern with symbols (think "-+-" )