@@ -271,6 +271,20 @@ public function set(int $x, int $y, bool $value, int $M_TYPE):self{
271
271
return $ this ;
272
272
}
273
273
274
+ /**
275
+ * Fills an area of $width * $height, from the given starting point [$startX, $startY] (top left) with $value for $M_TYPE.
276
+ */
277
+ public function setArea (int $ startX , int $ startY , int $ width , int $ height , bool $ value , int $ M_TYPE ):self {
278
+
279
+ for ($ y = $ startY ; $ y < ($ startY + $ height ); $ y ++){
280
+ for ($ x = $ startX ; $ x < ($ startX + $ width ); $ x ++){
281
+ $ this ->set ($ x , $ y , $ value , $ M_TYPE );
282
+ }
283
+ }
284
+
285
+ return $ this ;
286
+ }
287
+
274
288
/**
275
289
* Flips the value of the module at ($x, $y)
276
290
*/
@@ -376,22 +390,11 @@ public function setFinderPattern():self{
376
390
];
377
391
378
392
foreach ($ pos as $ c ){
379
- for ($ y = 0 ; $ y < 7 ; $ y ++){
380
- for ($ x = 0 ; $ x < 7 ; $ x ++){
381
- // outer (dark) 7*7 square
382
- if ($ x === 0 || $ x === 6 || $ y === 0 || $ y === 6 ){
383
- $ this ->set (($ c [0 ] + $ y ), ($ c [1 ] + $ x ), true , $ this ::M_FINDER );
384
- }
385
- // inner (light) 5*5 square
386
- elseif ($ x === 1 || $ x === 5 || $ y === 1 || $ y === 5 ){
387
- $ this ->set (($ c [0 ] + $ y ), ($ c [1 ] + $ x ), false , $ this ::M_FINDER );
388
- }
389
- // 3*3 dot
390
- else {
391
- $ this ->set (($ c [0 ] + $ y ), ($ c [1 ] + $ x ), true , $ this ::M_FINDER_DOT );
392
- }
393
- }
394
- }
393
+ $ this
394
+ ->setArea ($ c [0 ], $ c [1 ], 7 , 7 , true , $ this ::M_FINDER )
395
+ ->setArea (($ c [0 ] + 1 ), ($ c [1 ] + 1 ), 5 , 5 , false , $ this ::M_FINDER )
396
+ ->setArea (($ c [0 ] + 2 ), ($ c [1 ] + 2 ), 3 , 3 , true , $ this ::M_FINDER_DOT )
397
+ ;
395
398
}
396
399
397
400
return $ this ;
@@ -443,13 +446,11 @@ public function setAlignmentPattern():self{
443
446
continue ;
444
447
}
445
448
446
- for ($ ry = -2 ; $ ry <= 2 ; $ ry ++){
447
- for ($ rx = -2 ; $ rx <= 2 ; $ rx ++){
448
- $ v = ($ ry === 0 && $ rx === 0 ) || $ ry === 2 || $ ry === -2 || $ rx === 2 || $ rx === -2 ;
449
-
450
- $ this ->set (($ x + $ rx ), ($ y + $ ry ), $ v , $ this ::M_ALIGNMENT );
451
- }
452
- }
449
+ $ this
450
+ ->setArea (($ x - 2 ), ($ y - 2 ), 5 , 5 , true , $ this ::M_ALIGNMENT )
451
+ ->setArea (($ x - 1 ), ($ y - 1 ), 3 , 3 , false , $ this ::M_ALIGNMENT )
452
+ ->set ($ x , $ y , true , $ this ::M_ALIGNMENT )
453
+ ;
453
454
454
455
}
455
456
}
0 commit comments