Close.php
1 week ago
Curve.php
1 week ago
EllipticArc.php
1 week ago
Line.php
1 week ago
Move.php
1 week ago
OperationInterface.php
1 week ago
Path.php
1 week ago
index.php
1 week ago
Path.php
89 lines
| 1 | <?php |
| 2 | |
| 3 | declare (strict_types=1); |
| 4 | namespace WP2FA_Vendor\BaconQrCode\Renderer\Path; |
| 5 | |
| 6 | use IteratorAggregate; |
| 7 | use Traversable; |
| 8 | /** |
| 9 | * Internal Representation of a vector path. |
| 10 | */ |
| 11 | final class Path implements IteratorAggregate |
| 12 | { |
| 13 | /** |
| 14 | * @var OperationInterface[] |
| 15 | */ |
| 16 | private $operations = []; |
| 17 | /** |
| 18 | * Moves the drawing operation to a certain position. |
| 19 | */ |
| 20 | public function move(float $x, float $y) : self |
| 21 | { |
| 22 | $path = clone $this; |
| 23 | $path->operations[] = new Move($x, $y); |
| 24 | return $path; |
| 25 | } |
| 26 | /** |
| 27 | * Draws a line from the current position to another position. |
| 28 | */ |
| 29 | public function line(float $x, float $y) : self |
| 30 | { |
| 31 | $path = clone $this; |
| 32 | $path->operations[] = new Line($x, $y); |
| 33 | return $path; |
| 34 | } |
| 35 | /** |
| 36 | * Draws an elliptic arc from the current position to another position. |
| 37 | */ |
| 38 | public function ellipticArc(float $xRadius, float $yRadius, float $xAxisRotation, bool $largeArc, bool $sweep, float $x, float $y) : self |
| 39 | { |
| 40 | $path = clone $this; |
| 41 | $path->operations[] = new EllipticArc($xRadius, $yRadius, $xAxisRotation, $largeArc, $sweep, $x, $y); |
| 42 | return $path; |
| 43 | } |
| 44 | /** |
| 45 | * Draws a curve from the current position to another position. |
| 46 | */ |
| 47 | public function curve(float $x1, float $y1, float $x2, float $y2, float $x3, float $y3) : self |
| 48 | { |
| 49 | $path = clone $this; |
| 50 | $path->operations[] = new Curve($x1, $y1, $x2, $y2, $x3, $y3); |
| 51 | return $path; |
| 52 | } |
| 53 | /** |
| 54 | * Closes a sub-path. |
| 55 | */ |
| 56 | public function close() : self |
| 57 | { |
| 58 | $path = clone $this; |
| 59 | $path->operations[] = Close::instance(); |
| 60 | return $path; |
| 61 | } |
| 62 | /** |
| 63 | * Appends another path to this one. |
| 64 | */ |
| 65 | public function append(self $other) : self |
| 66 | { |
| 67 | $path = clone $this; |
| 68 | $path->operations = \array_merge($this->operations, $other->operations); |
| 69 | return $path; |
| 70 | } |
| 71 | public function translate(float $x, float $y) : self |
| 72 | { |
| 73 | $path = new self(); |
| 74 | foreach ($this->operations as $operation) { |
| 75 | $path->operations[] = $operation->translate($x, $y); |
| 76 | } |
| 77 | return $path; |
| 78 | } |
| 79 | /** |
| 80 | * @return OperationInterface[]|Traversable |
| 81 | */ |
| 82 | public function getIterator() : Traversable |
| 83 | { |
| 84 | foreach ($this->operations as $operation) { |
| 85 | (yield $operation); |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 |