@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
71 lines (70 loc) • 1.31 kB
JavaScript
;
export function setFirstValue(set) {
for (const item of set) {
return item;
}
}
let i = 0;
export function setToArray(set, target) {
target.length = set.size;
i = 0;
for (const item of set) {
target[i] = item;
i++;
}
return target;
}
export function setCopy(src, target) {
target.clear();
for (const item of src) {
target.add(item);
}
return target;
}
export function setUnion(set0, set1, target) {
target.clear();
for (const item of set0) {
target.add(item);
}
for (const item of set1) {
target.add(item);
}
return target;
}
export function setIntersection(set0, set1, target) {
target.clear();
for (const item of set0) {
if (set1.has(item)) {
target.add(item);
}
}
for (const item of set1) {
if (set0.has(item)) {
target.add(item);
}
}
return target;
}
export function setDifference(set0, set1, target) {
target.clear();
for (const item of set0) {
if (!set1.has(item)) {
target.add(item);
}
}
return target;
}
export function setXOR(set0, set1, target) {
target.clear();
for (const item of set0) {
if (!set1.has(item)) {
target.add(item);
}
}
for (const item of set1) {
if (!set0.has(item)) {
target.add(item);
}
}
return target;
}