private static Coordinate2 <double> MeanNearest(Coordinate2 <double> p1, Coordinate2 <double> p2, Coordinate2 <double> q1, Coordinate2 <double> q2) { Coordinate2 <double> mean = new Coordinate2 <double>((p1.X + p2.X + q1.X + q2.X) * 0.25, (p1.Y + p2.Y + q1.Y + q2.Y) * 0.25); Coordinate2 <double> intPt = p1; double bestDist = SegmentUtils.Length(mean.X, mean.Y, intPt.X, intPt.Y); double curDist = SegmentUtils.Length(mean.X, mean.Y, p2.X, p2.Y); if (curDist < bestDist) { bestDist = curDist; intPt = p2; } curDist = SegmentUtils.Length(mean.X, mean.Y, q1.X, q1.Y); if (curDist < bestDist) { bestDist = curDist; intPt = q1; } curDist = SegmentUtils.Length(mean.X, mean.Y, q2.X, q2.Y); if (curDist < bestDist) { //bestDist = curDist; //intPt = q2; return(q2); } return(intPt); }
public static Polygon2 <double> Simplify(double minSegmentLength, Polygon2 <double> poly) { if (poly == null) { return(null); } Ring2 <double> outer = RingUtils.Simplify(minSegmentLength, poly.OuterRing); if (outer == null) { return(null); } if (poly.HasHoles) { List <Ring2 <double> > inners = new List <Ring2 <double> >(); Ring2 <double> curInner; double distSum; double minDist = 3.0 * minSegmentLength; for (int i = 0; i < poly.InnerRings.Rings.Length; i++) { curInner = poly.InnerRings.Rings[i]; //quick reject if the ring is "small" distSum = 0; for (uint j = 1; j < curInner.VertexCount; j++) { distSum += SegmentUtils.Length(curInner[j - 1], curInner[j]); if (distSum >= minDist) //quick exit for big rings { break; } } distSum += SegmentUtils.Length(curInner[curInner.VertexCount - 1], curInner[0]); if (distSum <= minDist) { continue; //can't exist as a ring with that small a boundary } curInner = RingUtils.Simplify(minSegmentLength, curInner); if (curInner != null) { inners.Add(curInner); } } if (inners.Count < 1) { return(outer); //no holes came through } RingSet2 <double> rs = poly.Factory.ConstructRingSet(inners); if (rs == null) { return(null); } return(poly.Factory.ConstructPolygon(outer, rs)); } else { return(outer); } }