Advertisement
PiMaster

WTF 3D matrix!?

Dec 26th, 2011
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.50 KB | None | 0 0
  1. /**
  2.  *
  3.  * @author PiMaster
  4.  */
  5.  
  6. package bloxpedition;
  7.  
  8. import java.util.ArrayList;
  9. import java.util.List;
  10.  
  11. public class Matrix<T>{
  12.     private List<T> data;
  13.     private int width;
  14.     private int length;
  15.     private int height;
  16.  
  17.     Matrix(int w,int h,int l){
  18.         resize(w,h,l);
  19.     }
  20.  
  21.     T get(int x,int y,int z){
  22.         if(x>=width){
  23.             throw new IndexOutOfBoundsException("x greater than or equal to width");}
  24.         if(z>=length){
  25.             throw new IndexOutOfBoundsException("z greater than or equal to length");}
  26.         if(y>=height){
  27.             throw new IndexOutOfBoundsException("y greater than or equal to height");}
  28.         return data.get(z*width*height+y*width+x);
  29.     }
  30.  
  31.     void set(int x,int y,int z,T value){
  32.         if(x>=width){
  33.             throw new IndexOutOfBoundsException("x greater than or equal to width");}
  34.         if(z>=length){
  35.             throw new IndexOutOfBoundsException("z greater than or equal to length");}
  36.         if(y>=height){
  37.             throw new IndexOutOfBoundsException("y greater than or equal to height");}
  38.         data.set(z*width*height+y*width+x,value);
  39.     }
  40.  
  41.     void resize(int w,int l,int h){
  42.         if(w<=0 || h<=0 || l<=0){
  43.             throw new IllegalArgumentException("Passed dimension <=0");}
  44.         width=w;
  45.         length=l;
  46.         height=h;
  47.         System.out.println("Calculated size:"+width*length*height);
  48.         data=new ArrayList<T>(width*length*height);
  49.         System.out.println("Size:"+data.size());
  50.     }
  51.    
  52.     int get_size(){
  53.         return data.size();
  54.     }
  55.  
  56.     int get_width(){
  57.         return width;
  58.     }
  59.  
  60.     int get_length(){
  61.         return length;
  62.     }
  63.  
  64.     int get_height(){
  65.         return height;
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement