forked from gibilogic/element-geocoding
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoute.php
96 lines (85 loc) · 1.83 KB
/
Route.php
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
<?php
/*
* This file is part of the GiBilogic Elements package.
*
* (c) GiBilogic Srl <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Gibilogic\Elements\Geocoding;
/**
* A geographical route between two points.
*
* @author Matteo Guindani https://github.com/Ingannatore
* @see Point
*/
class Route
{
/**
* @var Point $from
*/
protected $from;
/**
* @var Point $to
*/
protected $to;
/**
* @var float $distance
*/
protected $distance;
/**
* Class constructor.
*
* @param Point $from The first point
* @param Point $to The second point
*/
public function __construct(Point $from, Point $to)
{
$this->from = $from;
$this->to = $to;
$this->distance = $from->distance($to);
}
/**
* @return string
*/
public function __toString()
{
return sprintf('%s -> %s = %.2f', (string)$this->from, (string)$this->to, $this->distance);
}
/**
* Compares the distances between routes.
*
* Returns < 0 if this route's distance is less than the other's distance;
* > 0 if this route's distance is greater than the other's distance, and
* 0 if their distances are equal.
*
* @param Route $other
* @return int
*/
public function compareTo(Route $other)
{
return round($this->distance - $other->getDistance());
}
/**
* @return Point
*/
public function getFrom()
{
return $this->from;
}
/**
* @return Point
*/
public function getTo()
{
return $this->to;
}
/**
* @return float
*/
public function getDistance()
{
return $this->distance;
}
}