@@ -337,16 +337,46 @@ export const MeasurementMixin = (superclass) =>
337
337
}
338
338
if ( this . shouldCalculateDistance ( ) ) {
339
339
const lastChosenAtoms = this . chosenAtoms . slice ( - 2 ) ;
340
- this . drawLineBetweenAtoms ( lastChosenAtoms ) ;
341
- const distance = this . calculateDistanceBetweenAtoms ( lastChosenAtoms ) ;
342
- this . drawDistanceText ( distance ) ;
343
- updateState ( { distance } ) ;
340
+ const isPairAlreadyExist = this . checkAtomPairExistence (
341
+ this . chosenAtoms . slice ( 0 , - 2 ) ,
342
+ lastChosenAtoms ,
343
+ ) ;
344
+ if ( ! isPairAlreadyExist ) {
345
+ this . drawLineBetweenAtoms ( lastChosenAtoms ) ;
346
+ const distance = this . calculateDistanceBetweenAtoms ( lastChosenAtoms ) ;
347
+ this . drawDistanceText ( distance ) ;
348
+ updateState ( { distance } ) ;
349
+ }
344
350
}
345
351
break ;
346
352
}
347
353
}
348
354
}
349
355
356
+ /**
357
+ *
358
+ * @param {Array } atomArray - array to be checked
359
+ * @param {Array } param1 - atom pair to checked
360
+ * @returns boolean value - true if atom pair is already exist in array.
361
+ */
362
+ checkAtomPairExistence ( atomArray , [ atomA , atomB ] ) {
363
+ for ( let i = 0 ; i < atomArray . length ; i += 2 ) {
364
+ const currentAtom = atomArray [ i ] ;
365
+ const nextAtom = atomArray [ i + 1 ] ;
366
+
367
+ if (
368
+ ( currentAtom . uuid === atomA . uuid && atomB . uuid === nextAtom . uuid ) ||
369
+ ( currentAtom . uuid === atomB . uuid && nextAtom . uuid === atomA . uuid )
370
+ ) {
371
+ this . chosenAtoms . pop ( ) ;
372
+ this . chosenAtoms . pop ( ) ;
373
+ return true ;
374
+ }
375
+ }
376
+
377
+ return false ;
378
+ }
379
+
350
380
shouldCalculateDistance ( ) {
351
381
return (
352
382
this . chosenAtoms . length &&
0 commit comments