Skip to content

Commit e68abea

Browse files
committed
feat: make fragmentutils
1 parent 1779e8f commit e68abea

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
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.5",
4+
"version": "2.3.0-alpha.6",
55
"author": "That Open Company",
66
"contributors": [
77
"Antonio Gonzalez Viegas (https://github.com/agviegas)",
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { FragmentIdMap } from "./base-types";
2+
3+
export class FragmentUtils {
4+
static combine(maps: Iterable<FragmentIdMap>) {
5+
const result: FragmentIdMap = {};
6+
for (const map of maps) {
7+
for (const fragID in map) {
8+
if (!result[fragID]) {
9+
result[fragID] = new Set<number>();
10+
}
11+
for (const expressID of map[fragID]) {
12+
result[fragID].add(expressID);
13+
}
14+
}
15+
}
16+
return result;
17+
}
18+
19+
static export(map: FragmentIdMap) {
20+
const serialized: { [fragID: string]: number[] } = {};
21+
for (const fragID in map) {
22+
serialized[fragID] = Array.from(map[fragID]);
23+
}
24+
return JSON.stringify(serialized);
25+
}
26+
27+
static import(serializedMap: string) {
28+
const serialized = JSON.parse(serializedMap) as {
29+
[fragID: string]: number[];
30+
};
31+
const map: FragmentIdMap = {};
32+
for (const fragID in serialized) {
33+
map[fragID] = new Set(serialized[fragID]);
34+
}
35+
return map;
36+
}
37+
}

packages/fragments/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ export * from "./fragment-mesh";
66
export * from "./streamer-file-db";
77
export * from "./civil";
88
export * from "./stream-serializer";
9+
export * from "./fragment-utils";

0 commit comments

Comments
 (0)