Skip to content

Commit

Permalink
fix: create a box3 when deserializing areas in treeindex collection (#…
Browse files Browse the repository at this point in the history
…2671)

Co-authored-by: cognite-bulldozer[bot] <51074376+cognite-bulldozer[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and Savokr committed Nov 8, 2022
1 parent f53c0db commit 161022c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

import { CogniteClient } from '@cognite/sdk';
import { IndexSet } from '@reveal/utilities';
import { Mock } from 'moq.ts';

import { createCadModel } from '../../../test-utilities/src/createCadModel';
import { CdfModelNodeCollectionDataProvider } from './CdfModelNodeCollectionDataProvider';
import { NodeCollectionDeserializer } from './NodeCollectionDeserializer';
import { SerializedNodeCollection } from './SerializedNodeCollection';
import { TreeIndexNodeCollection } from './TreeIndexNodeCollection';

describe('NodeCollectionDeserializer', () => {
describe(NodeCollectionDeserializer.name, () => {
test('deserialize TreeIndexSet without option parameter', async () => {
const sdk = new CogniteClient({
appId: 'cognite.reveal.unittest',
Expand All @@ -35,4 +38,39 @@ describe('NodeCollectionDeserializer', () => {
})
).toBeTruthy();
});

test('deserialize TreeIndexNodeCollection with areas', async () => {
const deserializer = NodeCollectionDeserializer.Instance;

const sdkMock = new Mock<CogniteClient>().object();
const nodeCollectionProviderMock = new Mock<CdfModelNodeCollectionDataProvider>().object();
const serializedNodeCollection: SerializedNodeCollection = {
token: 'TreeIndexNodeCollection',
state: [
{
from: 0,
count: 3,
toInclusive: 2
}
],
options: {
areas: [
{
min: {
x: 0,
y: 0,
z: 0
},
max: {
x: 1,
y: 1,
z: 1
}
}
]
}
};
const deserialize = deserializer.deserialize(sdkMock, nodeCollectionProviderMock, serializedNodeCollection);
await expect(deserialize).resolves.not.toThrow();
});
});
12 changes: 11 additions & 1 deletion viewer/packages/cad-styling/src/NodeCollectionDeserializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Copyright 2021 Cognite AS
*/

import * as THREE from 'three';
import assert from 'assert';
import { CogniteClient } from '@cognite/sdk';
import { NumericRange, IndexSet } from '@reveal/utilities';
Expand Down Expand Up @@ -104,7 +105,16 @@ export class NodeCollectionDeserializer {
descriptor.state.forEach((range: NumericRange) => indexSet.addRange(new NumericRange(range.from, range.count)));
const nodeCollection = new TreeIndexNodeCollection(indexSet);
if (descriptor.options?.areas !== undefined) {
nodeCollection.addAreas(descriptor.options.areas);
const areas = descriptor.options?.areas as {
min: { x: number; y: number; z: number };
max: { x: number; y: number; z: number };
}[];
const areaBoxes = areas.map(area => {
const min = new THREE.Vector3(area.min.x, area.min.y, area.min.z);
const max = new THREE.Vector3(area.max.x, area.max.y, area.max.z);
return new THREE.Box3(min, max);
});
nodeCollection.addAreas(areaBoxes);
}

return Promise.resolve(nodeCollection);
Expand Down

0 comments on commit 161022c

Please sign in to comment.