ingo@535: package de.intevation.flys.client.shared; ingo@535: ingo@535: import java.io.Serializable; ingo@535: ingo@610: import com.google.gwt.core.client.GWT; ingo@610: ingo@535: ingo@535: /** ingo@535: * This object supports a linear transformation to transform xy coordinates into ingo@535: * an other coordinate system based on scale and translation values. ingo@535: * ingo@535: * @author Ingo Weinzierl ingo@535: */ ingo@535: public class Transform2D implements Serializable { ingo@535: ingo@535: protected double sx; ingo@535: protected double sy; ingo@535: ingo@535: protected double tx; ingo@535: protected double ty; ingo@535: ingo@535: ingo@535: public Transform2D() { ingo@535: } ingo@535: ingo@535: ingo@535: /** ingo@535: * Creates a new transformation with scale and translation factors. ingo@535: * ingo@535: * @param sx The scale factor for the x axis. ingo@535: * @param sy The scale factor for the y axis. ingo@535: * @param tx The translation factor for the x axis. ingo@535: * @param ty The translation factor for the y axis. ingo@535: */ ingo@535: public Transform2D(double sx, double sy, double tx, double ty) { ingo@535: this.sx = sx; ingo@535: this.sy = sy; ingo@535: this.tx = tx; ingo@535: this.ty = ty; ingo@535: } ingo@535: ingo@535: ingo@535: /** ingo@535: * Transforms the pixel x and y into a new coordinate system based on the ingo@535: * scale and translation values specified in the constructor. ingo@535: */ ingo@535: public double[] transform(double x, double y) { ingo@535: double resX = sx * x + tx; ingo@535: double resY = sy * y + ty; ingo@535: ingo@535: return new double[] { resX, resY }; ingo@535: } ingo@610: ingo@610: ingo@610: public void dumpGWT() { ingo@610: GWT.log("SX = " + sx); ingo@610: GWT.log("SY = " + sy); ingo@610: GWT.log("TX = " + tx); ingo@610: GWT.log("TY = " + ty); ingo@610: } ingo@535: } ingo@535: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :