Debian Codegraph @

src/Renderer/Path/Line.php

raw
1 <?php
2 declare(strict_types = 1);
3
4 namespace BaconQrCode\Renderer\Path;
5
6 final class Line implements OperationInterface
7 {
8 public function __construct(private readonly float $x, private readonly float $y)
9 {
10 }
11
12 public function getX() : float
13 {
14 return $this->x;
15 }
16
17 public function getY() : float
18 {
19 return $this->y;
20 }
21
22 /**
23 * @return self
24 */
25 public function translate(float $x, float $y) : OperationInterface
26 {
27 return new self($this->x + $x, $this->y + $y);
28 }
29
30 /**
31 * @return self
32 */
33 public function rotate(int $degrees) : OperationInterface
34 {
35 $radians = deg2rad($degrees);
36 $sin = sin($radians);
37 $cos = cos($radians);
38 $xr = $this->x * $cos - $this->y * $sin;
39 $yr = $this->x * $sin + $this->y * $cos;
40 return new self($xr, $yr);
41 }
42 }