-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGridSection.java
33 lines (30 loc) · 1.1 KB
/
GridSection.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
/**
* Austin Briggs and Nick Evans
* CSE 332 AB
* Project 3B
*
* GridSection represents a grid and the area it occupies in the grid described in coordinates.
* */
public class GridSection {
public int[][] grid; //Population grid of the GridSection
public GridCoordinates gridCoordinates; //Coordinates of the main grid this GridSection contains
/** Constructs GridSection
* @param grid is the grid that contains
* @param coordinates is the location that this represents in the main grid.
* */
public GridSection(int[][] grid, GridCoordinates coordinates){
this.grid = grid;
this.gridCoordinates = coordinates;
}
/** Returns the population at the given location. Returns zero if outside of grid location.
* @param x the locations horizontal coordinate being queried
* @param y the locations vertical coordinate being queried
* */
public int getPopAtLocation(int x, int y){
if(x> gridCoordinates.maxX || x < gridCoordinates.minX
|| y > gridCoordinates.maxY || y < gridCoordinates.minY){
return 0;
}
return grid[x-gridCoordinates.minX][y - gridCoordinates.minY];
}
}