Skip to content

Commit 47a243d

Browse files
authored
Document the precise behavior of VoxelRayTrace::betweenPoints (#74)
1 parent 1647f8a commit 47a243d

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/VoxelRayTrace.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ private function __construct(){
3535
* Performs a ray trace from the start position in the given direction, for a distance of $maxDistance. This
3636
* returns a Generator which yields Vector3s containing the coordinates of voxels it passes through.
3737
*
38+
* @see VoxelRayTrace::betweenPoints for precise semantics
39+
*
3840
* @return \Generator|Vector3[]
3941
* @phpstan-return \Generator<int, Vector3, void, void>
4042
*/
@@ -46,11 +48,21 @@ public static function inDirection(Vector3 $start, Vector3 $directionVector, flo
4648
* Performs a ray trace between the start and end coordinates. This returns a Generator which yields Vector3s
4749
* containing the coordinates of voxels it passes through.
4850
*
51+
* The first Vector3 is `$start->floor()`.
52+
* Every subsequent Vector3 has a taxicab distance of exactly 1 from the previous Vector3;
53+
* if the ray crosses the intersection of multiple axis boundaries directly,
54+
* the algorithm prefers crossing the boundaries in the order `Z -> Y -> X`.
55+
*
56+
* If `$end` is on an axis boundary, the final Vector3 may or may not cross that boundary.
57+
* Otherwise, the final Vector3 is equal to `$end->floor()`.
58+
*
4959
* This is an implementation of the algorithm described in the link below.
5060
* @link http://www.cse.yorku.ca/~amana/research/grid.pdf
5161
*
5262
* @return \Generator|Vector3[]
5363
* @phpstan-return \Generator<int, Vector3, void, void>
64+
*
65+
* @throws \InvalidArgumentException if $start and $end have zero distance.
5466
*/
5567
public static function betweenPoints(Vector3 $start, Vector3 $end) : \Generator{
5668
$currentBlock = $start->floor();

0 commit comments

Comments
 (0)