/** * Adapter to take one interface of type IProjection and make a * IProjection which maps its inputs to a translation of the results * of the wrapped IProjection on the same inputs * @author Michael Schuresko * @version %I%, %G% * @since 1.0 */ public class ProjectionXlateWrapper implements IProjection { IProjection m_projWrapped; int m_arrNOffset[]; /** * provides a pointer to the projection to be wrapped */ void setProjection(IProjection proj) { m_projWrapped = proj; } /** * provides the (post-projection) translation offset */ void setOffset(int nXOff, int nYOff) { if(m_arrNOffset == null) { m_arrNOffset = new int[2]; } m_arrNOffset[0] = nXOff; m_arrNOffset[1] = nYOff; } public void resize(int nNewWidth, int nNewHeight) {m_projWrapped.resize(nNewWidth, nNewHeight);} public void scaleProjection(int nNewX, int nNewY) {m_projWrapped.scaleProjection(nNewX, nNewY);} public void xlateProjection(int nXOff, int nYOff) {m_projWrapped.xlateProjection(nXOff, nYOff);} /** * Initializes offset to 0,0 */ ProjectionXlateWrapper(IProjection proj) { setProjection(proj); } /** * initializes all internals with supplied parameters */ ProjectionXlateWrapper(IProjection proj, int nXOff, int nYOff) { setProjection(proj); setOffset(nXOff, nYOff); } /** * Finds the ith component in screen coordinates of a vector * indicated by the portion of the array arrLfState starting * at nIdxOff; Fails if nIdxOff >= 2, or if wrapped projection is null. * @param i which component of screen coordinates to get (0=x, 1=y) * @param arrLfState global state vector in sim coordinates * @param nIdxOff offset index in arrLfState of the coord we're looking * for * @return ith component in screen coordinates */ public int getScreenComp(int i, double [] arrLfState, int nIdxOff) { return m_projWrapped.getScreenComp(i, arrLfState, nIdxOff) + m_arrNOffset[i]; } /** * Scales (possibly including rotation and flip) * a vector, without applying global translation * @param arrLfVec array containing vector to scale (transform) * @param nIdxOff offset of begining of vector to scale in * arrLfVec * @return integer array containing scaled vector discretized * to pixel differences. */ public int [] scaleVector(double [] arrLfVec, int nIdxOff) { return m_projWrapped.scaleVector(arrLfVec, nIdxOff); } /** * Simple scale function for 2d circles etc. */ public int scaleRadius(double lfRad) throws Exception { return m_projWrapped.scaleRadius(lfRad); } public int width() { return m_projWrapped.width(); } public int height() { return m_projWrapped.height();} public int top() { return m_projWrapped.top() +m_arrNOffset[1]; } public int left() { return m_projWrapped.left()+m_arrNOffset[0]; } }