@@ -36,21 +36,21 @@ class _box3
3636 vMin.set (_min);
3737 vMax.set (_max);
3838 return *this ;
39- };
39+ }
4040
4141 SelfRef set (T x1, T y1, T z1, T x2, T y2, T z2)
4242 {
4343 vMin.set (x1, y1, z1);
4444 vMax.set (x2, y2, z2);
4545 return *this ;
46- };
46+ }
4747
4848 SelfRef set (SelfCRef b)
4949 {
5050 vMin.set (b.vMin );
5151 vMax.set (b.vMax );
5252 return *this ;
53- };
53+ }
5454
5555 SelfRef setb (const Tvector& center, const Tvector& dim)
5656 {
@@ -64,14 +64,14 @@ class _box3
6464 vMin.set (0 , 0 , 0 );
6565 vMax.set (0 , 0 , 0 );
6666 return *this ;
67- };
67+ }
6868
6969 SelfRef identity ()
7070 {
7171 vMin.set (-0.5 , -0.5 , -0.5 );
7272 vMax.set (0.5 , 0.5 , 0.5 );
7373 return *this ;
74- };
74+ }
7575
7676 SelfRef invalidate ()
7777 {
@@ -85,71 +85,73 @@ class _box3
8585 vMin.add (s);
8686 vMax.sub (s);
8787 return *this ;
88- };
88+ }
8989
9090 SelfRef shrink (const Tvector& s)
9191 {
9292 vMin.add (s);
9393 vMax.sub (s);
9494 return *this ;
95- };
95+ }
9696
9797 SelfRef grow (T s)
9898 {
9999 vMin.sub (s);
100100 vMax.add (s);
101101 return *this ;
102- };
102+ }
103103
104104 SelfRef grow (const Tvector& s)
105105 {
106106 vMin.sub (s);
107107 vMax.add (s);
108108 return *this ;
109- };
109+ }
110110
111111 SelfRef add (const Tvector& p)
112112 {
113113 vMin.add (p);
114114 vMax.add (p);
115115 return *this ;
116- };
116+ }
117117
118118 SelfRef sub (const Tvector& p)
119119 {
120120 vMin.sub (p);
121121 vMax.sub (p);
122122 return *this ;
123- };
123+ }
124124
125125 SelfRef offset (const Tvector& p)
126126 {
127127 vMin.add (p);
128128 vMax.add (p);
129129 return *this ;
130- };
130+ }
131131
132132 SelfRef add (SelfCRef b, const Tvector& p)
133133 {
134- vMin.add (b.min , p);
135- vMax.add (b.max , p);
134+ vMin.add (b.vMin , p);
135+ vMax.add (b.vMax , p);
136136 return *this ;
137- };
137+ }
138138
139- ICF BOOL contains (T x, T y, T z) const
139+ ICF bool contains (T x, T y, T z) const
140140 {
141141 return (x >= x1) && (x <= x2) && (y >= y1) && (y <= y2) && (z >= z1) && (z <= z2);
142- };
143- ICF BOOL contains (const Tvector& p) const { return contains (p.x , p.y , p.z ); };
144- ICF BOOL contains (SelfCRef b) const { return contains (b.vMin ) && contains (b.vMax ); };
145- BOOL similar (SelfCRef b) const { return vMin.similar (b.vMin ) && vMax.similar (b.vMax ); };
142+ }
143+
144+ ICF bool contains (const Tvector& p) const { return contains (p.x , p.y , p.z ); }
145+ ICF bool contains (SelfCRef b) const { return contains (b.vMin ) && contains (b.vMax ); }
146+ bool similar (SelfCRef b) const { return vMin.similar (b.vMin ) && vMax.similar (b.vMax ); }
146147
147148 ICF SelfRef modify (const Tvector& p)
148149 {
149150 vMin.min (p);
150151 vMax.max (p);
151152 return *this ;
152153 }
154+
153155 ICF SelfRef modify (T x, T y, T z)
154156 {
155157 _vector3<T> tmp = {x, y, z};
@@ -161,7 +163,7 @@ class _box3
161163 modify (b.vMin );
162164 modify (b.vMax );
163165 return *this ;
164- };
166+ }
165167
166168 SelfRef merge (SelfCRef b1, SelfCRef b2)
167169 {
@@ -230,35 +232,35 @@ class _box3
230232 return xform (b, m);
231233 }
232234
233- void getsize (Tvector& R) const { R.sub (vMax, vMin); };
235+ void getsize (Tvector& R) const { R.sub (vMax, vMin); }
234236
235237 void getradius (Tvector& R) const
236238 {
237239 getsize (R);
238240 R.mul (0 .5f );
239- };
241+ }
240242
241243 T getradius () const
242244 {
243245 Tvector R;
244246 getradius (R);
245247 return R.magnitude ();
246- };
248+ }
247249
248250 T getvolume () const
249251 {
250252 Tvector sz;
251253 getsize (sz);
252254 return sz.x * sz.y * sz.z ;
253- };
255+ }
254256
255257 SelfCRef getcenter (Tvector& C) const
256258 {
257259 C.x = (vMin.x + vMax.x ) * 0 .5f ;
258260 C.y = (vMin.y + vMax.y ) * 0 .5f ;
259261 C.z = (vMin.z + vMax.z ) * 0 .5f ;
260262 return *this ;
261- };
263+ }
262264
263265 SelfCRef get_CD (Tvector& bc, Tvector& bd) const // center + dimensions
264266 {
@@ -280,28 +282,28 @@ class _box3
280282 getcenter (C);
281283 R = C.distance_to (vMax);
282284 return *this ;
283- };
285+ }
284286
285287 // Detects if this box intersect other
286- ICF BOOL intersect (SelfCRef box)
288+ ICF bool intersect (SelfCRef box)
287289 {
288290 if (vMax.x < box.vMin .x )
289- return FALSE ;
291+ return false ;
290292 if (vMax.y < box.vMin .y )
291- return FALSE ;
293+ return false ;
292294 if (vMax.z < box.vMin .z )
293- return FALSE ;
295+ return false ;
294296 if (vMin.x > box.vMax .x )
295- return FALSE ;
297+ return false ;
296298 if (vMin.y > box.vMax .y )
297- return FALSE ;
299+ return false ;
298300 if (vMin.z > box.vMax .z )
299- return FALSE ;
300- return TRUE ;
301- };
301+ return false ;
302+ return true ;
303+ }
302304
303305 // Does the vector3 intersects box
304- BOOL Pick (const Tvector& start, const Tvector& dir)
306+ bool Pick (const Tvector& start, const Tvector& dir)
305307 {
306308 T alpha, xt, yt, zt;
307309 Tvector rvmin, rvmax;
@@ -372,6 +374,7 @@ class _box3
372374 };
373375
374376 u32 & IntRref (T& x) { return (u32 &)x; }
377+
375378 enum ERP_Result
376379 {
377380 rpNone = 0 ,
@@ -382,7 +385,7 @@ class _box3
382385
383386 ERP_Result Pick2 (const Tvector& origin, const Tvector& dir, Tvector& coord)
384387 {
385- BOOL Inside = TRUE ;
388+ bool Inside = true ;
386389 Tvector MaxT;
387390 MaxT.x = MaxT.y = MaxT.z = -1 .0f ;
388391
@@ -391,14 +394,14 @@ class _box3
391394 if (origin[0 ] < vMin[0 ])
392395 {
393396 coord[0 ] = vMin[0 ];
394- Inside = FALSE ;
397+ Inside = false ;
395398 if (IntRref (dir[0 ])) MaxT[0 ] = (vMin[0 ] - origin[0 ]) / dir[0 ]; // Calculate T distances to candidate planes
396399 MaxT[0 ] = (vMin[0 ] - origin[0 ]) / dir[0 ]; // Calculate T distances to candidate planes
397400 }
398401 else if (origin[0 ] > vMax[0 ])
399402 {
400403 coord[0 ] = vMax[0 ];
401- Inside = FALSE ;
404+ Inside = false ;
402405 if (IntRref (dir[0 ])) MaxT[0 ] = (vMax[0 ] - origin[0 ]) / dir[0 ]; // Calculate T distances to candidate planes
403406 MaxT[0 ] = (vMax[0 ] - origin[0 ]) / dir[0 ]; // Calculate T distances to candidate planes
404407 }
@@ -407,14 +410,14 @@ class _box3
407410 if (origin[1 ] < vMin[1 ])
408411 {
409412 coord[1 ] = vMin[1 ];
410- Inside = FALSE ;
413+ Inside = false ;
411414 if (IntRref (dir[1 ])) MaxT[1 ] = (vMin[1 ] - origin[1 ]) / dir[1 ]; // Calculate T distances to candidate planes
412415 MaxT[1 ] = (vMin[1 ] - origin[1 ]) / dir[1 ]; // Calculate T distances to candidate planes
413416 }
414417 else if (origin[1 ] > vMax[1 ])
415418 {
416419 coord[1 ] = vMax[1 ];
417- Inside = FALSE ;
420+ Inside = false ;
418421 if (IntRref (dir[1 ])) MaxT[1 ] = (vMax[1 ] - origin[1 ]) / dir[1 ]; // Calculate T distances to candidate planes
419422 MaxT[1 ] = (vMax[1 ] - origin[1 ]) / dir[1 ]; // Calculate T distances to candidate planes
420423 }
@@ -423,14 +426,14 @@ class _box3
423426 if (origin[2 ] < vMin[2 ])
424427 {
425428 coord[2 ] = vMin[2 ];
426- Inside = FALSE ;
429+ Inside = false ;
427430 if (IntRref (dir[2 ])) MaxT[2 ] = (vMin[2 ] - origin[2 ]) / dir[2 ]; // Calculate T distances to candidate planes
428431 MaxT[2 ] = (vMin[2 ] - origin[2 ]) / dir[2 ]; // Calculate T distances to candidate planes
429432 }
430433 else if (origin[2 ] > vMax[2 ])
431434 {
432435 coord[2 ] = vMax[2 ];
433- Inside = FALSE ;
436+ Inside = false ;
434437 if (IntRref (dir[2 ])) MaxT[2 ] = (vMax[2 ] - origin[2 ]) / dir[2 ]; // Calculate T distances to candidate planes
435438 MaxT[2 ] = (vMax[2 ] - origin[2 ]) / dir[2 ]; // Calculate T distances to candidate planes
436439 }
@@ -452,39 +455,44 @@ class _box3
452455
453456 // Check final candidate actually inside box
454457 if (IntRref (MaxT[WhichPlane]) & 0x80000000 ) return rpNone;
455- return rpNone;
456458
457459 if (0 == WhichPlane)
458460 {
459461 // 1 & 2
460462 coord[1 ] = origin[1 ] + MaxT[0 ] * dir[1 ];
463+
461464 if ((coord[1 ] < vMin[1 ]) || (coord[1 ] > vMax[1 ])) return rpNone;
462- return rpNone;
465+
463466 coord[2 ] = origin[2 ] + MaxT[0 ] * dir[2 ];
467+
464468 if ((coord[2 ] < vMin[2 ]) || (coord[2 ] > vMax[2 ])) return rpNone;
465- return rpNone;
469+
466470 return rpOriginOutside;
467471 }
468472 if (1 == WhichPlane)
469473 {
470474 // 0 & 2
471475 coord[0 ] = origin[0 ] + MaxT[1 ] * dir[0 ];
476+
472477 if ((coord[0 ] < vMin[0 ]) || (coord[0 ] > vMax[0 ])) return rpNone;
473- return rpNone;
478+
474479 coord[2 ] = origin[2 ] + MaxT[1 ] * dir[2 ];
480+
475481 if ((coord[2 ] < vMin[2 ]) || (coord[2 ] > vMax[2 ])) return rpNone;
476- return rpNone;
482+
477483 return rpOriginOutside;
478484 }
479485 if (2 == WhichPlane)
480486 {
481487 // 0 & 1
482488 coord[0 ] = origin[0 ] + MaxT[2 ] * dir[0 ];
489+
483490 if ((coord[0 ] < vMin[0 ]) || (coord[0 ] > vMax[0 ])) return rpNone;
484- return rpNone;
491+
485492 coord[1 ] = origin[1 ] + MaxT[2 ] * dir[1 ];
493+
486494 if ((coord[1 ] < vMin[1 ]) || (coord[1 ] > vMax[1 ])) return rpNone;
487- return rpNone;
495+
488496 return rpOriginOutside;
489497 }
490498 return rpNone;
@@ -504,7 +512,7 @@ class _box3
504512 case 7 : result.set (vMax.x , vMax.y , vMin.z ); break ;
505513 default : result.set (0 , 0 , 0 ); break ;
506514 }
507- };
515+ }
508516
509517 void getpoints (Tvector* result)
510518 {
@@ -516,7 +524,7 @@ class _box3
516524 result[5 ].set (vMin.x , vMax.y , vMax.z );
517525 result[6 ].set (vMax.x , vMax.y , vMax.z );
518526 result[7 ].set (vMax.x , vMax.y , vMin.z );
519- };
527+ }
520528
521529 SelfRef modify (SelfCRef src, const Tmatrix& M)
522530 {
@@ -531,13 +539,14 @@ class _box3
531539 }
532540};
533541
534- typedef _box3<float > Fbox;
535- typedef _box3<float > Fbox3;
536- typedef _box3<double > Dbox;
537- typedef _box3<double > Dbox3;
542+ using Fbox = _box3<float >;
543+ using Fbox3 = _box3<float >;
544+
545+ using Dbox = _box3<double >;
546+ using Dbox3 = _box3<double >;
538547
539548template <class T >
540- BOOL _valid (const _box3<T>& c)
549+ bool _valid (const _box3<T>& c)
541550{
542551 return _valid (c.vMin ) && _valid (c.vMax );
543552}
0 commit comments