Completed
Push — master ( 0ecc5d...19edd4 )
by Marcus
03:36
created

BoundsFactory::expandFromCenterCoordinate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Location\Factory;
6
7
use InvalidArgumentException;
8
use Location\Bearing\BearingInterface;
9
use Location\Bounds;
10
use Location\Coordinate;
11
12
/**
13
 * Bounds Factory
14
 */
15
class BoundsFactory
16
{
17
    /**
18
     * Creates a Bounds instance which corners have the given distance from its center.
19
     *
20
     * @param Coordinate $center
21
     * @param float $distance in meters
22
     * @param BearingInterface $bearing
23
     * @return Bounds
24
     * @throws InvalidArgumentException if bounds crosses the 180/-180 degrees meridian.
25
     */
26
    public static function expandFromCenterCoordinate(
27
        Coordinate $center,
28
        float $distance,
29
        BearingInterface $bearing
30
    ): Bounds {
31
        $northWest = $bearing->calculateDestination($center, 315, $distance);
32
        $southEast = $bearing->calculateDestination($center, 135, $distance);
33
34
        return new Bounds($northWest, $southEast);
35
    }
36
}
37