src/context.js
function pathToLines(path) {
    var lines = [];
    var curr = null;

    path.forEach(function(cmd) {
        if(cmd[0] == PATH_COMMAND.MOVE) {
            curr = cmd[1];
        }
        if(cmd[0] == PATH_COMMAND.LINE) {
            var pt = cmd[1];
            lines.push(new Line(curr, pt));
            curr = pt;
        }
        if(cmd[0] == PATH_COMMAND.QUADRATIC_CURVE) {
            var pts = [curr, cmd[1], cmd[2]];
            for(var t=0; t<1; t+=0.1) {
                var pt = calcQuadraticAtT(pts,t);
                lines.push(new Line(curr, pt));
                curr = pt;
            }
        }
        if(cmd[0] === PATH_COMMAND.BEZIER_CURVE) {
            var pts = [curr, cmd[1], cmd[2], cmd[3]];
            bezierToLines(pts,10).forEach(pt => {
                lines.push(new Line(curr,pt))
                curr = pt
            })
        }
    });
    return lines;
}
function pathToLines(path) {
    var lines = [];
    var curr = null;

    path.forEach(function(cmd) {
        if(cmd[0] == PATH_COMMAND.MOVE) {
            curr = cmd[1];
        }
        if(cmd[0] == PATH_COMMAND.LINE) {
            var pt = cmd[1];
            lines.push(new Line(curr, pt));
            curr = pt;
        }
        if(cmd[0] == PATH_COMMAND.QUADRATIC_CURVE) {
            var pts = [curr, cmd[1], cmd[2]];
            for(var t=0; t<1; t+=0.1) {
                var pt = calcQuadraticAtT(pts,t);
                lines.push(new Line(curr, pt));
                curr = pt;
            }
        }
        if(cmd[0] === PATH_COMMAND.BEZIER_CURVE) {
            var pts = [curr, cmd[1], cmd[2], cmd[3]];
            bezierToLines(pts,10).forEach(pt => {
                lines.push(new Line(curr,pt))
                curr = pt
            })
        }
    });
    return lines;
}
function pathToLines ( path ) { var lines = [ ] ; var curr = null ; path . forEach ( function ( cmd ) { if ( cmd [ 0 ] == PATH_COMMAND . MOVE ) { curr = cmd [ 1 ] ; } if ( cmd [ 0 ] == PATH_COMMAND . LINE ) { var pt = cmd [ 1 ] ; lines . push ( new Line ( curr , pt ) ) ; curr = pt ; } if ( cmd [ 0 ] == PATH_COMMAND . QUADRATIC_CURVE ) { var pts = [ curr , cmd [ 1 ] , cmd [ 2 ] ] ; for ( var t = 0 ; t < 1 ; t += 0.1 ) { var pt = calcQuadraticAtT ( pts , t ) ; lines . push ( new Line ( curr , pt ) ) ; curr = pt ; } } if ( cmd [ 0 ] === PATH_COMMAND . BEZIER_CURVE ) { var pts = [ curr , cmd [ 1 ] , cmd [ 2 ] , cmd [ 3 ] ] ; bezierToLines ( pts , 10 ) . forEach ( pt => { lines . push ( new Line ( curr , pt ) ) curr = pt } ) } } ) ; return lines ; }
Convert a path of points to an array of lines

@param {Array} path List of sub-paths

@returns {Array<Line>}
Convert a path of points to an array of lines