Skip to content

Commit

Permalink
feat(sort): Add sorting in pickedPositions
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigobasilio2022 committed Oct 26, 2023
1 parent 80e77c3 commit c14b315
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Sources/Rendering/Core/Picker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,32 @@ function vtkPicker(publicAPI, model) {
publicAPI.invokePickChange(model.pickedPositions);
return 1;
});
// sort array by distance
const tempArray = [];
for (let i = 0; i < model.pickedPositions.length; i++) {
tempArray.push({
actor: model.actors[i],
pickedPosition: model.pickedPositions[i],
distance: vtkMath.distance2BetweenPoints(
p1World,
model.pickedPositions[i]
),
});
}
tempArray.sort((a, b) => {
const keyA = a.distance;
const keyB = b.distance;
// Compare the 2 dates
if (keyA < keyB) return -1;
if (keyA > keyB) return 1;
return 0;
});
model.pickedPositions = [];
model.actors = [];
tempArray.forEach((obj) => {
model.pickedPositions.push(obj.pickedPosition);
model.actors.push(obj.actor);
});
};
}

Expand Down

0 comments on commit c14b315

Please sign in to comment.