@@ -538,9 +538,8 @@ class TaperedCapsuleVoxelizer
538538 " The tapered capsule is degenerate, in this case it is a capsule. Consider using the CapsuleVoxelizer class instead." );
539539 }
540540
541- initialize (pt1, pt2, radius1, radius2);
542-
543- BaseT::iterate ();
541+ if (initialize (pt1, pt2, radius1, radius2))
542+ BaseT::iterate ();
544543 }
545544
546545private:
@@ -899,7 +898,7 @@ class TaperedCapsuleVoxelizer
899898 // world space points and radius inputs
900899 // initializes class members in index space
901900 template <typename ScalarType>
902- inline void
901+ inline bool
903902 initialize (const math::Vec3<ScalarType>& pt1, const math::Vec3<ScalarType>& pt2,
904903 const ScalarType& r1, const ScalarType& r2)
905904 {
@@ -925,6 +924,25 @@ class TaperedCapsuleVoxelizer
925924 mORad1Sqr = mORad1 * mORad1 ;
926925 mORad2Sqr = mORad2 * mORad2 ;
927926
927+ // all voxels outside the narrow band -- nothing to populate
928+ if (mORad1 <= ScalarType (0 )) // this implies mORad2 <= 0 too
929+ return false ;
930+
931+ // at this point we know mORad1 > 0
932+ // but if mORad2 < 0, truncate the line segment to where radius equals 0
933+ // this way things like pullyPoints make geometric sense.
934+ if (mORad2 < ScalarType (0 )){
935+ const ScalarType t = (r2 <= r1 ? r2/(r2 - r1) : r1/(r1 - r2));
936+
937+ const math::Vec3<ScalarType> pt_0 = r2 <= r1 ? pt1 : pt2;
938+ const ScalarType r_0 = r2 <= r1 ? r1 : r2;
939+
940+ const math::Vec3<ScalarType> pt_mid = t*pt1 + (ScalarType (1 )-t)*pt2;
941+ const ScalarType r_mid = ScalarType (0 );
942+
943+ return initialize (pt_0, pt_mid, r_0, r_mid);
944+ }
945+
928946 mV = mPt2 - mPt1 ;
929947 mVLenSqr = mV .lengthSqr ();
930948 mInvVLenSqr = mVLenSqr != ValueT (0 ) ? ValueT (1 )/mVLenSqr : ValueT (1 );
@@ -969,6 +987,8 @@ class TaperedCapsuleVoxelizer
969987 mC2Inv = mC2 != 0.0 ? 1.0 /mC2 : 1.0 ;
970988
971989 BaseT::bottomTop = taperedCapsuleBottomTop;
990+
991+ return true ;
972992 }
973993
974994 // ------------ private members ------------
0 commit comments