Debian Codegraph @

src/Renderer/Path/Curve.php

raw
1 <?php
2 declare(strict_types = 1);
3
4 namespace BaconQrCode\Renderer\Path;
5
6 final class Curve implements OperationInterface
7 {
8 public function __construct(
9 private readonly float $x1,
10 private readonly float $y1,
11 private readonly float $x2,
12 private readonly float $y2,
13 private readonly float $x3,
14 private readonly float $y3
15 ) {
16 }
17
18 public function getX1() : float
19 {
20 return $this->x1;
21 }
22
23 public function getY1() : float
24 {
25 return $this->y1;
26 }
27
28 public function getX2() : float
29 {
30 return $this->x2;
31 }
32
33 public function getY2() : float
34 {
35 return $this->y2;
36 }
37
38 public function getX3() : float
39 {
40 return $this->x3;
41 }
42
43 public function getY3() : float
44 {
45 return $this->y3;
46 }
47
48 /**
49 * @return self
50 */
51 public function translate(float $x, float $y) : OperationInterface
52 {
53 return new self(
54 $this->x1 + $x,
55 $this->y1 + $y,
56 $this->x2 + $x,
57 $this->y2 + $y,
58 $this->x3 + $x,
59 $this->y3 + $y
60 );
61 }
62
63 /**
64 * @return self
65 */
66 public function rotate(int $degrees) : OperationInterface
67 {
68 $radians = deg2rad($degrees);
69 $sin = sin($radians);
70 $cos = cos($radians);
71 $x1r = $this->x1 * $cos - $this->y1 * $sin;
72 $y1r = $this->x1 * $sin + $this->y1 * $cos;
73 $x2r = $this->x2 * $cos - $this->y2 * $sin;
74 $y2r = $this->x2 * $sin + $this->y2 * $cos;
75 $x3r = $this->x3 * $cos - $this->y3 * $sin;
76 $y3r = $this->x3 * $sin + $this->y3 * $cos;
77 return new self(
78 $x1r,
79 $y1r,
80 $x2r,
81 $y2r,
82 $x3r,
83 $y3r
84 );
85 }
86 }