svg_path/ellipse

Lower-level helpers for transforming SVG elliptical arcs.

Most users should use svg_path/transform instead. This module exposes the ellipse-specific math helpers used to transform arc axes and represent arcs that collapse under affine transforms.

Types

Affine

opaque

Equivalent of transform.Matrix, redefined by the ellipse module to avoid a circular dependency.

Has the same six-value layout as SVG matrix(a b c d e f).

pub opaque type Affine

A cubic Bezier curve produced by the ellipse math helpers.

pub type Cubic {
  Cubic(
    start: Point,
    control1: Point,
    control2: Point,
    end: Point,
  )
}

Constructors

Errors returned by ellipse and collapsed-arc helpers.

pub type Error {
  DegenerateInputArc
  NotCollapsedToLine
}

Constructors

  • DegenerateInputArc

    The source arc cannot be converted to center-parameter form.

  • NotCollapsedToLine

    The transformed arc did not collapse to a line.

A lightweight point used by the ellipse math helpers.

pub type Point {
  Point(x: Float, y: Float)
}

Constructors

  • Point(x: Float, y: Float)

Values

pub fn arc_to_cubics(
  start start: Point,
  radius radius: Point,
  x_axis_rotation x_axis_rotation: Float,
  large_arc large_arc: Bool,
  sweep sweep: Bool,
  end end: Point,
) -> Result(List(Cubic), Error)

Convert an elliptical arc to one or more cubic Bezier curves.

The arc is split into chunks of at most a quarter turn. This is the common deterministic SVG arc approximation strategy. This function does not accept a tolerance; use a higher-level helper if you want SVG path segments back.

pub fn collapsed_arc_line(
  start start: Point,
  radius radius: Point,
  x_axis_rotation x_axis_rotation: Float,
  large_arc large_arc: Bool,
  sweep sweep: Bool,
  end end: Point,
  by transform: Affine,
) -> Result(#(Point, Point), Error)

Convert an arc collapsed by an affine transform into a single line segment.

If the collapsed arc’s extrema require more than one segment to preserve its out-and-back motion, use collapsed_arc_subpath.

pub fn collapsed_arc_subpath(
  start start: Point,
  radius radius: Point,
  x_axis_rotation x_axis_rotation: Float,
  large_arc large_arc: Bool,
  sweep sweep: Bool,
  end end: Point,
  by transform: Affine,
) -> Result(List(Point), Error)

Convert an arc collapsed by an affine transform into a line-based subpath.

pub fn ellipse_affine(
  a a: Float,
  b b: Float,
  c c: Float,
  d d: Float,
  e e: Float,
  f f: Float,
) -> Affine

Create an affine matrix for ellipse helpers.

pub fn point(point: Point, by transform: Affine) -> Point

Transform a point by an affine matrix.

pub fn transformed_axes(
  radius radius: Point,
  x_axis_rotation x_axis_rotation: Float,
  by transform: Affine,
) -> Result(#(Point, Float), Error)

Transform an arc’s radius and x-axis rotation.

Returns the new radius and x-axis rotation for the transformed ellipse.

Search Document