Skip to content

Instantly share code, notes, and snippets.

@rveciana
Last active March 2, 2024 13:35
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save rveciana/209fa7efeb01f05fa4a544a76ac8ed91 to your computer and use it in GitHub Desktop.
Canvas path animation using svg-path-properties

Creating visualizations like this one but using canvas is possible.

Since the Canvas element hasn't got the getTotalLength() method as it exists in SVG, I'm using the svg-path-properties, that allows this calculations with a good precision (<0.1px), as well as allowing the getPointAtLength function too.

<!DOCTYPE html>
<meta charset="utf-8">
<style>
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script src="path-properties.js"></script>
<script>
var width = 700,
height = 500;
var canvas = d3.select("body").append("canvas")
.attr("width", width)
.attr("height", height);
var context = canvas.node().getContext("2d");
var projection = d3.geo.stereographic()
.scale(900)
.translate([width / 2, height / 2])
.rotate([-90, -60])
.clipAngle(180 - 1e-4)
.clipExtent([[0, 0], [width, height]])
.precision(1);
var path = d3.geo.path()
.projection(projection);
//.context(context);
var graticule = d3.geo.graticule();
d3.json("transsiberian.json", function(error, transsiberian) {
d3.json("world-110m.json", function(error, world) {
var countries = topojson.feature(world, world.objects.countries);
var track = topojson.feature(transsiberian, transsiberian.objects.transsiberian);
var properties = spp.svgPathProperties(path(track));
var length = properties.getLength();
d3.transition()
.duration(5000)
.ease("linear")
.tween("zoom", function() {
return function(t) {
context.clearRect(0, 0, width, height);
context.strokeStyle = '#aaa';
context.fillStyle = '#ccc';
context.beginPath();
path.context(context)(graticule());
context.lineWidth = 0.2;
context.strokeStyle = 'rgba(30,30,30, 0.5)';
context.stroke();
context.beginPath();
path.context(context)(countries);
context.fill();
context.beginPath();
path.context(context)(countries);
context.stroke();
context.lineWidth = 1;
context.strokeStyle = 'rgba(120,60,60, 1)';
context.setLineDash([length]);
context.lineDashOffset = length*(1-t);
context.beginPath();
path.context(context)(track);
context.stroke();
context.setLineDash([]);
}
});
});
});
d3.select(self.frameElement).style("height", height + "px");
</script>
// http://geoexamples.com/path-properties/ Version 0.0.1. Copyright 2016 Roger Veciana i Rovira.
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.spp = global.spp || {})));
}(this, function (exports) { 'use strict';
//Parses an SVG path into an object.
//Taken from https://github.com/jkroso/parse-svg-path
//Re-written so it can be used with rollup
var length = {a: 7, c: 6, h: 1, l: 2, m: 2, q: 4, s: 4, t: 2, v: 1, z: 0};
var segment = /([astvzqmhlc])([^astvzqmhlc]*)/ig;
function parse(path) {
var data = [];
path.replace(segment, function(_, command, args){
var type = command.toLowerCase();
args = parseValues(args);
// overloaded moveTo
if (type === 'm' && args.length > 2) {
data.push([command].concat(args.splice(0, 2)));
type = 'l';
command = command === 'm' ? 'l' : 'L';
}
while (args.length >= 0) {
if (args.length === length[type]) {
args.unshift(command);
return data.push(args);
}
if (args.length < length[type]) {
throw new Error('malformed path data');
}
data.push([command].concat(args.splice(0, length[type])));
}
});
return data;
}
var number = /-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig;
function parseValues(args) {
var numbers = args.match(number);
return numbers ? numbers.map(Number) : [];
}
//Calculate Bezier curve length and positionAtLength
//Algorithms taken from http://bl.ocks.org/hnakamur/e7efd0602bfc15f66fc5, https://gist.github.com/tunght13488/6744e77c242cc7a94859 and http://stackoverflow.com/questions/11854907/calculate-the-length-of-a-segment-of-a-quadratic-bezier
function Bezier(ax, ay, bx, by, cx, cy, dx, dy) {
return new Bezier$1(ax, ay, bx, by, cx, cy, dx, dy);
}
function Bezier$1(ax, ay, bx, by, cx, cy, dx, dy) {
this.a = {x:ax, y:ay};
this.b = {x:bx, y:by};
this.c = {x:cx, y:cy};
this.d = {x:dx, y:dy};
if(dx && dy){
this.getArcLength = getCubicArcLength;
this.getPoint = cubicPoint;
} else {
this.getArcLength = getQuadraticArcLength;
this.getPoint = quadraticPoint;
}
this.init();
}
Bezier$1.prototype = {
constructor: Bezier$1,
init: function() {
this.length = this.getArcLength([this.a.x, this.b.x, this.c.x, this.d.x],
[this.a.y, this.b.y, this.c.y, this.d.y]);
},
getLength: function() {
return this.length;
},
getPointAtLength: function(length) {
var error = 1;
var t = length/this.length;
while (error > 0.008){
var calcLength = this.getArcLength([this.a.x, this.b.x, this.c.x, this.d.x],
[this.a.y, this.b.y, this.c.y, this.d.y],
t);
error = Math.abs(length - calcLength)/this.length;
t = t + (length-calcLength)/this.length;
}
return this.getPoint([this.a.x, this.b.x, this.c.x, this.d.x],
[this.a.y, this.b.y, this.c.y, this.d.y],
t);
}
};
function quadraticPoint(xs, ys, t){
var x = (1 - t) * (1 - t) * xs[0] + 2 * (1 - t) * t * xs[1] + t * t * xs[2];
var y = (1 - t) * (1 - t) * ys[0] + 2 * (1 - t) * t * ys[1] + t * t * ys[2];
return {x: x, y: y};
}
function cubicPoint(xs, ys, t){
var x = (1 - t) * (1 - t) * (1 - t) * xs[0] + 3 * (1 - t) * (1 - t) * t * xs[1] +
3 * (1 - t) * t * t * xs[2] + t * t * t * xs[3];
var y = (1 - t) * (1 - t) * (1 - t) * ys[0] + 3 * (1 - t) * (1 - t) * t * ys[1] +
3 * (1 - t) * t * t * ys[2] + t * t * t * ys[3];
return {x: x, y: y};
}
function getQuadraticArcLength(xs, ys, t) {
if (t === undefined) {
t = 1;
}
var ax = xs[0] - 2 * xs[1] + xs[2];
var ay = ys[0] - 2 * ys[1] + ys[2];
var bx = 2 * xs[1] - 2 * xs[0];
var by = 2 * ys[1] - 2 * ys[0];
var A = 4 * (ax * ax + ay * ay);
var B = 4 * (ax * bx + ay * by);
var C = bx * bx + by * by;
var b = B/(2*A);
var c = C/A;
var u = t + b;
var k = c - b*b;
return (Math.sqrt(A)/2)*(
u*Math.sqrt(u*u+k)-b*Math.sqrt(b*b+k)+
k*Math.log(Math.abs(
(u+Math.sqrt(u*u+k))/(b+Math.sqrt(b*b+k))
))
);
}
// Legendre-Gauss abscissae (xi values, defined at i=n as the roots of the nth order Legendre polynomial Pn(x))
var tValues = [
[],
[],
[-0.5773502691896257645091487805019574556476,0.5773502691896257645091487805019574556476],
[0,-0.7745966692414833770358530799564799221665,0.7745966692414833770358530799564799221665],
[-0.3399810435848562648026657591032446872005,0.3399810435848562648026657591032446872005,-0.8611363115940525752239464888928095050957,0.8611363115940525752239464888928095050957],
[0,-0.5384693101056830910363144207002088049672,0.5384693101056830910363144207002088049672,-0.9061798459386639927976268782993929651256,0.9061798459386639927976268782993929651256],
[0.6612093864662645136613995950199053470064,-0.6612093864662645136613995950199053470064,-0.2386191860831969086305017216807119354186,0.2386191860831969086305017216807119354186,-0.9324695142031520278123015544939946091347,0.9324695142031520278123015544939946091347],
[0, 0.4058451513773971669066064120769614633473,-0.4058451513773971669066064120769614633473,-0.7415311855993944398638647732807884070741,0.7415311855993944398638647732807884070741,-0.9491079123427585245261896840478512624007,0.9491079123427585245261896840478512624007],
[-0.1834346424956498049394761423601839806667,0.1834346424956498049394761423601839806667,-0.5255324099163289858177390491892463490419,0.5255324099163289858177390491892463490419,-0.7966664774136267395915539364758304368371,0.7966664774136267395915539364758304368371,-0.9602898564975362316835608685694729904282,0.9602898564975362316835608685694729904282],
[0,-0.8360311073266357942994297880697348765441,0.8360311073266357942994297880697348765441,-0.9681602395076260898355762029036728700494,0.9681602395076260898355762029036728700494,-0.3242534234038089290385380146433366085719,0.3242534234038089290385380146433366085719,-0.6133714327005903973087020393414741847857,0.6133714327005903973087020393414741847857],
[-0.1488743389816312108848260011297199846175,0.1488743389816312108848260011297199846175,-0.4333953941292471907992659431657841622000,0.4333953941292471907992659431657841622000,-0.6794095682990244062343273651148735757692,0.6794095682990244062343273651148735757692,-0.8650633666889845107320966884234930485275,0.8650633666889845107320966884234930485275,-0.9739065285171717200779640120844520534282,0.9739065285171717200779640120844520534282],
[0,-0.2695431559523449723315319854008615246796,0.2695431559523449723315319854008615246796,-0.5190961292068118159257256694586095544802,0.5190961292068118159257256694586095544802,-0.7301520055740493240934162520311534580496,0.7301520055740493240934162520311534580496,-0.8870625997680952990751577693039272666316,0.8870625997680952990751577693039272666316,-0.9782286581460569928039380011228573907714,0.9782286581460569928039380011228573907714],
[-0.1252334085114689154724413694638531299833,0.1252334085114689154724413694638531299833,-0.3678314989981801937526915366437175612563,0.3678314989981801937526915366437175612563,-0.5873179542866174472967024189405342803690,0.5873179542866174472967024189405342803690,-0.7699026741943046870368938332128180759849,0.7699026741943046870368938332128180759849,-0.9041172563704748566784658661190961925375,0.9041172563704748566784658661190961925375,-0.9815606342467192506905490901492808229601,0.9815606342467192506905490901492808229601],
[0,-0.2304583159551347940655281210979888352115,0.2304583159551347940655281210979888352115,-0.4484927510364468528779128521276398678019,0.4484927510364468528779128521276398678019,-0.6423493394403402206439846069955156500716,0.6423493394403402206439846069955156500716,-0.8015780907333099127942064895828598903056,0.8015780907333099127942064895828598903056,-0.9175983992229779652065478365007195123904,0.9175983992229779652065478365007195123904,-0.9841830547185881494728294488071096110649,0.9841830547185881494728294488071096110649],
[-0.1080549487073436620662446502198347476119,0.1080549487073436620662446502198347476119,-0.3191123689278897604356718241684754668342,0.3191123689278897604356718241684754668342,-0.5152486363581540919652907185511886623088,0.5152486363581540919652907185511886623088,-0.6872929048116854701480198030193341375384,0.6872929048116854701480198030193341375384,-0.8272013150697649931897947426503949610397,0.8272013150697649931897947426503949610397,-0.9284348836635735173363911393778742644770,0.9284348836635735173363911393778742644770,-0.9862838086968123388415972667040528016760,0.9862838086968123388415972667040528016760],
[0,-0.2011940939974345223006283033945962078128,0.2011940939974345223006283033945962078128,-0.3941513470775633698972073709810454683627,0.3941513470775633698972073709810454683627,-0.5709721726085388475372267372539106412383,0.5709721726085388475372267372539106412383,-0.7244177313601700474161860546139380096308,0.7244177313601700474161860546139380096308,-0.8482065834104272162006483207742168513662,0.8482065834104272162006483207742168513662,-0.9372733924007059043077589477102094712439,0.9372733924007059043077589477102094712439,-0.9879925180204854284895657185866125811469,0.9879925180204854284895657185866125811469],
[-0.0950125098376374401853193354249580631303,0.0950125098376374401853193354249580631303,-0.2816035507792589132304605014604961064860,0.2816035507792589132304605014604961064860,-0.4580167776572273863424194429835775735400,0.4580167776572273863424194429835775735400,-0.6178762444026437484466717640487910189918,0.6178762444026437484466717640487910189918,-0.7554044083550030338951011948474422683538,0.7554044083550030338951011948474422683538,-0.8656312023878317438804678977123931323873,0.8656312023878317438804678977123931323873,-0.9445750230732325760779884155346083450911,0.9445750230732325760779884155346083450911,-0.9894009349916499325961541734503326274262,0.9894009349916499325961541734503326274262],
[0,-0.1784841814958478558506774936540655574754,0.1784841814958478558506774936540655574754,-0.3512317634538763152971855170953460050405,0.3512317634538763152971855170953460050405,-0.5126905370864769678862465686295518745829,0.5126905370864769678862465686295518745829,-0.6576711592166907658503022166430023351478,0.6576711592166907658503022166430023351478,-0.7815140038968014069252300555204760502239,0.7815140038968014069252300555204760502239,-0.8802391537269859021229556944881556926234,0.8802391537269859021229556944881556926234,-0.9506755217687677612227169578958030214433,0.9506755217687677612227169578958030214433,-0.9905754753144173356754340199406652765077,0.9905754753144173356754340199406652765077],
[-0.0847750130417353012422618529357838117333,0.0847750130417353012422618529357838117333,-0.2518862256915055095889728548779112301628,0.2518862256915055095889728548779112301628,-0.4117511614628426460359317938330516370789,0.4117511614628426460359317938330516370789,-0.5597708310739475346078715485253291369276,0.5597708310739475346078715485253291369276,-0.6916870430603532078748910812888483894522,0.6916870430603532078748910812888483894522,-0.8037049589725231156824174550145907971032,0.8037049589725231156824174550145907971032,-0.8926024664975557392060605911271455154078,0.8926024664975557392060605911271455154078,-0.9558239495713977551811958929297763099728,0.9558239495713977551811958929297763099728,-0.9915651684209309467300160047061507702525,0.9915651684209309467300160047061507702525],
[0,-0.1603586456402253758680961157407435495048,0.1603586456402253758680961157407435495048,-0.3165640999636298319901173288498449178922,0.3165640999636298319901173288498449178922,-0.4645707413759609457172671481041023679762,0.4645707413759609457172671481041023679762,-0.6005453046616810234696381649462392798683,0.6005453046616810234696381649462392798683,-0.7209661773352293786170958608237816296571,0.7209661773352293786170958608237816296571,-0.8227146565371428249789224867127139017745,0.8227146565371428249789224867127139017745,-0.9031559036148179016426609285323124878093,0.9031559036148179016426609285323124878093,-0.9602081521348300308527788406876515266150,0.9602081521348300308527788406876515266150,-0.9924068438435844031890176702532604935893,0.9924068438435844031890176702532604935893],
[-0.0765265211334973337546404093988382110047,0.0765265211334973337546404093988382110047,-0.2277858511416450780804961953685746247430,0.2277858511416450780804961953685746247430,-0.3737060887154195606725481770249272373957,0.3737060887154195606725481770249272373957,-0.5108670019508270980043640509552509984254,0.5108670019508270980043640509552509984254,-0.6360536807265150254528366962262859367433,0.6360536807265150254528366962262859367433,-0.7463319064601507926143050703556415903107,0.7463319064601507926143050703556415903107,-0.8391169718222188233945290617015206853296,0.8391169718222188233945290617015206853296,-0.9122344282513259058677524412032981130491,0.9122344282513259058677524412032981130491,-0.9639719272779137912676661311972772219120,0.9639719272779137912676661311972772219120,-0.9931285991850949247861223884713202782226,0.9931285991850949247861223884713202782226],
[0,-0.1455618541608950909370309823386863301163,0.1455618541608950909370309823386863301163,-0.2880213168024010966007925160646003199090,0.2880213168024010966007925160646003199090,-0.4243421202074387835736688885437880520964,0.4243421202074387835736688885437880520964,-0.5516188358872198070590187967243132866220,0.5516188358872198070590187967243132866220,-0.6671388041974123193059666699903391625970,0.6671388041974123193059666699903391625970,-0.7684399634756779086158778513062280348209,0.7684399634756779086158778513062280348209,-0.8533633645833172836472506385875676702761,0.8533633645833172836472506385875676702761,-0.9200993341504008287901871337149688941591,0.9200993341504008287901871337149688941591,-0.9672268385663062943166222149076951614246,0.9672268385663062943166222149076951614246,-0.9937521706203895002602420359379409291933,0.9937521706203895002602420359379409291933],
[-0.0697392733197222212138417961186280818222,0.0697392733197222212138417961186280818222,-0.2078604266882212854788465339195457342156,0.2078604266882212854788465339195457342156,-0.3419358208920842251581474204273796195591,0.3419358208920842251581474204273796195591,-0.4693558379867570264063307109664063460953,0.4693558379867570264063307109664063460953,-0.5876404035069115929588769276386473488776,0.5876404035069115929588769276386473488776,-0.6944872631866827800506898357622567712673,0.6944872631866827800506898357622567712673,-0.7878168059792081620042779554083515213881,0.7878168059792081620042779554083515213881,-0.8658125777203001365364256370193787290847,0.8658125777203001365364256370193787290847,-0.9269567721871740005206929392590531966353,0.9269567721871740005206929392590531966353,-0.9700604978354287271239509867652687108059,0.9700604978354287271239509867652687108059,-0.9942945854823992920730314211612989803930,0.9942945854823992920730314211612989803930],
[0,-0.1332568242984661109317426822417661370104,0.1332568242984661109317426822417661370104,-0.2641356809703449305338695382833096029790,0.2641356809703449305338695382833096029790,-0.3903010380302908314214888728806054585780,0.3903010380302908314214888728806054585780,-0.5095014778460075496897930478668464305448,0.5095014778460075496897930478668464305448,-0.6196098757636461563850973116495956533871,0.6196098757636461563850973116495956533871,-0.7186613631319501944616244837486188483299,0.7186613631319501944616244837486188483299,-0.8048884016188398921511184069967785579414,0.8048884016188398921511184069967785579414,-0.8767523582704416673781568859341456716389,0.8767523582704416673781568859341456716389,-0.9329710868260161023491969890384229782357,0.9329710868260161023491969890384229782357,-0.9725424712181152319560240768207773751816,0.9725424712181152319560240768207773751816,-0.9947693349975521235239257154455743605736,0.9947693349975521235239257154455743605736],
[-0.0640568928626056260850430826247450385909,0.0640568928626056260850430826247450385909,-0.1911188674736163091586398207570696318404,0.1911188674736163091586398207570696318404,-0.3150426796961633743867932913198102407864,0.3150426796961633743867932913198102407864,-0.4337935076260451384870842319133497124524,0.4337935076260451384870842319133497124524,-0.5454214713888395356583756172183723700107,0.5454214713888395356583756172183723700107,-0.6480936519369755692524957869107476266696,0.6480936519369755692524957869107476266696,-0.7401241915785543642438281030999784255232,0.7401241915785543642438281030999784255232,-0.8200019859739029219539498726697452080761,0.8200019859739029219539498726697452080761,-0.8864155270044010342131543419821967550873,0.8864155270044010342131543419821967550873,-0.9382745520027327585236490017087214496548,0.9382745520027327585236490017087214496548,-0.9747285559713094981983919930081690617411,0.9747285559713094981983919930081690617411,-0.9951872199970213601799974097007368118745,0.9951872199970213601799974097007368118745]
];
// Legendre-Gauss weights (wi values, defined by a function linked to in the Bezier primer article)
var cValues = [
[],[],
[1.0,1.0],
[0.8888888888888888888888888888888888888888,0.5555555555555555555555555555555555555555,0.5555555555555555555555555555555555555555],
[0.6521451548625461426269360507780005927646,0.6521451548625461426269360507780005927646,0.3478548451374538573730639492219994072353,0.3478548451374538573730639492219994072353],
[0.5688888888888888888888888888888888888888,0.4786286704993664680412915148356381929122,0.4786286704993664680412915148356381929122,0.2369268850561890875142640407199173626432,0.2369268850561890875142640407199173626432],
[0.3607615730481386075698335138377161116615,0.3607615730481386075698335138377161116615,0.4679139345726910473898703439895509948116,0.4679139345726910473898703439895509948116,0.1713244923791703450402961421727328935268,0.1713244923791703450402961421727328935268],
[0.4179591836734693877551020408163265306122,0.3818300505051189449503697754889751338783,0.3818300505051189449503697754889751338783,0.2797053914892766679014677714237795824869,0.2797053914892766679014677714237795824869,0.1294849661688696932706114326790820183285,0.1294849661688696932706114326790820183285],
[0.3626837833783619829651504492771956121941,0.3626837833783619829651504492771956121941,0.3137066458778872873379622019866013132603,0.3137066458778872873379622019866013132603,0.2223810344533744705443559944262408844301,0.2223810344533744705443559944262408844301,0.1012285362903762591525313543099621901153,0.1012285362903762591525313543099621901153],
[0.3302393550012597631645250692869740488788,0.1806481606948574040584720312429128095143,0.1806481606948574040584720312429128095143,0.0812743883615744119718921581105236506756,0.0812743883615744119718921581105236506756,0.3123470770400028400686304065844436655987,0.3123470770400028400686304065844436655987,0.2606106964029354623187428694186328497718,0.2606106964029354623187428694186328497718],
[0.2955242247147528701738929946513383294210,0.2955242247147528701738929946513383294210,0.2692667193099963550912269215694693528597,0.2692667193099963550912269215694693528597,0.2190863625159820439955349342281631924587,0.2190863625159820439955349342281631924587,0.1494513491505805931457763396576973324025,0.1494513491505805931457763396576973324025,0.0666713443086881375935688098933317928578,0.0666713443086881375935688098933317928578],
[0.2729250867779006307144835283363421891560,0.2628045445102466621806888698905091953727,0.2628045445102466621806888698905091953727,0.2331937645919904799185237048431751394317,0.2331937645919904799185237048431751394317,0.1862902109277342514260976414316558916912,0.1862902109277342514260976414316558916912,0.1255803694649046246346942992239401001976,0.1255803694649046246346942992239401001976,0.0556685671161736664827537204425485787285,0.0556685671161736664827537204425485787285],
[0.2491470458134027850005624360429512108304,0.2491470458134027850005624360429512108304,0.2334925365383548087608498989248780562594,0.2334925365383548087608498989248780562594,0.2031674267230659217490644558097983765065,0.2031674267230659217490644558097983765065,0.1600783285433462263346525295433590718720,0.1600783285433462263346525295433590718720,0.1069393259953184309602547181939962242145,0.1069393259953184309602547181939962242145,0.0471753363865118271946159614850170603170,0.0471753363865118271946159614850170603170],
[0.2325515532308739101945895152688359481566,0.2262831802628972384120901860397766184347,0.2262831802628972384120901860397766184347,0.2078160475368885023125232193060527633865,0.2078160475368885023125232193060527633865,0.1781459807619457382800466919960979955128,0.1781459807619457382800466919960979955128,0.1388735102197872384636017768688714676218,0.1388735102197872384636017768688714676218,0.0921214998377284479144217759537971209236,0.0921214998377284479144217759537971209236,0.0404840047653158795200215922009860600419,0.0404840047653158795200215922009860600419],
[0.2152638534631577901958764433162600352749,0.2152638534631577901958764433162600352749,0.2051984637212956039659240656612180557103,0.2051984637212956039659240656612180557103,0.1855383974779378137417165901251570362489,0.1855383974779378137417165901251570362489,0.1572031671581935345696019386238421566056,0.1572031671581935345696019386238421566056,0.1215185706879031846894148090724766259566,0.1215185706879031846894148090724766259566,0.0801580871597602098056332770628543095836,0.0801580871597602098056332770628543095836,0.0351194603317518630318328761381917806197,0.0351194603317518630318328761381917806197],
[0.2025782419255612728806201999675193148386,0.1984314853271115764561183264438393248186,0.1984314853271115764561183264438393248186,0.1861610000155622110268005618664228245062,0.1861610000155622110268005618664228245062,0.1662692058169939335532008604812088111309,0.1662692058169939335532008604812088111309,0.1395706779261543144478047945110283225208,0.1395706779261543144478047945110283225208,0.1071592204671719350118695466858693034155,0.1071592204671719350118695466858693034155,0.0703660474881081247092674164506673384667,0.0703660474881081247092674164506673384667,0.0307532419961172683546283935772044177217,0.0307532419961172683546283935772044177217],
[0.1894506104550684962853967232082831051469,0.1894506104550684962853967232082831051469,0.1826034150449235888667636679692199393835,0.1826034150449235888667636679692199393835,0.1691565193950025381893120790303599622116,0.1691565193950025381893120790303599622116,0.1495959888165767320815017305474785489704,0.1495959888165767320815017305474785489704,0.1246289712555338720524762821920164201448,0.1246289712555338720524762821920164201448,0.0951585116824927848099251076022462263552,0.0951585116824927848099251076022462263552,0.0622535239386478928628438369943776942749,0.0622535239386478928628438369943776942749,0.0271524594117540948517805724560181035122,0.0271524594117540948517805724560181035122],
[0.1794464703562065254582656442618856214487,0.1765627053669926463252709901131972391509,0.1765627053669926463252709901131972391509,0.1680041021564500445099706637883231550211,0.1680041021564500445099706637883231550211,0.1540457610768102880814315948019586119404,0.1540457610768102880814315948019586119404,0.1351363684685254732863199817023501973721,0.1351363684685254732863199817023501973721,0.1118838471934039710947883856263559267358,0.1118838471934039710947883856263559267358,0.0850361483171791808835353701910620738504,0.0850361483171791808835353701910620738504,0.0554595293739872011294401653582446605128,0.0554595293739872011294401653582446605128,0.0241483028685479319601100262875653246916,0.0241483028685479319601100262875653246916],
[0.1691423829631435918406564701349866103341,0.1691423829631435918406564701349866103341,0.1642764837458327229860537764659275904123,0.1642764837458327229860537764659275904123,0.1546846751262652449254180038363747721932,0.1546846751262652449254180038363747721932,0.1406429146706506512047313037519472280955,0.1406429146706506512047313037519472280955,0.1225552067114784601845191268002015552281,0.1225552067114784601845191268002015552281,0.1009420441062871655628139849248346070628,0.1009420441062871655628139849248346070628,0.0764257302548890565291296776166365256053,0.0764257302548890565291296776166365256053,0.0497145488949697964533349462026386416808,0.0497145488949697964533349462026386416808,0.0216160135264833103133427102664524693876,0.0216160135264833103133427102664524693876],
[0.1610544498487836959791636253209167350399,0.1589688433939543476499564394650472016787,0.1589688433939543476499564394650472016787,0.1527660420658596667788554008976629984610,0.1527660420658596667788554008976629984610,0.1426067021736066117757461094419029724756,0.1426067021736066117757461094419029724756,0.1287539625393362276755157848568771170558,0.1287539625393362276755157848568771170558,0.1115666455473339947160239016817659974813,0.1115666455473339947160239016817659974813,0.0914900216224499994644620941238396526609,0.0914900216224499994644620941238396526609,0.0690445427376412265807082580060130449618,0.0690445427376412265807082580060130449618,0.0448142267656996003328381574019942119517,0.0448142267656996003328381574019942119517,0.0194617882297264770363120414644384357529,0.0194617882297264770363120414644384357529],
[0.1527533871307258506980843319550975934919,0.1527533871307258506980843319550975934919,0.1491729864726037467878287370019694366926,0.1491729864726037467878287370019694366926,0.1420961093183820513292983250671649330345,0.1420961093183820513292983250671649330345,0.1316886384491766268984944997481631349161,0.1316886384491766268984944997481631349161,0.1181945319615184173123773777113822870050,0.1181945319615184173123773777113822870050,0.1019301198172404350367501354803498761666,0.1019301198172404350367501354803498761666,0.0832767415767047487247581432220462061001,0.0832767415767047487247581432220462061001,0.0626720483341090635695065351870416063516,0.0626720483341090635695065351870416063516,0.0406014298003869413310399522749321098790,0.0406014298003869413310399522749321098790,0.0176140071391521183118619623518528163621,0.0176140071391521183118619623518528163621],
[0.1460811336496904271919851476833711882448,0.1445244039899700590638271665537525436099,0.1445244039899700590638271665537525436099,0.1398873947910731547221334238675831108927,0.1398873947910731547221334238675831108927,0.1322689386333374617810525744967756043290,0.1322689386333374617810525744967756043290,0.1218314160537285341953671771257335983563,0.1218314160537285341953671771257335983563,0.1087972991671483776634745780701056420336,0.1087972991671483776634745780701056420336,0.0934444234560338615532897411139320884835,0.0934444234560338615532897411139320884835,0.0761001136283793020170516533001831792261,0.0761001136283793020170516533001831792261,0.0571344254268572082836358264724479574912,0.0571344254268572082836358264724479574912,0.0369537897708524937999506682993296661889,0.0369537897708524937999506682993296661889,0.0160172282577743333242246168584710152658,0.0160172282577743333242246168584710152658],
[0.1392518728556319933754102483418099578739,0.1392518728556319933754102483418099578739,0.1365414983460151713525738312315173965863,0.1365414983460151713525738312315173965863,0.1311735047870623707329649925303074458757,0.1311735047870623707329649925303074458757,0.1232523768105124242855609861548144719594,0.1232523768105124242855609861548144719594,0.1129322960805392183934006074217843191142,0.1129322960805392183934006074217843191142,0.1004141444428809649320788378305362823508,0.1004141444428809649320788378305362823508,0.0859416062170677274144436813727028661891,0.0859416062170677274144436813727028661891,0.0697964684245204880949614189302176573987,0.0697964684245204880949614189302176573987,0.0522933351526832859403120512732112561121,0.0522933351526832859403120512732112561121,0.0337749015848141547933022468659129013491,0.0337749015848141547933022468659129013491,0.0146279952982722006849910980471854451902,0.0146279952982722006849910980471854451902],
[0.1336545721861061753514571105458443385831,0.1324620394046966173716424647033169258050,0.1324620394046966173716424647033169258050,0.1289057221880821499785953393997936532597,0.1289057221880821499785953393997936532597,0.1230490843067295304675784006720096548158,0.1230490843067295304675784006720096548158,0.1149966402224113649416435129339613014914,0.1149966402224113649416435129339613014914,0.1048920914645414100740861850147438548584,0.1048920914645414100740861850147438548584,0.0929157660600351474770186173697646486034,0.0929157660600351474770186173697646486034,0.0792814117767189549228925247420432269137,0.0792814117767189549228925247420432269137,0.0642324214085258521271696151589109980391,0.0642324214085258521271696151589109980391,0.0480376717310846685716410716320339965612,0.0480376717310846685716410716320339965612,0.0309880058569794443106942196418845053837,0.0309880058569794443106942196418845053837,0.0134118594871417720813094934586150649766,0.0134118594871417720813094934586150649766],
[0.1279381953467521569740561652246953718517,0.1279381953467521569740561652246953718517,0.1258374563468282961213753825111836887264,0.1258374563468282961213753825111836887264,0.1216704729278033912044631534762624256070,0.1216704729278033912044631534762624256070,0.1155056680537256013533444839067835598622,0.1155056680537256013533444839067835598622,0.1074442701159656347825773424466062227946,0.1074442701159656347825773424466062227946,0.0976186521041138882698806644642471544279,0.0976186521041138882698806644642471544279,0.0861901615319532759171852029837426671850,0.0861901615319532759171852029837426671850,0.0733464814110803057340336152531165181193,0.0733464814110803057340336152531165181193,0.0592985849154367807463677585001085845412,0.0592985849154367807463677585001085845412,0.0442774388174198061686027482113382288593,0.0442774388174198061686027482113382288593,0.0285313886289336631813078159518782864491,0.0285313886289336631813078159518782864491,0.0123412297999871995468056670700372915759,0.0123412297999871995468056670700372915759]
];
// LUT for binomial coefficient arrays per curve order 'n'
var binomialCoefficients = [[1], [1, 1], [1, 2, 1], [1, 3, 3, 1]];
// Look up what the binomial coefficient is for pair {n,k}
function binomials(n, k) {
return binomialCoefficients[n][k];
}
/**
* Compute the curve derivative (hodograph) at t.
*/
function getDerivative(derivative, t, vs) {
// the derivative of any 't'-less function is zero.
var n = vs.length - 1,
_vs,
value,
k;
if (n === 0) {
return 0;
}
// direct values? compute!
if (derivative === 0) {
value = 0;
for (k = 0; k <= n; k++) {
value += binomials(n, k) * Math.pow(1 - t, n - k) * Math.pow(t, k) * vs[k];
}
return value;
} else {
// Still some derivative? go down one order, then try
// for the lower order curve's.
_vs = new Array(n);
for (k = 0; k < n; k++) {
_vs[k] = n * (vs[k + 1] - vs[k]);
}
return getDerivative(derivative - 1, t, _vs);
}
}
function B(xs, ys, t) {
var xbase = getDerivative(1, t, xs);
var ybase = getDerivative(1, t, ys);
var combined = xbase * xbase + ybase * ybase;
return Math.sqrt(combined);
}
function getCubicArcLength(xs, ys, t) {
var z, sum, i, correctedT;
/*if (xs.length >= tValues.length) {
throw new Error('too high n bezier');
}*/
if (t === undefined) {
t = 1;
}
var n = 20;
z = t / 2;
sum = 0;
for (i = 0; i < n; i++) {
correctedT = z * tValues[n][i] + z;
sum += cValues[n][i] * B(xs, ys, correctedT);
}
return z * sum;
}
function LinearPosition(x0, x1, y0, y1) {
return new LinearPosition$1(x0, x1, y0, y1);
}
function LinearPosition$1(x0, x1, y0, y1){
this.x0 = x0;
this.x1 = x1;
this.y0 = y0;
this.y1 = y1;
}
LinearPosition$1.prototype.getLength = function(){
return Math.sqrt(Math.pow(this.x0 - this.x1, 2) +
Math.pow(this.y0 - this.y1, 2));
};
LinearPosition$1.prototype.getPointAtLength = function(pos){
var fraction = pos/ (Math.sqrt(Math.pow(this.x0 - this.x1, 2) +
Math.pow(this.y0 - this.y1, 2)));
var newDeltaX = (this.x1 - this.x0)*fraction;
var newDeltaY = (this.y1 - this.y0)*fraction;
return { x: this.x0 + newDeltaX, y: this.y0 + newDeltaY };
};
function pathProperties(svgString) {
var length = 0;
var partial_lengths = [];
var functions = [];
function svgProperties(string){
var parsed = parse(string);
var cur = [0, 0];
var prev_point = [0, 0];
var curve;
for (var i = 0; i < parsed.length; i++){
//moveTo
if(parsed[i][0] === "M"){
cur = [parsed[i][1], parsed[i][2]];
functions.push(null);
} else if(parsed[i][0] === "m"){
cur = [parsed[i][1] + cur[0], parsed[i][2] + cur[1]];
functions.push(null);
}
//lineTo
else if(parsed[i][0] === "L"){
length = length + Math.sqrt(Math.pow(cur[0] - parsed[i][1], 2) + Math.pow(cur[1] - parsed[i][2], 2));
functions.push(new LinearPosition(cur[0], parsed[i][1], cur[1], parsed[i][2]));
cur = [parsed[i][1], parsed[i][2]];
} else if(parsed[i][0] === "l"){
length = length + Math.sqrt(Math.pow(parsed[i][1], 2) + Math.pow(parsed[i][2], 2));
cur = [parsed[i][1] + cur[0], parsed[i][2] + cur[1]];
functions.push();
} else if(parsed[i][0] === "H"){
length = length + Math.abs(cur[0] - parsed[i][1]);
functions.push(new LinearPosition(cur[0], parsed[i][1], cur[1], cur[1]));
cur[0] = parsed[i][1];
} else if(parsed[i][0] === "h"){
length = length + Math.abs(parsed[i][1]);
functions.push(new LinearPosition(cur[0], cur[0] + parsed[i][1], cur[1], cur[1]));
cur[0] = parsed[i][1] + cur[0];
} else if(parsed[i][0] === "V"){
length = length + Math.abs(cur[1] - parsed[i][1]);
functions.push(new LinearPosition(cur[0], cur[0], cur[1], parsed[i][1]));
cur[1] = parsed[i][1];
} else if(parsed[i][0] === "v"){
length = length + Math.abs(parsed[i][1]);
functions.push(new LinearPosition(cur[0], cur[0], cur[1], cur[1] + parsed[i][1]));
cur[1] = parsed[i][1] + cur[1];
functions.push();
//Close path
} else if(parsed[i][0] === "z" || parsed[i][0] === "Z"){
length = length + Math.sqrt(Math.pow(parsed[0][1] - cur[0], 2) + Math.pow(parsed[0][2] - cur[1], 2));
functions.push(new LinearPosition(cur[0], parsed[0][1], cur[1], parsed[0][2]));
cur = [parsed[0][1], parsed[0][2]];
}
//Cubic Bezier curves
else if(parsed[i][0] === "C"){
curve = new Bezier(cur[0], cur[1] , parsed[i][1], parsed[i][2] , parsed[i][3], parsed[i][4] , parsed[i][5], parsed[i][6]);
length = length + curve.getLength();
cur = [parsed[i][5], parsed[i][6]];
functions.push(curve);
} else if(parsed[i][0] === "c"){
curve = new Bezier(cur[0], cur[1] , cur[0] + parsed[i][1], cur[1] + parsed[i][2] , cur[0] + parsed[i][3], cur[1] + parsed[i][4] , cur[0] + parsed[i][5], cur[1] + parsed[i][6]);
length = length + curve.getLength();
cur = [parsed[i][5] + cur[0], parsed[i][6] + cur[1]];
functions.push(curve);
} else if(parsed[i][0] === "S"){
if(i>0 && ["C","c","S","s"].indexOf(parsed[i-1][0]) > -1){
curve = new Bezier(cur[0], cur[1] , cur[0] + parsed[i][1] - parsed[i][3], cur[1] + parsed[i][2] - parsed[i][4], parsed[i][1], parsed[i][2] , parsed[i][3], parsed[i][4]);
} else {
curve = new Bezier(cur[0], cur[1] , cur[0], cur[1], parsed[i][1], parsed[i][2] , parsed[i][3], parsed[i][4]);
}
length = length + curve.getLength();
cur = [parsed[i][3], parsed[i][4]];
functions.push(curve);
} else if(parsed[i][0] === "s"){
if(i>0 && ["C","c","S","s"].indexOf(parsed[i-1][0]) > -1){
curve = new Bezier(cur[0], cur[1] , cur[0] + parsed[i][1] - parsed[i][3], cur[1] + parsed[i][2] - parsed[i][4], cur[0] + parsed[i][1], cur[1] + parsed[i][2] , cur[0] + parsed[i][3], cur[1] + parsed[i][4]);
} else {
curve = new Bezier(cur[0], cur[1] , cur[0], cur[1], cur[0] + parsed[i][1], cur[1] + parsed[i][2] , cur[0] + parsed[i][3], cur[1] + parsed[i][4]);
}
length = length + curve.getLength();
cur = [parsed[i][3] + cur[0], parsed[i][4] + cur[1]];
functions.push(curve);
}
//Quadratic Bezier curves
else if(parsed[i][0] === "Q"){
curve = new Bezier(cur[0], cur[1] , parsed[i][1], parsed[i][2] , parsed[i][3], parsed[i][4]);
length = length + curve.getLength();
functions.push(curve);
cur = [parsed[i][3], parsed[i][4]];
prev_point = [parsed[i][1], parsed[i][2]];
} else if(parsed[i][0] === "q"){
curve = new Bezier(cur[0], cur[1] , cur[0] + parsed[i][1], cur[1] + parsed[i][2] , cur[0] + parsed[i][3], cur[1] + parsed[i][4]);
length = length + curve.getLength();
prev_point = [cur[0] + parsed[i][1], cur[1] + parsed[i][2]];
cur = [parsed[i][3] + cur[0], parsed[i][4] + cur[1]];
functions.push(curve);
} else if(parsed[i][0] === "T"){
if(i>0 && ["Q","q","T","t"].indexOf(parsed[i-1][0]) > -1){
curve = new Bezier(cur[0], cur[1] , 2 * cur[0] - prev_point[0] , 2 * cur[1] - prev_point[1] , parsed[i][1], parsed[i][2]);
} else {
curve = new LinearPosition(cur[0], parsed[i][1], cur[1], parsed[i][2]);
}
functions.push(curve);
length = length + curve.getLength();
prev_point = [2 * cur[0] - prev_point[0] , 2 * cur[1] - prev_point[1]];
cur = [parsed[i][1], parsed[i][2]];
} else if(parsed[i][0] === "t"){
if(i>0 && ["Q","q","T","t"].indexOf(parsed[i-1][0]) > -1){
curve = new Bezier(cur[0], cur[1] , 2 * cur[0] - prev_point[0] , 2 * cur[1] - prev_point[1] , cur[0] + parsed[i][1], cur[1] + parsed[i][2]);
} else {
curve = new LinearPosition(cur[0], cur[0] + parsed[i][1], cur[1], cur[1] + parsed[i][2]);
}
length = length + curve.getLength();
prev_point = [2 * cur[0] - prev_point[0] , 2 * cur[1] - prev_point[1]];
cur = [parsed[i][1] + cur[0], parsed[i][2] + cur[0]];
functions.push(curve);
}
partial_lengths.push(length);
}
return svgProperties;
}
svgProperties.getLength = function(){
return length;
};
svgProperties.getPointAtLength = function(fractionLength){
if(fractionLength < 0){
fractionLength = 0;
} else if(fractionLength > length){
fractionLength = length;
}
var i = partial_lengths.length - 1;
while(partial_lengths[i] >= fractionLength && partial_lengths[i] > 0){
i--;
}
i++;
var fractionPart = fractionLength-partial_lengths[i-1];
return functions[i].getPointAtLength(fractionPart);
};
return svgProperties(svgString);
}
exports.svgPathProperties = pathProperties;
exports.parse = parse;
exports.Bezier = Bezier;
Object.defineProperty(exports, '__esModule', { value: true });
}));
// http://geoexamples.com/path-properties/ Version 0.0.1. Copyright 2016 Roger Veciana i Rovira.
!function(t,h){"object"==typeof exports&&"undefined"!=typeof module?h(exports):"function"==typeof define&&define.amd?define(["exports"],h):h(t.spp=t.spp||{})}(this,function(t){"use strict";function h(t){var h=[];return t.replace(x,function(t,e,s){var i=e.toLowerCase();for(s=n(s),"m"===i&&s.length>2&&(h.push([e].concat(s.splice(0,2))),i="l",e="m"===e?"l":"L");s.length>=0;){if(s.length===y[i])return s.unshift(e),h.push(s);if(s.length<y[i])throw new Error("malformed path data");h.push([e].concat(s.splice(0,y[i])))}}),h}function n(t){var h=t.match(M);return h?h.map(Number):[]}function e(t,h,n,e,i,r,o,a){return new s(t,h,n,e,i,r,o,a)}function s(t,h,n,e,s,a,u,p){this.a={x:t,y:h},this.b={x:n,y:e},this.c={x:s,y:a},this.d={x:u,y:p},u&&p?(this.getArcLength=g,this.getPoint=r):(this.getArcLength=o,this.getPoint=i),this.init()}function i(t,h,n){var e=(1-n)*(1-n)*t[0]+2*(1-n)*n*t[1]+n*n*t[2],s=(1-n)*(1-n)*h[0]+2*(1-n)*n*h[1]+n*n*h[2];return{x:e,y:s}}function r(t,h,n){var e=(1-n)*(1-n)*(1-n)*t[0]+3*(1-n)*(1-n)*n*t[1]+3*(1-n)*n*n*t[2]+n*n*n*t[3],s=(1-n)*(1-n)*(1-n)*h[0]+3*(1-n)*(1-n)*n*h[1]+3*(1-n)*n*n*h[2]+n*n*n*h[3];return{x:e,y:s}}function o(t,h,n){void 0===n&&(n=1);var e=t[0]-2*t[1]+t[2],s=h[0]-2*h[1]+h[2],i=2*t[1]-2*t[0],r=2*h[1]-2*h[0],o=4*(e*e+s*s),a=4*(e*i+s*r),u=i*i+r*r,p=a/(2*o),g=u/o,c=n+p,f=g-p*p;return Math.sqrt(o)/2*(c*Math.sqrt(c*c+f)-p*Math.sqrt(p*p+f)+f*Math.log(Math.abs((c+Math.sqrt(c*c+f))/(p+Math.sqrt(p*p+f)))))}function a(t,h){return d[t][h]}function u(t,h,n){var e,s,i,r=n.length-1;if(0===r)return 0;if(0===t){for(s=0,i=0;i<=r;i++)s+=a(r,i)*Math.pow(1-h,r-i)*Math.pow(h,i)*n[i];return s}for(e=new Array(r),i=0;i<r;i++)e[i]=r*(n[i+1]-n[i]);return u(t-1,h,e)}function p(t,h,n){var e=u(1,n,t),s=u(1,n,h),i=e*e+s*s;return Math.sqrt(i)}function g(t,h,n){var e,s,i,r;void 0===n&&(n=1);var o=20;for(e=n/2,s=0,i=0;i<o;i++)r=e*l[o][i]+e,s+=v[o][i]*p(t,h,r);return e*s}function c(t,h,n,e){return new f(t,h,n,e)}function f(t,h,n,e){this.x0=t,this.x1=h,this.y0=n,this.y1=e}function w(t){function n(t){for(var o,a=h(t),u=[0,0],p=[0,0],g=0;g<a.length;g++)"M"===a[g][0]?(u=[a[g][1],a[g][2]],r.push(null)):"m"===a[g][0]?(u=[a[g][1]+u[0],a[g][2]+u[1]],r.push(null)):"L"===a[g][0]?(s+=Math.sqrt(Math.pow(u[0]-a[g][1],2)+Math.pow(u[1]-a[g][2],2)),r.push(new c(u[0],a[g][1],u[1],a[g][2])),u=[a[g][1],a[g][2]]):"l"===a[g][0]?(s+=Math.sqrt(Math.pow(a[g][1],2)+Math.pow(a[g][2],2)),u=[a[g][1]+u[0],a[g][2]+u[1]],r.push()):"H"===a[g][0]?(s+=Math.abs(u[0]-a[g][1]),r.push(new c(u[0],a[g][1],u[1],u[1])),u[0]=a[g][1]):"h"===a[g][0]?(s+=Math.abs(a[g][1]),r.push(new c(u[0],u[0]+a[g][1],u[1],u[1])),u[0]=a[g][1]+u[0]):"V"===a[g][0]?(s+=Math.abs(u[1]-a[g][1]),r.push(new c(u[0],u[0],u[1],a[g][1])),u[1]=a[g][1]):"v"===a[g][0]?(s+=Math.abs(a[g][1]),r.push(new c(u[0],u[0],u[1],u[1]+a[g][1])),u[1]=a[g][1]+u[1],r.push()):"z"===a[g][0]||"Z"===a[g][0]?(s+=Math.sqrt(Math.pow(a[0][1]-u[0],2)+Math.pow(a[0][2]-u[1],2)),r.push(new c(u[0],a[0][1],u[1],a[0][2])),u=[a[0][1],a[0][2]]):"C"===a[g][0]?(o=new e(u[0],u[1],a[g][1],a[g][2],a[g][3],a[g][4],a[g][5],a[g][6]),s+=o.getLength(),u=[a[g][5],a[g][6]],r.push(o)):"c"===a[g][0]?(o=new e(u[0],u[1],u[0]+a[g][1],u[1]+a[g][2],u[0]+a[g][3],u[1]+a[g][4],u[0]+a[g][5],u[1]+a[g][6]),s+=o.getLength(),u=[a[g][5]+u[0],a[g][6]+u[1]],r.push(o)):"S"===a[g][0]?(o=g>0&&["C","c","S","s"].indexOf(a[g-1][0])>-1?new e(u[0],u[1],u[0]+a[g][1]-a[g][3],u[1]+a[g][2]-a[g][4],a[g][1],a[g][2],a[g][3],a[g][4]):new e(u[0],u[1],u[0],u[1],a[g][1],a[g][2],a[g][3],a[g][4]),s+=o.getLength(),u=[a[g][3],a[g][4]],r.push(o)):"s"===a[g][0]?(o=g>0&&["C","c","S","s"].indexOf(a[g-1][0])>-1?new e(u[0],u[1],u[0]+a[g][1]-a[g][3],u[1]+a[g][2]-a[g][4],u[0]+a[g][1],u[1]+a[g][2],u[0]+a[g][3],u[1]+a[g][4]):new e(u[0],u[1],u[0],u[1],u[0]+a[g][1],u[1]+a[g][2],u[0]+a[g][3],u[1]+a[g][4]),s+=o.getLength(),u=[a[g][3]+u[0],a[g][4]+u[1]],r.push(o)):"Q"===a[g][0]?(o=new e(u[0],u[1],a[g][1],a[g][2],a[g][3],a[g][4]),s+=o.getLength(),r.push(o),u=[a[g][3],a[g][4]],p=[a[g][1],a[g][2]]):"q"===a[g][0]?(o=new e(u[0],u[1],u[0]+a[g][1],u[1]+a[g][2],u[0]+a[g][3],u[1]+a[g][4]),s+=o.getLength(),p=[u[0]+a[g][1],u[1]+a[g][2]],u=[a[g][3]+u[0],a[g][4]+u[1]],r.push(o)):"T"===a[g][0]?(o=g>0&&["Q","q","T","t"].indexOf(a[g-1][0])>-1?new e(u[0],u[1],2*u[0]-p[0],2*u[1]-p[1],a[g][1],a[g][2]):new c(u[0],a[g][1],u[1],a[g][2]),r.push(o),s+=o.getLength(),p=[2*u[0]-p[0],2*u[1]-p[1]],u=[a[g][1],a[g][2]]):"t"===a[g][0]&&(o=g>0&&["Q","q","T","t"].indexOf(a[g-1][0])>-1?new e(u[0],u[1],2*u[0]-p[0],2*u[1]-p[1],u[0]+a[g][1],u[1]+a[g][2]):new c(u[0],u[0]+a[g][1],u[1],u[1]+a[g][2]),s+=o.getLength(),p=[2*u[0]-p[0],2*u[1]-p[1]],u=[a[g][1]+u[0],a[g][2]+u[0]],r.push(o)),i.push(s);return n}var s=0,i=[],r=[];return n.getLength=function(){return s},n.getPointAtLength=function(t){t<0?t=0:t>s&&(t=s);for(var h=i.length-1;i[h]>=t&&i[h]>0;)h--;h++;var n=t-i[h-1];return r[h].getPointAtLength(n)},n(t)}var y={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},x=/([astvzqmhlc])([^astvzqmhlc]*)/gi,M=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/gi;s.prototype={constructor:s,init:function(){this.length=this.getArcLength([this.a.x,this.b.x,this.c.x,this.d.x],[this.a.y,this.b.y,this.c.y,this.d.y])},getLength:function(){return this.length},getPointAtLength:function(t){for(var h=1,n=t/this.length;h>.008;){var e=this.getArcLength([this.a.x,this.b.x,this.c.x,this.d.x],[this.a.y,this.b.y,this.c.y,this.d.y],n);h=Math.abs(t-e)/this.length,n+=(t-e)/this.length}return this.getPoint([this.a.x,this.b.x,this.c.x,this.d.x],[this.a.y,this.b.y,this.c.y,this.d.y],n)}};var l=[[],[],[-.5773502691896257,.5773502691896257],[0,-.7745966692414834,.7745966692414834],[-.33998104358485626,.33998104358485626,-.8611363115940526,.8611363115940526],[0,-.5384693101056831,.5384693101056831,-.906179845938664,.906179845938664],[.6612093864662645,-.6612093864662645,-.2386191860831969,.2386191860831969,-.932469514203152,.932469514203152],[0,.4058451513773972,-.4058451513773972,-.7415311855993945,.7415311855993945,-.9491079123427585,.9491079123427585],[-.1834346424956498,.1834346424956498,-.525532409916329,.525532409916329,-.7966664774136267,.7966664774136267,-.9602898564975363,.9602898564975363],[0,-.8360311073266358,.8360311073266358,-.9681602395076261,.9681602395076261,-.3242534234038089,.3242534234038089,-.6133714327005904,.6133714327005904],[-.14887433898163122,.14887433898163122,-.4333953941292472,.4333953941292472,-.6794095682990244,.6794095682990244,-.8650633666889845,.8650633666889845,-.9739065285171717,.9739065285171717],[0,-.26954315595234496,.26954315595234496,-.5190961292068118,.5190961292068118,-.7301520055740494,.7301520055740494,-.8870625997680953,.8870625997680953,-.978228658146057,.978228658146057],[-.1252334085114689,.1252334085114689,-.3678314989981802,.3678314989981802,-.5873179542866175,.5873179542866175,-.7699026741943047,.7699026741943047,-.9041172563704749,.9041172563704749,-.9815606342467192,.9815606342467192],[0,-.2304583159551348,.2304583159551348,-.44849275103644687,.44849275103644687,-.6423493394403402,.6423493394403402,-.8015780907333099,.8015780907333099,-.9175983992229779,.9175983992229779,-.9841830547185881,.9841830547185881],[-.10805494870734367,.10805494870734367,-.31911236892788974,.31911236892788974,-.5152486363581541,.5152486363581541,-.6872929048116855,.6872929048116855,-.827201315069765,.827201315069765,-.9284348836635735,.9284348836635735,-.9862838086968123,.9862838086968123],[0,-.20119409399743451,.20119409399743451,-.3941513470775634,.3941513470775634,-.5709721726085388,.5709721726085388,-.7244177313601701,.7244177313601701,-.8482065834104272,.8482065834104272,-.937273392400706,.937273392400706,-.9879925180204854,.9879925180204854],[-.09501250983763744,.09501250983763744,-.2816035507792589,.2816035507792589,-.45801677765722737,.45801677765722737,-.6178762444026438,.6178762444026438,-.755404408355003,.755404408355003,-.8656312023878318,.8656312023878318,-.9445750230732326,.9445750230732326,-.9894009349916499,.9894009349916499],[0,-.17848418149584785,.17848418149584785,-.3512317634538763,.3512317634538763,-.5126905370864769,.5126905370864769,-.6576711592166907,.6576711592166907,-.7815140038968014,.7815140038968014,-.8802391537269859,.8802391537269859,-.9506755217687678,.9506755217687678,-.9905754753144174,.9905754753144174],[-.0847750130417353,.0847750130417353,-.2518862256915055,.2518862256915055,-.41175116146284263,.41175116146284263,-.5597708310739475,.5597708310739475,-.6916870430603532,.6916870430603532,-.8037049589725231,.8037049589725231,-.8926024664975557,.8926024664975557,-.9558239495713977,.9558239495713977,-.9915651684209309,.9915651684209309],[0,-.16035864564022537,.16035864564022537,-.31656409996362983,.31656409996362983,-.46457074137596094,.46457074137596094,-.600545304661681,.600545304661681,-.7209661773352294,.7209661773352294,-.8227146565371428,.8227146565371428,-.9031559036148179,.9031559036148179,-.96020815213483,.96020815213483,-.9924068438435844,.9924068438435844],[-.07652652113349734,.07652652113349734,-.22778585114164507,.22778585114164507,-.37370608871541955,.37370608871541955,-.5108670019508271,.5108670019508271,-.636053680726515,.636053680726515,-.7463319064601508,.7463319064601508,-.8391169718222188,.8391169718222188,-.912234428251326,.912234428251326,-.9639719272779138,.9639719272779138,-.9931285991850949,.9931285991850949],[0,-.1455618541608951,.1455618541608951,-.2880213168024011,.2880213168024011,-.4243421202074388,.4243421202074388,-.5516188358872198,.5516188358872198,-.6671388041974123,.6671388041974123,-.7684399634756779,.7684399634756779,-.8533633645833173,.8533633645833173,-.9200993341504008,.9200993341504008,-.9672268385663063,.9672268385663063,-.9937521706203895,.9937521706203895],[-.06973927331972223,.06973927331972223,-.20786042668822127,.20786042668822127,-.34193582089208424,.34193582089208424,-.469355837986757,.469355837986757,-.5876404035069116,.5876404035069116,-.6944872631866827,.6944872631866827,-.7878168059792081,.7878168059792081,-.8658125777203002,.8658125777203002,-.926956772187174,.926956772187174,-.9700604978354287,.9700604978354287,-.9942945854823992,.9942945854823992],[0,-.1332568242984661,.1332568242984661,-.26413568097034495,.26413568097034495,-.3903010380302908,.3903010380302908,-.5095014778460075,.5095014778460075,-.6196098757636461,.6196098757636461,-.7186613631319502,.7186613631319502,-.8048884016188399,.8048884016188399,-.8767523582704416,.8767523582704416,-.9329710868260161,.9329710868260161,-.9725424712181152,.9725424712181152,-.9947693349975522,.9947693349975522],[-.06405689286260563,.06405689286260563,-.1911188674736163,.1911188674736163,-.3150426796961634,.3150426796961634,-.4337935076260451,.4337935076260451,-.5454214713888396,.5454214713888396,-.6480936519369755,.6480936519369755,-.7401241915785544,.7401241915785544,-.820001985973903,.820001985973903,-.8864155270044011,.8864155270044011,-.9382745520027328,.9382745520027328,-.9747285559713095,.9747285559713095,-.9951872199970213,.9951872199970213]],v=[[],[],[1,1],[.8888888888888888,.5555555555555556,.5555555555555556],[.6521451548625461,.6521451548625461,.34785484513745385,.34785484513745385],[.5688888888888889,.47862867049936647,.47862867049936647,.23692688505618908,.23692688505618908],[.3607615730481386,.3607615730481386,.46791393457269104,.46791393457269104,.17132449237917036,.17132449237917036],[.4179591836734694,.3818300505051189,.3818300505051189,.27970539148927664,.27970539148927664,.1294849661688697,.1294849661688697],[.362683783378362,.362683783378362,.31370664587788727,.31370664587788727,.22238103445337448,.22238103445337448,.10122853629037626,.10122853629037626],[.3302393550012598,.1806481606948574,.1806481606948574,.08127438836157441,.08127438836157441,.31234707704000286,.31234707704000286,.26061069640293544,.26061069640293544],[.29552422471475287,.29552422471475287,.26926671930999635,.26926671930999635,.21908636251598204,.21908636251598204,.1494513491505806,.1494513491505806,.06667134430868814,.06667134430868814],[.2729250867779006,.26280454451024665,.26280454451024665,.23319376459199048,.23319376459199048,.18629021092773426,.18629021092773426,.1255803694649046,.1255803694649046,.05566856711617366,.05566856711617366],[.24914704581340277,.24914704581340277,.2334925365383548,.2334925365383548,.20316742672306592,.20316742672306592,.16007832854334622,.16007832854334622,.10693932599531843,.10693932599531843,.04717533638651183,.04717533638651183],[.2325515532308739,.22628318026289723,.22628318026289723,.2078160475368885,.2078160475368885,.17814598076194574,.17814598076194574,.13887351021978725,.13887351021978725,.09212149983772845,.09212149983772845,.04048400476531588,.04048400476531588],[.2152638534631578,.2152638534631578,.2051984637212956,.2051984637212956,.18553839747793782,.18553839747793782,.15720316715819355,.15720316715819355,.12151857068790319,.12151857068790319,.08015808715976021,.08015808715976021,.03511946033175186,.03511946033175186],[.2025782419255613,.19843148532711158,.19843148532711158,.1861610000155622,.1861610000155622,.16626920581699392,.16626920581699392,.13957067792615432,.13957067792615432,.10715922046717194,.10715922046717194,.07036604748810812,.07036604748810812,.03075324199611727,.03075324199611727],[.1894506104550685,.1894506104550685,.18260341504492358,.18260341504492358,.16915651939500254,.16915651939500254,.14959598881657674,.14959598881657674,.12462897125553388,.12462897125553388,.09515851168249279,.09515851168249279,.062253523938647894,.062253523938647894,.027152459411754096,.027152459411754096],[.17944647035620653,.17656270536699264,.17656270536699264,.16800410215645004,.16800410215645004,.15404576107681028,.15404576107681028,.13513636846852548,.13513636846852548,.11188384719340397,.11188384719340397,.08503614831717918,.08503614831717918,.0554595293739872,.0554595293739872,.02414830286854793,.02414830286854793],[.1691423829631436,.1691423829631436,.16427648374583273,.16427648374583273,.15468467512626524,.15468467512626524,.14064291467065065,.14064291467065065,.12255520671147846,.12255520671147846,.10094204410628717,.10094204410628717,.07642573025488905,.07642573025488905,.0497145488949698,.0497145488949698,.02161601352648331,.02161601352648331],[.1610544498487837,.15896884339395434,.15896884339395434,.15276604206585967,.15276604206585967,.1426067021736066,.1426067021736066,.12875396253933621,.12875396253933621,.11156664554733399,.11156664554733399,.09149002162245,.09149002162245,.06904454273764123,.06904454273764123,.0448142267656996,.0448142267656996,.019461788229726478,.019461788229726478],[.15275338713072584,.15275338713072584,.14917298647260374,.14917298647260374,.14209610931838204,.14209610931838204,.13168863844917664,.13168863844917664,.11819453196151841,.11819453196151841,.10193011981724044,.10193011981724044,.08327674157670475,.08327674157670475,.06267204833410907,.06267204833410907,.04060142980038694,.04060142980038694,.017614007139152118,.017614007139152118],[.14608113364969041,.14452440398997005,.14452440398997005,.13988739479107315,.13988739479107315,.13226893863333747,.13226893863333747,.12183141605372853,.12183141605372853,.10879729916714838,.10879729916714838,.09344442345603386,.09344442345603386,.0761001136283793,.0761001136283793,.057134425426857205,.057134425426857205,.036953789770852494,.036953789770852494,.016017228257774335,.016017228257774335],[.13925187285563198,.13925187285563198,.13654149834601517,.13654149834601517,.13117350478706238,.13117350478706238,.12325237681051242,.12325237681051242,.11293229608053922,.11293229608053922,.10041414444288096,.10041414444288096,.08594160621706773,.08594160621706773,.06979646842452049,.06979646842452049,.052293335152683286,.052293335152683286,.03377490158481415,.03377490158481415,.0146279952982722,.0146279952982722],[.13365457218610619,.1324620394046966,.1324620394046966,.12890572218808216,.12890572218808216,.12304908430672953,.12304908430672953,.11499664022241136,.11499664022241136,.10489209146454141,.10489209146454141,.09291576606003515,.09291576606003515,.07928141177671895,.07928141177671895,.06423242140852585,.06423242140852585,.04803767173108467,.04803767173108467,.030988005856979445,.030988005856979445,.013411859487141771,.013411859487141771],[.12793819534675216,.12793819534675216,.1258374563468283,.1258374563468283,.12167047292780339,.12167047292780339,.1155056680537256,.1155056680537256,.10744427011596563,.10744427011596563,.09761865210411388,.09761865210411388,.08619016153195327,.08619016153195327,.0733464814110803,.0733464814110803,.05929858491543678,.05929858491543678,.04427743881741981,.04427743881741981,.028531388628933663,.028531388628933663,.0123412297999872,.0123412297999872]],d=[[1],[1,1],[1,2,1],[1,3,3,1]];f.prototype.getLength=function(){return Math.sqrt(Math.pow(this.x0-this.x1,2)+Math.pow(this.y0-this.y1,2))},f.prototype.getPointAtLength=function(t){var h=t/Math.sqrt(Math.pow(this.x0-this.x1,2)+Math.pow(this.y0-this.y1,2)),n=(this.x1-this.x0)*h,e=(this.y1-this.y0)*h;return{x:this.x0+n,y:this.y0+e}},t.svgPathProperties=w,t.parse=h,t.Bezier=e,Object.defineProperty(t,"__esModule",{value:!0})});
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]
GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]]
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment