Cell Neighbor List: Java Code
public class Space2DCell.Coordinate extends Space2D.Coordinate
public class Coordinate extends Space2D.Coordinate implements Lattice.Occupant {
Coordinate nextNeighbor, previousNeighbor; //next and previous coordinates in neighbor list
public LatticeSquare.Site cell; //cell currently occupied by this coordinate
public Coordinate(Space.Occupant o) {super(o);} //constructor
public final Lattice.Site site() {return cell;} //Lattice.Occupant interface method
public final void setNextNeighbor(Coordinate c) {
if(c != null) {c.previousNeighbor = this;}
public final void clearPreviousNeighbor() {previousNeighbor = null;}
public final Coordinate nextNeighbor() {return nextNeighbor;}
public final Coordinate previousNeighbor() {return previousNeighbor;}
//Determines appropriate cell and assigns it
public void assignCell() {
LatticeSquare cells = ((NeighborIterator)parentPhase().iterator()).cells;
LatticeSquare.Site newCell = cells.nearestSite(this.r);
if(newCell != cell) {assignCell(newCell);}
//Assigns atom to given cell; if removed from another cell, repairs tear in list
public void assignCell(LatticeSquare.Site newCell) {
if(previousNeighbor != null) {previousNeighbor.setNextNeighbor(nextNeighbor);}
if(cell != null) cell.setFirst(nextNeighbor);
if(nextNeighbor != null) nextNeighbor.clearPreviousNeighbor();} //removing first atom in cell
if(newCell == null) return;
setNextNeighbor((Space2DCell.Coordinate)cell.first());
public final Site nearestSite(Space2D.Vector r) {
int ix = (int)Math.floor(r.x * dimensions[0]);
int iy = (int)Math.floor(r.y * dimensions[1]);
public class LatticeSquare