This file contains 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
if(!String.prototype.matchAll) { | |
String.prototype.matchAll = function (rx) { | |
if (typeof rx === "string") rx = new RegExp(rx, "g"); // coerce a string to be a global regex | |
rx = new RegExp(rx); // Clone the regex so we don't update the last index on the regex they pass us | |
let cap = []; // the single capture | |
let all = []; // all the captures (return this) | |
while ((cap = rx.exec(this)) !== null) all.push(cap); // execute and add | |
return all; // profit! | |
}; | |
} |
This file contains 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
// Taken From: | |
// https://stackoverflow.com/questions/849211/shortest-distance-between-a-point-and-a-line-segment | |
function sqr (x) { | |
return x * x; | |
} | |
function dist2 (v, w) { | |
return sqr(v[0] - w[0]) + sqr(v[1] - w[1]); | |
} |