AList Nodes = new AList(); class Node extends Base { static final int POINT = 0; static final int BOX = 1; static final int SPHERE = 2; //float x=0.0, y=0.0, z=0.0; float rad; int shape; AList edges = new AList(); int distToBottom = 1000; Node (color c, float rad, int shape, String label, String type, AList l) { super(c, label, type, l); this.rad = rad; this.shape = shape; } Node (color c, float rad, int shape, String label, String type) { this(c, rad, shape, label, type, Nodes); } void setShape(color c, int shape, float rad) { setColor(c); this.rad = rad; this.shape = shape; } float getRadius() { return rad; } void addEdge(Edge e) { //called by Edge constructor. edges.add(e); } AList getEdges() { return edges; } int minExitFor() { return minIndexOf((ArrayList)getData(Graph.ExitDistances)); } // Edge getMinEdge(Object KList, Object KIndex, Edge exclude) { // return getMinEdge(KList, getIntData(KIndex), exclude); // } Edge getMinEdge(Object KList, int ix) { return getMinEdge(KList, ix, null); } Edge getRandomEdge() { return (Edge) getEdges().get(floor(random(getEdges().size()))); } Edge getMinEdge(Object KList, int ix, Edge exclude) { Edge minEdge = null; float minEdgeDist = Float.MAX_VALUE; //int ix = getIntData(KIndex); // returns the index of the exit layer for(int i = 0; iotherNode(e).getFloatData(V)) float nextEdgeDist = e.nOther(this).getFloatData(KList, ix) + e.len(); if(minEdgeDist>nextEdgeDist) { minEdge = e; minEdgeDist = nextEdgeDist; } } return minEdge; } // Node otherNode(Edge e) { // return (e.n0==this)?e.n1:e.n0; // could use ID // } AList getNodes() { AList nodes = new AList(); for(int i = 0; i Base? float lenTo(Node n) { return sqrt(sq(n.x-x)+sq(n.y-y)+sq(n.z-z)); } void moveTowards(Node n, float delta) { float l = lenTo(n); moveBy(delta*(n.x-x)/l, delta*(n.y-y)/l, delta*(n.z-z)/l); } void paint() { fill(c); if(shape != POINT) { pushMatrix(); noStroke(); translate(x, y, z); if(shape==SPHERE) sphere(rad); else box(rad); popMatrix(); } paintLabel(LEFT,x+rad,y+rad,z+rad); } // Floodfill from this node. // For each node, adds a dict entry with this as key and the value a float distance to me. void floodFill() { Nodes.setData(this, Float.MAX_VALUE); this.setData(this,0f); ArrayList stack = new ArrayList(); stack.add(this); int loops = 0; while (stack.size() > 0) { loops++; Node n = (Node)stack.remove(0); float nDist = n.getFloatData(this); AList edges = n.getEdges(); for(int i = 0; i0) ? eDist * e.trampled : eDist; Node eNode = e.nOther(n); float eNodeDist = eNode.getFloatData(this); if(eDist < eNodeDist) { eNode.setData(this,eDist); stack.add(eNode); } } } } }