@@ -14,14 +14,14 @@ discard block |
||
14 | 14 | |
15 | 15 | use function array_fill, array_keys, 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 | |
21 | 21 | /** |
22 | 22 | * PolylineSimplifyer constructor. |
23 | 23 | */ |
24 | - public function __construct(array $polylineCoords){ |
|
24 | + public function __construct(array $polylineCoords) { |
|
25 | 25 | $this->coords = $polylineCoords; |
26 | 26 | } |
27 | 27 | |
@@ -31,12 +31,12 @@ discard block |
||
31 | 31 | public function simplify(float $tolerance = 1, bool $highestQuality = false):array{ |
32 | 32 | $coords = array_values($this->coords ?? []); |
33 | 33 | |
34 | - if(count($coords) < 2){ |
|
34 | + if (count($coords) < 2) { |
|
35 | 35 | throw new GeoJSONException('not enough points'); |
36 | 36 | } |
37 | 37 | |
38 | - foreach($this->coords as $coord){ |
|
39 | - if(!is_array($coord) || count($coord) < 2){ |
|
38 | + foreach ($this->coords as $coord) { |
|
39 | + if (!is_array($coord) || count($coord) < 2) { |
|
40 | 40 | throw new GeoJSONException('invalid coords found'); |
41 | 41 | } |
42 | 42 | } |
@@ -56,16 +56,16 @@ discard block |
||
56 | 56 | $point = null; |
57 | 57 | $len = count($points); |
58 | 58 | |
59 | - for($i = 1; $i < $len; $i++){ |
|
59 | + for ($i = 1; $i < $len; $i++) { |
|
60 | 60 | $point = $points[$i]; |
61 | 61 | |
62 | - if($this->getSqDist(array_values($point), array_values($prevPoint)) > $sqTolerance){ |
|
62 | + if ($this->getSqDist(array_values($point), array_values($prevPoint)) > $sqTolerance) { |
|
63 | 63 | $newPoints[] = $point; |
64 | 64 | $prevPoint = $point; |
65 | 65 | } |
66 | 66 | } |
67 | 67 | |
68 | - if($prevPoint !== $point){ |
|
68 | + if ($prevPoint !== $point) { |
|
69 | 69 | $newPoints[] = $point; |
70 | 70 | } |
71 | 71 | |
@@ -96,24 +96,24 @@ discard block |
||
96 | 96 | |
97 | 97 | $markers[$first] = $markers[$last] = 1; |
98 | 98 | |
99 | - while($last){ |
|
99 | + while ($last) { |
|
100 | 100 | |
101 | 101 | $maxSqDist = 0; |
102 | 102 | |
103 | - for($i = $first + 1; $i < $last; $i++){ |
|
103 | + for ($i = $first + 1; $i < $last; $i++) { |
|
104 | 104 | $sqDist = $this->getSqSegDist( |
105 | 105 | array_values($points[$i]), |
106 | 106 | array_values($points[$first]), |
107 | 107 | array_values($points[$last]) |
108 | 108 | ); |
109 | 109 | |
110 | - if($sqDist > $maxSqDist){ |
|
110 | + if ($sqDist > $maxSqDist) { |
|
111 | 111 | $index = $i; |
112 | 112 | $maxSqDist = $sqDist; |
113 | 113 | } |
114 | 114 | } |
115 | 115 | |
116 | - if($maxSqDist > $sqTolerance){ |
|
116 | + if ($maxSqDist > $sqTolerance) { |
|
117 | 117 | $markers[$index] = 1; |
118 | 118 | array_push($stack, $first, $index, $index, $last); |
119 | 119 | } |
@@ -122,8 +122,8 @@ discard block |
||
122 | 122 | $first = array_pop($stack); |
123 | 123 | } |
124 | 124 | |
125 | - foreach($points as $i => $point){ |
|
126 | - if($markers[$i]){ |
|
125 | + foreach ($points as $i => $point) { |
|
126 | + if ($markers[$i]) { |
|
127 | 127 | $newPoints[] = $point; |
128 | 128 | } |
129 | 129 | } |
@@ -140,16 +140,16 @@ discard block |
||
140 | 140 | $dx = $p2[0] - $x; |
141 | 141 | $dy = $p2[1] - $y; |
142 | 142 | |
143 | - if((int)$dx !== 0 || (int)$dy !== 0){ |
|
143 | + if ((int) $dx !== 0 || (int) $dy !== 0) { |
|
144 | 144 | |
145 | 145 | $t = (($p[0] - $x) * $dx + ($p[1] - $y) * $dy) / ($dx * $dx + $dy * $dy); |
146 | 146 | |
147 | - if($t > 1){ |
|
147 | + if ($t > 1) { |
|
148 | 148 | $x = $p2[0]; |
149 | 149 | $y = $p2[1]; |
150 | 150 | |
151 | 151 | } |
152 | - elseif($t > 0){ |
|
152 | + elseif ($t > 0) { |
|
153 | 153 | $x += $dx * $t; |
154 | 154 | $y += $dy * $t; |
155 | 155 | } |