public double Dist(Pt p)
 {
     //distance from p to the edge
     if (vect.Dot(p - p1) <= 0)
         return p.Dist(p1);         //from p to p1
     if (vect.Dot(p - p2) >= 0)
         return p.Dist(p2);         //from p to p2
     //distance to the line itself
     return Math.Abs(-vect.Y * p.X + vect.X * p.Y + p1.X * p2.Y - p1.Y * p2.X) / norm;
 }
 public static double Dist(Pt v1, Pt v2)
 {
     return v1.Dist(v2);
 }