UNPKG

@js-basics/vector

Version:

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

27 lines (26 loc) 714 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.VectorArray = void 0; exports.vectorArray = vectorArray; var _operator = require("./operator.cjs"); var _math = require("./utils/math.cjs"); class VectorArray extends Array { constructor(...vals) { if (!vals.length) { throw new Error('no empty array allowd'); } const first = vals[0]; const src = (0, _math.isArray)(first) ? first : vals; super(src.length); for (let i = 0; i < src.length; i += 1) { this[i] = src[i]; } } } exports.VectorArray = VectorArray; (0, _operator.cachedValueOf)(VectorArray, src => src); function vectorArray(...vals) { return new VectorArray(...vals); }