Guest User

Untitled

a guest
Sep 14th, 2011
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1.     public void test(){
  2.         rectangles = optimiseHorizon();
  3.         //rectangles = convert(tiles);
  4.         rectangles = optimiseVertical(rectangles);     
  5.     }
  6.  
  7.     public ArrayList<Rectangle> optimiseHorizon(){
  8.         ArrayList<Rectangle> b = convert(tiles);
  9.         int counter = 0;
  10.         while(counter<b.size()-1){
  11.             Rectangle r = b.get(counter);
  12.             Rectangle r2= b.get(counter+1);
  13.             int first = r.x + r.width;
  14.             if(first == r2.x && r.height == r2.height){
  15.                 b.set(counter, addRectWidth(r,r2));
  16.                 b.remove(r2);
  17.             } else {
  18.                 counter++;
  19.             }
  20.         }
  21.         return b;
  22.     }
  23.    
  24.     public ArrayList<Rectangle> optimiseVertical(ArrayList<Rectangle> b){
  25.         int count = 0;
  26.         int count2 = count+1;
  27.         while(count<b.size()){
  28.             Rectangle r = b.get(count);
  29.             Rectangle r2= b.get(count2);
  30.             System.out.format("Checking %s with %s\nb.size(): %s\n", count, count2, b.size());
  31.             if(r.y + r.height == r2.y && r.width == r2.width && r.x == r2.x){
  32.                 b.set(count, addRectHeight(r,r2));
  33.                 b.remove(count2);
  34.             } else if(count<b.size()&&count2+1<b.size()){
  35.                 count2++;
  36.             }
  37.             if(count2+1>=b.size()){
  38.                 count++;
  39.                 count2=count+1;
  40.             }
  41.             if(count2>=b.size())
  42.                 break;
  43.         }
  44.         return b;
  45.     }
  46.  
  47.     public Rectangle addRectWidth(Rectangle r, Rectangle r2){
  48.         return new Rectangle(r.x,
  49.                 r.y,
  50.                 r.width + r2.width,
  51.                 r.height);
  52.     }
  53.     public Rectangle addRectHeight(Rectangle r, Rectangle r2){
  54.         return new Rectangle(r.x,
  55.                 r.y,
  56.                 r.width,
  57.                 r.height + r2.height);
  58.     }
Advertisement
Add Comment
Please, Sign In to add comment