@@ -93,7 +93,7 @@ |
||
| 93 | 93 | for($x = 0; $x <= $width; $x++){ |
| 94 | 94 | |
| 95 | 95 | if($new_tab[$x][$y]<=100){ |
| 96 | - $k3 = 9999; |
|
| 96 | + $k3 = 9999; |
|
| 97 | 97 | }else{ |
| 98 | 98 | $k = $x; $k2 = $y; |
| 99 | 99 | if($x<$modX) $k = $width-$x; |
@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | namespace PatchFind\Graph; |
| 4 | 4 | |
| 5 | - class Generate implements GenerateInterface{ |
|
| 5 | + class Generate implements GenerateInterface { |
|
| 6 | 6 | |
| 7 | 7 | /** |
| 8 | 8 | * width of graph |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | * @param int $height |
| 24 | 24 | * @return array |
| 25 | 25 | */ |
| 26 | - public function createGraph($width, $height){ |
|
| 26 | + public function createGraph($width, $height) { |
|
| 27 | 27 | $this->x_w = $width; |
| 28 | 28 | $this->y_h = $height; |
| 29 | 29 | |
@@ -31,25 +31,25 @@ discard block |
||
| 31 | 31 | $modY = ceil($height/2); |
| 32 | 32 | |
| 33 | 33 | $relations = array(); |
| 34 | - for($y = 0; $y <= $height; $y++){ |
|
| 35 | - for($x = 0; $x <= $width; $x++){ |
|
| 34 | + for ($y = 0; $y <= $height; $y++) { |
|
| 35 | + for ($x = 0; $x <= $width; $x++) { |
|
| 36 | 36 | $k = $x; $k2 = $y; |
| 37 | - if($x<$modX) $k = $width-$x; |
|
| 38 | - if($y<$modY) $k2 = $height-$y; |
|
| 37 | + if ($x < $modX) $k = $width-$x; |
|
| 38 | + if ($y < $modY) $k2 = $height-$y; |
|
| 39 | 39 | $k3 = $k; |
| 40 | - if($k2>$k) $k3 = $k2; |
|
| 40 | + if ($k2 > $k) $k3 = $k2; |
|
| 41 | 41 | |
| 42 | 42 | $tmpX = $x-1; $tmpY = $y; |
| 43 | - if($this->checkParams($tmpX, $tmpY)) $relations["($tmpX,$tmpY)"]["($x,$y)"] = $k3; |
|
| 43 | + if ($this->checkParams($tmpX, $tmpY)) $relations["($tmpX,$tmpY)"]["($x,$y)"] = $k3; |
|
| 44 | 44 | |
| 45 | 45 | $tmpX2 = $x+1; $tmpY2 = $y; |
| 46 | - if($this->checkParams($tmpX2, $tmpY2)) $relations["($tmpX2,$tmpY2)"]["($x,$y)"] = $k3; |
|
| 46 | + if ($this->checkParams($tmpX2, $tmpY2)) $relations["($tmpX2,$tmpY2)"]["($x,$y)"] = $k3; |
|
| 47 | 47 | |
| 48 | 48 | $tmpX3 = $x; $tmpY3 = $y-1; |
| 49 | - if($this->checkParams($tmpX3, $tmpY3)) $relations["($tmpX3,$tmpY3)"]["($x,$y)"] = $k3; |
|
| 49 | + if ($this->checkParams($tmpX3, $tmpY3)) $relations["($tmpX3,$tmpY3)"]["($x,$y)"] = $k3; |
|
| 50 | 50 | |
| 51 | 51 | $tmpX4 = $x; $tmpY4 = $y+1; |
| 52 | - if($this->checkParams($tmpX4, $tmpY4)) $relations["($tmpX4,$tmpY4)"]["($x,$y)"] = $k3; |
|
| 52 | + if ($this->checkParams($tmpX4, $tmpY4)) $relations["($tmpX4,$tmpY4)"]["($x,$y)"] = $k3; |
|
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | 55 | |
@@ -62,20 +62,20 @@ discard block |
||
| 62 | 62 | * @param string $file |
| 63 | 63 | * @return array |
| 64 | 64 | */ |
| 65 | - public function loadFromFile($file){ |
|
| 65 | + public function loadFromFile($file) { |
|
| 66 | 66 | |
| 67 | 67 | $res = @imagecreatefromjpeg($file); |
| 68 | 68 | |
| 69 | - if(!$res){ |
|
| 69 | + if (!$res) { |
|
| 70 | 70 | $width = imagesx($res); |
| 71 | 71 | $height = imagesy($res); |
| 72 | 72 | |
| 73 | 73 | $new_tab = array(); |
| 74 | - for($y = 0; $y <= $height; $y++){ |
|
| 75 | - for($x = 0; $x <= $width; $x++){ |
|
| 76 | - if($y==$height || $x==$width){ |
|
| 74 | + for ($y = 0; $y <= $height; $y++) { |
|
| 75 | + for ($x = 0; $x <= $width; $x++) { |
|
| 76 | + if ($y==$height || $x==$width) { |
|
| 77 | 77 | $color = 10; |
| 78 | - }else{ |
|
| 78 | + }else { |
|
| 79 | 79 | $color = imagecolorat($res, $x, $y); |
| 80 | 80 | } |
| 81 | 81 | $new_tab[$x][$y] = $color; |
@@ -89,29 +89,29 @@ discard block |
||
| 89 | 89 | $modY = ceil($height/2); |
| 90 | 90 | |
| 91 | 91 | $relations = array(); |
| 92 | - for($y = 0; $y <= $height; $y++){ |
|
| 93 | - for($x = 0; $x <= $width; $x++){ |
|
| 92 | + for ($y = 0; $y <= $height; $y++) { |
|
| 93 | + for ($x = 0; $x <= $width; $x++) { |
|
| 94 | 94 | |
| 95 | - if($new_tab[$x][$y]<=100){ |
|
| 95 | + if ($new_tab[$x][$y] <= 100) { |
|
| 96 | 96 | $k3 = 9999; |
| 97 | - }else{ |
|
| 97 | + }else { |
|
| 98 | 98 | $k = $x; $k2 = $y; |
| 99 | - if($x<$modX) $k = $width-$x; |
|
| 100 | - if($y<$modY) $k2 = $height-$y; |
|
| 99 | + if ($x < $modX) $k = $width-$x; |
|
| 100 | + if ($y < $modY) $k2 = $height-$y; |
|
| 101 | 101 | $k3 = $k; |
| 102 | - if($k2>$k) $k3 = $k2; |
|
| 102 | + if ($k2 > $k) $k3 = $k2; |
|
| 103 | 103 | } |
| 104 | 104 | $tmpX = $x-1; $tmpY = $y; |
| 105 | - if($this->checkParams($tmpX, $tmpY)) $relations["($tmpX,$tmpY)"]["($x,$y)"] = $k3; |
|
| 105 | + if ($this->checkParams($tmpX, $tmpY)) $relations["($tmpX,$tmpY)"]["($x,$y)"] = $k3; |
|
| 106 | 106 | |
| 107 | 107 | $tmpX2 = $x+1; $tmpY2 = $y; |
| 108 | - if($this->checkParams($tmpX2, $tmpY2)) $relations["($tmpX2,$tmpY2)"]["($x,$y)"] = $k3; |
|
| 108 | + if ($this->checkParams($tmpX2, $tmpY2)) $relations["($tmpX2,$tmpY2)"]["($x,$y)"] = $k3; |
|
| 109 | 109 | |
| 110 | 110 | $tmpX3 = $x; $tmpY3 = $y-1; |
| 111 | - if($this->checkParams($tmpX3, $tmpY3)) $relations["($tmpX3,$tmpY3)"]["($x,$y)"] = $k3; |
|
| 111 | + if ($this->checkParams($tmpX3, $tmpY3)) $relations["($tmpX3,$tmpY3)"]["($x,$y)"] = $k3; |
|
| 112 | 112 | |
| 113 | 113 | $tmpX4 = $x; $tmpY4 = $y+1; |
| 114 | - if($this->checkParams($tmpX4, $tmpY4)) $relations["($tmpX4,$tmpY4)"]["($x,$y)"] = $k3; |
|
| 114 | + if ($this->checkParams($tmpX4, $tmpY4)) $relations["($tmpX4,$tmpY4)"]["($x,$y)"] = $k3; |
|
| 115 | 115 | } |
| 116 | 116 | } |
| 117 | 117 | $relations = $res; |
@@ -129,10 +129,10 @@ discard block |
||
| 129 | 129 | * @param int $tmpY |
| 130 | 130 | * @return bool |
| 131 | 131 | */ |
| 132 | - private function checkParams($tmpX, $tmpY){ |
|
| 133 | - if($tmpX >= 0 && $tmpY >= 0 && $tmpX <= $this->x_w && $tmpY <= $this->y_h){ |
|
| 132 | + private function checkParams($tmpX, $tmpY) { |
|
| 133 | + if ($tmpX >= 0 && $tmpY >= 0 && $tmpX <= $this->x_w && $tmpY <= $this->y_h) { |
|
| 134 | 134 | $output = true; |
| 135 | - }else{ |
|
| 135 | + }else { |
|
| 136 | 136 | $output = false; |
| 137 | 137 | } |
| 138 | 138 | |
@@ -34,22 +34,36 @@ discard block |
||
| 34 | 34 | for($y = 0; $y <= $height; $y++){ |
| 35 | 35 | for($x = 0; $x <= $width; $x++){ |
| 36 | 36 | $k = $x; $k2 = $y; |
| 37 | - if($x<$modX) $k = $width-$x; |
|
| 38 | - if($y<$modY) $k2 = $height-$y; |
|
| 37 | + if($x<$modX) { |
|
| 38 | + $k = $width-$x; |
|
| 39 | + } |
|
| 40 | + if($y<$modY) { |
|
| 41 | + $k2 = $height-$y; |
|
| 42 | + } |
|
| 39 | 43 | $k3 = $k; |
| 40 | - if($k2>$k) $k3 = $k2; |
|
| 44 | + if($k2>$k) { |
|
| 45 | + $k3 = $k2; |
|
| 46 | + } |
|
| 41 | 47 | |
| 42 | 48 | $tmpX = $x-1; $tmpY = $y; |
| 43 | - if($this->checkParams($tmpX, $tmpY)) $relations["($tmpX,$tmpY)"]["($x,$y)"] = $k3; |
|
| 49 | + if($this->checkParams($tmpX, $tmpY)) { |
|
| 50 | + $relations["($tmpX,$tmpY)"]["($x,$y)"] = $k3; |
|
| 51 | + } |
|
| 44 | 52 | |
| 45 | 53 | $tmpX2 = $x+1; $tmpY2 = $y; |
| 46 | - if($this->checkParams($tmpX2, $tmpY2)) $relations["($tmpX2,$tmpY2)"]["($x,$y)"] = $k3; |
|
| 54 | + if($this->checkParams($tmpX2, $tmpY2)) { |
|
| 55 | + $relations["($tmpX2,$tmpY2)"]["($x,$y)"] = $k3; |
|
| 56 | + } |
|
| 47 | 57 | |
| 48 | 58 | $tmpX3 = $x; $tmpY3 = $y-1; |
| 49 | - if($this->checkParams($tmpX3, $tmpY3)) $relations["($tmpX3,$tmpY3)"]["($x,$y)"] = $k3; |
|
| 59 | + if($this->checkParams($tmpX3, $tmpY3)) { |
|
| 60 | + $relations["($tmpX3,$tmpY3)"]["($x,$y)"] = $k3; |
|
| 61 | + } |
|
| 50 | 62 | |
| 51 | 63 | $tmpX4 = $x; $tmpY4 = $y+1; |
| 52 | - if($this->checkParams($tmpX4, $tmpY4)) $relations["($tmpX4,$tmpY4)"]["($x,$y)"] = $k3; |
|
| 64 | + if($this->checkParams($tmpX4, $tmpY4)) { |
|
| 65 | + $relations["($tmpX4,$tmpY4)"]["($x,$y)"] = $k3; |
|
| 66 | + } |
|
| 53 | 67 | } |
| 54 | 68 | } |
| 55 | 69 | |
@@ -75,7 +89,7 @@ discard block |
||
| 75 | 89 | for($x = 0; $x <= $width; $x++){ |
| 76 | 90 | if($y==$height || $x==$width){ |
| 77 | 91 | $color = 10; |
| 78 | - }else{ |
|
| 92 | + } else{ |
|
| 79 | 93 | $color = imagecolorat($res, $x, $y); |
| 80 | 94 | } |
| 81 | 95 | $new_tab[$x][$y] = $color; |
@@ -94,24 +108,38 @@ discard block |
||
| 94 | 108 | |
| 95 | 109 | if($new_tab[$x][$y]<=100){ |
| 96 | 110 | $k3 = 9999; |
| 97 | - }else{ |
|
| 111 | + } else{ |
|
| 98 | 112 | $k = $x; $k2 = $y; |
| 99 | - if($x<$modX) $k = $width-$x; |
|
| 100 | - if($y<$modY) $k2 = $height-$y; |
|
| 113 | + if($x<$modX) { |
|
| 114 | + $k = $width-$x; |
|
| 115 | + } |
|
| 116 | + if($y<$modY) { |
|
| 117 | + $k2 = $height-$y; |
|
| 118 | + } |
|
| 101 | 119 | $k3 = $k; |
| 102 | - if($k2>$k) $k3 = $k2; |
|
| 120 | + if($k2>$k) { |
|
| 121 | + $k3 = $k2; |
|
| 122 | + } |
|
| 103 | 123 | } |
| 104 | 124 | $tmpX = $x-1; $tmpY = $y; |
| 105 | - if($this->checkParams($tmpX, $tmpY)) $relations["($tmpX,$tmpY)"]["($x,$y)"] = $k3; |
|
| 125 | + if($this->checkParams($tmpX, $tmpY)) { |
|
| 126 | + $relations["($tmpX,$tmpY)"]["($x,$y)"] = $k3; |
|
| 127 | + } |
|
| 106 | 128 | |
| 107 | 129 | $tmpX2 = $x+1; $tmpY2 = $y; |
| 108 | - if($this->checkParams($tmpX2, $tmpY2)) $relations["($tmpX2,$tmpY2)"]["($x,$y)"] = $k3; |
|
| 130 | + if($this->checkParams($tmpX2, $tmpY2)) { |
|
| 131 | + $relations["($tmpX2,$tmpY2)"]["($x,$y)"] = $k3; |
|
| 132 | + } |
|
| 109 | 133 | |
| 110 | 134 | $tmpX3 = $x; $tmpY3 = $y-1; |
| 111 | - if($this->checkParams($tmpX3, $tmpY3)) $relations["($tmpX3,$tmpY3)"]["($x,$y)"] = $k3; |
|
| 135 | + if($this->checkParams($tmpX3, $tmpY3)) { |
|
| 136 | + $relations["($tmpX3,$tmpY3)"]["($x,$y)"] = $k3; |
|
| 137 | + } |
|
| 112 | 138 | |
| 113 | 139 | $tmpX4 = $x; $tmpY4 = $y+1; |
| 114 | - if($this->checkParams($tmpX4, $tmpY4)) $relations["($tmpX4,$tmpY4)"]["($x,$y)"] = $k3; |
|
| 140 | + if($this->checkParams($tmpX4, $tmpY4)) { |
|
| 141 | + $relations["($tmpX4,$tmpY4)"]["($x,$y)"] = $k3; |
|
| 142 | + } |
|
| 115 | 143 | } |
| 116 | 144 | } |
| 117 | 145 | $relations = $res; |
@@ -132,7 +160,7 @@ discard block |
||
| 132 | 160 | private function checkParams($tmpX, $tmpY){ |
| 133 | 161 | if($tmpX >= 0 && $tmpY >= 0 && $tmpX <= $this->x_w && $tmpY <= $this->y_h){ |
| 134 | 162 | $output = true; |
| 135 | - }else{ |
|
| 163 | + } else{ |
|
| 136 | 164 | $output = false; |
| 137 | 165 | } |
| 138 | 166 | |