-
Notifications
You must be signed in to change notification settings - Fork 3
/
Viewport.java
40 lines (34 loc) · 922 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
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 void shift(int col, int row)
{
this.col = col;
this.row = row;
}
public boolean contains(Point p)
{
return p.getY() >= this.row && p.getY() < this.row + this.numRows &&
p.getX() >= this.col && p.getX() < 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 getCol(){ return col; }
public int getRow(){ return row; }
public int getNumRows(){ return numRows; }
public int getNumCols(){ return numCols; }
}