Created
July 23, 2020 19:08
-
-
Save dmitric/003be3d5a62d09f92dc19266783d65b7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { svgPathProperties } from "svg-path-properties" | |
calculateConnectionsBetweenPaths (d, lastd, segments) { | |
// Take in two "d" attribute string and break then down into N segements | |
// and return a list of those points | |
const connections = [] | |
// Given a path's value of d, get the total length of the path | |
const pp = new svgPathProperties(d) | |
const pLength = pp.getTotalLength() | |
// Given another path's value of d, get the total length of the path | |
const lastpp = new svgPathProperties(lastd) | |
const lastpLength = lastpp.getTotalLength() | |
// break up each path into N even segments, and connect them at those corresponding intervals | |
for (let section=0; section <= segments; section++) { | |
let pPoint = pp.getPointAtLength(pLength*section/segments) | |
let lastpPoint = lastpp.getPointAtLength(lastpLength*section/segments) | |
connections.push([ pPoint , lastpPoint ]) | |
} | |
return connections | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment