Skip to content

Commit a84a5b1

Browse files
committed
fixed edge case for grid walking
1 parent b58e091 commit a84a5b1

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

raylib/rayutils.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,12 @@ void walkGrid(const Eigen::Vector3d &start, const Eigen::Vector3d &end, T &objec
379379

380380
const Eigen::Vector3i step(sign(direction[0]), sign(direction[1]), sign(direction[2]));
381381
direction /= max_length;
382+
float eps = 1e-10; // remove tiny about so grid walking doesn't exceed its boundary
383+
max_length -= eps;
382384
Eigen::Vector3d lengths, length_delta;
383385
for (int j = 0; j<3; j++)
384386
{
385-
const double to = std::abs(start[j] - p[j] - (double)std::max(0, step[j]));
387+
const double to = step[j] > 0 ? (double)p[j] + 1.0 - start[j] : start[j] - (double)p[j];
386388
const double dir = std::max(std::numeric_limits<double>::epsilon(), std::abs(direction[j]));
387389
lengths[j] = to / dir;
388390
length_delta[j] = 1.0 / dir;
@@ -393,7 +395,7 @@ void walkGrid(const Eigen::Vector3d &start, const Eigen::Vector3d &end, T &objec
393395
return; // only adding to one cell
394396
}
395397

396-
while (p != target)
398+
while (lengths[ax] < max_length)
397399
{
398400
p[ax] += step[ax];
399401
const double in_length = lengths[ax];

0 commit comments

Comments
 (0)