Commits

Anonymous committed 4084fbd

formatting

Comments (0)

Files changed (1)

trunk/Slick/src/org/newdawn/slick/geom/Transform.java

 
 import org.newdawn.slick.util.FastTrig;
 
-/**   
- * A 2 dimensional transformation that can be applied to <code>Shape</code> implemenations.   
- *    
- * @author Mark   
- */   
-public class Transform {   
-    /**   
-     * Value for each position in the matrix   
-     *    
-     * |0 1 2|   
-     * |3 4 5|   
-     * |6 7 8|   
-     */   
-    private float matrixPosition[];   
-   
-    /**   
-     * Create and identity transform   
-     *   
-     */   
-    public Transform() {   
-        matrixPosition = new float[]{1, 0, 0, 0, 1, 0, 0, 0, 1};   
-    }   
+/**
+ * A 2 dimensional transformation that can be applied to <code>Shape</code> implemenations.
+ *
+ * @author Mark
+ */
+public class Transform {
+    /**
+     * Value for each position in the matrix
+     *
+     * |0 1 2|
+     * |3 4 5|
+     * |6 7 8|
+     */
+    private float matrixPosition[];
     
-    /**   
+    /**
+     * Create and identity transform
+     *
+     */
+    public Transform() {
+        matrixPosition = new float[] {
+        		1, 0, 0,
+        		0, 1, 0,
+        		0, 0, 1,
+        };
+    }
+    
+    /**
      * Copy a transform
-     * 
+     *
      * @param other The other transform to copy
-     */   
-    public Transform(Transform other) {   
+     */
+    public Transform(Transform other) {
     	matrixPosition = new float[9];
-    	for (int i=0;i<9;i++) {
+    	for (int i = 0; i < 9; i++) {
     		matrixPosition[i] = other.matrixPosition[i];
     	}
-    }   
+    }
        
     /**
      * Concatanate to transform into one
         if(matrixPosition.length != 6) {   
             throw new RuntimeException("The parameter must be a float array of length 6.");   
         }   
-        this.matrixPosition = new float[]{matrixPosition[0], matrixPosition[1], matrixPosition[2],    
+        this.matrixPosition = new float[] {
+        		matrixPosition[0], matrixPosition[1], matrixPosition[2],    
                 matrixPosition[3], matrixPosition[4], matrixPosition[5],    
-                0, 0, 1};   
+                0, 0, 1,
+        };
     }   
        
     /**   
      * @param point12 float for the sixth position   
      */   
     public Transform(float point00, float point01, float point02, float point10, float point11, float point12) {   
-        matrixPosition = new float[]{point00, point01, point02, point10, point11, point12, 0, 0, 1};   
+        matrixPosition = new float[] {
+        		point00, point01, point02,
+        		point10, point11, point12,
+        		0, 0, 1,
+        };   
     }   
        
     /**   
         //TODO performance can be improved by removing the safety to the destination array   
         float result[] = source == destination ? new float[numberOfPoints * 2] : destination;
            
-        for(int i=0;i<numberOfPoints * 2;i+=2) {   
-            for(int j=0;j<6;j+=3) {   
-                result[i + (j / 3)] = source[i + sourceOffset] * matrixPosition[j] + source[i + sourceOffset + 1] * matrixPosition[j + 1] + 1 * matrixPosition[j + 2];   
-            }   
-        }   
+        for (int i = 0; i < numberOfPoints*2; i += 2) {
+            for (int j = 0; j < 6; j += 3) {
+                result[i + (j / 3)] = source[i + sourceOffset] * matrixPosition[j] +
+                		source[i + sourceOffset + 1] * matrixPosition[j + 1] + 1 * matrixPosition[j + 2];   
+            }
+        }
         
         if (source == destination) {
 	        //for safety of the destination, the results are copied after the entire operation.   
-	        for(int i=0;i<numberOfPoints * 2;i+=2) {   
-	            destination[i + destOffset] = result[i];   
-	            destination[i + destOffset + 1] = result[i + 1];   
+	        for (int i = 0; i < numberOfPoints*2; i += 2) {
+	            destination[i + destOffset] = result[i];
+	            destination[i + destOffset + 1] = result[i + 1];
 	        }   
         }
     }   
 //        
         matrixPosition = mp;
         return this;
-    }   
-   
-       
-    /**   
-     * Convert this Transform to a String.   
-     *    
-     * @return This Transform in human readable format.   
-     */   
-    public String toString() {   
-        String result = "Transform[[" + matrixPosition[0] + "," + matrixPosition[1] + "," + matrixPosition[2] +    
-        "][" + matrixPosition[3] + "," + matrixPosition[4] + "," + matrixPosition[5] + 
-        "][" + matrixPosition[6] + "," + matrixPosition[7] + "," + matrixPosition[8] + "]]";   
-           
-        return result.toString();   
-    }   
-   
-    /**   
-     * Get an array representing this Transform.   
-     *    
-     * @return an array representing this Transform.    
-     */   
-    public float[] getMatrixPosition() {   
-        return matrixPosition;   
-    }   
-       
+    }
+    
+    /**
+     * Convert this Transform to a String.
+     *
+     * @return This Transform in human readable format.
+     */
+    public String toString() {
+        String result = "Transform[[" + matrixPosition[0] + "," + matrixPosition[1] + "," + matrixPosition[2] +
+        "][" + matrixPosition[3] + "," + matrixPosition[4] + "," + matrixPosition[5] +
+        "][" + matrixPosition[6] + "," + matrixPosition[7] + "," + matrixPosition[8] + "]]";
+        
+        return result.toString();
+    }
+    
+    /**
+     * Get an array representing this Transform.
+     *
+     * @return an array representing this Transform.
+     */
+    public float[] getMatrixPosition() {
+        return matrixPosition;
+    }
+    
     /**   
      * Create a new rotation Transform   
      *    
      * @param angle The angle in radians to set the transform.   
      * @return The resulting Transform   
      */   
-    public static Transform createRotateTransform(float angle) {   
-        return new Transform((float)FastTrig.cos(angle), -(float)FastTrig.sin(angle), 0, (float)FastTrig.sin(angle), (float)FastTrig.cos(angle), 0);   
-    }   
+    public static Transform createRotateTransform(float angle) {
+        return new Transform(
+        		(float)FastTrig.cos(angle), -(float)FastTrig.sin(angle), 0,
+        		(float)FastTrig.sin(angle), (float)FastTrig.cos(angle), 0);
+    }
        
     /**   
      * Create a new rotation Transform around the specified point   
 
         return temp;   
     }   
-       
-    /**   
-     * Create a new translation Transform   
-     *    
-     * @param xOffset The amount to move in the x direction   
-     * @param yOffset The amount to move in the y direction   
-     * @return The resulting Transform   
-     */   
-    public static Transform createTranslateTransform(float xOffset, float yOffset) {   
-        return new Transform(1, 0, xOffset, 0, 1, yOffset);   
-    }   
-       
-    /**   
-     * Create an new scaling Transform   
-     *    
-     * @param xScale The amount to scale in the x coordinate   
-     * @param yScale The amount to scale in the x coordinate   
-     * @return The resulting Transform   
-     */   
-    public static Transform createScaleTransform(float xScale, float yScale) {   
-        return new Transform(xScale, 0, 0, 0, yScale, 0);   
+    
+    /**
+     * Create a new translation Transform
+     *
+     * @param xOffset The amount to move in the x direction
+     * @param yOffset The amount to move in the y direction
+     * @return The resulting Transform
+     */
+    public static Transform createTranslateTransform(float xOffset, float yOffset) {
+        return new Transform(1, 0, xOffset, 0, 1, yOffset);
+    }
+    
+    /**
+     * Create an new scaling Transform
+     *
+     * @param xScale The amount to scale in the x coordinate
+     * @param yScale The amount to scale in the x coordinate
+     * @return The resulting Transform
+     */
+    public static Transform createScaleTransform(float xScale, float yScale) {
+        return new Transform(xScale, 0, 0, 0, yScale, 0);
     }
     
     /**
      * Transform the vector2f based on the matrix defined in this transform
-     * 
+     *
      * @param pt The point to be transformed
      * @return The resulting point transformed by this matrix
      */
     public Vector2f transform(Vector2f pt) {
-    	float[] in = new float[] {pt.x, pt.y};
+    	float[] in = new float[] { pt.x, pt.y };
     	float[] out = new float[2];
-    	
     	transform(in, 0, out, 0, 1);
-    	
     	return new Vector2f(out[0], out[1]);
     }
-}   
+}