AtomPlacer { public void populatePolygonCorners(final List<IAtom> atoms, final Point2d center, final double thetaBeg, final double thetaStep, final double radius) { final int numAtoms = atoms.size(); double theta = thetaBeg; logger.debug("populatePolygonCorners(numAtoms=", numAtoms, ", center=", center, ", thetaBeg=", Math.toDegrees(thetaBeg), ", r=", radius); for (IAtom atom : atoms) { theta += thetaStep; double x = Math.cos(theta) * radius; double y = Math.sin(theta) * radius; double newX = x + center.x; double newY = y + center.y; atom.setPoint2d(new Point2d(newX, newY)); atom.setFlag(CDKConstants.ISPLACED, true); logger.debug("populatePolygonCorners - angle=", Math.toDegrees(theta), ", newX=", newX, ", newY=", newY); } } AtomPlacer(); IAtomContainer getMolecule(); void setMolecule(IAtomContainer molecule); void distributePartners(IAtom atom, IAtomContainer placedNeighbours, Point2d sharedAtomsCenter,
            IAtomContainer unplacedNeighbours, double bondLength); void placeLinearChain(IAtomContainer atomContainer, Vector2d initialBondVector, double bondLength); Vector2d getNextBondVector(IAtom atom, IAtom previousAtom, Point2d distanceMeasure, boolean trans); void populatePolygonCorners(final List<IAtom> atoms,
                                       final Point2d center,
                                       final double thetaBeg,
                                       final double thetaStep,
                                       final double radius); void partitionPartners(IAtom atom, IAtomContainer unplacedPartners, IAtomContainer placedPartners); static IAtomContainer getInitialLongestChain(IAtomContainer molecule); static IAtomContainer getLongestUnplacedChain(IAtomContainer molecule, IAtom startAtom); static void breadthFirstSearch(IAtomContainer ac, List<IAtom> sphere, IAtomContainer[] pathes); String listPlaced(IAtomContainer ac); static String listNumbers(IAtomContainer mol, IAtomContainer ac); static String listNumbers(IAtomContainer mol, List<IAtom> ac); static boolean allPlaced(IAtomContainer ac); static void markNotPlaced(IAtomContainer ac); static void markPlaced(IAtomContainer ac); static IAtomContainer getPlacedAtoms(IAtomContainer ac); @Deprecated static boolean shouldBeLinear(IAtom atom, IAtomContainer molecule); final static boolean debug; static final String PRIORITY; }
@Test public void emptyAtomsListTest() { List<IAtom> atoms = new ArrayList<IAtom>(); AtomPlacer placer = new AtomPlacer(); boolean npeThrown = false; try { placer.populatePolygonCorners(atoms, new Point2d(0, 0), 0, 10, 10); } catch (NullPointerException npe) { npeThrown = true; } Assert.assertFalse("Null pointer for empty atoms list", npeThrown); }
@Test public void triangleTest() { List<IAtom> atoms = new ArrayList<IAtom>(); atoms.add(new Atom("C")); atoms.add(new Atom("C")); atoms.add(new Atom("C")); AtomPlacer placer = new AtomPlacer(); placer.populatePolygonCorners(atoms, new Point2d(0, 0), 0, 10, 10); for (IAtom atom : atoms) { Assert.assertNotNull(atom.getPoint2d()); } }