-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewport.java
More file actions
47 lines (39 loc) · 1.1 KB
/
Viewport.java
File metadata and controls
47 lines (39 loc) · 1.1 KB
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
public final class Viewport {
private int row;
private int col;
private int numRows;
private int numCols;
private WorldModel world;
public Viewport(int numRows, int numCols) {
this.numRows = numRows;
this.numCols = numCols;
}
public int clamp(int value, int low, int high) {
return Math.min(high, Math.max(value, low));
}
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;
}
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 int getnumRows(){
return this.numRows;
}
public int getnumCols(){
return this.numCols;
}
public int getcol() {
return this.col;
}
public int getrow() {
return this.row;
}
}