1
|
|
|
<?php |
2
|
|
|
namespace nstdio\svg\shape; |
3
|
|
|
|
4
|
|
|
use nstdio\svg\ElementInterface; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Class Ellipse |
8
|
|
|
* The 'ellipse' element defines an ellipse which is axis-aligned with the current user coordinate system based on a |
9
|
|
|
* center point and two radii. |
10
|
|
|
* |
11
|
|
|
* @link https://www.w3.org/TR/SVG11/shapes.html#EllipseElement |
12
|
|
|
* |
13
|
|
|
* @property float rx |
14
|
|
|
* @property float $ry |
15
|
|
|
* |
16
|
|
|
* @package nstdio\svg\shape |
17
|
|
|
* @author Edgar Asatryan <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class Ellipse extends RoundedShape |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Ellipse constructor. |
23
|
|
|
* |
24
|
|
|
* @param ElementInterface $parent |
25
|
|
|
* @param $cx |
26
|
|
|
* @param $cy |
27
|
|
|
* @param $rx |
28
|
|
|
* @param $ry |
29
|
|
|
*/ |
30
|
8 |
|
public function __construct(ElementInterface $parent, $cx, $cy, $rx, $ry) |
31
|
|
|
{ |
32
|
8 |
|
parent::__construct($parent, $cx, $cy); |
33
|
|
|
|
34
|
8 |
|
$this->rx = $rx; |
35
|
8 |
|
$this->ry = $ry; |
36
|
8 |
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param ElementInterface $parent |
40
|
|
|
* @param $cx |
41
|
|
|
* @param $cy |
42
|
|
|
* @param $rx |
43
|
|
|
* @param $ry |
44
|
|
|
* |
45
|
|
|
* @return Ellipse |
46
|
|
|
*/ |
47
|
|
|
public static function create(ElementInterface $parent, $cx, $cy, $rx, $ry) |
48
|
|
|
{ |
49
|
|
|
return new Ellipse($parent, $cx, $cy, $rx, $ry); |
50
|
|
|
} |
51
|
|
|
|
52
|
8 |
|
public function getName() |
53
|
|
|
{ |
54
|
8 |
|
return 'ellipse'; |
55
|
|
|
} |
56
|
|
|
|
57
|
1 |
|
public function getBoundingBox() |
58
|
|
|
{ |
59
|
|
|
return [ |
60
|
1 |
|
'width' => 2 * $this->rx, |
61
|
1 |
|
'height' => 2 * $this->ry, |
62
|
1 |
|
'x' => abs($this->cx - $this->rx), |
63
|
1 |
|
'y' => abs($this->cy - $this->ry), |
64
|
1 |
|
]; |
65
|
|
|
} |
66
|
|
|
} |