1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Line Implementation |
4
|
|
|
* |
5
|
|
|
* PHP version 5 |
6
|
|
|
* |
7
|
|
|
* @category Location |
8
|
|
|
* @author Marcus Jaschen <[email protected]> |
9
|
|
|
* @license https://opensource.org/licenses/GPL-3.0 GPL |
10
|
|
|
* @link https://github.com/mjaschen/phpgeo |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Location; |
14
|
|
|
|
15
|
|
|
use Location\Distance\DistanceInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Line Implementation |
19
|
|
|
* |
20
|
|
|
* @category Location |
21
|
|
|
* @author Marcus Jaschen <[email protected]> |
22
|
|
|
* @license https://opensource.org/licenses/GPL-3.0 GPL |
23
|
|
|
* @link https://github.com/mjaschen/phpgeo |
24
|
|
|
*/ |
25
|
|
|
class Line |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var \Location\Coordinate |
29
|
|
|
*/ |
30
|
|
|
protected $point1; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var \Location\Coordinate |
34
|
|
|
*/ |
35
|
|
|
protected $point2; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param Coordinate $point1 |
39
|
|
|
* @param Coordinate $point2 |
40
|
|
|
*/ |
41
|
|
|
public function __construct(Coordinate $point1, Coordinate $point2) |
42
|
|
|
{ |
43
|
|
|
$this->point1 = $point1; |
44
|
|
|
$this->point2 = $point2; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param \Location\Coordinate $point1 |
49
|
|
|
*/ |
50
|
|
|
public function setPoint1($point1) |
51
|
|
|
{ |
52
|
|
|
$this->point1 = $point1; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return \Location\Coordinate |
57
|
|
|
*/ |
58
|
|
|
public function getPoint1() |
59
|
|
|
{ |
60
|
|
|
return $this->point1; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param \Location\Coordinate $point2 |
65
|
|
|
*/ |
66
|
|
|
public function setPoint2($point2) |
67
|
|
|
{ |
68
|
|
|
$this->point2 = $point2; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return \Location\Coordinate |
73
|
|
|
*/ |
74
|
|
|
public function getPoint2() |
75
|
|
|
{ |
76
|
|
|
return $this->point2; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Calculates the length of the line (distance between the two |
81
|
|
|
* coordinates). |
82
|
|
|
* |
83
|
|
|
* @param DistanceInterface $calculator instance of distance calculation class |
84
|
|
|
* |
85
|
|
|
* @return float |
86
|
|
|
*/ |
87
|
|
|
public function getLength(DistanceInterface $calculator) |
88
|
|
|
{ |
89
|
|
|
return $calculator->getDistance($this->point1, $this->point2); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Create a new instance with reversed point order, i. e. reversed direction. |
94
|
|
|
* |
95
|
|
|
* @return Line |
96
|
|
|
*/ |
97
|
|
|
public function getReverse() |
98
|
|
|
{ |
99
|
|
|
return new static($this->point2, $this->point1); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|