1 | <?php |
||
17 | class Line implements GeometryInterface |
||
18 | { |
||
19 | use GetBoundsTrait; |
||
20 | |||
21 | /** |
||
22 | * @var Coordinate |
||
23 | */ |
||
24 | protected $point1; |
||
25 | |||
26 | /** |
||
27 | * @var Coordinate |
||
28 | */ |
||
29 | protected $point2; |
||
30 | |||
31 | /** |
||
32 | * @param Coordinate $point1 |
||
33 | * @param Coordinate $point2 |
||
34 | */ |
||
35 | public function __construct(Coordinate $point1, Coordinate $point2) |
||
40 | |||
41 | /** |
||
42 | * @param Coordinate $point1 |
||
43 | * |
||
44 | * @return void |
||
45 | */ |
||
46 | public function setPoint1(Coordinate $point1) |
||
50 | |||
51 | /** |
||
52 | * @return Coordinate |
||
53 | */ |
||
54 | public function getPoint1(): Coordinate |
||
58 | |||
59 | /** |
||
60 | * @param Coordinate $point2 |
||
61 | * |
||
62 | * @return void |
||
63 | */ |
||
64 | public function setPoint2(Coordinate $point2) |
||
68 | |||
69 | /** |
||
70 | * @return Coordinate |
||
71 | */ |
||
72 | public function getPoint2(): Coordinate |
||
76 | |||
77 | /** |
||
78 | * Returns an array containing the two points. |
||
79 | * |
||
80 | * @return Coordinate[] |
||
81 | */ |
||
82 | public function getPoints(): array |
||
86 | |||
87 | /** |
||
88 | * Calculates the length of the line (distance between the two |
||
89 | * coordinates). |
||
90 | * |
||
91 | * @param DistanceInterface $calculator instance of distance calculation class |
||
92 | * |
||
93 | * @return float |
||
94 | */ |
||
95 | public function getLength(DistanceInterface $calculator): float |
||
99 | |||
100 | /** |
||
101 | * @param BearingInterface $bearingCalculator |
||
102 | * |
||
103 | * @return float |
||
104 | */ |
||
105 | public function getBearing(BearingInterface $bearingCalculator): float |
||
109 | |||
110 | /** |
||
111 | * @param BearingInterface $bearingCalculator |
||
112 | * |
||
113 | * @return float |
||
114 | */ |
||
115 | public function getFinalBearing(BearingInterface $bearingCalculator): float |
||
119 | |||
120 | /** |
||
121 | * Create a new instance with reversed point order, i. e. reversed direction. |
||
122 | * |
||
123 | * @return Line |
||
124 | */ |
||
125 | public function getReverse(): Line |
||
129 | |||
130 | /** |
||
131 | * Get the midpoint of a Line segment |
||
132 | * |
||
133 | * @see http://www.movable-type.co.uk/scripts/latlong.html#midpoint |
||
134 | * |
||
135 | * @return Coordinate |
||
136 | */ |
||
137 | public function getMidpoint(): Coordinate |
||
154 | |||
155 | /** |
||
156 | * Returns the point which is located on the line at the |
||
157 | * given fraction (starting at point 1). |
||
158 | * |
||
159 | * @see http://www.movable-type.co.uk/scripts/latlong.html#intermediate-point |
||
160 | * @see http://www.edwilliams.org/avform.htm#Intermediate |
||
161 | * |
||
162 | * @param float $fraction 0.0 ... 1.0 (smaller or larger values work too) |
||
163 | * |
||
164 | * @return Coordinate |
||
165 | * |
||
166 | * @throws RuntimeException |
||
167 | */ |
||
168 | public function getIntermediatePoint(float $fraction): Coordinate |
||
199 | } |
||
200 |