georust / geo-svg

A rust library to generate SVGs for geo-types
5 stars 4 forks source link

fix: use only one stroke for LineStrings #12

Closed milo-brandt closed 4 months ago

milo-brandt commented 4 months ago

Instead of converting a LineString (or MultiLineString) into a bunch of small line paths, convert it into a single continuous path. This should lead to better results when using with_stroke_width, as the renderer will be able to appropriate apply its join/cap styles, instead of having to treat each corner as the end/start of a segment, leading to weird artifacts near the corners. For closed loops, it's important to close with the "Z" command to make sure that renderers treat the starting point as being a corner, rather than the start and end of a path separately. The geo_types library's docs suggest this is the correct semantics for LineString.

To avoid drawing closed LineStrings as polygons, this removes any fill parameters passed to the rendering function for LineStrings. It also just doesn't render any LineStrings with fewer than 2 points. Both of these cases should be in line with prior behavior.

See before + after below, rendering a line string which is the boundary of a triangle; notice the more intentional joins in the latter at each corner. Screenshot from 2024-05-05 17-12-02 Screenshot from 2024-05-05 17-11-27