Smooth the specified line, preserving the end points. Author: Eugene Katrukha
(int[] a, int n)
| 422 | Author: Eugene Katrukha |
| 423 | */ |
| 424 | int[] smooth(int[] a, int n) { |
| 425 | float [] out = new float[n]; |
| 426 | int i,j; |
| 427 | //no point in averaging 2 points |
| 428 | if(n<3) |
| 429 | return a; |
| 430 | //preserve end points |
| 431 | out[0]= a[0]; |
| 432 | out[n-1] = a[n-1]; |
| 433 | //average middle points |
| 434 | for (i=1; i<(n-1); i++) { |
| 435 | out[i]=0.0f; |
| 436 | for(j=(i-1);j<(i+2);j++){ |
| 437 | out[i] += a[j]; |
| 438 | } |
| 439 | out[i] /= 3.0f; |
| 440 | } |
| 441 | for (i=0; i<n; i++) |
| 442 | a[i] = (int)Math.round(out[i]); |
| 443 | return a; |
| 444 | } |
| 445 | |
| 446 | /** |
| 447 | Smooth the specified line, preserving the end points.<br> |
no test coverage detected