1
|
|
|
<?php |
2
|
|
|
namespace nstdio\svg\shape; |
3
|
|
|
|
4
|
|
|
use nstdio\svg\ElementInterface; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Class Line |
8
|
|
|
* The 'line' element defines a line segment that starts at one point and ends at another. |
9
|
|
|
* |
10
|
|
|
* @link https://www.w3.org/TR/SVG11/shapes.html#LineElement |
11
|
|
|
* @property float x1 The x-axis coordinate of the start of the line. If the attribute is not specified, the effect is |
12
|
|
|
* as if a value of "0" were specified. |
13
|
|
|
* @property float y1 The y-axis coordinate of the start of the line. If the attribute is not specified, the effect is |
14
|
|
|
* as if a value of "0" were specified. |
15
|
|
|
* @property float x2 The x-axis coordinate of the end of the line. If the attribute is not specified, the effect is as |
16
|
|
|
* if a value of "0" were specified. |
17
|
|
|
* @property float y2 The y-axis coordinate of the end of the line. If the attribute is not specified, the effect is as |
18
|
|
|
* if a value of "0" were specified. |
19
|
|
|
* |
20
|
|
|
* @package shape |
21
|
|
|
* @author Edgar Asatryan <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class Line extends Shape |
24
|
|
|
{ |
25
|
|
|
public function __construct(ElementInterface $parent, $x1 = 0, $y1 = 0, $x2 = 0, $y2 = 0) |
26
|
|
|
{ |
27
|
|
|
parent::__construct($parent); |
28
|
|
|
|
29
|
|
|
$this->x1 = $x1; |
30
|
|
|
$this->y1 = $y1; |
31
|
|
|
$this->x2 = $x2; |
32
|
|
|
$this->y2 = $y2; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param bool $closePath |
37
|
|
|
* |
38
|
|
|
* @return Path |
39
|
|
|
*/ |
40
|
|
|
public function toPath($closePath = false) |
41
|
|
|
{ |
42
|
|
|
$path = new Path($this->getRoot(), $this->x1, $this->y1); |
|
|
|
|
43
|
|
|
$path->lineTo($this->x2, $this->y2); |
44
|
|
|
|
45
|
|
|
if ($closePath === true) { |
46
|
|
|
$path->closePath(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
return $path; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return Polygon |
54
|
|
|
*/ |
55
|
|
|
public function toPolygon() |
56
|
|
|
{ |
57
|
|
|
$polygon = new Polygon($this->getRoot()); |
|
|
|
|
58
|
|
|
$polygon->addPointArray([ |
59
|
|
|
[$this->x1, $this->y1], |
60
|
|
|
[$this->x2, $this->y2], |
61
|
|
|
]); |
62
|
|
|
|
63
|
|
|
return $polygon; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function getName() |
67
|
|
|
{ |
68
|
|
|
return 'line'; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
protected function getCenterX() |
72
|
|
|
{ |
73
|
|
|
// TODO: Implement getCenterX() method. |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
protected function getCenterY() |
77
|
|
|
{ |
78
|
|
|
// TODO: Implement getCenterY() method. |
79
|
|
|
} |
80
|
|
|
} |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: