1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
package utilities;
import utilities.Image2D;
import utilities.Coords2D;
public class Image2DCoords2D extends Image2D {
public Coords2D[] image;
/**
* Creates an Image2DCoords2D.
*/
public Image2DCoords2D(int width, int height, int borderSize, Coords2D value) {
// border
this.borderSize = borderSize;
// original dimensions
this.width = width;
this.height = height;
// dimensions with the border
this.widthWithBorder = width + 2 * borderSize;
this.heightWithBorder = height + 2 * borderSize;
// coordinates
int x = value.getX();
int y = value.getY();
// the image with the border
fill(x, y);
}
/**************************************************************************/
/**
* Fills the Image2DCoords2D with the specified value.
*/
public void fill(int x, int y) {
this.image = new Coords2D[this.widthWithBorder*this.heightWithBorder];
for (int u=0; u<this.widthWithBorder; u++) {
for (int v=0; v<this.heightWithBorder; v++) {
this.image[v*this.widthWithBorder+u] = new Coords2D(x, y);
}
}
}
/**************************************************************************/
/**
* Gets the value of a pixel.
*/
public Coords2D getValue(int x, int y) {
return this.image[y*this.widthWithBorder+x];
}
/**************************************************************************/
/**
* Gets the value of a pixel.
*/
public Coords2D getValue(Coords2D coords) {
return this.image[coords.getY()*this.widthWithBorder+coords.getX()];
}
/**************************************************************************/
/**
* Sets the value of a pixel.
*/
public void setValue(int x, int y, Coords2D value) {
this.image[y*this.widthWithBorder+x] = value;
}
/**************************************************************************/
/**
* Sets the value of a pixel.
*/
public void setValue(Coords2D coords, Coords2D value) {
this.image[coords.getY()*this.widthWithBorder+coords.getX()] = value;
}
} |
Partager