@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
104 lines (103 loc) • 2.28 kB
JavaScript
;
import { NamedFunction1, NamedFunction2, NamedFunction3 } from "./_Base";
import { _matchArrayLength } from "./_ArrayUtils";
export class arrayLength extends NamedFunction1 {
static type() {
return "arrayLength";
}
func(array) {
return array.length;
}
}
export class elementsToArrayPrimitive extends NamedFunction2 {
static type() {
return "elementsToArrayPrimitive";
}
func(src, target) {
_matchArrayLength(src, target, () => src[0]);
let i = 0;
for (let srcElement of src) {
target[i] = srcElement;
i++;
}
return target;
}
}
export class elementsToArrayVector extends NamedFunction2 {
static type() {
return "elementsToArrayVector";
}
func(src, target) {
_matchArrayLength(src, target, () => src[0].clone());
let i = 0;
for (let srcElement of src) {
target[i].copy(srcElement);
i++;
}
return target;
}
}
export class arrayElementPrimitive extends NamedFunction2 {
static type() {
return "arrayElementPrimitive";
}
func(src, index) {
const element = src[index];
return element != null ? element : src[0];
}
}
export class arrayElementVector extends NamedFunction3 {
static type() {
return "arrayElementVector";
}
func(src, index, target) {
let element = src[index];
element != null ? element : src[0];
if (element) {
target.copy(element);
}
return target;
}
}
export class arrayPopPrimitive extends NamedFunction1 {
static type() {
return "arrayPopPrimitive";
}
func(src) {
const element = src.pop();
return element;
}
}
export class arrayPopVector extends NamedFunction2 {
static type() {
return "arrayPopVector";
}
func(src, target) {
const element = src.pop();
if (element) {
target.copy(element);
}
return target;
}
}
export class arrayShiftPrimitive extends NamedFunction1 {
static type() {
return "arrayShiftPrimitive";
}
func(src) {
const element = src.shift();
return element;
}
}
export class arrayShiftVector extends NamedFunction2 {
static type() {
return "arrayShiftVector";
}
func(src, target) {
const element = src.shift();
if (element) {
target.copy(element);
}
return target;
}
}