First you need equations of the sides of rectangle.
If you have points of it $A,B,C,D$ described by vectors, $r_{_A},r_{_B},r_{_C},r_{_D}$ where coordinates of $r_{_A}$ are $(x_{_A},y_{_A})$ etc..
you can write down 4 separate parametric equations for lines which are incidental to sides of rectangle
(1) $r_{_P}=(1-\lambda)r_{_A}+\lambda{r_{_B}}$
(2) $r_{_P}=(1-\lambda)r_{_B}+\lambda{r_{_C}}$
(3) $r_{_P}=(1-\lambda)r_{_C}+\lambda{r_{_D}}$
(4) $r_{_P}=(1-\lambda)r_{_D}+\lambda{r_{_A}}$ where $P$ lies on the line.
Now compose equation for your moving object from point $P_0$
(5) $r_{_P}= r_{_P0}+k{r{_u}}$
where $r{_u}$ is a unit vector in the direction of movement and $k$ some parameter.
Then solve 4 separate systems of equations for (1) and (5), (2) and (5), (3) and (5), (4) and (5) for unknown $k$ and $\lambda$.
System which gives solution $k>0$ and $\lambda\geq 0$ and $\lambda \leq 1$ is your proper solution for the given side of the rectangle.
Weak probability but you can have two systems solved on conditions above. It means that you hit .. a vertex.