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 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /externals/g4tools/include/tools/lina/box3 (Version 11.3.0) and /externals/g4tools/include/tools/lina/box3 (Version 10.0.p4)


  1 // Copyright (C) 2010, Guy Barrand. All rights    
  2 // See the file tools.license for terms.          
  3                                                   
  4 #ifndef tools_box3                                
  5 #define tools_box3                                
  6                                                   
  7 #include "../mnmx"                                
  8                                                   
  9 //#include <limits>                               
 10 #include <ostream>                                
 11                                                   
 12 namespace tools {                                 
 13                                                   
 14 template <class VEC3>                             
 15 class box3 {                                      
 16 protected:                                        
 17   typedef typename VEC3::elem_t T_t;              
 18   //static T_t num_max() {return std::numeric_    
 19   static T_t zero() {return T_t();}               
 20 protected:                                        
 21   box3(){                                         
 22     //make_empty();                               
 23   }                                               
 24 public:                                           
 25   virtual ~box3() {}                              
 26 public:                                           
 27   box3(const box3& a_from)                        
 28   :m_min(a_from.m_min)                            
 29   ,m_max(a_from.m_max)                            
 30   {}                                              
 31   box3& operator=(const box3& a_from){            
 32     m_min = a_from.m_min;                         
 33     m_max = a_from.m_max;                         
 34     return *this;                                 
 35   }                                               
 36 public:                                           
 37   bool center(VEC3& a_center) const {             
 38     if(is_empty()) {a_center.set_value(0,0,0);    
 39     a_center.set_value((m_max[0] + m_min[0])/T    
 40                        (m_max[1] + m_min[1])/T    
 41                        (m_max[2] + m_min[2])/T    
 42     return true;                                  
 43   }                                               
 44                                                   
 45   bool set_bounds(const VEC3& a_mn,const VEC3&    
 46     if( a_mn[0]>a_mx[0] || a_mn[1]>a_mx[1] ||     
 47     m_min = a_mn;                                 
 48     m_max = a_mx;                                 
 49     return true;                                  
 50   }                                               
 51   bool set_bounds(T_t a_mn_x,T_t a_mn_y,T_t a_    
 52                   T_t a_mx_x,T_t a_mx_y,T_t a_    
 53     if( a_mn_x>a_mx_x || a_mn_y>a_mx_y || a_mn    
 54     m_min.set_value(a_mn_x,a_mn_y,a_mn_z);        
 55     m_max.set_value(a_mx_x,a_mx_y,a_mx_z);        
 56     return true;                                  
 57   }                                               
 58                                                   
 59   bool get_size(T_t& a_dx,T_t& a_dy,T_t& a_dz)    
 60     if(is_empty()) {a_dx = 0;a_dy = 0;a_dz = 0    
 61     a_dx = m_max[0] - m_min[0];                   
 62     a_dy = m_max[1] - m_min[1];                   
 63     a_dz = m_max[2] - m_min[2];                   
 64     return true;                                  
 65   }                                               
 66                                                   
 67   bool is_empty() const {return m_max[0] < m_m    
 68                                                   
 69   const VEC3& mn() const {return m_min;}          
 70   const VEC3& mx() const {return m_max;}          
 71                                                   
 72   bool back(VEC3& a_min,VEC3& a_min_y,VEC3& a_    
 73     T_t dx,dy,dz;                                 
 74     if(!get_size(dx,dy,dz)) return false; //WA    
 75     // back (from m_min, clockwise order looki    
 76     a_min = m_min;                                
 77     a_min_y.set_value (m_min.x()   ,m_min.y()+    
 78     a_min_xy.set_value(m_min.x()+dx,m_min.y()+    
 79     a_min_x.set_value (m_min.x()+dx,m_min.y()     
 80     return true;                                  
 81   }                                               
 82                                                   
 83   bool front(VEC3& a_max,VEC3& a_max_x,VEC3& a    
 84     T_t dx,dy,dz;                                 
 85     if(!get_size(dx,dy,dz)) return false; //WA    
 86     // front (from m_max, clockwise order look    
 87     a_max = m_max;                                
 88     a_max_x.set_value (m_max.x()-dx,m_max.y()     
 89     a_max_xy.set_value(m_max.x()-dx,m_max.y()-    
 90     a_max_y.set_value (m_max.x()   ,m_max.y()-    
 91     return true;                                  
 92   }                                               
 93                                                   
 94   void extend_by(const VEC3& a_point) {           
 95     // Extend the boundaries of the box by the    
 96     // point fit inside the box if it isn't al    
 97     if(is_empty()) {                              
 98       set_bounds(a_point,a_point);                
 99     } else {                                      
100       m_min.set_value(min_of<T_t>(a_point[0],m    
101                       min_of<T_t>(a_point[1],m    
102                       min_of<T_t>(a_point[2],m    
103       m_max.set_value(max_of<T_t>(a_point[0],m    
104                       max_of<T_t>(a_point[1],m    
105                       max_of<T_t>(a_point[2],m    
106     }                                             
107   }                                               
108                                                   
109   void extend_by(T_t a_x,T_t a_y,T_t a_z) {       
110     // Extend the boundaries of the box by the    
111     // point fit inside the box if it isn't al    
112     if(is_empty()) {                              
113       set_bounds(a_x,a_y,a_z,a_x,a_y,a_z);        
114     } else {                                      
115       m_min.set_value(min_of<T_t>(a_x,m_min[0]    
116                       min_of<T_t>(a_y,m_min[1]    
117                       min_of<T_t>(a_z,m_min[2]    
118       m_max.set_value(max_of<T_t>(a_x,m_max[0]    
119                       max_of<T_t>(a_y,m_max[1]    
120                       max_of<T_t>(a_z,m_max[2]    
121     }                                             
122   }                                               
123                                                   
124   bool get_cube_size(T_t& a_dx,T_t& a_dy,T_t&     
125     if(!get_size(a_dx,a_dy,a_dz)) return false    
126     if((a_dx<=zero())&&(a_dy<=zero())&&(a_dz<=    
127     if((a_dx<=zero())&&(a_dy<=zero())) { //dz     
128       a_dx = T_t(0.1)*a_dz;                       
129       a_dy = T_t(0.1)*a_dz;                       
130     } else if((a_dy<=zero())&&(a_dz<=zero()))     
131       a_dy = T_t(0.1)*a_dx;                       
132       a_dz = T_t(0.1)*a_dx;                       
133     } else if((a_dz<=zero())&&(a_dx<=zero()))     
134       a_dz = T_t(0.1)*a_dy;                       
135       a_dx = T_t(0.1)*a_dy;                       
136                                                   
137     } else if(a_dx<=zero()) { //dy,dz not 0 :     
138       a_dx = T_t(0.1)*a_sqrt(a_dy*a_dy+a_dz*a_    
139     } else if(a_dy<=zero()) { //dx,dz not 0 :     
140       a_dy = T_t(0.1)*a_sqrt(a_dx*a_dx+a_dz*a_    
141     } else if(a_dz<=zero()) { //dx,dy not 0 :     
142       a_dz = T_t(0.1)*a_sqrt(a_dx*a_dx+a_dy*a_    
143     }                                             
144     return true;                                  
145   }                                               
146                                                   
147   //NOTE : print is a Python keyword.             
148   void dump(std::ostream& a_out) {                
149     T_t dx,dy,dz;                                 
150     if(!get_size(dx,dy,dz)) {                     
151       a_out << "box is empty." << std::endl;      
152     } else {                                      
153       a_out << " size " << dx << " " << dy <<     
154     }                                             
155     a_out << " min " << m_min[0] << " " << m_m    
156     a_out << " max " << m_max[0] << " " << m_m    
157     VEC3 c;                                       
158     center(c);                                    
159     a_out << " center " << c[0] << " " << c[1]    
160   }                                               
161                                                   
162 protected:                                        
163   VEC3 m_min;                                     
164   VEC3 m_max;                                     
165 };                                                
166                                                   
167 }                                                 
168                                                   
169 #endif