import java.io.Reader; import java.io.Writer; /** * Implementat ion of * interface for specifying per-agent information neccessary to * perform formation morphing to morph to a rectangle with a * "comb" topology. Rect width is specified at construction time. * @author Michael Schuresko * @version %I%, %G% * @since 1.0 */ public class MorphSpecCombRect implements IMorphSpec { int m_nWidth; double m_lfDist; /** * defaults for the first demo */ public MorphSpecCombRect() { m_lfDist = 0.2; m_nWidth = 4; } public MorphSpecCombRect(int nRectWidth, double lfSpacing) { m_lfDist = lfSpacing; m_nWidth = nRectWidth; } public double [] getFinalUv(int nAgentId) { double [] arrLfUv = new double[2]; if(nAgentId == 0) { arrLfUv[0] = arrLfUv[1] = 0.0; } else if(nAgentId % m_nWidth == 1) { arrLfUv[0] = 0.0; arrLfUv[1] = m_lfDist; } else { arrLfUv[0] = -m_lfDist; arrLfUv[1] = 0.0; } return arrLfUv; } public int getNumChildren(int nAgentId) { if(nAgentId % m_nWidth == 0 && nAgentId/m_nWidth < m_nWidth-1) { return 2; } if(nAgentId % m_nWidth == m_nWidth-1) { return 0; } return 1; } public int getTopoLastVisit(int nAgentId) { if(nAgentId % m_nWidth == 0) { return (m_nWidth+m_nWidth-1)*(nAgentId/m_nWidth)+ m_nWidth-1+2*m_nWidth*(m_nWidth-nAgentId/m_nWidth); } else { return (m_nWidth+m_nWidth-1)*(nAgentId/m_nWidth)+ m_nWidth+m_nWidth-(nAgentId % m_nWidth)-1; } } public int getTopoFirstVisit(int nAgentId) { return (m_nWidth+m_nWidth-1)*(nAgentId/m_nWidth)+ (nAgentId % m_nWidth); } public int getTopoDepth(int nAgentId) { return (nAgentId/m_nWidth) + (nAgentId%m_nWidth); } public int getMaxDepth() { return 2*m_nWidth; } /** * Make this more then a stub later */ public void dump(Writer writeTo) {} /** * Make this more then a stub later */ public void load(Reader readFrom) {} }