/
IntersectionNodeCollection.ts
39 lines (34 loc) · 1.18 KB
/
IntersectionNodeCollection.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*!
* Copyright 2021 Cognite AS
*/
import { NodeCollectionBase, SerializedNodeCollection } from './NodeCollectionBase';
import { UnionNodeCollection } from './UnionNodeCollection';
import { CombineNodeCollectionBase } from './CombineNodeCollectionBase';
import { IndexSet } from '@reveal/utilities';
/**
* Node collection that is the intersection between a set of underlying node collections.
*/
export class IntersectionNodeCollection extends CombineNodeCollectionBase {
public static readonly classToken = 'IntersectionNodeCollection';
constructor(nodeCollections?: NodeCollectionBase[]) {
super(UnionNodeCollection.classToken, nodeCollections);
}
serialize(): SerializedNodeCollection {
return {
token: this.classToken,
state: {
subCollections: this._nodeCollections.map(set => set.serialize())
}
};
}
protected createCombinedIndexSet(): IndexSet {
if (this._nodeCollections.length === 0) {
return new IndexSet();
}
const set = this._nodeCollections[0].getIndexSet().clone();
for (let i = 1; i < this._nodeCollections.length; ++i) {
set.intersectWith(this._nodeCollections[i].getIndexSet());
}
return set;
}
}