1 | <?php |
||
10 | class Vector |
||
11 | { |
||
12 | /** |
||
13 | * @var float |
||
14 | */ |
||
15 | protected $x; |
||
16 | |||
17 | /** |
||
18 | * @var float |
||
19 | */ |
||
20 | protected $y; |
||
21 | |||
22 | /** |
||
23 | * Constructor |
||
24 | * @param float $x |
||
25 | * @param float $y |
||
26 | */ |
||
27 | 30 | public function __construct($x = 0.0, $y = 0.0) |
|
32 | |||
33 | /** |
||
34 | * Factory method. |
||
35 | * @param float $x |
||
36 | * @param float $y |
||
37 | * @return Vector |
||
38 | */ |
||
39 | 9 | public static function create($x = 0.0, $y = 0.0) : Vector |
|
43 | |||
44 | /** |
||
45 | * Get Y coordinate. |
||
46 | * @param float $x |
||
47 | * @return Vector |
||
48 | */ |
||
49 | 1 | public function setX($x) : Vector |
|
54 | |||
55 | /** |
||
56 | * Get X coordinate. |
||
57 | * @return float |
||
58 | */ |
||
59 | 24 | public function getX() : float |
|
63 | |||
64 | /** |
||
65 | * Set Y coordinate. |
||
66 | * @param float $y |
||
67 | * @return Vector |
||
68 | */ |
||
69 | 1 | public function setY($y) : Vector |
|
74 | |||
75 | /** |
||
76 | * Get Y coordinate. |
||
77 | * @return float |
||
78 | */ |
||
79 | 24 | public function getY() : float |
|
83 | |||
84 | /** |
||
85 | * Length of vector (magnitude) |
||
86 | * @return float |
||
87 | */ |
||
88 | 2 | public function length() : float |
|
92 | |||
93 | /** |
||
94 | * Scalar displacement. |
||
95 | * @param float $deltaX |
||
96 | * @param float $deltaY |
||
97 | * @return Vector |
||
98 | */ |
||
99 | 1 | public function move($deltaX, $deltaY) : Vector |
|
103 | |||
104 | /** |
||
105 | * Scalar multiplication. |
||
106 | * @param float $factor |
||
107 | * @return Vector |
||
108 | */ |
||
109 | 1 | public function mult($factor) : Vector |
|
113 | |||
114 | /** |
||
115 | * Vector addition. |
||
116 | * @param Vector $other |
||
117 | * @return Vector |
||
118 | */ |
||
119 | 1 | public function add(Vector $other) : Vector |
|
123 | |||
124 | /** |
||
125 | * Dot product. |
||
126 | * @param Vector $other |
||
127 | * @return float |
||
128 | */ |
||
129 | 1 | public function dot(Vector $other) : float |
|
133 | |||
134 | /** |
||
135 | * @param Box $box |
||
136 | * @param bool $strict |
||
137 | * @return bool |
||
138 | * @SuppressWarnings(PHPMD.BooleanArgumentFlag) |
||
139 | */ |
||
140 | 4 | public function inside(Box $box, $strict = false) : bool |
|
150 | |||
151 | /** |
||
152 | * @return string |
||
153 | */ |
||
154 | 1 | public function __toString() : string |
|
158 | |||
159 | 1 | public function serialize() : string |
|
166 | } |
||
167 |