svg_path/basic_shapes

Convert SVG basic shape elements into subpaths.

These helpers follow SVG’s equivalent path algorithms for rect, circle, ellipse, line, polyline, and polygon.

Types

Errors returned by SVG primitive conversion helpers.

pub type Error {
  InvalidRectWidth(width: Float)
  InvalidRectHeight(height: Float)
  InvalidRectRadiusX(rx: Float)
  InvalidRectRadiusY(ry: Float)
  InvalidCircleRadius(r: Float)
  InvalidEllipseRadiusX(rx: Float)
  InvalidEllipseRadiusY(ry: Float)
  DisabledRendering
  Core(svg_path.Error)
}

Constructors

  • InvalidRectWidth(width: Float)

    A rect width was negative.

  • InvalidRectHeight(height: Float)

    A rect height was negative.

  • InvalidRectRadiusX(rx: Float)

    A rect x-axis corner radius was negative.

  • InvalidRectRadiusY(ry: Float)

    A rect y-axis corner radius was negative.

  • InvalidCircleRadius(r: Float)

    A circle radius was negative.

  • InvalidEllipseRadiusX(rx: Float)

    An ellipse x-axis radius was negative.

  • InvalidEllipseRadiusY(ry: Float)

    An ellipse y-axis radius was negative.

  • DisabledRendering

    The SVG element would not render because at least one required extent is zero.

  • An error from the core path model.

Values

pub fn circle(
  cx cx: Float,
  cy cy: Float,
  r r: Float,
) -> Result(svg_path.Subpath, Error)

Convert an SVG circle element to a subpath.

The equivalent path starts at the 3 o’clock point and uses four quarter-arc segments.

pub fn ellipse(
  cx cx: Float,
  cy cy: Float,
  rx rx: Float,
  ry ry: Float,
) -> Result(svg_path.Subpath, Error)

Convert an SVG ellipse element to a subpath.

The equivalent path starts at the 3 o’clock point and uses four quarter-arc segments.

pub fn line(
  x1 x1: Float,
  y1 y1: Float,
  x2 x2: Float,
  y2 y2: Float,
) -> Result(svg_path.Subpath, Error)

Convert an SVG line element to a subpath.

pub fn polygon(
  points: List(vec2.Vec2(Float)),
) -> Result(svg_path.Subpath, Error)

Convert an SVG polygon element to a subpath.

pub fn polyline(
  points: List(vec2.Vec2(Float)),
) -> Result(svg_path.Subpath, Error)

Convert an SVG polyline element to a subpath.

pub fn rect(
  x x: Float,
  y y: Float,
  width width: Float,
  height height: Float,
  rx rx: option.Option(Float),
  ry ry: option.Option(Float),
) -> Result(svg_path.Subpath, Error)

Convert an SVG rect element to a subpath.

The equivalent path starts at (x + rx, y) and proceeds clockwise. If only one corner radius is present, the missing radius uses the same value. Radii are clamped so they are no greater than half the rectangle extent.

Search Document