svg_path/stroke

Stroke outline construction.

This module turns path geometry into filled outline paths by delegating nonzero strokes to symmetric bands in svg_path/offset. That module owns the side construction, caps, and trimming. This module also exposes SVG-style dash extraction: turning a continuous path into the open subpaths that would be stroked as visible dashes.

Outline operations take explicit join and cap arguments, including the forms that use default options. Pure dash extraction takes neither.

Types

Cap style used at open subpath endpoints.

pub type Cap {
  Butt
  RoundCap
  Square
}

Constructors

  • Butt

    Connect the two offset sides directly at the endpoint.

  • RoundCap

    Add a half-circle cap at the endpoint.

  • Square

    Extend the stroke by half the stroke width before capping.

Options for SVG-style dash extraction.

Dash lengths are already-resolved user-coordinate lengths. CSS parsing, percentages, and pathLength scaling are intentionally outside this type. Empty patterns and all-zero patterns behave like stroke-dasharray: none.

pub type DashOptions {
  DashOptions(
    pattern: List(Float),
    offset: Float,
    length_options: svg_path.LengthOptions,
  )
}

Constructors

  • DashOptions(
      pattern: List(Float),
      offset: Float,
      length_options: svg_path.LengthOptions,
    )

    Arguments

    pattern

    Alternating visible and hidden lengths in path-coordinate units.

    offset

    Signed path-coordinate offset into the repeated dash pattern.

    length_options

    Options used for arc-length measurement and splitting.

Errors returned by stroke helpers.

pub type Error {
  PathError(error: svg_path.Error)
  OffsetError(error: offset.Error)
  InvalidWidth(width: Float)
  InvalidDashLength(length: Float)
  InvalidDashOffset(offset: Float)
  InvalidDashPatternLength
}

Constructors

  • PathError(error: svg_path.Error)

    An underlying path operation failed.

  • OffsetError(error: offset.Error)

    An underlying offset operation failed.

  • InvalidWidth(width: Float)

    Stroke width must be finite and greater than zero.

  • InvalidDashLength(length: Float)

    Dash lengths must be finite and non-negative.

  • InvalidDashOffset(offset: Float)

    Dash offset must be finite.

  • InvalidDashPatternLength

    The normalized dash pattern’s total length must be finite.

Join style for the stroke.

Supports SVG bevel, miter, miter-clip, round, and arcs.

pub type Join {
  Bevel
  Miter(miter_limit: Float)
  MiterClip(miter_limit: Float)
  Arcs(miter_limit: Float)
  Round
}

Constructors

  • Bevel

    Connect adjacent offset segments with a straight line.

  • Miter(miter_limit: Float)

    Extend the offset tangents toward their intersection when the miter stays within miter_limit; otherwise fall back to Bevel.

  • MiterClip(miter_limit: Float)

    Clip an over-limit miter at miter_limit * width / 2 from the pivot. The limit must be finite and positive. Uses Bevel if the extensions do not meet or clipping would cut behind either join endpoint; it does not trim adjacent segments to satisfy a limit below the bevel.

  • Arcs(miter_limit: Float)

    Curvature-continuing SVG 2 join with an arc-length miter limit. Uses Round for diverging rays or reversed source endpoints; a missing endpoint curvature uses a line continuation. Limits must be positive and finite. See offset.Arcs for the offset-layer counterpart.

  • Round

    Connect adjacent offset segments with a circular SVG arc.

Width and technical options for stroke outline construction. Join and cap styles are explicit operation arguments.

pub type Options {
  Options(width: Float, offset: offset.Options)
}

Constructors

  • Options(width: Float, offset: offset.Options)

    Arguments

    width

    Finite, positive full stroke width in path-coordinate units.

    offset

    Technical options used to construct the two half-width offsets. Stroke construction overrides trimming choices: side-local cusp trimming is disabled and final in-band trimming is enabled. Single-offset trimming options do not apply.

Values

pub fn default_dash_options(
  pattern pattern: List(Float),
  offset offset: Float,
) -> DashOptions

Return default dash extraction options for a pattern and dash offset.

pattern and offset are interpreted as resolved user-coordinate lengths.

pub fn default_options() -> Options

Return default stroke options.

pub fn path(
  path: svg_path.Path,
  width width: Float,
  join join: Join,
  cap cap: Cap,
) -> Result(svg_path.Path, Error)

Stroke every subpath in a path using default options with the given width.

pub fn path_dashed(
  path: svg_path.Path,
  width width: Float,
  pattern pattern: List(Float),
  offset offset: Float,
  join join: Join,
  cap cap: Cap,
) -> Result(svg_path.Path, Error)

Stroke a path after applying SVG dasharray semantics to each subpath.

The dash pattern resets at the start of each subpath.

pub fn path_dashed_with(
  path path: svg_path.Path,
  join join: Join,
  cap cap: Cap,
  options options: Options,
  dash_options dash_options: DashOptions,
) -> Result(svg_path.Path, Error)

Stroke a path after applying SVG dasharray semantics using explicit stroke and dash options.

The dash pattern resets at the start of each subpath.

pub fn path_dashes(
  path: svg_path.Path,
  pattern pattern: List(Float),
  offset offset: Float,
) -> Result(svg_path.Path, Error)

Return the visible dash pieces of every subpath in a path.

The dash pattern resets at the start of each subpath.

pub fn path_dashes_with(
  path path: svg_path.Path,
  dash_options dash_options: DashOptions,
) -> Result(svg_path.Path, Error)

Return the visible dash pieces of every subpath in a path using explicit dash options.

The dash pattern resets at the start of each subpath.

pub fn path_with(
  path path: svg_path.Path,
  join join: Join,
  cap cap: Cap,
  options options: Options,
) -> Result(svg_path.Path, Error)

Stroke every subpath in a path using explicit options.

pub fn segment(
  segment: svg_path.Segment,
  width width: Float,
  join join: Join,
  cap cap: Cap,
) -> Result(svg_path.Path, Error)

Stroke a segment using default options with the given width.

pub fn segment_with(
  segment segment: svg_path.Segment,
  join join: Join,
  cap cap: Cap,
  options options: Options,
) -> Result(svg_path.Path, Error)

Stroke a segment using explicit options.

pub fn subpath(
  subpath: svg_path.Subpath,
  width width: Float,
  join join: Join,
  cap cap: Cap,
) -> Result(svg_path.Path, Error)

Stroke a subpath using default options with the given width.

pub fn subpath_dashed(
  subpath: svg_path.Subpath,
  width width: Float,
  pattern pattern: List(Float),
  offset offset: Float,
  join join: Join,
  cap cap: Cap,
) -> Result(svg_path.Path, Error)

Stroke a subpath after applying SVG dasharray semantics.

This first extracts open dash subpaths, then strokes each dash independently.

pub fn subpath_dashed_with(
  subpath subpath: svg_path.Subpath,
  join join: Join,
  cap cap: Cap,
  options options: Options,
  dash_options dash_options: DashOptions,
) -> Result(svg_path.Path, Error)

Stroke a subpath after applying SVG dasharray semantics using explicit stroke and dash options.

This first extracts open dash subpaths, then strokes each dash independently. Zero-length visible dashes produce Round or Square caps (nothing for Butt). Square caps use the source direction at the dash address.

pub fn subpath_dashes(
  subpath: svg_path.Subpath,
  pattern pattern: List(Float),
  offset offset: Float,
) -> Result(List(svg_path.Subpath), Error)

Return the visible dash pieces of a subpath using SVG dasharray semantics.

Each returned dash is an open subpath preserving the original segment types where possible. Empty and all-zero patterns return the original continuous subpath as a singleton when the subpath has positive length. An active dash pattern on a closed subpath has a visible seam: a dash covering the whole closed subpath is opened at the subpath start so cap styles can apply there. Zero-length visible entries are retained as coincident-endpoint Lines.

pub fn subpath_dashes_with(
  subpath subpath: svg_path.Subpath,
  dash_options dash_options: DashOptions,
) -> Result(List(svg_path.Subpath), Error)

Return the visible dash pieces of a subpath using explicit dash options.

pub fn subpath_with(
  subpath subpath: svg_path.Subpath,
  join join: Join,
  cap cap: Cap,
  options options: Options,
) -> Result(svg_path.Path, Error)

Stroke a subpath as a symmetric band with offsets -width/2 and +width/2. Band construction owns normalization, side construction, caps, and trimming. For compatibility, strokes disable per-side cusp trimming and always enable final in-band trimming, irrespective of the supplied band trimming options.

Search Document