-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewport.java
More file actions
40 lines (35 loc) · 979 Bytes
/
Copy pathViewport.java
File metadata and controls
40 lines (35 loc) · 979 Bytes
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
public 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 this.row;
}
public int getCol(){
return this.col;
}
public int getNumRows(){
return this.numRows;
}
public int getNumCols(){
return this.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);
}
public void shift(int col, int row) {
this.col = col;
this.row = row;
}
public boolean contains(Point p) {
return p.y >= this.row && p.y < this.row + this.numRows && p.x >= this.col && p.x < this.col + this.numCols;
}
}