aboutsummaryrefslogtreecommitdiff
path: root/srcs/phpmyadmin/vendor/bacon/bacon-qr-code/src/Encoder/ByteMatrix.php
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-01-09 10:55:03 +0100
committerCharles <sircharlesaze@gmail.com>2020-01-09 13:09:38 +0100
commit04d6d5ca99ebfd1cebb8ce06618fb3811fc1a8aa (patch)
tree5c691241355c943a3c68ddb06b8cf8c60aa11319 /srcs/phpmyadmin/vendor/bacon/bacon-qr-code/src/Encoder/ByteMatrix.php
parent7e0d85db834d6351ed85d01e5126ac31dc510b86 (diff)
downloadft_server-04d6d5ca99ebfd1cebb8ce06618fb3811fc1a8aa.tar.gz
ft_server-04d6d5ca99ebfd1cebb8ce06618fb3811fc1a8aa.tar.bz2
ft_server-04d6d5ca99ebfd1cebb8ce06618fb3811fc1a8aa.zip
phpmyadmin working
Diffstat (limited to 'srcs/phpmyadmin/vendor/bacon/bacon-qr-code/src/Encoder/ByteMatrix.php')
-rw-r--r--srcs/phpmyadmin/vendor/bacon/bacon-qr-code/src/Encoder/ByteMatrix.php150
1 files changed, 150 insertions, 0 deletions
diff --git a/srcs/phpmyadmin/vendor/bacon/bacon-qr-code/src/Encoder/ByteMatrix.php b/srcs/phpmyadmin/vendor/bacon/bacon-qr-code/src/Encoder/ByteMatrix.php
new file mode 100644
index 0000000..b58cc0a
--- /dev/null
+++ b/srcs/phpmyadmin/vendor/bacon/bacon-qr-code/src/Encoder/ByteMatrix.php
@@ -0,0 +1,150 @@
+<?php
+declare(strict_types = 1);
+
+namespace BaconQrCode\Encoder;
+
+use SplFixedArray;
+use Traversable;
+
+/**
+ * Byte matrix.
+ */
+final class ByteMatrix
+{
+ /**
+ * Bytes in the matrix, represented as array.
+ *
+ * @var SplFixedArray<SplFixedArray<int>>
+ */
+ private $bytes;
+
+ /**
+ * Width of the matrix.
+ *
+ * @var int
+ */
+ private $width;
+
+ /**
+ * Height of the matrix.
+ *
+ * @var int
+ */
+ private $height;
+
+ public function __construct(int $width, int $height)
+ {
+ $this->height = $height;
+ $this->width = $width;
+ $this->bytes = new SplFixedArray($height);
+
+ for ($y = 0; $y < $height; ++$y) {
+ $this->bytes[$y] = SplFixedArray::fromArray(array_fill(0, $width, 0));
+ }
+ }
+
+ /**
+ * Gets the width of the matrix.
+ */
+ public function getWidth() : int
+ {
+ return $this->width;
+ }
+
+ /**
+ * Gets the height of the matrix.
+ */
+ public function getHeight() : int
+ {
+ return $this->height;
+ }
+
+ /**
+ * Gets the internal representation of the matrix.
+ *
+ * @return SplFixedArray<SplFixedArray<int>>
+ */
+ public function getArray() : SplFixedArray
+ {
+ return $this->bytes;
+ }
+
+ /**
+ * @return Traversable<int>
+ */
+ public function getBytes() : Traversable
+ {
+ foreach ($this->bytes as $row) {
+ foreach ($row as $byte) {
+ yield $byte;
+ }
+ }
+ }
+
+ /**
+ * Gets the byte for a specific position.
+ */
+ public function get(int $x, int $y) : int
+ {
+ return $this->bytes[$y][$x];
+ }
+
+ /**
+ * Sets the byte for a specific position.
+ */
+ public function set(int $x, int $y, int $value) : void
+ {
+ $this->bytes[$y][$x] = $value;
+ }
+
+ /**
+ * Clears the matrix with a specific value.
+ */
+ public function clear(int $value) : void
+ {
+ for ($y = 0; $y < $this->height; ++$y) {
+ for ($x = 0; $x < $this->width; ++$x) {
+ $this->bytes[$y][$x] = $value;
+ }
+ }
+ }
+
+ public function __clone()
+ {
+ $this->bytes = clone $this->bytes;
+
+ foreach ($this->bytes as $index => $row) {
+ $this->bytes[$index] = clone $row;
+ }
+ }
+
+ /**
+ * Returns a string representation of the matrix.
+ */
+ public function __toString() : string
+ {
+ $result = '';
+
+ for ($y = 0; $y < $this->height; $y++) {
+ for ($x = 0; $x < $this->width; $x++) {
+ switch ($this->bytes[$y][$x]) {
+ case 0:
+ $result .= ' 0';
+ break;
+
+ case 1:
+ $result .= ' 1';
+ break;
+
+ default:
+ $result .= ' ';
+ break;
+ }
+ }
+
+ $result .= "\n";
+ }
+
+ return $result;
+ }
+}