UNPKG

@thi.ng/vectors

Version:

Optimized 2d/3d/4d and arbitrary length vector operations, support for memory mapping/layouts

33 lines (32 loc) 616 B
import { compile } from "./compile/emit.js"; import { vop } from "./vop.js"; const $ = (dim) => distChebyshev.add( dim, compile( dim, ([a, b]) => `Math.abs(${a}-${b})`, "a,b", void 0, "", ",", "return Math.max(", ");" ) ); const distChebyshev = vop(); distChebyshev.default((a, b) => { let max = 0; for (let i = a.length; i-- > 0; ) { max = Math.max(max, Math.abs(a[i] - b[i])); } return max; }); const distChebyshev2 = $(2); const distChebyshev3 = $(3); const distChebyshev4 = $(4); export { distChebyshev, distChebyshev2, distChebyshev3, distChebyshev4 };