SVGPath

Structured representation of an SVG path that supports morphing

Stores path as a list of command objects (MoveTo, LineTo, etc.) rather than a string, enabling smooth interpolation between paths.

Constructor

SVGPath(
    commands: List[PathCommand],
    path_string: Optional[str] = None
) -> None

Methods

from_string

from_string(path_string: str) -> SVGPath

Parses an SVG path data string (e.g., "M 0,0 L 100,100") into an SVGPath object.

Parameters

path_string
The raw SVG path data string.

Returns

A new SVGPath instance. Raises: ValueError: If parsing encounters an unexpected command or missing coordinates.

interpolate

interpolate(
    path1: 'SVGPath',
    path2: 'SVGPath',
    t: float,
    auto_normalize: bool = True
) -> 'SVGPath'

Interpolate between two paths with automatic normalization

Parameters

path1
Starting path
path2
Ending path
t
Interpolation factor (0.0 to 1.0)
auto_normalize
If True, automatically normalize paths for morphing

Returns

Interpolated path at time t Raises: ValueError: If paths are incompatible and auto_normalize fails

is_compatible_for_morphing

is_compatible_for_morphing(other: SVGPath) -> bool

Check if two paths can be morphed

Parameters

other
Path to check compatibility with

Returns

True if paths can be morphed

normalize_for_morphing

normalize_for_morphing(other: 'SVGPath') -> tuple['SVGPath', 'SVGPath']

Normalize two paths to be compatible for morphing

Parameters

other
Path to normalize with

Returns

Tuple of (normalized_self, normalized_other) Raises: ValueError: If paths can't be made compatible

to_absolute

to_absolute()

Convert all commands to absolute coordinates

Returns

New SVGPath with all absolute commands

to_cubic_beziers

to_cubic_beziers()

Convert all curve commands to cubic Bezier curves

to_string

to_string()

Convert to SVG path data string

Returns

SVG path data string (e.g., "M 0,0 L 100,100")