67 if($from->equals($to)){
69 $this->currentBlock = -1;
72 $direction = $to->subtract($from)->normalize();
73 $maxDistance = $from->distance($to);
74 $this->level = $level;
75 $this->maxDistance = (int) $maxDistance;
76 $this->positionQueue = new \SplFixedArray(3);
78 $startClone =
new Vector3($from->x, $from->y, $from->z);
80 $this->currentDistance = 0;
90 $pos =
new Vector3($startClone->x, $startClone->y, $startClone->z);
91 $startBlock =
new Vector3(floor($pos->x), floor($pos->y), floor($pos->z));
93 if($this->getXLength($direction) > $mainDirection){
94 $this->mainFace = $this->getXFace($direction);
95 $mainDirection = $this->getXLength($direction);
96 $mainPosition = $this->getXPosition($direction, $startClone, $startBlock);
98 $this->secondFace = $this->getYFace($direction);
99 $secondDirection = $this->getYLength($direction);
100 $secondPosition = $this->getYPosition($direction, $startClone, $startBlock);
102 $this->thirdFace = $this->getZFace($direction);
103 $thirdDirection = $this->getZLength($direction);
104 $thirdPosition = $this->getZPosition($direction, $startClone, $startBlock);
106 if($this->getYLength($direction) > $mainDirection){
107 $this->mainFace = $this->getYFace($direction);
108 $mainDirection = $this->getYLength($direction);
109 $mainPosition = $this->getYPosition($direction, $startClone, $startBlock);
111 $this->secondFace = $this->getZFace($direction);
112 $secondDirection = $this->getZLength($direction);
113 $secondPosition = $this->getZPosition($direction, $startClone, $startBlock);
115 $this->thirdFace = $this->getXFace($direction);
116 $thirdDirection = $this->getXLength($direction);
117 $thirdPosition = $this->getXPosition($direction, $startClone, $startBlock);
119 if($this->getZLength($direction) > $mainDirection){
120 $this->mainFace = $this->getZFace($direction);
121 $mainDirection = $this->getZLength($direction);
122 $mainPosition = $this->getZPosition($direction, $startClone, $startBlock);
124 $this->secondFace = $this->getXFace($direction);
125 $secondDirection = $this->getXLength($direction);
126 $secondPosition = $this->getXPosition($direction, $startClone, $startBlock);
128 $this->thirdFace = $this->getYFace($direction);
129 $thirdDirection = $this->getYLength($direction);
130 $thirdPosition = $this->getYPosition($direction, $startClone, $startBlock);
133 $d = $mainPosition / $mainDirection;
134 $secondd = $secondPosition - $secondDirection * $d;
135 $thirdd = $thirdPosition - $thirdDirection * $d;
137 $this->secondError = floor($secondd * self::$gridSize);
138 $this->secondStep = round($secondDirection / $mainDirection * self::$gridSize);
139 $this->thirdError = floor($thirdd * self::$gridSize);
140 $this->thirdStep = round($thirdDirection / $mainDirection * self::$gridSize);
142 if($this->secondError + $this->secondStep <= 0){
143 $this->secondError = -$this->secondStep + 1;
146 if($this->thirdError + $this->thirdStep <= 0){
147 $this->thirdError = -$this->thirdStep + 1;
152 if($this->secondError < 0){
153 $this->secondError += self::$gridSize;
157 if($this->thirdError < 0){
158 $this->thirdError += self::$gridSize;
162 $this->secondError -= self::$gridSize;
163 $this->thirdError -= self::$gridSize;
165 $this->positionQueue[0] = $lastBlock;
167 $this->currentBlock = -1;
171 $startBlockFound =
false;
173 for($cnt = $this->currentBlock; $cnt >= 0; --$cnt){
174 if($this->posEquals($this->positionQueue[$cnt], $startBlock)){
175 $this->currentBlock = $cnt;
176 $startBlockFound =
true;
181 if(!$startBlockFound){
182 throw new \InvalidStateException(
"Start block missed in BlockIterator");
185 $this->maxDistanceInt = round($maxDistance / (sqrt($mainDirection ** 2 + $secondDirection ** 2 + $thirdDirection ** 2) / $mainDirection));