From 94c005f0fd75c67f8d63c22a2a2b97cc762d88b4 Mon Sep 17 00:00:00 2001 From: cha0s Date: Tue, 23 Jul 2019 00:18:59 -0500 Subject: [PATCH] feat: Vector::distance --- packages/math/vector/index.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/math/vector/index.js b/packages/math/vector/index.js index 3ff9d30..9dcf841 100644 --- a/packages/math/vector/index.js +++ b/packages/math/vector/index.js @@ -41,6 +41,12 @@ export function mul(l, r) { return [l[0] * r[0], l[1] * r[1]]; } +export function distance(l, r) { + const xd = l[0] - r[0]; + const yd = l[1] - r[1]; + return Math.sqrt(xd * xd + yd * yd); +} + // Divide two vectors. // // avocado> Vector.div [15, 5], [5, 5]