Distance from a point to the segment in the plane

(* Input: point T ∈ (ℝ^2), segment [μ,ν]; 
Output: distance;
Submodules: none needed *)

dist[t_,Seg_]:=Module[{lam,a=Seg[[1]],b=Seg[[2]],t0,dd},
If[(b-a).(t-a)<0,t0=a;dd=Norm[t-a],
If[(a-b).(t-b)<0,t0=b;dd=Norm[t-b],
lam=(b-a).(b-t)/Norm[b-a]^2;
t0=lam a+(1-lam)b;
dd=Norm[t0-t]]];  
dd
];

Dmn[t_,xm_,ym_,xn_,yn_]:=Module[{lam,a,b,t0,dd},
a={xm,ym};b={xn,yn};
If[(b-a).(t-a)<0,t0=a;dd=Norm[t-a],
If[(a-b).(t-b)<0,t0=b;dd=Norm[t-b],
lam=(b-a).(b-t)/Norm[b-a]^2;
t0=lam a+(1-lam)b;
Norm[t0-t]]]
];