function [rev_x, rev_y] = BoundaryRev(FCx, FCy, vx, vy, BDW);

if abs(FCx + vx) > BDW    % X boundary is crossed

    dBDx = abs(BDW - FCx);  % x distance to the cell point to the boundary
    rx = dBDx / abs(vx);     % reduction ratio
else
    rx = 1;
end


if abs(FCy + vy) > BDW    % X boundary is crossed

    dBDy = abs(BDW - FCy);  % x distance to the cell point to the boundary
    ry = dBDy / abs(vy);     % reduction ratio
else
    ry = 1;
end

net_r = 0.5*min(rx, ry);   % 0.5 was multipled not to make the cell to stick to the boundary

rev_x = FCx + net_r*vx;
rev_y = FCy + net_r*vy;