-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathViewport.java
45 lines (36 loc) · 950 Bytes
/
Viewport.java
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
final class Viewport {
private int row;
private int col;
private int numRows;
private int numCols;
public Viewport(int numRows, int numCols) {
this.numRows = numRows;
this.numCols = numCols;
}
public int getRow() {
return row;
}
public int getCol() {
return col;
}
public int getNumCols() {
return numCols;
}
public int getNumRows() {
return numRows;
}
public void shift(int col, int row) {
this.col = col;
this.row = row;
}
public boolean contains(Point p) {
return p.y >= row && p.y < row + numRows &&
p.x >= col && p.x < col + numCols;
}
public Point viewportToWorld(int col, int row) {
return new Point( col + this.col, row + this.row );
}
public Point worldToViewport(int col, int row) {
return new Point( col - this.col, row - this.row );
}
}