public static List < MapElementContainer > collisionFreeOrdered ( List < MapElementContainer > input ) { // sort items by priority (highest first) Collections . sort ( input , Collections . reverseOrder ( ) ) ; // in order of priority, see if an item can be drawn, i.e. none of the items // in the currentItemsToDraw list clashes with it. List < MapElementContainer > output = new LinkedList < MapElementContainer > ( ) ; for ( MapElementContainer item : input ) { boolean hasSpace = true ; for ( MapElementContainer outputElement : output ) { if ( outputElement . clashesWith ( item ) ) { hasSpace = false ; break ; } } if ( hasSpace ) { output . add ( item ) ; } } return output ; }
Transforms a list of MapElements orders it and removes those elements that overlap . This operation is useful for an early elimination of elements in a list that will never be drawn because they overlap .