add a method to calculate distance between a point and triangle, if the projected point is outside the triangle, use shortest distance between the point and all edges

Setting to infinity here makes sense. The final return will never be reached.