@@ -150,6 +150,9 @@ typedef Box<V2i> Box2i;
150150// / 2D box of base type `int64_t`.
151151typedef Box<V2i64> Box2i64;
152152
153+ // / 2D box of base type `half`.
154+ typedef Box<V2h> Box2h;
155+
153156// / 2D box of base type `float`.
154157typedef Box<V2f> Box2f;
155158
@@ -165,6 +168,9 @@ typedef Box<V3i> Box3i;
165168// / 3D box of base type `int64_t`.
166169typedef Box<V3i64> Box3i64;
167170
171+ // / 3D box of base type `half`.
172+ typedef Box<V3h> Box3h;
173+
168174// / 3D box of base type `float`.
169175typedef Box<V3f> Box3f;
170176
@@ -515,48 +521,36 @@ template <class T>
515521IMATH_HOSTDEVICE inline void
516522Box<Vec2<T>>::extendBy (const Vec2<T>& point) IMATH_NOEXCEPT
517523{
518- if (point[0 ] < min[0 ]) min[0 ] = point[0 ];
519-
520- if (point[0 ] > max[0 ]) max[0 ] = point[0 ];
521-
522- if (point[1 ] < min[1 ]) min[1 ] = point[1 ];
523-
524- if (point[1 ] > max[1 ]) max[1 ] = point[1 ];
524+ min.x = std::min (min.x , point.x );
525+ max.x = std::max (max.x , point.x );
526+ min.y = std::min (min.y , point.y );
527+ max.y = std::max (max.y , point.y );
525528}
526529
527530template <class T >
528531IMATH_HOSTDEVICE inline void
529532Box<Vec2<T>>::extendBy (const Box<Vec2<T>>& box) IMATH_NOEXCEPT
530533{
531- if (box.min [0 ] < min[0 ]) min[0 ] = box.min [0 ];
532-
533- if (box.max [0 ] > max[0 ]) max[0 ] = box.max [0 ];
534-
535- if (box.min [1 ] < min[1 ]) min[1 ] = box.min [1 ];
536-
537- if (box.max [1 ] > max[1 ]) max[1 ] = box.max [1 ];
534+ min.x = std::min (min.x , box.min .x );
535+ max.x = std::max (max.x , box.max .x );
536+ min.y = std::min (min.y , box.min .y );
537+ max.y = std::max (max.y , box.max .y );
538538}
539539
540540template <class T >
541541IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool
542542Box<Vec2<T>>::intersects (const Vec2<T>& point) const IMATH_NOEXCEPT
543543{
544- if (point[0 ] < min[0 ] || point[0 ] > max[0 ] || point[1 ] < min[1 ] ||
545- point[1 ] > max[1 ])
546- return false ;
547-
548- return true ;
544+ return (point.x >= min.x ) && (point.x <= max.x ) &&
545+ (point.y >= min.y ) && (point.y <= max.y );
549546}
550547
551548template <class T >
552549IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool
553550Box<Vec2<T>>::intersects (const Box<Vec2<T>>& box) const IMATH_NOEXCEPT
554551{
555- if (box.max [0 ] < min[0 ] || box.min [0 ] > max[0 ] || box.max [1 ] < min[1 ] ||
556- box.min [1 ] > max[1 ])
557- return false ;
558-
559- return true ;
552+ return (box.min .x <= max.x ) && (box.max .x >= min.x ) &&
553+ (box.min .y <= max.y ) && (box.max .y >= min.y );
560554}
561555
562556template <class T >
@@ -579,19 +573,17 @@ template <class T>
579573IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool
580574Box<Vec2<T>>::isEmpty () const IMATH_NOEXCEPT
581575{
582- if (max[0 ] < min[0 ] || max[1 ] < min[1 ]) return true ;
583-
584- return false ;
576+ return (max.x < min.x || max.y < min.y );
585577}
586578
587579template <class T >
588580IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool
589581Box<Vec2<T>>::isInfinite () const IMATH_NOEXCEPT
590582{
591- if (min[ 0 ] != std::numeric_limits<T>::lowest () ||
592- max[ 0 ] != std::numeric_limits<T>::max () ||
593- min[ 1 ] != std::numeric_limits<T>::lowest () ||
594- max[ 1 ] != std::numeric_limits<T>::max ())
583+ if (min. x != std::numeric_limits<T>::lowest () ||
584+ max. x != std::numeric_limits<T>::max () ||
585+ min. y != std::numeric_limits<T>::lowest () ||
586+ max. y != std::numeric_limits<T>::max ())
595587 return false ;
596588
597589 return true ;
@@ -601,7 +593,7 @@ template <class T>
601593IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool
602594Box<Vec2<T>>::hasVolume () const IMATH_NOEXCEPT
603595{
604- if (max[ 0 ] <= min[ 0 ] || max[ 1 ] <= min[ 1 ] ) return false ;
596+ if (max. x <= min. x || max. y <= min. y ) return false ;
605597
606598 return true ;
607599}
@@ -610,12 +602,9 @@ template <class T>
610602IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline unsigned int
611603Box<Vec2<T>>::majorAxis () const IMATH_NOEXCEPT
612604{
613- unsigned int major = 0 ;
614- Vec2<T> s = size ();
615-
616- if (s[1 ] > s[major]) major = 1 ;
605+ Vec2<T> s = size ();
617606
618- return major ;
607+ return (s. x >= s. y ) ? 0 : 1 ;
619608}
620609
621610// /
@@ -769,56 +758,42 @@ template <class T>
769758IMATH_HOSTDEVICE inline void
770759Box<Vec3<T>>::extendBy (const Vec3<T>& point) IMATH_NOEXCEPT
771760{
772- if (point[0 ] < min[0 ]) min[0 ] = point[0 ];
773-
774- if (point[0 ] > max[0 ]) max[0 ] = point[0 ];
775-
776- if (point[1 ] < min[1 ]) min[1 ] = point[1 ];
777-
778- if (point[1 ] > max[1 ]) max[1 ] = point[1 ];
779-
780- if (point[2 ] < min[2 ]) min[2 ] = point[2 ];
781-
782- if (point[2 ] > max[2 ]) max[2 ] = point[2 ];
761+ min.x = std::min (min.x , point.x );
762+ min.y = std::min (min.y , point.y );
763+ min.z = std::min (min.z , point.z );
764+ max.x = std::max (max.x , point.x );
765+ max.y = std::max (max.y , point.y );
766+ max.z = std::max (max.z , point.z );
783767}
784768
785769template <class T >
786770IMATH_HOSTDEVICE inline void
787771Box<Vec3<T>>::extendBy (const Box<Vec3<T>>& box) IMATH_NOEXCEPT
788772{
789- if (box.min [0 ] < min[0 ]) min[0 ] = box.min [0 ];
790-
791- if (box.max [0 ] > max[0 ]) max[0 ] = box.max [0 ];
792-
793- if (box.min [1 ] < min[1 ]) min[1 ] = box.min [1 ];
794-
795- if (box.max [1 ] > max[1 ]) max[1 ] = box.max [1 ];
796-
797- if (box.min [2 ] < min[2 ]) min[2 ] = box.min [2 ];
798-
799- if (box.max [2 ] > max[2 ]) max[2 ] = box.max [2 ];
773+ min.x = std::min (min.x , box.min .x );
774+ min.y = std::min (min.y , box.min .y );
775+ min.z = std::min (min.z , box.min .z );
776+ max.x = std::max (max.x , box.max .x );
777+ max.y = std::max (max.y , box.max .y );
778+ max.z = std::max (max.z , box.max .z );
800779}
801780
802781template <class T >
803782IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool
804783Box<Vec3<T>>::intersects (const Vec3<T>& point) const IMATH_NOEXCEPT
805784{
806- if (point[0 ] < min[0 ] || point[0 ] > max[0 ] || point[1 ] < min[1 ] ||
807- point[1 ] > max[1 ] || point[2 ] < min[2 ] || point[2 ] > max[2 ])
808- return false ;
809-
810- return true ;
785+ return (point.x >= min.x ) && (point.x <= max.x ) &&
786+ (point.y >= min.y ) && (point.y <= max.y ) &&
787+ (point.z >= min.z ) && (point.z <= max.z );
811788}
812789
813790template <class T >
814791IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool
815792Box<Vec3<T>>::intersects (const Box<Vec3<T>>& box) const IMATH_NOEXCEPT
816793{
817- if (box.max [0 ] < min[0 ] || box.min [0 ] > max[0 ] || box.max [1 ] < min[1 ] ||
818- box.min [1 ] > max[1 ] || box.max [2 ] < min[2 ] || box.min [2 ] > max[2 ])
819- return false ;
820-
821- return true ;
794+ return (box.min .x <= max.x ) && (box.max .x >= min.x ) &&
795+ (box.min .y <= max.y ) && (box.max .y >= min.y ) &&
796+ (box.min .z <= max.z ) && (box.max .z >= min.z );
822797}
823798
824799template <class T >
@@ -841,21 +816,19 @@ template <class T>
841816IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool
842817Box<Vec3<T>>::isEmpty () const IMATH_NOEXCEPT
843818{
844- if (max[0 ] < min[0 ] || max[1 ] < min[1 ] || max[2 ] < min[2 ]) return true ;
845-
846- return false ;
819+ return (max.x < min.x || max.y < min.y || max.z < min.z );
847820}
848821
849822template <class T >
850823IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool
851824Box<Vec3<T>>::isInfinite () const IMATH_NOEXCEPT
852825{
853- if (min[ 0 ] != std::numeric_limits<T>::lowest () ||
854- max[ 0 ] != std::numeric_limits<T>::max () ||
855- min[ 1 ] != std::numeric_limits<T>::lowest () ||
856- max[ 1 ] != std::numeric_limits<T>::max () ||
857- min[ 2 ] != std::numeric_limits<T>::lowest () ||
858- max[ 2 ] != std::numeric_limits<T>::max ())
826+ if (min. x != std::numeric_limits<T>::lowest () ||
827+ max. x != std::numeric_limits<T>::max () ||
828+ min. y != std::numeric_limits<T>::lowest () ||
829+ max. y != std::numeric_limits<T>::max () ||
830+ min. z != std::numeric_limits<T>::lowest () ||
831+ max. z != std::numeric_limits<T>::max ())
859832 return false ;
860833
861834 return true ;
@@ -865,7 +838,7 @@ template <class T>
865838IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool
866839Box<Vec3<T>>::hasVolume () const IMATH_NOEXCEPT
867840{
868- if (max[ 0 ] <= min[ 0 ] || max[ 1 ] <= min[ 1 ] || max[ 2 ] <= min[ 2 ] ) return false ;
841+ if (max. x <= min. x || max. y <= min. y || max. z <= min. z ) return false ;
869842
870843 return true ;
871844}
@@ -874,14 +847,11 @@ template <class T>
874847IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline unsigned int
875848Box<Vec3<T>>::majorAxis () const IMATH_NOEXCEPT
876849{
877- unsigned int major = 0 ;
878- Vec3<T> s = size ();
879-
880- if (s[1 ] > s[major]) major = 1 ;
850+ Vec3<T> s = size ();
881851
882- if (s[ 2 ] > s[major]) major = 2 ;
883-
884- return major ;
852+ if (s. x >= s. y )
853+ return (s. x >= s. z ) ? 0 : 2 ;
854+ return (s. y >= s. z ) ? 1 : 2 ;
885855}
886856
887857IMATH_INTERNAL_NAMESPACE_HEADER_EXIT
0 commit comments