public class cornerTransform {
  double x0, y0, x1, y1, x2, y2, x3, y3;
  double h, w;

  cornerTransform(ImArray i) {
    x0 = 0;
    y0 = 0;
    x1 = i.width;
    y1 = 0;
    x2 = 0;
    y2 = i.height;
    x3 = i.width;
    y3 = i.height;
    h = i.height;
    w = i.width;
  }

  cornerTransform(double a, double b, double c, double d, double e, double f,
		  double g, double i, double j, double k) {
    x0 = a;
    y0 = b;
    x1 = c;
    y1 = d;
    x2 = e;
    y2 = f;
    x3 = g;
    y3 = i;
    h = j;
    w = k;
  }

  int x(int i, int j){
    return (int) ((( ((x1-x0)*(h-j)*i) + ( (x3-x2)*(i*j) ) + 
	      ( (x2-x0)*(w-i)*j ) + ( (x3-x1)*i*j ) )/(h*w)) + x0);
  }
  int y(int i, int j){
    return (int) ((( ((y1-y0)*(h-j)*i) + ( (y3-y2)*(i*j) ) + 
	      ( (y2-y0)*(w-i)*j ) + ( (y3-y1)*i*j ) )/(h*w)) + y0);
  }

  int x(double i, double j){
    return (int) ((( ((x1-x0)*(h-j)*i) + ( (x3-x2)*(i*j) ) + 
	      ( (x2-x0)*(w-i)*j ) + ( (x3-x1)*i*j ) )/(h*w)) + x0);
  }
  int y(double i, double j){
    return (int) ((( ((y1-y0)*(h-j)*i) + ( (y3-y2)*(i*j) ) + 
	      ( (y2-y0)*(w-i)*j ) + ( (y3-y1)*i*j ) )/(h*w)) + y0);
  }


  cornerTransform translate(double dx, double dy) {
    return new cornerTransform(x0+dx, y0+dy, x1+dx, y1+dy,
			       x2+dx, y2+dy, x3+dx, y3+dy,
			       h, w);
  }

  cornerTransform shrink(int s) {
    return new cornerTransform(x0/s, y0/s, x1/s, y1/s,
			       x2/s, y2/s, x3/s, y3/s,
			       h/s, w/s);
  }
  cornerTransform grow(int s) {
    return new cornerTransform(x0*s, y0*s, x1*s, y1*s,
			       x2*s, y2*s, x3*s, y3*s,
			       h*s, w*s);
  }

  cornerTransform copy() {
    return new cornerTransform(x0, y0, x1, y1, x2, y2, x3, y3, h, w);
  }

}

