Skip to content

Commit feb9852

Browse files
committed
Now catching empty arrays in getCentroid
1 parent c11c0d2 commit feb9852

File tree

1 file changed

+6
-1
lines changed
  • biojava-structure/src/main/java/org/biojava/nbio/structure

1 file changed

+6
-1
lines changed

biojava-structure/src/main/java/org/biojava/nbio/structure/Calc.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,12 +699,17 @@ public static final void shift(Group group , Atom a ){
699699

700700

701701

702-
/** Returns the center of mass of the set of atoms.
702+
/**
703+
* Returns the center of mass of the set of atoms.
703704
* @param atomSet a set of Atoms
704705
* @return an Atom representing the Centroid of the set of atoms
705706
*/
706707
public static final Atom getCentroid(Atom[] atomSet){
707708

709+
// if we don't catch this case, the centroid returned is (NaN,NaN,NaN), which can cause lots of problems down the line
710+
if (atomSet.length==0)
711+
throw new IllegalArgumentException("Atom array has length 0, can't calculate centroid!");
712+
708713
double[] coords = new double[3];
709714

710715
coords[0] = 0;

0 commit comments

Comments
 (0)