ContinentRect::getPoly()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * Class ContinentRect
4
 *
5
 * @created      25.06.2018
6
 * @author       smiley <[email protected]>
7
 * @copyright    2018 smiley
8
 * @license      MIT
9
 */
10
11
namespace chillerlan\GeoJSON;
12
13
class ContinentRect{
14
15
	protected array $rect;
16
17
	/**
18
	 * ContinentRect constructor.
19
	 *
20
	 * @param array $continent_rect (NW/SE corners [[nw_x, nw_y],[se_x, se_y]])
21
	 */
22
	public function __construct(array $continent_rect){
23
		$this->rect = $continent_rect;
24
	}
25
26
	/**
27
	 * returns bounds for L.LatLngBounds() (NE/SW corners)
28
	 */
29
	public function getBounds():array{
30
		return [
31
			[$this->rect[0][0], $this->rect[1][1]],
32
			[$this->rect[1][0], $this->rect[0][1]],
33
		];
34
	}
35
36
	/**
37
	 * returns the center of the rectangle
38
	 */
39
	public function getCenter():array{
40
		return [
41
			($this->rect[0][0] + $this->rect[1][0]) / 2,
42
			($this->rect[0][1] + $this->rect[1][1]) / 2,
43
		];
44
	}
45
46
	/**
47
	 * returns a polygon made of the rectangles corners
48
	 */
49
	public function getPoly():array{
50
		return [[
51
			[$this->rect[0][0], $this->rect[0][1]],
52
			[$this->rect[1][0], $this->rect[0][1]],
53
			[$this->rect[1][0], $this->rect[1][1]],
54
			[$this->rect[0][0], $this->rect[1][1]]
55
		]];
56
	}
57
58
}
59