@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | |
15 | 15 | use function array_fill, array_pop, array_push, array_values, count, is_array; |
16 | 16 | |
17 | -class PolylineSimplifyer{ |
|
17 | +class PolylineSimplifyer { |
|
18 | 18 | |
19 | 19 | protected array $coords; |
20 | 20 | |
@@ -23,17 +23,17 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @throws \chillerlan\GeoJSON\GeoJSONException |
25 | 25 | */ |
26 | - public function __construct(array $polylineCoords){ |
|
26 | + public function __construct(array $polylineCoords) { |
|
27 | 27 | |
28 | - if(count($polylineCoords) < 2){ |
|
28 | + if (count($polylineCoords) < 2) { |
|
29 | 29 | throw new GeoJSONException('not enough points'); |
30 | 30 | } |
31 | 31 | |
32 | 32 | $this->coords = array_values($polylineCoords); |
33 | 33 | |
34 | - foreach($this->coords as $i => $coord){ |
|
34 | + foreach ($this->coords as $i => $coord) { |
|
35 | 35 | |
36 | - if(!is_array($coord) || count($coord) < 2){ |
|
36 | + if (!is_array($coord) || count($coord) < 2) { |
|
37 | 37 | throw new GeoJSONException('invalid coords found'); |
38 | 38 | } |
39 | 39 | |
@@ -61,16 +61,16 @@ discard block |
||
61 | 61 | $point = null; |
62 | 62 | $len = count($this->coords); |
63 | 63 | |
64 | - for($i = 1; $i < $len; $i++){ |
|
64 | + for ($i = 1; $i < $len; $i++) { |
|
65 | 65 | $point = $this->coords[$i]; |
66 | 66 | |
67 | - if($this->getSqDist($point, $prevPoint) > $sqTolerance){ |
|
67 | + if ($this->getSqDist($point, $prevPoint) > $sqTolerance) { |
|
68 | 68 | $newPoints[] = $point; |
69 | 69 | $prevPoint = $point; |
70 | 70 | } |
71 | 71 | } |
72 | 72 | |
73 | - if($prevPoint !== $point){ |
|
73 | + if ($prevPoint !== $point) { |
|
74 | 74 | $newPoints[] = $point; |
75 | 75 | } |
76 | 76 | |
@@ -101,20 +101,20 @@ discard block |
||
101 | 101 | |
102 | 102 | $markers[$first] = $markers[$last] = 1; |
103 | 103 | |
104 | - while($last){ |
|
104 | + while ($last) { |
|
105 | 105 | |
106 | 106 | $maxSqDist = 0; |
107 | 107 | |
108 | - for($i = $first + 1; $i < $last; $i++){ |
|
108 | + for ($i = $first + 1; $i < $last; $i++) { |
|
109 | 109 | $sqDist = $this->getSqSegDist($points[$i], $points[$first], $points[$last]); |
110 | 110 | |
111 | - if($sqDist > $maxSqDist){ |
|
111 | + if ($sqDist > $maxSqDist) { |
|
112 | 112 | $index = $i; |
113 | 113 | $maxSqDist = $sqDist; |
114 | 114 | } |
115 | 115 | } |
116 | 116 | |
117 | - if($maxSqDist > $sqTolerance){ |
|
117 | + if ($maxSqDist > $sqTolerance) { |
|
118 | 118 | $markers[$index] = 1; |
119 | 119 | array_push($stack, $first, $index, $index, $last); |
120 | 120 | } |
@@ -123,8 +123,8 @@ discard block |
||
123 | 123 | $first = array_pop($stack); |
124 | 124 | } |
125 | 125 | |
126 | - foreach($points as $i => $point){ |
|
127 | - if($markers[$i]){ |
|
126 | + foreach ($points as $i => $point) { |
|
127 | + if ($markers[$i]) { |
|
128 | 128 | $newPoints[] = $point; |
129 | 129 | } |
130 | 130 | } |
@@ -141,16 +141,16 @@ discard block |
||
141 | 141 | $dx = $p2[0] - $x; |
142 | 142 | $dy = $p2[1] - $y; |
143 | 143 | |
144 | - if((int)$dx !== 0 || (int)$dy !== 0){ |
|
144 | + if ((int) $dx !== 0 || (int) $dy !== 0) { |
|
145 | 145 | |
146 | 146 | $t = (($p[0] - $x) * $dx + ($p[1] - $y) * $dy) / ($dx * $dx + $dy * $dy); |
147 | 147 | |
148 | - if($t > 1){ |
|
148 | + if ($t > 1) { |
|
149 | 149 | $x = $p2[0]; |
150 | 150 | $y = $p2[1]; |
151 | 151 | |
152 | 152 | } |
153 | - elseif($t > 0){ |
|
153 | + elseif ($t > 0) { |
|
154 | 154 | $x += $dx * $t; |
155 | 155 | $y += $dy * $t; |
156 | 156 | } |