Skip to content

Commit

Permalink
fix(react-components): make sure model matrices are compared properly…
Browse files Browse the repository at this point in the history
… before removal and bump to react-components 0.44.4 (#4521)

* fix(react-components): make sure model comparison correctly compares matrices

* chore: lint fix

* chore: bump to version 0.44.4
  • Loading branch information
haakonflatval-cognite authored May 22, 2024
1 parent e7ff4be commit c578181
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion react-components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cognite/reveal-react-components",
"version": "0.44.3",
"version": "0.44.4",
"exports": {
".": {
"import": "./dist/index.js",
Expand Down
25 changes: 17 additions & 8 deletions react-components/src/utilities/isSameModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ import {
type PointCloudModelOptions,
type CadModelOptions
} from '../components/Reveal3DResources/types';
import { Matrix4 } from 'three';

export function isSameCadModel(model0: CadModelOptions, model1: CadModelOptions): boolean {
return (
model0.modelId === model1.modelId &&
model0.revisionId === model1.revisionId &&
(model0.transform === model1.transform ||
(model0.transform !== undefined &&
model1.transform !== undefined &&
model0.transform.equals(model1.transform))) &&
isSameTransform(model0.transform, model1.transform) &&
isSameGeometryFilter(model0.geometryFilter, model1.geometryFilter)
);
}
Expand Down Expand Up @@ -52,13 +50,24 @@ export function isSamePointCloudModel(
return (
model0.modelId === model1.modelId &&
model0.revisionId === model1.revisionId &&
(model0.transform === model1.transform ||
(model0.transform !== undefined &&
model1.transform !== undefined &&
model0.transform.equals(model1.transform)))
isSameTransform(model0.transform, model1.transform)
);
}

const identity = new Matrix4();

function isSameTransform(m0: Matrix4 | undefined, m1: Matrix4 | undefined): boolean {
if ((m0 === undefined || m0.equals(identity)) && (m1 === undefined || m1.equals(identity))) {
return true;
}

if (m0 === undefined || m1 === undefined) {
return false;
}

return m0.equals(m1);
}

export function isSameModel(model1: CadModelOptions, model2: CadModelOptions): boolean {
return model1.modelId === model2.modelId && model1.revisionId === model2.revisionId;
}

0 comments on commit c578181

Please sign in to comment.