public int compareTo(CHRTile tile){      
        if(tile.tileWidth != tileWidth){
            return ((tile.tileWidth < tileWidth) ? 1 : -1);
        }
        if(tile.tileHeight != tileHeight){
            return ((tile.tileHeight < tileHeight) ? 1 : -1);
        }
        
       
        if(IMAGE_SIMILARITY_THRESHOLD > 0) {
//        	double RMS_THRESHOLD = IMAGE_SIMILARITY_THRESHOLD / 100.0;
        	int rms_error = calculateRMS(tile.rgb, IMAGE_SIMILARITY_THRESHOLD/100.0);
        	
        	if(rms_error ==0) {
        		return 0;
        	}
        }
/*       if(IMAGE_SIMILARITY_THRESHOLD > 0) {
    	   
        	int diffCount = 0;
        	// do pixel by pixel check
            for(int i=0;i<pix.length;i++){
                if(tile.pix[i] != pix[i]){
                	diffCount++;
                	if(diffCount> IMAGE_SIMILARITY_THRESHOLD)
                		return ((tile.pix[i]< pix[i]) ? 1 : -1);
                }
            }
        } else {
*/        
        	// do mask check
        	for(int i=0;i<mask.length;i++){
        		if(tile.mask[i] != mask[i]){
            		return ((tile.mask[i]< mask[i]) ? 1 : -1);
        		}
        	}
 //       }
        return 0;
    }