Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...

MorphSVGPlugin.rawPathToString()

Added in version: 0.9.0
MorphSVGPlugin.rawPathToString( rawPath:Array (RawPath), precision:Number ) : String

Converts a RawPath (array) into a string of path data, like "M0,0 C100,20 300,50 400,0..." which is what's typically found in the d attribute of a <path>

Parameters

rawPath: Array (RawPath)

The RawPath that should be converted to a string

precision: Number

The maximum number of decimal places that should be used when converting all of the numeric values from the RawPath. For example, 3 would mean that a number like 2.125874896 will be clipped to 2.125. This can be helpful in keeping long path strings more memory-efficient. The default is 2.

Returns : String

The string of path data commands in cubic bezier format, like "M0,0 C10,20,15,30,5,18 M0,100 C50,120,80,110,100,100"

Details

Converts a RawPath (array) into a string of path data, like "M0,0 C100,20 300,50 400,0..." which is what's typically found in the d attribute of a <path>.

A RawPath is basically an array containing an array for each contiguous segment, always populated with cubic bezier data. There's one segment (array) for each "M" command; All of the cubic bezier coordinates are in alternating x/y format (just like SVG path data) in numeric form which is nice because that way you don't have to parse a long string and convert things. For example, this SVG <path> has two separate segments because there are two "M" commands:

<path d="M0,0 C10,20,15,30,5,18 M0,100 C50,120,80,110,100,100" />
So the resulting RawPath would be:
[
  [0, 0, 10, 20, 15, 30, 5, 18],
  [0, 100, 50, 120, 80, 110, 100, 100]
]

There is also a corresponding MorphSVGPlugin.stringToPathData() method so that you can convert back and forth.

Copyright 2017, GreenSock. All rights reserved. This work is subject to theterms of useor for Club GreenSock members, the software agreement that was issued with the membership.
×