/** * 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); }
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) {
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); }
public void testCombineWithLogA () { Transcaler tr = new Transcaler(0.0, 0.0, 1.0, 1.0, 0, 0, 100, 100); Projector xp = new Projector(10.0, 1000.0, AxisScale.LOG10); Projector yp = new Projector(1.0, 1000.0, AxisScale.LOG10); Transcaler tr_c = tr.combineWith(xp, yp); assertToleranceClose(Math.log10(15.0), tr_c.x(tr_c.x(15.0)), 0.02); assertToleranceClose(Math.log10(5.0), tr_c.y(tr_c.y(5.0)), 0.02); assertToleranceClose(75, tr_c.x(Math.pow(10,tr_c.x(75))), 0.02); assertToleranceClose(75, tr_c.y(Math.pow(10,tr_c.y(75))), 0.02); }
/** * 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); }
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))); }
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))); }
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))); }