Python 2, 317 bytes
def f(w,h,B):
A=[w*[2]for c in' '*h]
for x,y,c in B:A[y][x]=c<'0'
for i in range(2*(w+h)):
x,y,u,v=[[[(0,2*w+2*h-i-1,1,0),(2*w+h-1-i,h-1,0,-1)][i<2*w+h],(w-1,i-w,-1,0)][i<w+h],(i,0,0,1)][i<w]
while w>x>=0<=y<h:u,v=[(-v,-u),(v,u),(u,v)][A[y][x]];x+=u;y+=v
print[[y+w,2*(w+h)+~y][x<0],[2*w+h-1-x,x][y<h]][w>x>=0],