Skip to content

Commit 4694098

Browse files
committed
fix: solve fragment utils edge cases
1 parent 7f3fb30 commit 4694098

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

packages/fragments/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@thatopen/fragments",
33
"description": "Simple geometric system built on top of Three.js to display 3D BIM data efficiently.",
4-
"version": "2.3.0-alpha.7",
4+
"version": "2.3.0-alpha.8",
55
"author": "That Open Company",
66
"contributors": [
77
"Antonio Gonzalez Viegas (https://github.com/agviegas)",

packages/fragments/src/fragment-utils.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
import { FragmentIdMap } from "./base-types";
22

33
export class FragmentUtils {
4-
static combine(maps: Iterable<FragmentIdMap>) {
4+
static combine(maps: FragmentIdMap[]) {
5+
if (maps.length === 0) {
6+
return {};
7+
}
8+
9+
if (maps.length === 1) {
10+
return maps[0];
11+
}
12+
513
const result: FragmentIdMap = {};
614
for (const map of maps) {
715
for (const fragID in map) {
@@ -16,10 +24,18 @@ export class FragmentUtils {
1624
return result;
1725
}
1826

19-
static intersect(maps: Iterable<FragmentIdMap>) {
27+
static intersect(maps: FragmentIdMap[]) {
2028
// Strategy: count all fragIDs and all IDs
2129
// only stay with values whose count equals the maps count
2230

31+
if (maps.length === 0) {
32+
return {};
33+
}
34+
35+
if (maps.length === 1) {
36+
return maps[0];
37+
}
38+
2339
const visitedIDs = new Map<
2440
string,
2541
{ count: number; ids: Map<number, number> }

0 commit comments

Comments
 (0)