public double DistanceToNearestSegment(clsPoint p1, ref int nSeg, ref int nPt, int avoidPt1 = -1, int avoidPt2 = -1, int includePt = -1) { int i; int j; clsLine l1; double d; double minD; //Find the point nearest nPt = GetNearestPointIndex(p1); //Find the segment closest to the point to add (ignore riser segments) nSeg = 0; minD = 10000; for (i = 0; i <= NumPoints; i++) { if ((i != avoidPt1 & i != avoidPt2) & (includePt == -1 || (i == includePt | i == includePt - 1 | (includePt == 0 & i == NumPoints)))) { j = i + 1; if (j > NumPoints) { j = 0; } l1 = new clsLine(Point(i), Point(j)); d = l1.DistanceToShortLine(p1); if (d < minD) { minD = d; nSeg = i; } } } return(minD); }