Skip to main content

Crate kurbo_se

Crate kurbo_se 

Source
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 normal n̂ = 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 P spans [P − d_left·n̂, P + d_right·n̂] with d_left + d_right = width. StrokeSide::Right means (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: Inside is 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 what Inside means. 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 Inside to the right of travel and Outside to the left. Set StrokeStyle::side to 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§

AlignedStrokeCtx
Reusable buffers for repeated stroke expansion. Mirrors kurbo’s StrokeCtx pattern, which was made public for exactly this purpose.
DashStyle
Dash configuration for StrokeStyle.
StrokeStyle
The visual style of an aligned stroke, mirroring Figma’s stroke panel.
SubpathInfo
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.
StrokeAlignment
Where the stroke band sits relative to the path, in user-facing terms.
StrokeSide
Geometric side selection relative to the path’s travel direction.

Traits§

StrokeAlignExt
Blanket convenience so any Shape can be stroked directly: shape.stroke_aligned(&style, tolerance).

Functions§

analyze_subpaths
Report how each subpath of path resolves under style.
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.