GeometryTools { public static double[] getMinMax(IAtomContainer container) { double maxX = -Double.MAX_VALUE; double maxY = -Double.MAX_VALUE; double minX = Double.MAX_VALUE; double minY = Double.MAX_VALUE; for (int i = 0; i < container.getAtomCount(); i++) { IAtom atom = container.getAtom(i); if (atom.getPoint2d() != null) { if (atom.getPoint2d().x > maxX) { maxX = atom.getPoint2d().x; } if (atom.getPoint2d().x < minX) { minX = atom.getPoint2d().x; } if (atom.getPoint2d().y > maxY) { maxY = atom.getPoint2d().y; } if (atom.getPoint2d().y < minY) { minY = atom.getPoint2d().y; } } } double[] minmax = new double[4]; minmax[0] = minX; minmax[1] = minY; minmax[2] = maxX; minmax[3] = maxY; return minmax; }  static void translateAllPositive(IAtomContainer atomCon); static void translate2D(IAtomContainer atomCon, double transX, double transY); static void scaleMolecule(IAtomContainer atomCon, Dimension areaDim, double fillFactor); static void scaleMolecule(IAtomContainer atomCon, double scaleFactor); static void center(IAtomContainer atomCon, Dimension areaDim); static void translate2D(IAtomContainer atomCon, Vector2d vector); static void rotate(IAtomContainer atomCon, Point2d center, double angle); static void rotate(IAtom atom, Point3d p1, Point3d p2, double angle); static void normalize(Point3d point); static Dimension get2DDimension(IAtomContainer atomCon); static Rectangle2D getRectangle2D(IAtomContainer container); static double[] getMinMax(IAtomContainer container); static void translate2DCentreOfMassTo(IAtomContainer atomCon, Point2d p); static Point2d get2DCenter(Iterable<IAtom> atoms); static Point2d get2DCenter(Iterator<IAtom> atoms); static Point2d get2DCenter(IRingSet ringSet); static Point2d get2DCentreOfMass(IAtomContainer ac); static Point2d get2DCenter(IAtomContainer container); static void translate2DCenterTo(IAtomContainer container, Point2d p); static Point3d get3DCentreOfMass(IAtomContainer ac); static Point3d get3DCenter(IAtomContainer ac); static double getAngle(double xDiff, double yDiff); static int[] distanceCalculator(int[] coords, double dist); static double[] distanceCalculator(double[] coords, double dist); static int[] getBondCoordinates(IBond bond); static IAtom getClosestAtom(int xPosition, int yPosition, IAtomContainer atomCon); static IAtom getClosestAtom(IAtomContainer atomCon, IAtom atom); static IAtom getClosestAtom(double xPosition, double yPosition, IAtomContainer atomCon, IAtom toignore); static IAtom getClosestAtom(double xPosition, double yPosition, IAtomContainer atomCon); static IBond getClosestBond(int xPosition, int yPosition, IAtomContainer atomCon); static IBond getClosestBond(double xPosition, double yPosition, IAtomContainer atomCon); static void sortBy2DDistance(IAtom[] atoms, Point2d point); static double getScaleFactor(IAtomContainer container, double bondLength); static double getBondLengthAverage(IAtomContainer container); static double getBondLengthMedian(final IAtomContainer container); static double getLength2D(IBond bond); static boolean has2DCoordinates(IAtomContainer container); static CoordinateCoverage get2DCoordinateCoverage(IAtomContainer container); @Deprecated static int has2DCoordinatesNew(IAtomContainer container); static boolean has2DCoordinates(IAtom atom); static boolean has2DCoordinates(IBond bond); static boolean has3DCoordinates(IAtomContainer container); static CoordinateCoverage get3DCoordinateCoverage(IAtomContainer container); static Vector2d calculatePerpendicularUnitVector(Point2d point1, Point2d point2); static double getNormalizationFactor(IAtomContainer container); static int getBestAlignmentForLabel(IAtomContainer container, IAtom atom); static int getBestAlignmentForLabelXY(IAtomContainer container, IAtom atom); static List<IAtom> findClosestInSpace(IAtomContainer container, IAtom startAtom, int max); static Map<Integer, Integer> mapAtomsOfAlignedStructures(IAtomContainer firstAtomContainer,
            IAtomContainer secondAtomContainer, double searchRadius, Map<Integer, Integer> mappedAtoms); static double getBondLengthRMSD(IAtomContainer firstAtomContainer, IAtomContainer secondAtomContainer,
            Map<Integer, Integer> mappedAtoms, boolean Coords3d); static double getAngleRMSD(IAtomContainer firstAtomContainer, IAtomContainer secondAtomContainer,
            Map<Integer, Integer> mappedAtoms); static double getAllAtomRMSD(IAtomContainer firstAtomContainer, IAtomContainer secondAtomContainer,
            Map<Integer, Integer> mappedAtoms, boolean Coords3d); static double getHeavyAtomRMSD(IAtomContainer firstAtomContainer, IAtomContainer secondAtomContainer,
            Map<Integer, Integer> mappedAtoms, boolean hetAtomOnly, boolean Coords3d); static double getBondLengthAverage3D(IAtomContainer container); static Rectangle2D shiftContainer(IAtomContainer container, Rectangle2D bounds, Rectangle2D last, double gap); static double getBondLengthAverage(IReaction reaction); static boolean has3DCoordinates(IChemModel chemModel); static Rectangle2D shiftReactionVertical(IReaction reaction, Rectangle2D bounds, Rectangle2D last, double gap);  }
@Test public void testGetMinMax_IAtomContainer() { Atom atom1 = new Atom("C"); atom1.setPoint2d(new Point2d(1, 1)); Atom atom2 = new Atom("C"); atom2.setPoint2d(new Point2d(1, 0)); IAtomContainer ac = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class); ac.addAtom(atom1); ac.addAtom(atom2); double[] minmax = GeometryTools.getMinMax(ac); Assert.assertEquals(minmax[0], 1d, .1); Assert.assertEquals(minmax[1], 0d, .1); Assert.assertEquals(minmax[2], 1d, .1); Assert.assertEquals(minmax[3], 1d, .1); }
@Test public void testGetMinMax2() { Atom atom1 = new Atom("C"); atom1.setPoint2d(new Point2d(-2, -1)); Atom atom2 = new Atom("C"); atom2.setPoint2d(new Point2d(-5, -1)); IAtomContainer ac = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class); ac.addAtom(atom1); ac.addAtom(atom2); double[] minmax = GeometryTools.getMinMax(ac); Assert.assertEquals(-5, minmax[0], .1); Assert.assertEquals(-1, minmax[1], .1); Assert.assertEquals(-2, minmax[2], .1); Assert.assertEquals(-1, minmax[3], .1); }