@@ -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,23 +62,23 @@ 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 | - if($res){ |
|
| 68 | + if ($res) { |
|
| 69 | 69 | $width = imagesx($res); |
| 70 | 70 | $height = imagesy($res); |
| 71 | - }else{ |
|
| 71 | + }else { |
|
| 72 | 72 | $width = 100; |
| 73 | 73 | $height = 100; |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | $new_tab = array(); |
| 77 | - for($y = 0; $y <= $height; $y++){ |
|
| 78 | - for($x = 0; $x <= $width; $x++){ |
|
| 79 | - if($y==$height || $x==$width){ |
|
| 77 | + for ($y = 0; $y <= $height; $y++) { |
|
| 78 | + for ($x = 0; $x <= $width; $x++) { |
|
| 79 | + if ($y==$height || $x==$width) { |
|
| 80 | 80 | $color = 10; |
| 81 | - }else{ |
|
| 81 | + }else { |
|
| 82 | 82 | $color = imagecolorat($res, $x, $y); |
| 83 | 83 | } |
| 84 | 84 | $new_tab[$x][$y] = $color; |
@@ -92,29 +92,29 @@ discard block |
||
| 92 | 92 | $modY = ceil($height/2); |
| 93 | 93 | |
| 94 | 94 | $relations = array(); |
| 95 | - for($y = 0; $y <= $height; $y++){ |
|
| 96 | - for($x = 0; $x <= $width; $x++){ |
|
| 95 | + for ($y = 0; $y <= $height; $y++) { |
|
| 96 | + for ($x = 0; $x <= $width; $x++) { |
|
| 97 | 97 | |
| 98 | - if($new_tab[$x][$y]<=100){ |
|
| 98 | + if ($new_tab[$x][$y] <= 100) { |
|
| 99 | 99 | $k3 = 9999; |
| 100 | - }else{ |
|
| 100 | + }else { |
|
| 101 | 101 | $k = $x; $k2 = $y; |
| 102 | - if($x<$modX) $k = $width-$x; |
|
| 103 | - if($y<$modY) $k2 = $height-$y; |
|
| 102 | + if ($x < $modX) $k = $width-$x; |
|
| 103 | + if ($y < $modY) $k2 = $height-$y; |
|
| 104 | 104 | $k3 = $k; |
| 105 | - if($k2>$k) $k3 = $k2; |
|
| 105 | + if ($k2 > $k) $k3 = $k2; |
|
| 106 | 106 | } |
| 107 | 107 | $tmpX = $x-1; $tmpY = $y; |
| 108 | - if($this->checkParams($tmpX, $tmpY)) $relations["($tmpX,$tmpY)"]["($x,$y)"] = $k3; |
|
| 108 | + if ($this->checkParams($tmpX, $tmpY)) $relations["($tmpX,$tmpY)"]["($x,$y)"] = $k3; |
|
| 109 | 109 | |
| 110 | 110 | $tmpX2 = $x+1; $tmpY2 = $y; |
| 111 | - if($this->checkParams($tmpX2, $tmpY2)) $relations["($tmpX2,$tmpY2)"]["($x,$y)"] = $k3; |
|
| 111 | + if ($this->checkParams($tmpX2, $tmpY2)) $relations["($tmpX2,$tmpY2)"]["($x,$y)"] = $k3; |
|
| 112 | 112 | |
| 113 | 113 | $tmpX3 = $x; $tmpY3 = $y-1; |
| 114 | - if($this->checkParams($tmpX3, $tmpY3)) $relations["($tmpX3,$tmpY3)"]["($x,$y)"] = $k3; |
|
| 114 | + if ($this->checkParams($tmpX3, $tmpY3)) $relations["($tmpX3,$tmpY3)"]["($x,$y)"] = $k3; |
|
| 115 | 115 | |
| 116 | 116 | $tmpX4 = $x; $tmpY4 = $y+1; |
| 117 | - if($this->checkParams($tmpX4, $tmpY4)) $relations["($tmpX4,$tmpY4)"]["($x,$y)"] = $k3; |
|
| 117 | + if ($this->checkParams($tmpX4, $tmpY4)) $relations["($tmpX4,$tmpY4)"]["($x,$y)"] = $k3; |
|
| 118 | 118 | } |
| 119 | 119 | } |
| 120 | 120 | |
@@ -130,10 +130,10 @@ discard block |
||
| 130 | 130 | * @param int $tmpY |
| 131 | 131 | * @return bool |
| 132 | 132 | */ |
| 133 | - private function checkParams($tmpX, $tmpY){ |
|
| 134 | - if($tmpX >= 0 && $tmpY >= 0 && $tmpX <= $this->x_w && $tmpY <= $this->y_h){ |
|
| 133 | + private function checkParams($tmpX, $tmpY) { |
|
| 134 | + if ($tmpX >= 0 && $tmpY >= 0 && $tmpX <= $this->x_w && $tmpY <= $this->y_h) { |
|
| 135 | 135 | $output = true; |
| 136 | - }else{ |
|
| 136 | + }else { |
|
| 137 | 137 | $output = false; |
| 138 | 138 | } |
| 139 | 139 | |
@@ -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 | |
@@ -68,7 +82,7 @@ discard block |
||
| 68 | 82 | if($res){ |
| 69 | 83 | $width = imagesx($res); |
| 70 | 84 | $height = imagesy($res); |
| 71 | - }else{ |
|
| 85 | + } else{ |
|
| 72 | 86 | $width = 100; |
| 73 | 87 | $height = 100; |
| 74 | 88 | } |
@@ -78,7 +92,7 @@ discard block |
||
| 78 | 92 | for($x = 0; $x <= $width; $x++){ |
| 79 | 93 | if($y==$height || $x==$width){ |
| 80 | 94 | $color = 10; |
| 81 | - }else{ |
|
| 95 | + } else{ |
|
| 82 | 96 | $color = imagecolorat($res, $x, $y); |
| 83 | 97 | } |
| 84 | 98 | $new_tab[$x][$y] = $color; |
@@ -97,24 +111,38 @@ discard block |
||
| 97 | 111 | |
| 98 | 112 | if($new_tab[$x][$y]<=100){ |
| 99 | 113 | $k3 = 9999; |
| 100 | - }else{ |
|
| 114 | + } else{ |
|
| 101 | 115 | $k = $x; $k2 = $y; |
| 102 | - if($x<$modX) $k = $width-$x; |
|
| 103 | - if($y<$modY) $k2 = $height-$y; |
|
| 116 | + if($x<$modX) { |
|
| 117 | + $k = $width-$x; |
|
| 118 | + } |
|
| 119 | + if($y<$modY) { |
|
| 120 | + $k2 = $height-$y; |
|
| 121 | + } |
|
| 104 | 122 | $k3 = $k; |
| 105 | - if($k2>$k) $k3 = $k2; |
|
| 123 | + if($k2>$k) { |
|
| 124 | + $k3 = $k2; |
|
| 125 | + } |
|
| 106 | 126 | } |
| 107 | 127 | $tmpX = $x-1; $tmpY = $y; |
| 108 | - if($this->checkParams($tmpX, $tmpY)) $relations["($tmpX,$tmpY)"]["($x,$y)"] = $k3; |
|
| 128 | + if($this->checkParams($tmpX, $tmpY)) { |
|
| 129 | + $relations["($tmpX,$tmpY)"]["($x,$y)"] = $k3; |
|
| 130 | + } |
|
| 109 | 131 | |
| 110 | 132 | $tmpX2 = $x+1; $tmpY2 = $y; |
| 111 | - if($this->checkParams($tmpX2, $tmpY2)) $relations["($tmpX2,$tmpY2)"]["($x,$y)"] = $k3; |
|
| 133 | + if($this->checkParams($tmpX2, $tmpY2)) { |
|
| 134 | + $relations["($tmpX2,$tmpY2)"]["($x,$y)"] = $k3; |
|
| 135 | + } |
|
| 112 | 136 | |
| 113 | 137 | $tmpX3 = $x; $tmpY3 = $y-1; |
| 114 | - if($this->checkParams($tmpX3, $tmpY3)) $relations["($tmpX3,$tmpY3)"]["($x,$y)"] = $k3; |
|
| 138 | + if($this->checkParams($tmpX3, $tmpY3)) { |
|
| 139 | + $relations["($tmpX3,$tmpY3)"]["($x,$y)"] = $k3; |
|
| 140 | + } |
|
| 115 | 141 | |
| 116 | 142 | $tmpX4 = $x; $tmpY4 = $y+1; |
| 117 | - if($this->checkParams($tmpX4, $tmpY4)) $relations["($tmpX4,$tmpY4)"]["($x,$y)"] = $k3; |
|
| 143 | + if($this->checkParams($tmpX4, $tmpY4)) { |
|
| 144 | + $relations["($tmpX4,$tmpY4)"]["($x,$y)"] = $k3; |
|
| 145 | + } |
|
| 118 | 146 | } |
| 119 | 147 | } |
| 120 | 148 | |
@@ -133,7 +161,7 @@ discard block |
||
| 133 | 161 | private function checkParams($tmpX, $tmpY){ |
| 134 | 162 | if($tmpX >= 0 && $tmpY >= 0 && $tmpX <= $this->x_w && $tmpY <= $this->y_h){ |
| 135 | 163 | $output = true; |
| 136 | - }else{ |
|
| 164 | + } else{ |
|
| 137 | 165 | $output = false; |
| 138 | 166 | } |
| 139 | 167 | |