@@ -495,6 +495,86 @@ IntersectionTests.rayEllipsoid = function (ray, ellipsoid) {
495495 return undefined ;
496496} ;
497497
498+ const scratchRayIntervalX = new Interval ( ) ;
499+ const scratchRayIntervalY = new Interval ( ) ;
500+ const scratchRayIntervalZ = new Interval ( ) ;
501+
502+ /**
503+ * Computes the intersection points of a ray with an axis-aligned bounding box. (axis-aligned in the same space as the ray)
504+ *
505+ * @param {Ray } ray The ray.
506+ * @param {AxisAlignedBoundingBox } box The axis-aligned bounding box.
507+ * @param {Interval | undefined } result The interval containing scalar points along the ray or undefined if there are no intersections.
508+ */
509+ IntersectionTests . rayAxisAlignedBoundingBox = function ( ray , box , result ) {
510+ //>>includeStart('debug', pragmas.debug);
511+ if ( ! defined ( ray ) ) {
512+ throw new DeveloperError ( "ray is required." ) ;
513+ }
514+ if ( ! defined ( box ) ) {
515+ throw new DeveloperError ( "box is required." ) ;
516+ }
517+ //>>includeEnd('debug');
518+
519+ if ( ! defined ( result ) ) {
520+ result = new Interval ( ) ;
521+ }
522+
523+ const tx = rayIntervalAlongAABBAxis (
524+ ray . origin . x ,
525+ ray . direction . x ,
526+ box . minimum . x ,
527+ box . maximum . x ,
528+ scratchRayIntervalX ,
529+ ) ;
530+ const ty = rayIntervalAlongAABBAxis (
531+ ray . origin . y ,
532+ ray . direction . y ,
533+ box . minimum . y ,
534+ box . maximum . y ,
535+ scratchRayIntervalY ,
536+ ) ;
537+ const tz = rayIntervalAlongAABBAxis (
538+ ray . origin . z ,
539+ ray . direction . z ,
540+ box . minimum . z ,
541+ box . maximum . z ,
542+ scratchRayIntervalZ ,
543+ ) ;
544+
545+ result . start = tx . start > ty . start ? tx . start : ty . start ; //Get Greatest Min
546+ result . stop = tx . stop < ty . stop ? tx . stop : ty . stop ; //Get Smallest Max
547+
548+ if ( tx . start > ty . stop || ty . start > tx . stop ) {
549+ return undefined ;
550+ }
551+
552+ if ( result . start > tz . stop || tz . start > result . stop ) {
553+ return undefined ;
554+ }
555+
556+ if ( tz . start > result . start ) {
557+ result . start = tz . start ;
558+ }
559+ if ( tz . stop < result . stop ) {
560+ result . stop = tz . stop ;
561+ }
562+
563+ return result ;
564+ } ;
565+
566+ function rayIntervalAlongAABBAxis ( origin , direction , min , max , result ) {
567+ result . start = ( min - origin ) / direction ;
568+ result . stop = ( max - origin ) / direction ;
569+ if ( result . stop < result . start ) {
570+ const tmp = result . stop ;
571+ result . stop = result . start ;
572+ result . start = tmp ;
573+ }
574+
575+ return result ;
576+ }
577+
498578function addWithCancellationCheck ( left , right , tolerance ) {
499579 const difference = left + right ;
500580 if (
0 commit comments