BoundingBox::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 3
1
<?php
2
3
namespace Wolnosciowiec\CoordinatesBundle\Model\Entity\Coordinates;
4
5
/**
6
 * BoundingBox
7
 * ===========
8
 * Calculates coordinates of a square which could be used to limit
9
 * count of results in geo location search
10
 *
11
 * @package Wolnosciowiec\CoordinatesBundle\Model\Entity\Coordinates
12
 */
13
class BoundingBox
14
{
15
    /** @var float[] $longitude */
16
    protected $latitude = [0, 0];
17
18
    /** @var float[] $longitude */
19
    protected $longitude = [0, 0];
20
21
    /**
22
     * @param float $lat Latitude of the point
23
     * @param float $lon Longitude of the point
24
     * @param float|int $distance And the distance radius
25
     */
26
    public function __construct($lat, $lon, $distance)
27
    {
28
        $latInMeters = ((1 - $lat/90)*2*M_PI*6371000)/360;
29
        $lonInMeters = (2*M_PI*6371000)/360;
30
        $mDist       = $distance * 1000;
31
32
        $this->longitude = [
33
            ($lon - $mDist * 1/$lonInMeters),
34
            ($lon + $mDist * 1/$lonInMeters),
35
        ];
36
37
        $this->latitude = [
38
            ($lat - $mDist * 1/$latInMeters),
39
            ($lat + $mDist * 1/$latInMeters),
40
        ];
41
    }
42
43
    /**
44
     * @return \float[]
45
     */
46
    public function getLongitude()
47
    {
48
        return $this->longitude;
49
    }
50
51
    /**
52
     * @return \float[]
53
     */
54
    public function getLatitude()
55
    {
56
        return $this->latitude;
57
    }
58
}