1 | <?php |
||
25 | class Vertex implements VertexInterface |
||
26 | { |
||
27 | use CoordinateCouple; |
||
28 | |||
29 | /** |
||
30 | * @var double |
||
31 | */ |
||
32 | protected $gradient; |
||
33 | |||
34 | /** |
||
35 | * @var double |
||
36 | */ |
||
37 | protected $ordinateIntercept; |
||
38 | |||
39 | /** |
||
40 | * @var integer |
||
41 | */ |
||
42 | private $precision = 8; |
||
43 | |||
44 | /** |
||
45 | * {@inheritDoc} |
||
46 | */ |
||
47 | 54 | public function setFrom(CoordinateInterface $from) |
|
59 | |||
60 | /** |
||
61 | * {@inheritDoc} |
||
62 | */ |
||
63 | 1 | public function getFrom() |
|
67 | |||
68 | /** |
||
69 | * {@inheritDoc} |
||
70 | */ |
||
71 | 45 | public function setTo(CoordinateInterface $to) |
|
84 | |||
85 | /** |
||
86 | * {@inheritDoc} |
||
87 | */ |
||
88 | 1 | public function getTo() |
|
92 | |||
93 | /** |
||
94 | * {@inheritDoc} |
||
95 | */ |
||
96 | 5 | public function getGradient() |
|
100 | |||
101 | /** |
||
102 | * {@inheritDoc} |
||
103 | */ |
||
104 | 2 | public function getOrdinateIntercept() |
|
108 | |||
109 | /** |
||
110 | * @return integer |
||
111 | */ |
||
112 | 5 | public function getPrecision() |
|
116 | |||
117 | /** |
||
118 | * @param integer $precision |
||
119 | * @return $this |
||
120 | */ |
||
121 | public function setPrecision($precision) |
||
127 | |||
128 | /** |
||
129 | * Returns the initial bearing from the origin coordinate |
||
130 | * to the destination coordinate in degrees. |
||
131 | * |
||
132 | * @return float The initial bearing in degrees |
||
133 | */ |
||
134 | 14 | public function initialBearing() |
|
147 | |||
148 | /** |
||
149 | * Returns the final bearing from the origin coordinate |
||
150 | * to the destination coordinate in degrees. |
||
151 | * |
||
152 | * @return float The final bearing in degrees |
||
153 | */ |
||
154 | 14 | public function finalBearing() |
|
167 | |||
168 | /** |
||
169 | * Returns the initial cardinal point / direction from the origin coordinate to |
||
170 | * the destination coordinate. |
||
171 | * @see http://en.wikipedia.org/wiki/Cardinal_direction |
||
172 | * |
||
173 | * @return string The initial cardinal point / direction |
||
174 | */ |
||
175 | 7 | public function initialCardinal() |
|
181 | |||
182 | /** |
||
183 | * Returns the final cardinal point / direction from the origin coordinate to |
||
184 | * the destination coordinate. |
||
185 | * @see http://en.wikipedia.org/wiki/Cardinal_direction |
||
186 | * |
||
187 | * @return string The final cardinal point / direction |
||
188 | */ |
||
189 | 7 | public function finalCardinal() |
|
195 | |||
196 | /** |
||
197 | * Returns the half-way point / coordinate along a great circle |
||
198 | * path between the origin and the destination coordinates. |
||
199 | * |
||
200 | * @return CoordinateInterface |
||
201 | */ |
||
202 | 7 | public function middle() |
|
219 | |||
220 | /** |
||
221 | * Returns the destination point with a given bearing in degrees travelling along a |
||
222 | * (shortest distance) great circle arc and a distance in meters. |
||
223 | * |
||
224 | * @param integer $bearing The bearing of the origin in degrees. |
||
225 | * @param integer $distance The distance from the origin in meters. |
||
226 | * |
||
227 | * @return CoordinateInterface |
||
228 | */ |
||
229 | 9 | public function destination($bearing, $distance) |
|
243 | |||
244 | /** |
||
245 | * Returns true if the vertex passed on argument is on the same line as this object |
||
246 | * |
||
247 | * @param Vertex $vertex The vertex to compare |
||
248 | * @return boolean |
||
249 | */ |
||
250 | 5 | public function isOnSameLine(Vertex $vertex) { |
|
251 | 5 | if (is_null($this->getGradient()) && is_null($vertex->getGradient()) && $this->from->getLongitude() == $vertex->getFrom()->getLongitude()) { |
|
252 | return true; |
||
253 | 5 | } elseif (!is_null($this->getGradient()) && !is_null($vertex->getGradient())) { |
|
254 | return ( |
||
255 | 5 | bccomp($this->getGradient(), $vertex->getGradient(), $this->getPrecision()) === 0 |
|
256 | 5 | && |
|
257 | 2 | bccomp($this->getOrdinateIntercept(), $vertex->getOrdinateIntercept(), $this->getPrecision()) ===0 |
|
258 | 5 | ); |
|
259 | } else { |
||
260 | return false; |
||
261 | } |
||
262 | } |
||
263 | |||
264 | /** |
||
265 | * Returns the other coordinate who is not the coordinate passed on argument |
||
266 | * @param CoordinateInterface $coordinate |
||
267 | * @return null|Coordinate |
||
268 | */ |
||
269 | 3 | public function getOtherCoordinate(CoordinateInterface $coordinate) { |
|
277 | |||
278 | } |
||
279 |