05 - Moving a rectangle

The green rectangle goes as far towards the pointer as it can. Drag anywhere on the map to pull it.

cast(originX, originY, directionX, directionY, maxDistance, options)
The only method the page uses, and the answer to a question the library does not ask: how far can a rectangle go?
A row of rays leaves the leading edge of the box in the direction of travel, and the shortest of them decides.

Anything narrower than the spacing between rays can pass between two of them unseen. Keep the spacing below the size of the smallest obstacle and it never comes up.