DuyTa's picture
Upload folder using huggingface_hub
bc20498 verified
raw
history blame
365 Bytes
export default function(polygon) {
var i = -1,
n = polygon.length,
b = polygon[n - 1],
xa,
ya,
xb = b[0],
yb = b[1],
perimeter = 0;
while (++i < n) {
xa = xb;
ya = yb;
b = polygon[i];
xb = b[0];
yb = b[1];
xa -= xb;
ya -= yb;
perimeter += Math.hypot(xa, ya);
}
return perimeter;
}