blob: 551c4c49bed1b917594c22298adab128ee996662 (
plain) (
blame)
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
|
package qtrees;
/**
* Bitmap: A class for representing bitmap;
* @author Sjaak Smetsers
* @version 18-03-2015
*/
public class Bitmap {
// each bit is stored into an two dimensional array
private final boolean[][] raster;
private final int bmWidth, bmHeight;
/**
* Creates an empty bitmap of size width * height
* @param width
* @param height
*/
public Bitmap( int width, int height ) {
raster = new boolean[width][height];
bmWidth = width;
bmHeight = height;
}
/**
* Gets a bit at the specified position
* @param x: x coordinate
* @param y: y coordinate
*/
public boolean getBit( int x, int y ) {
return raster[x][y];
}
/**
* Sets a bit at the specified position
* @param x: x coordinate
* @param y: y coordinate
* @param val: the bit value
*/
public void setBit( int x, int y, boolean val ){
raster[x][y] = val;
}
/**
* Converts a bitmap into a string
* 1 is represented by '*'; 0 by 'O'
* @return the string representation
*/
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
for (int y = 0; y < bmHeight; y++) {
for (int x = 0; x < bmWidth; x++) {
sb.append( raster[x][y] ? '*' : 'O' );
}
sb.append( '\n' );
}
return sb.toString();
}
/**
* @return the width of the bitmap
*/
public int getWidth() {
return bmWidth;
}
/**
* @return the height of the bitmap
*/
public int getHeight() {
return bmHeight;
}
}
|