Converts each command (beside move to) of a svg path to a list of Cubics by calling SvgPathParser.parseCubics. Any svg path complying to the specification found at https://www.w3.org/TR/SVG/paths.html is supported. Parameters can either be split by whitespace or by commas. There is very little error handling, so use with valid paths and consult the debug logs for unexpected Cubic objects.

Summary

Public companion functions

List<Feature>

Converts an SVG path string into a list of Feature objects.

Cmn

Public companion functions

parseFeatures

fun parseFeatures(svgPath: String): List<Feature>

Converts an SVG path string into a list of Feature objects. The polygon described in the path should be representing a single, closed, non-self-intersecting polygon. Otherwise, either an error is thrown or the Morph that the polygon is used in will be distorted.

Note:

  • Only the first shape within the SVG path is processed. Subsequent shapes or holes are ignored.

  • This method is primarily intended for development and testing purposes. For production use, serialize and parse the Feature objects with FeatureSerializer.

Usage:

// Do the following three *once*
val triangleSVGPath: String = "M0,0 0.5,1 1,0Z"
val triangleFeatures: List<Feature> = SvgPathParser.parseFeatures(triangleSVGPath)
val serializedTriangle: String = FeatureSerializer.serialize(triangleFeatures)

// Parse the serialized triangle features in your production code.
// You can adjust them (e.g. the type) however you want before parsing.
val features: List<Feature> = FeatureSerializer.parse(serializedTriangle)
val triangle: RoundedPolygon = RoundedPolygon(features, centerX = 0.5f, centerY = 0.5f)
Morph(triangle, ...)
Parameters
svgPath: String

The SVG path string, typically extracted from the d attribute of an SVG element.

Returns
List<Feature>

A list of Feature objects that can be used to create RoundedPolygons

Throws
kotlin.IllegalArgumentException
  • if the SVG path is invalid or represents a non-closed or self-intersecting polygon.