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