1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
private void removeOverlappingPoints(int minlen) {
// for each point of the snake
for(int i=0;i<snake.size();i++) {
Point cur = snake.get(i);
// check the other points (right half)
for(int di=1+snake.size()/2;di>0;di--) {
Point end = snake.get((i+di)%snake.size());
double dist = distance2D(cur,end);
// if the two points are to close...
if ( dist>minlen ) continue;
// ... cut the "loop" part og the snake
for(int k=0;k<di;k++) snake.remove( (i+1) %snake.size() );
break;
}
}
} |