1 | <?php |
||
19 | class Coordinate implements GeometryInterface |
||
20 | { |
||
21 | /** |
||
22 | * @var float |
||
23 | */ |
||
24 | protected $lat; |
||
25 | |||
26 | /** |
||
27 | * @var float |
||
28 | */ |
||
29 | protected $lng; |
||
30 | |||
31 | /** |
||
32 | * @var Ellipsoid |
||
33 | */ |
||
34 | protected $ellipsoid; |
||
35 | |||
36 | /** |
||
37 | * @param float $lat -90.0 .. +90.0 |
||
38 | * @param float $lng -180.0 .. +180.0 |
||
39 | * @param Ellipsoid $ellipsoid if omitted, WGS-84 is used |
||
40 | * |
||
41 | * @throws \InvalidArgumentException |
||
42 | */ |
||
43 | public function __construct(float $lat, float $lng, Ellipsoid $ellipsoid = null) |
||
66 | |||
67 | /** |
||
68 | * @return float |
||
69 | */ |
||
70 | public function getLat(): float |
||
74 | |||
75 | /** |
||
76 | * @return float |
||
77 | */ |
||
78 | public function getLng(): float |
||
82 | |||
83 | /** |
||
84 | * Returns an array containing the point |
||
85 | * |
||
86 | * @return Coordinate[] |
||
87 | */ |
||
88 | public function getPoints(): array |
||
92 | |||
93 | /** |
||
94 | * @return Ellipsoid |
||
95 | */ |
||
96 | public function getEllipsoid(): Ellipsoid |
||
100 | |||
101 | /** |
||
102 | * Calculates the distance between the given coordinate |
||
103 | * and this coordinate. |
||
104 | * |
||
105 | * @param Coordinate $coordinate |
||
106 | * @param DistanceInterface $calculator instance of distance calculation class |
||
107 | * |
||
108 | * @return float |
||
109 | */ |
||
110 | public function getDistance(Coordinate $coordinate, DistanceInterface $calculator): float |
||
114 | |||
115 | /** |
||
116 | * Calculates the cardinal direction distances from this coordinate |
||
117 | * to given coordinate. |
||
118 | * |
||
119 | * @param Coordinate $coordinate |
||
120 | * @param DistanceInterface $calculator instance of distance calculation class |
||
121 | * |
||
122 | * @return CardinalDirectionDistances |
||
123 | */ |
||
124 | public function getCardinalDirectionDistances( |
||
131 | |||
132 | /** |
||
133 | * Checks if two points describe the same location within an allowed distance. |
||
134 | * |
||
135 | * Uses the Haversine distance calculator for distance calculation as it's |
||
136 | * precise enough for short-distance calculations. |
||
137 | * |
||
138 | * @param Coordinate $coordinate |
||
139 | * @param float $allowedDistance the default value is one millimeter. |
||
140 | * |
||
141 | * @return bool |
||
142 | * |
||
143 | * @see Haversine |
||
144 | */ |
||
145 | public function hasSameLocation(Coordinate $coordinate, float $allowedDistance = .001): bool |
||
149 | |||
150 | /** |
||
151 | * @param FormatterInterface $formatter |
||
152 | * |
||
153 | * @return mixed |
||
154 | */ |
||
155 | public function format(FormatterInterface $formatter) |
||
159 | |||
160 | /** |
||
161 | * Validates latitude |
||
162 | * |
||
163 | * @param float $latitude |
||
164 | * |
||
165 | * @return bool |
||
166 | */ |
||
167 | protected function isValidLatitude(float $latitude): bool |
||
171 | |||
172 | /** |
||
173 | * Validates longitude |
||
174 | * |
||
175 | * @param float $longitude |
||
176 | * |
||
177 | * @return bool |
||
178 | */ |
||
179 | protected function isValidLongitude(float $longitude): bool |
||
183 | |||
184 | /** |
||
185 | * Checks if the given value is (1) numeric, and (2) between lower |
||
186 | * and upper bounds (including the bounds values). |
||
187 | * |
||
188 | * @param float $value |
||
189 | * @param float $lower |
||
190 | * @param float $upper |
||
191 | * |
||
192 | * @return bool |
||
193 | */ |
||
194 | protected function isNumericInBounds(float $value, float $lower, float $upper): bool |
||
198 | } |
||
199 |