wp-2fa
/
includes
/
classes
/
bacon
/
bacon-qr-code
/
src
/
Renderer
/
Image
/
TransformationMatrix.php
EpsImageBackEnd.php
11 months ago
ImageBackEndInterface.php
11 months ago
ImagickImageBackEnd.php
11 months ago
SvgImageBackEnd.php
11 months ago
TransformationMatrix.php
11 months ago
TransformationMatrix.php
56 lines
| 1 | <?php |
| 2 | |
| 3 | declare (strict_types=1); |
| 4 | namespace WP2FA_Vendor\BaconQrCode\Renderer\Image; |
| 5 | |
| 6 | final class TransformationMatrix |
| 7 | { |
| 8 | /** |
| 9 | * @var float[] |
| 10 | */ |
| 11 | private $values; |
| 12 | public function __construct() |
| 13 | { |
| 14 | $this->values = [1, 0, 0, 1, 0, 0]; |
| 15 | } |
| 16 | public function multiply(self $other) : self |
| 17 | { |
| 18 | $matrix = new self(); |
| 19 | $matrix->values[0] = $this->values[0] * $other->values[0] + $this->values[2] * $other->values[1]; |
| 20 | $matrix->values[1] = $this->values[1] * $other->values[0] + $this->values[3] * $other->values[1]; |
| 21 | $matrix->values[2] = $this->values[0] * $other->values[2] + $this->values[2] * $other->values[3]; |
| 22 | $matrix->values[3] = $this->values[1] * $other->values[2] + $this->values[3] * $other->values[3]; |
| 23 | $matrix->values[4] = $this->values[0] * $other->values[4] + $this->values[2] * $other->values[5] + $this->values[4]; |
| 24 | $matrix->values[5] = $this->values[1] * $other->values[4] + $this->values[3] * $other->values[5] + $this->values[5]; |
| 25 | return $matrix; |
| 26 | } |
| 27 | public static function scale(float $size) : self |
| 28 | { |
| 29 | $matrix = new self(); |
| 30 | $matrix->values = [$size, 0, 0, $size, 0, 0]; |
| 31 | return $matrix; |
| 32 | } |
| 33 | public static function translate(float $x, float $y) : self |
| 34 | { |
| 35 | $matrix = new self(); |
| 36 | $matrix->values = [1, 0, 0, 1, $x, $y]; |
| 37 | return $matrix; |
| 38 | } |
| 39 | public static function rotate(int $degrees) : self |
| 40 | { |
| 41 | $matrix = new self(); |
| 42 | $rad = \deg2rad($degrees); |
| 43 | $matrix->values = [\cos($rad), \sin($rad), -\sin($rad), \cos($rad), 0, 0]; |
| 44 | return $matrix; |
| 45 | } |
| 46 | /** |
| 47 | * Applies this matrix onto a point and returns the resulting viewport point. |
| 48 | * |
| 49 | * @return float[] |
| 50 | */ |
| 51 | public function apply(float $x, float $y) : array |
| 52 | { |
| 53 | return [$x * $this->values[0] + $y * $this->values[2] + $this->values[4], $x * $this->values[1] + $y * $this->values[3] + $this->values[5]]; |
| 54 | } |
| 55 | } |
| 56 |