-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGrid.php
More file actions
35 lines (33 loc) · 778 Bytes
/
Grid.php
File metadata and controls
35 lines (33 loc) · 778 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
<?php
class DGrid {
/**
* Grid
*
* Sort of like a 2D array, but simplified for the purposes of this extension
*/
private $matrix;
private $width;
private $height;
public function __construct() {
$this->matrix = array();
}
public function get($r, $c){
while (count($this->matrix) <= $r) {
$this->matrix[] = array();
}
while (count($this->matrix[$r]) <= $c) {
$this->matrix[$r][] = false;
}
return $this->matrix[$r][$c];
}
public function set($r, $c, $value) {
$this->height = max($this->height, $r+1);
$this->width = max($this->width, $c+1);
$this->get($r, $c);
return $this->matrix[$r][$c] = $value;
}
public function __get($name) {
if ($name == 'width') return $this->width;
if ($name == 'height') return $this->height;
}
}