68 $currentBlock = $start->floor();
70 $directionVector = $end->subtractVector($start)->normalize();
71 if($directionVector->lengthSquared() <= 0){
72 throw new \InvalidArgumentException(
"Start and end points are the same, giving a zero direction vector");
75 $radius = $start->distance($end);
77 $stepX = $directionVector->x <=> 0;
78 $stepY = $directionVector->y <=> 0;
79 $stepZ = $directionVector->z <=> 0;
83 $tMaxX = self::rayTraceDistanceToBoundary($start->x, $directionVector->x);
84 $tMaxY = self::rayTraceDistanceToBoundary($start->y, $directionVector->y);
85 $tMaxZ = self::rayTraceDistanceToBoundary($start->z, $directionVector->z);
88 $tDeltaX = $directionVector->x == 0 ? 0 : $stepX / $directionVector->x;
89 $tDeltaY = $directionVector->y == 0 ? 0 : $stepY / $directionVector->y;
90 $tDeltaZ = $directionVector->z == 0 ? 0 : $stepZ / $directionVector->z;
98 if($tMaxX < $tMaxY and $tMaxX < $tMaxZ){
102 $currentBlock = $currentBlock->add($stepX, 0, 0);
104 }elseif($tMaxY < $tMaxZ){
105 if($tMaxY > $radius){
108 $currentBlock = $currentBlock->add(0, $stepY, 0);
111 if($tMaxZ > $radius){
114 $currentBlock = $currentBlock->add(0, 0, $stepZ);