Skip to content

Commit cf89dcc

Browse files
committed
Bounding box optimization
1 parent 2df8c55 commit cf89dcc

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

src/Circle.php

+5-6
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,10 @@ public function draw(Image $image, MapData $mapData): Circle
117117
*/
118118
public function getBoundingBox(): array
119119
{
120-
$distance = GeographicConverter::latLngToMeters($this->center, $this->edge);
121-
$latLng1 = GeographicConverter::metersToLatLng($this->center, $distance, 0);
122-
$latLng2 = GeographicConverter::metersToLatLng($this->center, $distance, 90);
123-
$latLng3 = GeographicConverter::metersToLatLng($this->center, $distance, 180);
124-
$latLng4 = GeographicConverter::metersToLatLng($this->center, $distance, 270);
125-
return [new LatLng($latLng1->getLat(), $latLng4->getLng()), new LatLng($latLng3->getLat(), $latLng2->getLng())];
120+
$distance = GeographicConverter::latLngToMeters($this->center, $this->edge) * 1.4142;
121+
return [
122+
GeographicConverter::metersToLatLng($this->center, $distance, 315),
123+
GeographicConverter::metersToLatLng($this->center, $distance, 135)
124+
];
126125
}
127126
}

src/samples/sample3.php

+3-13
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,14 @@
2020
->setAnchor(Markers::ANCHOR_CENTER, Markers::ANCHOR_BOTTOM)
2121
->addMarker(new LatLng(44.351933, 2.568113))
2222
->addMarker(new LatLng(44.351510, 2.570020))
23-
->addMarker(new LatLng(44.351873, 2.566250))
23+
->addMarker(new LatLng(44.351073, 2.566480))
2424
)
2525
->addDraw(
26-
(new Circle(
27-
new LatLng(44.351933, 2.568113),
28-
'FF0000',
29-
5,
30-
'FF0000CC'
31-
))
26+
(new Circle(new LatLng(44.351933, 2.568113), 'FF0000', 5, 'FF0000CC'))
3227
->setEdgePoint(new LatLng(44.351510, 2.570020))
3328
)
3429
->addDraw(
35-
(new Circle(
36-
new LatLng(44.351933, 2.568113),
37-
'FF0000',
38-
5,
39-
'FF0000CC'
40-
))
30+
(new Circle(new LatLng(44.351933, 2.568113), 'FF0000', 5, 'FF0000CC'))
4131
->setRadius(40)
4232
)
4333
->fitToDraws(10)

0 commit comments

Comments
 (0)