Method _vars
Method to create variables
options
util variables
Constructor
the class can work as a "creator" of self instances so no need to init if 'creator' passed insted of path
normalize start and end x value of the path
console.time 'pre sample'
console.timeEnd 'pre sample'
Method _preSample sideEffect {Array} _samples - set of sampled points
Samples the path on init
Method _findBounds
Parameters:
to
must be an Array.progress
must be a Number.Returns an Object
(- start {Number}: lowest boundry - end {Number}: highest boundry)
get the start index in the array reset the cached prev index if new progress is smaller then previous one or it is not defined
get start and end indexes of the loop and save the direction
set default start and end bounds to the very first and the very last items in array
if direction is reverse swap pointX and pointP for if statement
the next statement is nicer but it creates a new object, so bothers GC {pointX, pointP} = {pointX: pointP, pointP: pointX} save the latest smaller value as start value
save the first larger value as end value and break immediately
return the first item if start wasn't found start ?= array[0] end ?= array[array.length-1] !end? and console.log p
Method sample
Loop thru path trying to find the most closer x compared to current progress value
Parameters:
easing
must be a Number.Returns a Number
(easing y)
Method _checkIfBoundsCloseEnough
Check if one of bounds.start or bounds.end is close enough to searched progress
Parameters:
progress
must be a Number.bounds
must be an Object.Returns a Number, Undefined
(returns Y value if true, undefined if false)
check if start bound is close enough
check if end bound is close enough
Method _checkIfPointCloseEnough
Check if bound point close enough to progress
Parameters:
progress
must be a Number.bound
must be an Object.Returns a Number, Undefined
(returns Y value if true, undefined if false)
Method _approximate
Parameters:
start
must be an Object.end
must be an Object.progress
must be a Number.Returns an Object
(approximation)
Method _findApproximate
Parameters:
progress
must be a Number.start
must be an Object.end
must be an Object.Returns a Nunomber
(y approximation)
if close enough resolve the y value
if looping for a long time
not precise enough so we will call self again recursively, lets find arguments for the call
Method resolveY
Parameters:
SVG
must be an Object.Returns a Number
(normalized y)
Method to normalize path's X start and end value since it must start at 0 and end at 100
Parameters:
Path
must be a String.Returns a String
(Normalized path coordinates)
SVG path commands
remove the first empty item - it is always empty cuz we split by M
normalize the x value of the start segment to 0
normalize the x value of the end segment to _rect value
form the normalized path
Method to form normalized path.
Parameters:
Commands
must be an Array.Points
must be an Array.Returns a String
(Formed normalized path.)
Method to normalize SVG path segment
Parameters:
Segment
must be a String.Value
must be a Number.Returns a String
(Normalized Segment.)
get x value of the latest point
if the x point isn't the same as value, set it to the value
join pairs to form segment
Method to geather array values to pairs.
Parameters:
Array
must be an Array.Returns an Array
(Matrix of pairs.)
loop over the array by 2 and save the pairs
Method create
Create new instance of PathEasing with specified parameters Please see the docs for PathEasing for more details on params.
Parameters:
path
must be a String, DOMNode.Returns an Object
(easing y)
PathEasing
Class allows you to specify custom easing function by SVG path line commands. Line commands should by in range of rect 100x100.
Parameters:
{String, DOMNode}
options
must be an Object.(- eps {Number} Epsilon specifies how precise we should be when sampling the path. Smaller number - more precise is computation, but more CPU power it takes default: 0.001 - precompute {Number} Quantity of steps for sampling the path on the init. In can be in range of [1000, 10000]. Larger number specified - more time it takes to init the module, but less time it takes during the animation. default: 2000 - rect {Number} The largest number SVG path coordinates can have default: 100 - approximateMax {Number} Number of loops avaliable when approximating the path value default: 5)