public void paintToRect(Graphics2D g2d, int x, int y, int w, int h) { g2d = createGraphics(g2d,x,y,w,h); //g2d.setRenderingHint( // RenderingHints.KEY_ANTIALIASING, // RenderingHints.VALUE_ANTIALIAS_ON); double x1u = 0.0; double y1u = 1.0; double x2u = 2.0*PI*_cycles; double y2u = -1.0; int x1d = 0; int y1d = 0; int x2d = w-1; int y2d = h-1; Transcaler ts = new Transcaler(x1u,y1u,x2u,y2u,x1d,y1d,x2d,y2d); int nx = 10000; double dx = (x2u-x1u)/(nx-1); double fx = 0.0; int x1 = ts.x(fx); int y1 = ts.y(sin(fx)); for (int ix=1; ix<nx; ++ix) { double xi = fx+ix*dx; int x2 = ts.x(xi); int y2 = ts.y(sin(xi)); g2d.drawLine(x1,y1,x2,y2); x1 = x2; y1 = y2; } g2d.dispose(); } protected void paintComponent(Graphics g) {
private void computeXY( Projector hp, Projector vp, Transcaler ts, int n, float[] x1, float[] x2, int[] x, int[] y) { ts = ts.combineWith(hp,vp); float[] xv = null; float[] yv = null; if (_orientation==Orientation.X1RIGHT_X2UP) { xv = x1; yv = x2; } else if (_orientation==Orientation.X1DOWN_X2RIGHT) { xv = x2; yv = x1; } for (int i=0; i<n; ++i) { x[i] = ts.x(xv[i]); y[i] = ts.y(yv[i]); } }
/** * Sets the user-coordinate part of the mapping for this transcaler. * @param x1u the user x-coordinate corresponding to the current x1d. * @param y1u the user y-coordinate corresponding to the current y1d. * @param x2u the user x-coordinate corresponding to the current x2d. * @param y2u the user y-coordinate corresponding to the current y2d. */ public void setMapping(double x1u, double y1u, double x2u, double y2u) { _x1u = x1u; _x2u = x2u; _y1u = y1u; _y2u = y2u; computeShiftAndScale(); }
public void testCombineWithLinearA () { Transcaler tr = new Transcaler(0.0, 0.0, 1.0, 1.0, 0, 0, 100, 100); Projector xp = new Projector(0.0, 10.0, AxisScale.LINEAR); Projector yp = new Projector(0.0, 50.0, AxisScale.LINEAR); Transcaler tr_c = tr.combineWith(xp, yp); assertVeryClose(5.0, tr_c.x(tr_c.x(5.0))); assertVeryClose(5.0, tr_c.y(tr_c.y(5.0))); assertVeryClose(75, tr_c.x(tr_c.x(75))); assertVeryClose(75, tr_c.y(tr_c.y(75))); }
int rx = ts.width(rbx); int ry = ts.height(rby); int rb = max(0,min(rx,ry)-1); int xf = ts.x(hp.u(fx)); int xl = ts.x(hp.u(lx)); int x1 = min(xf,xl)-rb; int x2 = max(xf,xl)+rb; int y0 = ts.y(vp.u(0.0)); g2d.drawLine(x1,y0,x2,y0); double xi = fx+ix*dx; double fi = _f[ix]; int x = ts.x(hp.u(xi)); int y = ts.y(vp.u(fi)); g2d.drawLine(x,y0,x,y); g2d.fillOval(x-rb,y-rb,1+2*rb,1+2*rb);
/** * Called by tile axes adjacent to this tile. * Also used internally, for consistency. */ Transcaler getTranscaler(int w, int h) { return new Transcaler( _vr.x,_vr.y,_vr.x+_vr.width,_vr.y+_vr.height,0,0,w-1,h-1); }
/** * Transforms a pixel y coordinate to a vertical world coordinate. * @param y the pixel y coordinate. * @return the vertical world coordinate. */ public double pixelToWorldVertical(int y) { return _vp.v(_ts.y(y)); }
/** * Transforms a pixel x coordinate to a horizontal world coordinate. * @param x the pixel x coordinate. * @return the horizontal world coordinate. */ public double pixelToWorldHorizontal(int x) { return _hp.v(_ts.x(x)); }
/** * Constructs a transcaler with specified coordinate mapping. * @param x1u the user x-coordinate corresponding to x1d. * @param y1u the user y-coordinate corresponding to y1d. * @param x2u the user x-coordinate corresponding to x2d. * @param y2u the user y-coordinate corresponding to y2d. * @param x1d the device x-coordinate corresponding to x1u. * @param y1d the device y-coordinate corresponding to y1u. * @param x2d the device x-coordinate corresponding to x2u. * @param y2d the device y-coordinate corresponding to y2u. */ public Transcaler( double x1u, double y1u, double x2u, double y2u, int x1d, int y1d, int x2d, int y2d) { setMapping(x1u,y1u,x2u,y2u,x1d,y1d,x2d,y2d); } /**
public void testCombineWithLinearB () { Transcaler tr = new Transcaler(0.0, 0.0, 1.0, 1.0, 0, 0, 100, 100); Projector xp = new Projector(0.0, 10.0, AxisScale.LINEAR); Projector yp = new Projector(50.0, 0.0, AxisScale.LINEAR); Transcaler tr_c = tr.combineWith(xp, yp); assertVeryClose(5.0, tr_c.x(tr_c.x(5.0))); assertVeryClose(5.0, tr_c.y(tr_c.y(5.0))); assertVeryClose(75, tr_c.x(tr_c.x(75))); assertVeryClose(75, tr_c.y(tr_c.y(75))); }
int w = ts.width(vr.width); int h = ts.height(vr.height); int y = ts.y(vp.u(0.0)); g2d.drawLine(0,y,w-1,y); } else if (_horizontal==Horizontal.MAJOR && axisLeftRight!=null) { double vtic = fticMajor+itic*dticMajor; double utic = vp.u(vtic); int y = ts.y(utic); g2d.drawLine(0,y,w-1,y); int x = ts.x(hp.u(0.0)); g2d.drawLine(x,0,x,h-1); } else if (_vertical==Vertical.MAJOR && axisTopBottom!=null) { double vtic = fticMajor+itic*dticMajor; double utic = hp.u(vtic); int x = ts.x(utic); g2d.drawLine(x,0,x,h-1);
private Cdouble pointToComplex(int x, int y) { Transcaler ts = _tile.getTranscaler(); Projector hp = _tile.getHorizontalProjector(); Projector vp = _tile.getVerticalProjector(); double xu = ts.x(x); double yu = ts.y(y); double xv = hp.v(xu); double yv = vp.v(yu); return roundToReal(new Cdouble(xv,yv)); }
/** * Returns a new transcaler that combines this transcaler with projectors. * The returned transcaler includes the transforms of the projectors. * Does not change this transcaler. * @param xp the projector for x coordinates. * @param yp the projector for y coordinates. * @return the new transcaler. */ public Transcaler combineWith(Projector xp, Projector yp) { AxisScale xsc = xp.getScale(); AxisScale ysc = yp.getScale(); double x1v = (xsc==AxisScale.LOG10)?log10(xp.v(_x1u)):xp.v(_x1u); double x2v = (xsc==AxisScale.LOG10)?log10(xp.v(_x2u)):xp.v(_x2u); double y1v = (ysc==AxisScale.LOG10)?log10(yp.v(_y1u)):yp.v(_y1u); double y2v = (ysc==AxisScale.LOG10)?log10(yp.v(_y2u)):yp.v(_y2u); return new Transcaler(x1v,y1v,x2v,y2v,_x1d,_y1d,_x2d,_y2d, xsc, ysc); }
/** * Constructs a transcaler with specified coordinate mapping * and specified Scales. This should only be used with the * combineWith() method when receiving projectors that * may be LOG scale. It is not the intention to be able * to create arbitrary LOG scaled Transcalers. * @param x1u the user x-coordinate corresponding to x1d. * @param y1u the user y-coordinate corresponding to y1d. * @param x2u the user x-coordinate corresponding to x2d. * @param y2u the user y-coordinate corresponding to y2d. * @param x1d the device x-coordinate corresponding to x1u. * @param y1d the device y-coordinate corresponding to y1u. * @param x2d the device x-coordinate corresponding to x2u. * @param y2d the device y-coordinate corresponding to y2u. * @param hscale the horizontal projector Scale * @param vscale the vertical projector Scale */ private Transcaler( double x1u, double y1u, double x2u, double y2u, int x1d, int y1d, int x2d, int y2d, AxisScale hscale, AxisScale vscale) { _xpScale = hscale; _ypScale = vscale; setMapping(x1u,y1u,x2u,y2u,x1d,y1d,x2d,y2d); } }
public void testCombineWithLogB () { Transcaler tr = new Transcaler(0.0, 0.0, 1.0, 1.0, 0, 0, 100, 100); Projector xp = new Projector(1.0, 10.0, AxisScale.LOG10); Projector yp = new Projector(50.0, 1.0, AxisScale.LOG10); Transcaler tr_c = tr.combineWith(xp, yp); assertToleranceClose(Math.log10(5.0), tr_c.x(tr_c.x(5.0)), 0.02); assertToleranceClose(Math.log10(26.0), tr_c.y(tr_c.y(26.0)), 0.02); assertToleranceClose(75, tr_c.x(Math.pow(10,tr_c.x(75))), 0.02); assertToleranceClose(13, tr_c.y(Math.pow(10,tr_c.y(13))), 0.02); }
/** * Computes coordinates for a contour segment. */ private void computeXY( Projector hp, Projector vp, Transcaler ts, int n, float[] x1, float[] x2, int[] x, int[] y) { ts = ts.combineWith(hp,vp); float[] xv,yv; if (_transposed) { xv = x2; yv = x1; } else { xv = x1; yv = x2; } for (int i=0; i<n; ++i) { x[i] = ts.x(xv[i]); y[i] = ts.y(yv[i]); } }
public void testBasicTranscale () { Transcaler tr = new Transcaler(0.0, 0.0, 1.0, 1.0, 0, 0, 100, 100); assertVeryClose(0.0, tr.x(0)); assertVeryClose(0.5, tr.y(50)); assertVeryClose(0.77, tr.x(77)); assertVeryClose(10, tr.y(0.1)); assertVeryClose(83, tr.x(0.83)); assertVeryClose(0.36, tr.x(tr.x(0.36))); assertVeryClose(0.74, tr.y(tr.y(0.74))); assertVeryClose(12, tr.x(tr.x(12))); assertVeryClose(63, tr.y(tr.y(63))); }