EdgeIterator
11 months ago
DotsModule.php
11 months ago
ModuleInterface.php
11 months ago
RoundnessModule.php
11 months ago
SquareModule.php
11 months ago
SquareModule.php
40 lines
| 1 | <?php |
| 2 | |
| 3 | declare (strict_types=1); |
| 4 | namespace WP2FA_Vendor\BaconQrCode\Renderer\Module; |
| 5 | |
| 6 | use WP2FA_Vendor\BaconQrCode\Encoder\ByteMatrix; |
| 7 | use WP2FA_Vendor\BaconQrCode\Renderer\Module\EdgeIterator\EdgeIterator; |
| 8 | use WP2FA_Vendor\BaconQrCode\Renderer\Path\Path; |
| 9 | /** |
| 10 | * Groups modules together to a single path. |
| 11 | */ |
| 12 | final class SquareModule implements ModuleInterface |
| 13 | { |
| 14 | /** |
| 15 | * @var self|null |
| 16 | */ |
| 17 | private static $instance; |
| 18 | private function __construct() |
| 19 | { |
| 20 | } |
| 21 | public static function instance() : self |
| 22 | { |
| 23 | return self::$instance ?: (self::$instance = new self()); |
| 24 | } |
| 25 | public function createPath(ByteMatrix $matrix) : Path |
| 26 | { |
| 27 | $path = new Path(); |
| 28 | foreach (new EdgeIterator($matrix) as $edge) { |
| 29 | $points = $edge->getSimplifiedPoints(); |
| 30 | $length = \count($points); |
| 31 | $path = $path->move($points[0][0], $points[0][1]); |
| 32 | for ($i = 1; $i < $length; ++$i) { |
| 33 | $path = $path->line($points[$i][0], $points[$i][1]); |
| 34 | } |
| 35 | $path = $path->close(); |
| 36 | } |
| 37 | return $path; |
| 38 | } |
| 39 | } |
| 40 |