StandardAtomGenerator { TextOutline positionChargeLabel(int hydrogens, HydrogenPosition position, TextOutline charge, TextOutline element, TextOutline hydrogen) { final Rectangle2D chargeBounds = charge.getBounds(); Rectangle2D referenceBounds = element.getBounds(); if (hydrogens > 0 && (position == Left || position == Right)) referenceBounds = hydrogen.getBounds(); if (position == Left) return charge.translate((referenceBounds.getMinX() - padding) - chargeBounds.getMaxX(), (referenceBounds.getMinY() - (chargeBounds.getHeight() / 2)) - chargeBounds.getMinY()); else return charge.translate((referenceBounds.getMaxX() + padding) - chargeBounds.getMinX(), (referenceBounds.getMinY() - (chargeBounds.getHeight() / 2)) - chargeBounds.getMinY()); } StandardAtomGenerator(Font font); private  StandardAtomGenerator(Font font, double adjunctSpacing, double scriptSize);   }
@Test public void positionOfChargeWhenHydrogensAreRight() { TextOutline charge = new TextOutline("+", font); TextOutline localHydrogen = hydrogen.translate(10, 10); TextOutline positioned = atomGenerator.positionChargeLabel(1, HydrogenPosition.Right, charge, element, localHydrogen); Rectangle2D hydrogenBounds = localHydrogen.getBounds(); Rectangle2D chargeBounds = positioned.getBounds(); assertThat(chargeBounds.getMinX(), greaterThan(hydrogenBounds.getMinX())); assertThat(chargeBounds.getCenterY(), closeTo(hydrogenBounds.getMinY(), 0.01)); }
@Test public void positionOfChargeWhenNoHydrogensAreRight() { TextOutline charge = new TextOutline("+", font); TextOutline localHydrogen = hydrogen.translate(10, 10); TextOutline positioned = atomGenerator.positionChargeLabel(0, HydrogenPosition.Right, charge, element, localHydrogen); Rectangle2D elementBounds = element.getBounds(); Rectangle2D chargeBounds = positioned.getBounds(); assertThat(chargeBounds.getMinX(), greaterThan(elementBounds.getMinX())); assertThat(chargeBounds.getCenterY(), closeTo(elementBounds.getMinY(), 0.01)); }
@Test public void positionOfChargeWhenHydrogensAreLeft() { TextOutline charge = new TextOutline("+", font); TextOutline localHydrogen = hydrogen.translate(10, 10); TextOutline positioned = atomGenerator.positionChargeLabel(1, HydrogenPosition.Left, charge, element, localHydrogen); Rectangle2D elementBounds = element.getBounds(); Rectangle2D chargeBounds = positioned.getBounds(); assertThat(chargeBounds.getMinX(), greaterThan(elementBounds.getMinX())); assertThat(chargeBounds.getCenterY(), closeTo(localHydrogen.getBounds().getMinY(), 0.01)); }
@Test public void positionOfChargeWhenHydrogensAreBelow() { TextOutline charge = new TextOutline("+", font); TextOutline positioned = atomGenerator.positionChargeLabel(1, HydrogenPosition.Below, charge, element, hydrogen.translate(0, 5)); Rectangle2D elementBounds = element.getBounds(); Rectangle2D chargeBounds = positioned.getBounds(); assertThat(chargeBounds.getMinX(), greaterThan(elementBounds.getMinX())); assertThat(chargeBounds.getCenterY(), closeTo(elementBounds.getMinY(), 0.01)); }
@Test public void positionOfChargeWhenTwoHydrogensAreAbove() { TextOutline charge = new TextOutline("+", font); TextOutline localHydrogen = hydrogen.translate(10, 10); TextOutline positioned = atomGenerator.positionChargeLabel(2, HydrogenPosition.Above, charge, element, localHydrogen); Rectangle2D hydrogenBounds = localHydrogen.getBounds(); Rectangle2D chargeBounds = positioned.getBounds(); Rectangle2D elementBounds = element.getBounds(); assertThat(chargeBounds.getMinX(), greaterThan(elementBounds.getMinX())); assertThat(chargeBounds.getCenterY(), closeTo(elementBounds.getMinY(), 0.01)); }
@Test public void positionOfChargeWhenOneHydrogenIsAbove() { TextOutline charge = new TextOutline("+", font); TextOutline localHydrogen = hydrogen.translate(10, 10); TextOutline positioned = atomGenerator.positionChargeLabel(1, HydrogenPosition.Above, charge, element, localHydrogen); Rectangle2D elementBounds = element.getBounds(); Rectangle2D chargeBounds = positioned.getBounds(); assertThat(chargeBounds.getMinX(), greaterThan(elementBounds.getMinX())); assertThat(chargeBounds.getCenterY(), closeTo(elementBounds.getMinY(), 0.01)); }