Revision 19623 trunk/libraries/libRaster/src/org/gvsig/raster/util/MathUtils.java

View differences:

MathUtils.java
33 33
	public static double MMSINCH = 25.4D;
34 34
	public static double CMSINCH = 2.54D;
35 35
	
36
	
37 36
	/**
38
     * Recorta el n?mero de decimales a n del n?mero pasado por par?metro
39
     * @return N?mero recortado
40
     */
41
    public static double tailDecimals(double num, int n){
42
    	long m = (long)Math.pow(10, n);
43
        num *= m;
44
        long aux = ((long)num);
45
        num = (double)((double)aux / (double)m);
46
        return num;
47
    }
48
    
37
	 * Recorta el n?mero de decimales a n del n?mero pasado por par?metro
38
	 * @return N?mero recortado
39
	 */
40
	public static double clipDecimals(double num, int n) {
41
		long m = (long) Math.pow(10, n);
42
		long aux = Math.round(num * m);
43
		return (double) aux / (double) m;
44
	}
45
		
49 46
	/**
50 47
	 * Convierte pixels en milimetros dependiendo del los puntos por pulgada
51 48
	 * @param pixels N?mero de pixels
......
122 119
	 * @param ppp Puntos por pulgada
123 120
	 * @return N?mero de pixeles
124 121
	 */
125
	public static int convertMmsToPixels(double mms, int ppp){
126
		return (int)(mms * MathUtils.INCHESMM * ppp);
122
	public static int convertMmsToPixels(double mms, int ppp) {
123
		return (int) (mms * MathUtils.INCHESMM * ppp);
127 124
	}
128
	
129
    /**
125

  
126
	/**
130 127
	 * Formats a double with an specified number of decimals. 
131 128
	 * @param num
132 129
	 * Value to tail
......
135 132
	 * @return
136 133
	 * The formatted double
137 134
	 */
138
    public static double format(double num, int n){
139
    	long m = (long)Math.pow(10, n);
140
        num *= m;
141
        long aux = ((long)num);
142
        num = (double)((double)aux / (double)m);
143
        return num;
144
    }
145
    
146
    /**
147
     * Convierte un array de Double en un array de tipos b?sicos double
148
     * @param list Lista de objetos Double
149
     * @return double[] lista de tipos b?sicos double
150
     */
151
    public static double[] convertDoubleList(Double[] list) {
152
    	if(list == null)
153
    		return null;
154
    	double[] result = new double[list.length];
155
		for (int i = 0; i < list.length; i++) 
135
	public static double format(double num, int n) {
136
		long m = (long) Math.pow(10, n);
137
		num *= m;
138
		long aux = ((long) num);
139
		num = (double) ((double) aux / (double) m);
140
		return num;
141
	}
142

  
143
	/**
144
	 * Convierte un array de Double en un array de tipos b?sicos double
145
	 * @param list Lista de objetos Double
146
	 * @return double[] lista de tipos b?sicos double
147
	 */
148
	public static double[] convertDoubleList(Double[] list) {
149
		if (list == null)
150
			return null;
151
		double[] result = new double[list.length];
152
		for (int i = 0; i < list.length; i++)
156 153
			result[i] = list[i].doubleValue();
157 154
		return result;
158
    }
159
    
160
    /**
161
     * Convierte un array de Integer en un array de tipos b?sicos int
162
     * @param list Lista de objetos Integer
163
     * @return int[] lista de tipos b?sicos int
164
     */
165
    public static int[] convertIntList(Integer[] list) {
166
    	if(list == null)
167
    		return null;
168
    	int[] result = new int[list.length];
169
		for (int i = 0; i < list.length; i++) 
155
	}
156

  
157
	/**
158
	 * Convierte un array de Integer en un array de tipos b?sicos int
159
	 * @param list Lista de objetos Integer
160
	 * @return int[] lista de tipos b?sicos int
161
	 */
162
	public static int[] convertIntList(Integer[] list) {
163
		if (list == null)
164
			return null;
165
		int[] result = new int[list.length];
166
		for (int i = 0; i < list.length; i++)
170 167
			result[i] = list[i].intValue();
171 168
		return result;
172
    }
173
}
169
	}
170
}

Also available in: Unified diff