@@ -158,9 +158,14 @@ public function size():int{
158
158
}
159
159
160
160
/**
161
- * Returns the value of the module at position [$x, $y]
161
+ * Returns the value of the module at position [$x, $y] or -1 if the coordinate is outside of the matrix
162
162
*/
163
163
public function get (int $ x , int $ y ):int {
164
+
165
+ if (!isset ($ this ->matrix [$ y ][$ x ])){
166
+ return -1 ;
167
+ }
168
+
164
169
return $ this ->matrix [$ y ][$ x ];
165
170
}
166
171
@@ -171,7 +176,10 @@ public function get(int $x, int $y):int{
171
176
* false => $M_TYPE
172
177
*/
173
178
public function set (int $ x , int $ y , bool $ value , int $ M_TYPE ):self {
174
- $ this ->matrix [$ y ][$ x ] = $ M_TYPE | ($ value ? $ this ::IS_DARK : 0 );
179
+
180
+ if (isset ($ this ->matrix [$ y ][$ x ])){
181
+ $ this ->matrix [$ y ][$ x ] = $ M_TYPE | ($ value ? $ this ::IS_DARK : 0 );
182
+ }
175
183
176
184
return $ this ;
177
185
}
@@ -180,7 +188,10 @@ public function set(int $x, int $y, bool $value, int $M_TYPE):self{
180
188
* Flips the value of the module
181
189
*/
182
190
public function flip (int $ x , int $ y ):self {
183
- $ this ->matrix [$ y ][$ x ] ^= $ this ::IS_DARK ;
191
+
192
+ if (isset ($ this ->matrix [$ y ][$ x ])){
193
+ $ this ->matrix [$ y ][$ x ] ^= $ this ::IS_DARK ;
194
+ }
184
195
185
196
return $ this ;
186
197
}
@@ -191,6 +202,11 @@ public function flip(int $x, int $y):self{
191
202
* true => $value & $M_TYPE === $M_TYPE
192
203
*/
193
204
public function checkType (int $ x , int $ y , int $ M_TYPE ):bool {
205
+
206
+ if (!isset ($ this ->matrix [$ y ][$ x ])){
207
+ return false ;
208
+ }
209
+
194
210
return ($ this ->matrix [$ y ][$ x ] & $ M_TYPE ) === $ M_TYPE ;
195
211
}
196
212
0 commit comments