Expand description
Stroke extensions for kurbo: stroke alignment (inside / center / outside), independent start and end caps, dash caps, and dashed aligned strokes. This is the feature set of Figma’s stroke panel, produced as fill outlines on top of kurbo’s public API.
kurbo-se is not a fork. It depends on unmodified kurbo from crates.io
and re-exports it as kurbo_se::kurbo, so the types are identical to
the ones your renderer already consumes.
§Output contract
stroke_aligned returns a BezPath describing the
stroke as a fill outline. Interpret it with the nonzero winding rule.
The outline may self-overlap by design (inner joins, cusps, 180° turns);
those overlaps cancel only under nonzero winding.
§Conventions
- Coordinates are Y-down, as in kurbo.
- For a unit tangent
t̂, the unit normaln̂ = t̂.turn_90()points to the right of the travel direction. - Positive signed area means clockwise winding in Y-down, matching
kurbo::Shape::area. A positive-area subpath has its interior on the right of travel. - The stroke band at a path point
Pspans[P − d_left·n̂, P + d_right·n̂]withd_left + d_right = width.StrokeSide::Rightmeans(d_left, d_right) = (0, width): the left boundary is then the source path itself, exactly.
§Alignment semantics
For closed contours the aligned band is defined as a set, matching Figma (whose inside/outside strokes are a doubled centered stroke masked by the fill):
Inside(w) = { p ∈ F : dist(p, path) ≤ w }
Outside(w) = { p ∉ F : dist(p, path) ≤ w }F is the filled region of the whole path under the nonzero rule.
Centered strokes on closed simple contours follow the same model:
Center(w) = { p : dist(p, path) ≤ w/2 }, built as the fill dilated by
w/2 minus the fill eroded by w/2.
Two consequences:
- An inside stroke never leaves the fill and an outside stroke never enters it, at any width. This includes dashed strokes: each dash is expanded and then masked by the fill.
- A width beyond the local thickness saturates instead of folding over
itself. The stroke fills the shape completely, as Figma renders it: a
rectangle narrower than
2w, a thin wedge, a small star, a circle stroked wider than its diameter.
Per subpath kind:
- Closed subpaths:
Insideis the side of the filled region of the whole compound path. Holes stroke into the ring, not into the void. Winding direction of the input does not change whatInsidemeans. Self-intersecting contours are split at their crossings, and each lobe resolves against the fill on its own. - Open subpaths: inside/outside is geometrically undefined there, so
kurbo-se maps
Insideto the right of travel andOutsideto the left. SetStrokeStyle::sideto pick a side explicitly. Open subpaths are banded independently of the closed contours’ region construction: a nearby open subpath never prunes or masks a closed contour’s band, and overlapping bands add under nonzero winding.
§Quickstart
use kurbo_se::{StrokeStyle, StrokeAlignment, stroke_aligned};
use kurbo_se::kurbo::{Rect, Shape};
let shape = Rect::new(0.0, 0.0, 100.0, 60.0);
let style = StrokeStyle::new(8.0).with_alignment(StrokeAlignment::Inside);
let outline = stroke_aligned(shape, &style, 0.1);
// Fill `outline` with the nonzero rule. Inside alignment never escapes the shape:
assert!(!outline.is_empty());
assert!(shape.bounding_box().contains_rect(outline.bounding_box()));Re-exports§
pub use kurbo;
Structs§
- Aligned
Stroke Ctx - Reusable buffers for repeated stroke expansion. Mirrors kurbo’s
StrokeCtxpattern, which was made public for exactly this purpose. - Dash
Style - Dash configuration for
StrokeStyle. - Stroke
Style - The visual style of an aligned stroke, mirroring Figma’s stroke panel.
- Subpath
Info - How one subpath was interpreted by
stroke_aligned.
Enums§
- Cap
- Defines the shape to be drawn at the ends of a stroke.
- Join
- Defines the connection between two segments of a stroke.
- Stroke
Alignment - Where the stroke band sits relative to the path, in user-facing terms.
- Stroke
Side - Geometric side selection relative to the path’s travel direction.
Traits§
- Stroke
Align Ext - Blanket convenience so any
Shapecan be stroked directly:shape.stroke_aligned(&style, tolerance).
Functions§
- analyze_
subpaths - Report how each subpath of
pathresolves understyle. - miter_
angle_ to_ limit - Convert a corner angle in degrees to the equivalent miter limit.
- miter_
limit_ to_ angle - Convert a miter limit to the equivalent corner angle in degrees.
- stroke_
aligned - Expand an aligned stroke into a fill outline.
- stroke_
aligned_ with - Allocation-reusing variant of
stroke_aligned.
Type Aliases§
- Dashes
- Collection of values representing lengths in a dash pattern.