Skip to content

Commit

Permalink
chore: isolate common logic
Browse files Browse the repository at this point in the history
  • Loading branch information
VsevolodX committed Jan 16, 2024
1 parent ed6dfe5 commit d9c9fbc
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions src/mixins/measurement.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,18 +153,7 @@ export const MeasurementMixin = (superclass) =>
* @Param event -> simple javascript DOM event
*/
onPointerMove(event) {
this.checkMouseCoordinates(event);
const atomGroup = this.getAtomGroups();
const searchedIntersects = [...atomGroup];
// TODO: Probably will be better to set this.atomConnections.children to optional target
if (this.measurementSettings.isDistanceShown) {
searchedIntersects.push(...this.atomConnections.children);
}
if (this.measurementSettings.isAnglesShown) {
searchedIntersects.push(...this.angles.children);
}

const intersects = this.raycaster.intersectObjects(searchedIntersects, false);
const intersects = this.getIntersectedObjects(event);

for (let i = 0; i < intersects.length; i++) {
const intersectItem = intersects[i].object;
Expand Down Expand Up @@ -299,16 +288,8 @@ export const MeasurementMixin = (superclass) =>
* @Param event -> js DOM event
*/
onClick(updateState, event) {
this.checkMouseCoordinates(event);
const atomGroup = this.getAtomGroups();
const searchedIntersects = [...atomGroup];
if (this.measurementSettings.isDistanceShown) {
searchedIntersects.push(...this.atomConnections.children);
}
if (this.measurementSettings.isAnglesShown) {
searchedIntersects.push(...this.angles.children);
}
const intersects = this.raycaster.intersectObjects(searchedIntersects, false);
const intersects = this.getIntersectedObjects(event);

for (let i = 0; i < intersects.length; i++) {
const intersectItem = intersects[i].object;

Expand Down Expand Up @@ -358,6 +339,24 @@ export const MeasurementMixin = (superclass) =>
}
}

/**
* Returns array of intersected objects.
* @param event
* @returns {[]}
*/
getIntersectedObjects(event) {
this.checkMouseCoordinates(event);
const atomGroup = this.getAtomGroups();
const searchedIntersects = [...atomGroup];
if (this.measurementSettings.isDistanceShown) {
searchedIntersects.push(...this.atomConnections.children);
}
if (this.measurementSettings.isAnglesShown) {
searchedIntersects.push(...this.angles.children);
}
return this.raycaster.intersectObjects(searchedIntersects, false);
}

/**
*
* @param {Array} atomArray - array to be checked
Expand Down

0 comments on commit d9c9fbc

Please sign in to comment.