UNPKG

@js-basics/vector

Version:

A 3D Vector lib including arithmetic operator overloading (+ - * / % **).

24 lines (19 loc) 533 B
import { cachedValueOf } from './operator.js'; import { isArray } from './utils/math.js'; export class VectorArray extends Array { constructor(...vals) { if (!vals.length) { throw new Error('no empty array allowd'); } const first = vals[0]; const src = isArray(first) ? first : vals; super(src.length); for (let i = 0; i < src.length; i += 1) { this[i] = src[i]; } } } cachedValueOf(VectorArray, src => src); export function vectorArray(...vals) { return new VectorArray(...vals); }