| 1 |
<?php |
| 2 |
declare(strict_types = 1); |
| 3 |
|
| 4 |
namespace BaconQrCode\Renderer\Eye; |
| 5 |
|
| 6 |
use BaconQrCode\Encoder\ByteMatrix; |
| 7 |
use BaconQrCode\Renderer\Module\ModuleInterface; |
| 8 |
use BaconQrCode\Renderer\Path\Path; |
| 9 |
|
| 10 |
/** |
| 11 |
* Renders an eye based on a module renderer. |
| 12 |
*/ |
| 13 |
final class ModuleEye implements EyeInterface |
| 14 |
{ |
| 15 |
public function __construct(private readonly ModuleInterface $module) |
| 16 |
{ |
| 17 |
} |
| 18 |
|
| 19 |
public function getExternalPath() : Path |
| 20 |
{ |
| 21 |
$matrix = new ByteMatrix(7, 7); |
| 22 |
|
| 23 |
for ($x = 0; $x < 7; ++$x) { |
| 24 |
$matrix->set($x, 0, 1); |
| 25 |
$matrix->set($x, 6, 1); |
| 26 |
} |
| 27 |
|
| 28 |
for ($y = 1; $y < 6; ++$y) { |
| 29 |
$matrix->set(0, $y, 1); |
| 30 |
$matrix->set(6, $y, 1); |
| 31 |
} |
| 32 |
|
| 33 |
return $this->module->createPath($matrix)->translate(-3.5, -3.5); |
| 34 |
} |
| 35 |
|
| 36 |
public function getInternalPath() : Path |
| 37 |
{ |
| 38 |
$matrix = new ByteMatrix(3, 3); |
| 39 |
|
| 40 |
for ($x = 0; $x < 3; ++$x) { |
| 41 |
for ($y = 0; $y < 3; ++$y) { |
| 42 |
$matrix->set($x, $y, 1); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
return $this->module->createPath($matrix)->translate(-1.5, -1.5); |
| 47 |
} |
| 48 |
} |