Revision 19516 trunk/extensions/extRasterTools-SE/src/org/gvsig/raster/beans/canvas/layers/functions/StraightLine.java
StraightLine.java | ||
---|---|---|
51 | 51 |
private int width = 6; |
52 | 52 |
private Color color = Color.WHITE; |
53 | 53 |
private int border = 2; |
54 |
|
|
54 |
|
|
55 |
|
|
55 | 56 |
/** |
56 | 57 |
* Constructor. Calcula las esquinas del cuadrado |
57 | 58 |
* @param p |
... | ... | |
151 | 152 |
} |
152 | 153 |
|
153 | 154 |
private int valueToPixelX(double value) { |
155 |
value = minx + ((maxx - minx) * value); |
|
154 | 156 |
return (int) Math.round(canvas.getCanvasMinX() + border + ((canvas.getCanvasMaxX() - canvas.getCanvasMinX() - (border * 2)) * value)); |
155 | 157 |
} |
156 | 158 |
|
157 | 159 |
private double pixelToValueX(int pixel) { |
158 |
return ((double) (pixel - canvas.getCanvasMinX() - border) / (double) (canvas.getCanvasMaxX() - canvas.getCanvasMinX() - (border * 2))); |
|
160 |
double value = ((double) (pixel - canvas.getCanvasMinX() - border) / (double) (canvas.getCanvasMaxX() - canvas.getCanvasMinX() - (border * 2.0D))); |
|
161 |
|
|
162 |
value = (value - minx) / (maxx - minx); |
|
163 |
|
|
164 |
return value; |
|
159 | 165 |
} |
160 | 166 |
|
161 | 167 |
private int valueToPixelY(double value) { |
... | ... | |
164 | 170 |
} |
165 | 171 |
|
166 | 172 |
private double pixelToValueY(int pixel) { |
167 |
return (1.0D - ((double) (pixel - canvas.getCanvasMinY() - border) / (double) (canvas.getCanvasMaxY() - canvas.getCanvasMinY() - (border * 2)))); |
|
173 |
return (1.0D - ((double) (pixel - canvas.getCanvasMinY() - border) / (double) (canvas.getCanvasMaxY() - canvas.getCanvasMinY() - (border * 2.0D))));
|
|
168 | 174 |
} |
169 | 175 |
} |
170 | 176 |
|
... | ... | |
198 | 204 |
// Dibujamos una l?nea desde un punto hasta el siguiente |
199 | 205 |
Square square = null; |
200 | 206 |
Square lastSquare = null; |
207 |
|
|
208 |
if (listSquare.size() > 0) { |
|
209 |
square = ((Square) listSquare.get(0)); |
|
210 |
g.drawLine(canvas.getCanvasMinX(), square.getPixelY(), square.getPixelX(), square.getPixelY()); |
|
211 |
} |
|
201 | 212 |
for (int i = 0; i < listSquare.size(); i++) { |
202 | 213 |
lastSquare = square; |
203 | 214 |
square = ((Square) listSquare.get(i)); |
204 | 215 |
if (lastSquare != null) |
205 | 216 |
g.drawLine(lastSquare.getPixelX(), lastSquare.getPixelY(), square.getPixelX(), square.getPixelY()); |
206 | 217 |
} |
218 |
if (listSquare.size() > 0) { |
|
219 |
square = ((Square) listSquare.get(listSquare.size() - 1)); |
|
220 |
g.drawLine(square.getPixelX(), square.getPixelY(), canvas.getCanvasMaxX(), square.getPixelY()); |
|
221 |
} |
|
207 | 222 |
|
208 | 223 |
// Dibujamos los cuadrados de los puntos |
209 | 224 |
for (int i = 0; i < listSquare.size(); i++) { |
... | ... | |
377 | 392 |
* @return |
378 | 393 |
*/ |
379 | 394 |
public double[] getInValues(double min, double max) { |
380 |
double[] in = new double[listSquare.size()]; |
|
395 |
double[] in = getPercentInValues(); |
|
396 |
for (int i = 0; i < in.length; i++) |
|
397 |
in[i] = min + (in[i] * (max - min)); |
|
398 |
return in; |
|
399 |
} |
|
400 |
|
|
401 |
/** |
|
402 |
* Valores de los datos de salida correspondientes al m?nimo y al m?ximo de |
|
403 |
* cada tramo. Estos tendr?n un rango entre 0 y 255. |
|
404 |
* @return |
|
405 |
*/ |
|
406 |
public int[] getOutValues() { |
|
407 |
double[] values = getPercentOutValues(); |
|
408 |
int[] out = new int[values.length]; |
|
409 |
for (int i = 0; i < values.length; i++) |
|
410 |
out[i] = (int) Math.round(values[i] * 255.0D); |
|
411 |
return out; |
|
412 |
} |
|
413 |
|
|
414 |
/** |
|
415 |
* Valores de los datos de entrada correspondientes al m?nimo y al m?ximo de |
|
416 |
* cada tramo devuelto en forma de porcentaje |
|
417 |
* |
|
418 |
* @param min |
|
419 |
* @param max |
|
420 |
* @return |
|
421 |
*/ |
|
422 |
public double[] getPercentInValues() { |
|
423 |
double[] in = new double[listSquare.size() + 2]; |
|
381 | 424 |
for (int i = 0; i < listSquare.size(); i++) { |
382 | 425 |
Square square = ((Square) listSquare.get(i)); |
383 |
in[i] = min + (square.getX() * (max - min));
|
|
426 |
in[i + 1] = minx + ((maxx - minx) * square.getX());
|
|
384 | 427 |
} |
428 |
in[0] = 0.0D; |
|
429 |
in[in.length - 1] = 1.0D; |
|
385 | 430 |
return in; |
386 | 431 |
} |
387 | 432 |
|
388 | 433 |
/** |
389 | 434 |
* Valores de los datos de salida correspondientes al m?nimo y al m?ximo de |
390 |
* cada tramo. Estos tendr?n un rango entre 0 y 255.
|
|
435 |
* cada tramo, devueltos en forma de porcentaje.
|
|
391 | 436 |
* @return |
392 | 437 |
*/ |
393 |
public int[] getOutValues() {
|
|
394 |
int[] out = new int[listSquare.size()];
|
|
438 |
public double[] getPercentOutValues() {
|
|
439 |
double[] out = new double[listSquare.size() + 2];
|
|
395 | 440 |
for (int i = 0; i < listSquare.size(); i++) { |
396 | 441 |
Square square = ((Square) listSquare.get(i)); |
397 |
out[i] = (int) Math.round(square.getY() * 255.0D);
|
|
442 |
out[i + 1] = square.getY();
|
|
398 | 443 |
} |
444 |
out[0] = out[1]; |
|
445 |
out[out.length - 1] = out[out.length - 2]; |
|
399 | 446 |
return out; |
400 | 447 |
} |
401 | 448 |
|
Also available in: Unified diff