| Conditions | 63 |
| Paths | 139 |
| Total Lines | 278 |
| Code Lines | 218 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 62 | public function FilledRectangle($xl, $yt, $xr, $yb, $from_color, $to_color, $style = 1) |
||
| 63 | { |
||
| 64 | $this->img->SetLineWeight(1); |
||
| 65 | switch ($style) { |
||
| 66 | case GRAD_VER: |
||
| 67 | $steps = ceil(abs($xr - $xl) + 1); |
||
| 68 | $delta = $xr >= $xl ? 1 : -1; |
||
| 69 | $this->GetColArray($from_color, $to_color, $steps, $colors, $this->numcolors); |
||
| 70 | for ($i = 0, $x = $xl; $i < $steps; ++$i) { |
||
| 71 | $this->img->current_color = $colors[$i]; |
||
| 72 | $this->img->Line($x, $yt, $x, $yb); |
||
| 73 | $x += $delta; |
||
| 74 | } |
||
| 75 | |||
| 76 | break; |
||
| 77 | case GRAD_HOR: |
||
| 78 | $steps = ceil(abs($yb - $yt) + 1); |
||
| 79 | $delta = $yb >= $yt ? 1 : -1; |
||
| 80 | $this->GetColArray($from_color, $to_color, $steps, $colors, $this->numcolors); |
||
| 81 | for ($i = 0, $y = $yt; $i < $steps; ++$i) { |
||
| 82 | $this->img->current_color = $colors[$i]; |
||
| 83 | $this->img->Line($xl, $y, $xr, $y); |
||
| 84 | $y += $delta; |
||
| 85 | } |
||
| 86 | |||
| 87 | break; |
||
| 88 | case GRAD_MIDHOR: |
||
| 89 | $steps = ceil(abs($yb - $yt) / 2); |
||
| 90 | $delta = $yb >= $yt ? 1 : -1; |
||
| 91 | $this->GetColArray($from_color, $to_color, $steps, $colors, $this->numcolors); |
||
| 92 | for ($y = $yt, $i = 0; $i < $steps; ++$i) { |
||
| 93 | $this->img->current_color = $colors[$i]; |
||
| 94 | $this->img->Line($xl, $y, $xr, $y); |
||
| 95 | $y += $delta; |
||
| 96 | } |
||
| 97 | --$i; |
||
| 98 | if (abs($yb - $yt) % 2 == 1) { |
||
| 99 | --$steps; |
||
| 100 | } |
||
| 101 | for ($j = 0; $j < $steps; ++$j, --$i) { |
||
| 102 | $this->img->current_color = $colors[$i]; |
||
| 103 | $this->img->Line($xl, $y, $xr, $y); |
||
| 104 | $y += $delta; |
||
| 105 | } |
||
| 106 | $this->img->Line($xl, $y, $xr, $y); |
||
| 107 | |||
| 108 | break; |
||
| 109 | case GRAD_MIDVER: |
||
| 110 | $steps = ceil(abs($xr - $xl) / 2); |
||
| 111 | $delta = $xr >= $xl ? 1 : -1; |
||
| 112 | $this->GetColArray($from_color, $to_color, $steps, $colors, $this->numcolors); |
||
| 113 | for ($x = $xl, $i = 0; $i < $steps; ++$i) { |
||
| 114 | $this->img->current_color = $colors[$i]; |
||
| 115 | $this->img->Line($x, $yb, $x, $yt); |
||
| 116 | $x += $delta; |
||
| 117 | } |
||
| 118 | --$i; |
||
| 119 | if (abs($xr - $xl) % 2 == 1) { |
||
| 120 | --$steps; |
||
| 121 | } |
||
| 122 | for ($j = 0; $j < $steps; ++$j, --$i) { |
||
| 123 | $this->img->current_color = $colors[$i]; |
||
| 124 | $this->img->Line($x, $yb, $x, $yt); |
||
| 125 | $x += $delta; |
||
| 126 | } |
||
| 127 | $this->img->Line($x, $yb, $x, $yt); |
||
| 128 | |||
| 129 | break; |
||
| 130 | case GRAD_WIDE_MIDVER: |
||
| 131 | $diff = ceil(abs($xr - $xl)); |
||
| 132 | $steps = floor(abs($diff) / 3); |
||
| 133 | $firststep = $diff - 2 * $steps; |
||
| 134 | $delta = $xr >= $xl ? 1 : -1; |
||
| 135 | $this->GetColArray($from_color, $to_color, $firststep, $colors, $this->numcolors); |
||
| 136 | for ($x = $xl, $i = 0; $i < $firststep; ++$i) { |
||
| 137 | $this->img->current_color = $colors[$i]; |
||
| 138 | $this->img->Line($x, $yb, $x, $yt); |
||
| 139 | $x += $delta; |
||
| 140 | } |
||
| 141 | --$i; |
||
| 142 | $this->img->current_color = $colors[$i]; |
||
| 143 | for ($j = 0; $j < $steps; ++$j) { |
||
| 144 | $this->img->Line($x, $yb, $x, $yt); |
||
| 145 | $x += $delta; |
||
| 146 | } |
||
| 147 | |||
| 148 | for ($j = 0; $j < $steps; ++$j, --$i) { |
||
| 149 | $this->img->current_color = $colors[$i]; |
||
| 150 | $this->img->Line($x, $yb, $x, $yt); |
||
| 151 | $x += $delta; |
||
| 152 | } |
||
| 153 | |||
| 154 | break; |
||
| 155 | case GRAD_WIDE_MIDHOR: |
||
| 156 | $diff = ceil(abs($yb - $yt)); |
||
| 157 | $steps = floor(abs($diff) / 3); |
||
| 158 | $firststep = $diff - 2 * $steps; |
||
| 159 | $delta = $yb >= $yt ? 1 : -1; |
||
| 160 | $this->GetColArray($from_color, $to_color, $firststep, $colors, $this->numcolors); |
||
| 161 | for ($y = $yt, $i = 0; $i < $firststep; ++$i) { |
||
| 162 | $this->img->current_color = $colors[$i]; |
||
| 163 | $this->img->Line($xl, $y, $xr, $y); |
||
| 164 | $y += $delta; |
||
| 165 | } |
||
| 166 | --$i; |
||
| 167 | $this->img->current_color = $colors[$i]; |
||
| 168 | for ($j = 0; $j < $steps; ++$j) { |
||
| 169 | $this->img->Line($xl, $y, $xr, $y); |
||
| 170 | $y += $delta; |
||
| 171 | } |
||
| 172 | for ($j = 0; $j < $steps; ++$j, --$i) { |
||
| 173 | $this->img->current_color = $colors[$i]; |
||
| 174 | $this->img->Line($xl, $y, $xr, $y); |
||
| 175 | $y += $delta; |
||
| 176 | } |
||
| 177 | |||
| 178 | break; |
||
| 179 | case GRAD_LEFT_REFLECTION: |
||
| 180 | $steps1 = ceil(0.3 * abs($xr - $xl)); |
||
| 181 | $delta = $xr >= $xl ? 1 : -1; |
||
| 182 | |||
| 183 | $from_color = $this->img->rgb->Color($from_color); |
||
| 184 | $adj = 1.4; |
||
| 185 | $m = ($adj - 1.0) * (255 - min(255, min($from_color[0], min($from_color[1], $from_color[2])))); |
||
| 186 | $from_color2 = [min(255, $from_color[0] + $m), |
||
| 187 | min(255, $from_color[1] + $m), min(255, $from_color[2] + $m), ]; |
||
| 188 | |||
| 189 | $this->GetColArray($from_color2, $to_color, $steps1, $colors, $this->numcolors); |
||
| 190 | $n = safe_count($colors); |
||
| 191 | for ($x = $xl, $i = 0; $i < $steps1 && $i < $n; ++$i) { |
||
| 192 | $this->img->current_color = $colors[$i]; |
||
| 193 | $this->img->Line($x, $yb, $x, $yt); |
||
| 194 | $x += $delta; |
||
| 195 | } |
||
| 196 | $steps2 = max(1, ceil(0.08 * abs($xr - $xl))); |
||
| 197 | $this->img->SetColor($to_color); |
||
| 198 | for ($j = 0; $j < $steps2; ++$j) { |
||
| 199 | $this->img->Line($x, $yb, $x, $yt); |
||
| 200 | $x += $delta; |
||
| 201 | } |
||
| 202 | $steps = abs($xr - $xl) - $steps1 - $steps2; |
||
| 203 | $this->GetColArray($to_color, $from_color, $steps, $colors, $this->numcolors); |
||
| 204 | $n = safe_count($colors); |
||
| 205 | for ($i = 0; $i < $steps && $i < $n; ++$i) { |
||
| 206 | $this->img->current_color = $colors[$i]; |
||
| 207 | $this->img->Line($x, $yb, $x, $yt); |
||
| 208 | $x += $delta; |
||
| 209 | } |
||
| 210 | |||
| 211 | break; |
||
| 212 | case GRAD_RIGHT_REFLECTION: |
||
| 213 | $steps1 = ceil(0.7 * abs($xr - $xl)); |
||
| 214 | $delta = $xr >= $xl ? 1 : -1; |
||
| 215 | |||
| 216 | $this->GetColArray($from_color, $to_color, $steps1, $colors, $this->numcolors); |
||
| 217 | $n = safe_count($colors); |
||
| 218 | for ($x = $xl, $i = 0; $i < $steps1 && $i < $n; ++$i) { |
||
| 219 | $this->img->current_color = $colors[$i]; |
||
| 220 | $this->img->Line($x, $yb, $x, $yt); |
||
| 221 | $x += $delta; |
||
| 222 | } |
||
| 223 | $steps2 = max(1, ceil(0.08 * abs($xr - $xl))); |
||
| 224 | $this->img->SetColor($to_color); |
||
| 225 | for ($j = 0; $j < $steps2; ++$j) { |
||
| 226 | $this->img->Line($x, $yb, $x, $yt); |
||
| 227 | $x += $delta; |
||
| 228 | } |
||
| 229 | |||
| 230 | $from_color = $this->img->rgb->Color($from_color); |
||
| 231 | $adj = 1.4; |
||
| 232 | $m = ($adj - 1.0) * (255 - min(255, min($from_color[0], min($from_color[1], $from_color[2])))); |
||
| 233 | $from_color = [min(255, $from_color[0] + $m), |
||
| 234 | min(255, $from_color[1] + $m), min(255, $from_color[2] + $m), ]; |
||
| 235 | |||
| 236 | $steps = abs($xr - $xl) - $steps1 - $steps2; |
||
| 237 | $this->GetColArray($to_color, $from_color, $steps, $colors, $this->numcolors); |
||
| 238 | $n = safe_count($colors); |
||
| 239 | for ($i = 0; $i < $steps && $i < $n; ++$i) { |
||
| 240 | $this->img->current_color = $colors[$i]; |
||
| 241 | $this->img->Line($x, $yb, $x, $yt); |
||
| 242 | $x += $delta; |
||
| 243 | } |
||
| 244 | |||
| 245 | break; |
||
| 246 | case GRAD_CENTER: |
||
| 247 | $steps = ceil(min(($yb - $yt) + 1, ($xr - $xl) + 1) / 2); |
||
| 248 | $this->GetColArray($from_color, $to_color, $steps, $colors, $this->numcolors); |
||
| 249 | $dx = ($xr - $xl) / 2; |
||
| 250 | $dy = ($yb - $yt) / 2; |
||
| 251 | $x = $xl; |
||
|
|
|||
| 252 | $y = $yt; |
||
| 253 | $x2 = $xr; |
||
| 254 | $y2 = $yb; |
||
| 255 | $n = safe_count($colors); |
||
| 256 | for ($x = $xl, $i = 0; $x < $xl + $dx && $y < $yt + $dy && $i < $n; ++$x, ++$y, --$x2, --$y2, ++$i) { |
||
| 257 | $this->img->current_color = $colors[$i]; |
||
| 258 | $this->img->Rectangle($x, $y, $x2, $y2); |
||
| 259 | } |
||
| 260 | $this->img->Line($x, $y, $x2, $y2); |
||
| 261 | |||
| 262 | break; |
||
| 263 | case GRAD_RAISED_PANEL: |
||
| 264 | // right to left |
||
| 265 | $steps1 = $xr - $xl; |
||
| 266 | $delta = $xr >= $xl ? 1 : -1; |
||
| 267 | $this->GetColArray($to_color, $from_color, $steps1, $colors, $this->numcolors); |
||
| 268 | $n = safe_count($colors); |
||
| 269 | for ($x = $xl, $i = 0; $i < $steps1 && $i < $n; ++$i) { |
||
| 270 | $this->img->current_color = $colors[$i]; |
||
| 271 | $this->img->Line($x, $yb, $x, $yt); |
||
| 272 | $x += $delta; |
||
| 273 | } |
||
| 274 | |||
| 275 | // left to right |
||
| 276 | $xr -= 3; |
||
| 277 | $xl += 3; |
||
| 278 | $yb -= 3; |
||
| 279 | $yt += 3; |
||
| 280 | $steps2 = $xr - $xl; |
||
| 281 | $delta = $xr >= $xl ? 1 : -1; |
||
| 282 | for ($x = $xl, $j = $steps2; $j >= 0; --$j) { |
||
| 283 | $this->img->current_color = $colors[$j]; |
||
| 284 | $this->img->Line($x, $yb, $x, $yt); |
||
| 285 | $x += $delta; |
||
| 286 | } |
||
| 287 | |||
| 288 | break; |
||
| 289 | case GRAD_DIAGONAL: |
||
| 290 | // use the longer dimension to determine the required number of steps. |
||
| 291 | // first loop draws from one corner to the mid-diagonal and the second |
||
| 292 | // loop draws from the mid-diagonal to the opposing corner. |
||
| 293 | if ($xr - $xl > $yb - $yt) { |
||
| 294 | // width is greater than height -> use x-dimension for steps |
||
| 295 | $steps = $xr - $xl; |
||
| 296 | $delta = $xr >= $xl ? 1 : -1; |
||
| 297 | $this->GetColArray($from_color, $to_color, $steps * 2, $colors, $this->numcolors); |
||
| 298 | $n = safe_count($colors); |
||
| 299 | |||
| 300 | for ($x = $xl, $i = 0; $i < $steps && $i < $n; ++$i) { |
||
| 301 | $this->img->current_color = $colors[$i]; |
||
| 302 | $y = $yt + ($i / $steps) * ($yb - $yt) * $delta; |
||
| 303 | $this->img->Line($x, $yt, $xl, $y); |
||
| 304 | $x += $delta; |
||
| 305 | } |
||
| 306 | |||
| 307 | for ($x = $xl, $i = 0; $i < $steps && $i < $n; ++$i) { |
||
| 308 | $this->img->current_color = $colors[$steps + $i]; |
||
| 309 | $y = $yt + ($i / $steps) * ($yb - $yt) * $delta; |
||
| 310 | $this->img->Line($x, $yb, $xr, $y); |
||
| 311 | $x += $delta; |
||
| 312 | } |
||
| 313 | } else { |
||
| 314 | // height is greater than width -> use y-dimension for steps |
||
| 315 | $steps = $yb - $yt; |
||
| 316 | $delta = $yb >= $yt ? 1 : -1; |
||
| 317 | $this->GetColArray($from_color, $to_color, $steps * 2, $colors, $this->numcolors); |
||
| 318 | $n = safe_count($colors); |
||
| 319 | |||
| 320 | for ($y = $yt, $i = 0; $i < $steps && $i < $n; ++$i) { |
||
| 321 | $this->img->current_color = $colors[$i]; |
||
| 322 | $x = $xl + ($i / $steps) * ($xr - $xl) * $delta; |
||
| 323 | $this->img->Line($x, $yt, $xl, $y); |
||
| 324 | $y += $delta; |
||
| 325 | } |
||
| 326 | |||
| 327 | for ($y = $yt, $i = 0; $i < $steps && $i < $n; ++$i) { |
||
| 328 | $this->img->current_color = $colors[$steps + $i]; |
||
| 329 | $x = $xl + ($i / $steps) * ($xr - $xl) * $delta; |
||
| 330 | $this->img->Line($x, $yb, $xr, $y); |
||
| 331 | $x += $delta; |
||
| 332 | } |
||
| 333 | } |
||
| 334 | |||
| 335 | break; |
||
| 336 | default: |
||
| 337 | Util\JpGraphError::RaiseL(7001, $style); |
||
| 338 | //("Unknown gradient style (=$style)."); |
||
| 339 | break; |
||
| 340 | } |
||
| 457 |