Skip to content

Commit

Permalink
Throw a descriptive exception when 2D coordinates are missing (fixes …
Browse files Browse the repository at this point in the history
…#3355921)

Signed-off-by: Rajarshi Guha <rajarshi.guha@gmail.com>
  • Loading branch information
egonw authored and rajarshi committed Nov 19, 2011
1 parent 7bc0772 commit cdc4cbd
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/main/org/openscience/cdk/renderer/BoundsCalculator.java
Expand Up @@ -137,8 +137,13 @@ public static Rectangle2D calculateBounds(IAtomContainer atomContainer) {
if (atomContainer.getAtomCount() == 0) {
return new Rectangle2D.Double();
} else if (atomContainer.getAtomCount() == 1) {
Point2d p = atomContainer.getAtom(0).getPoint2d();
return new Rectangle2D.Double(p.x, p.y, 0, 0);
Point2d point = atomContainer.getAtom(0).getPoint2d();
if (point == null) {
throw new IllegalArgumentException(
"Cannot calculate bounds when 2D coordinates are missing."
);
}
return new Rectangle2D.Double(point.x, point.y, 0, 0);
}

double xmin = Double.POSITIVE_INFINITY;
Expand All @@ -148,6 +153,11 @@ public static Rectangle2D calculateBounds(IAtomContainer atomContainer) {

for (IAtom atom : atomContainer.atoms()) {
Point2d point = atom.getPoint2d();
if (point == null) {
throw new IllegalArgumentException(
"Cannot calculate bounds when 2D coordinates are missing."
);
}
xmin = Math.min(xmin, point.x);
xmax = Math.max(xmax, point.x);
ymin = Math.min(ymin, point.y);
Expand Down

0 comments on commit cdc4cbd

Please sign in to comment.