1 | <?php |
||
17 | class Point implements GeometryInterface |
||
18 | { |
||
19 | /** |
||
20 | * @var float |
||
21 | */ |
||
22 | protected $lat; |
||
23 | |||
24 | /** |
||
25 | * @var float |
||
26 | */ |
||
27 | protected $lng; |
||
28 | |||
29 | /** |
||
30 | * @var Ellipsoid |
||
31 | */ |
||
32 | protected $ellipsoid; |
||
33 | |||
34 | /** |
||
35 | * @param float $lat -90.0 .. +90.0 |
||
36 | * @param float $lng -180.0 .. +180.0 |
||
37 | * @param Ellipsoid $ellipsoid if omitted, WGS-84 is used |
||
38 | * |
||
39 | * @throws \InvalidArgumentException |
||
40 | */ |
||
41 | public function __construct(float $lat, float $lng, Ellipsoid $ellipsoid = null) |
||
64 | |||
65 | /** |
||
66 | * @return float |
||
67 | */ |
||
68 | public function getLat(): float |
||
72 | |||
73 | /** |
||
74 | * @return float |
||
75 | */ |
||
76 | public function getLng(): float |
||
80 | |||
81 | /** |
||
82 | * Returns an array containing the point |
||
83 | * |
||
84 | * @return Point[] |
||
85 | */ |
||
86 | public function getPoints(): array |
||
90 | |||
91 | /** |
||
92 | * @return Ellipsoid |
||
93 | */ |
||
94 | public function getEllipsoid(): Ellipsoid |
||
98 | |||
99 | /** |
||
100 | * Calculates the distance between the given point |
||
101 | * and this point. |
||
102 | * |
||
103 | * @param Point $point |
||
104 | * @param DistanceInterface $calculator instance of distance calculation class |
||
105 | * |
||
106 | * @return float |
||
107 | */ |
||
108 | public function getDistance(Point $point, DistanceInterface $calculator): float |
||
112 | |||
113 | /** |
||
114 | * Checks if two points describe the same location within an allowed distance. |
||
115 | * |
||
116 | * Uses the Haversine distance calculator for distance calculation as it's |
||
117 | * precise enough for short-distance calculations. |
||
118 | * |
||
119 | * @param Point $point |
||
120 | * @param float $allowedDistance the default value is one millimeter. |
||
121 | * |
||
122 | * @return bool |
||
123 | * |
||
124 | * @see Haversine |
||
125 | */ |
||
126 | public function hasSameLocation(Point $point, float $allowedDistance = .001): bool |
||
130 | |||
131 | /** |
||
132 | * @param FormatterInterface $formatter |
||
133 | * |
||
134 | * @return mixed |
||
135 | */ |
||
136 | public function format(FormatterInterface $formatter) |
||
140 | |||
141 | /** |
||
142 | * Validates latitude |
||
143 | * |
||
144 | * @param float $latitude |
||
145 | * |
||
146 | * @return bool |
||
147 | */ |
||
148 | protected function isValidLatitude(float $latitude): bool |
||
152 | |||
153 | /** |
||
154 | * Validates longitude |
||
155 | * |
||
156 | * @param float $longitude |
||
157 | * |
||
158 | * @return bool |
||
159 | */ |
||
160 | protected function isValidLongitude(float $longitude): bool |
||
164 | |||
165 | /** |
||
166 | * Checks if the given value is (1) numeric, and (2) between lower |
||
167 | * and upper bounds (including the bounds values). |
||
168 | * |
||
169 | * @param float $value |
||
170 | * @param float $lower |
||
171 | * @param float $upper |
||
172 | * |
||
173 | * @return bool |
||
174 | */ |
||
175 | protected function isNumericInBounds(float $value, float $lower, float $upper): bool |
||
179 | } |
||
180 |