public PointF GetNearestPointInEdge(PointF p) { float dist = Calc.Modulus(Calc.Magnitude(P1, p)); PointF np = P1; // for (int C = 1; C <= 4; C++) { //Point CP = GetPointByNumber(C); //// //float cDist = Calc.Modulus(Calc.Magnitude(CP, p)); //if (cDist < dist) //{ // dist = cDist; // np = CP; //} Line ln = new Line(); ln.P1 = Point.Round(GetPointByNumber(C)); ln.P2 = Point.Round(GetPointByNumber(C + 1 == 5 ? 1 : C + 1)); // PointF intersectionPos = Calc.PointLineNormalizedIntersection(p, ln.P1, ln.P2); float cDist = Calc.Modulus(Calc.DistancePointLine(p, ln.P1, ln.P2)); if (cDist < dist) { dist = cDist; np = intersectionPos; } } // return(np); }