ModuleEye.php 1.2 KB

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