Given a rectangle, a start point, and an end point, find any path from start to finish that avoids the rectangle.
Example
Suppose you were at \$(1.5, -1.5)\$ and you needed to get to \$(2, 4)\$. However, there is a rectangle with upper left corner \$(1, 3)\$ and bottom right corner \$(4, 1)\$ in your way. It would look like this:
There are lots of paths you could take to get from the (green) start to the (red) end:
- You could go via \$(-3, 3)\$.
- You could go to \$(-1.5, -0.5)\$ and then to \$(-1, 4)\$.
- Since you're infinitely thin (having perfected your workout routine), you could go via \$(4, 1)\$ and \$(4, 3)\$.
- Among many others.
Here's what those three options look like (click for full size):
Challenge
Given a starting point \$S\$, an end point \$E\$, and the coordinates for the upper left and bottom right corners of a rectangle (in any format reasonable for your language, including complex numbers if you wish), output a series of points \$A_1, A_2, \ldots, A_n\$ of any length such that the piecewise linear path \$S \rightarrow A_1 \rightarrow A_2 \rightarrow \ldots \rightarrow A_n \rightarrow E\$ does not intersect the interior of the rectangle. Note that:
- The start point and end point will not be inside the rectangle, nor on the edge or corner of the rectangle.
- Your path may touch the corners and edges of the rectangle, but must not intersect the rectangle's interior.
- You may output nothing, an empty list or similar if you wish to traverse \$S \rightarrow E\$ directly.
- You may assume that the rectangle has a strictly positive width and height.
- Your approach need not use the same number of points for all testcases.
- The path may have duplicate points, and may intersect itself, if you so wish.
Testcases
Here, (sx,sy)
is the start point, (ex,ey)
is the end point, (tlx,tly)
is the top left corner of the rectangle and (brx,bry)
is the bottom right corner. Note that from the spec we will always have tlx < brx
and tly > bry
.
Input -> Sample output (one of infinite valid answers)
(sx,sy), (ex,ey), (tlx,tly), (brx,bry) -> ...
(1.5,-1.5), (2,4), (1,3), (4,1) -> (-3,3)
or (-1.5,0.5),(-1,4)
or (4,1),(4,3)
(-5,0), (5,0), (-1,1), (2,-2) -> (0,5)
or (-5,1),(5,1)
(0.5,-2), (0.5,1), (2,2), (4,-3) -> []
or (0.5,-0.5)
or (-1,-0.5)
Scoring
The shortest code in bytes wins.
f(s,e,t,b):[s,(1,1,1),e]
. \$\endgroup\$