/// <summary>Closes the last path of this multipath with a line segment.</summary> /// <remarks> /// Closes the last path of this multipath with a line segment. The closing /// segment is a segment that connects the last and the first points of the /// path. This is a virtual segment. The first point is not duplicated to /// close the path. /// Call this method only for polylines. For polygons this method is /// implicitly called for the Polygon class. /// </remarks> public virtual void ClosePathWithLine() { m_impl.ClosePathWithLine(); }
private void GeneralizePath(com.epl.geometry.MultiPathImpl mpsrc, int ipath, com.epl.geometry.MultiPathImpl mpdst, com.epl.geometry.Line lineHelper) { if (mpsrc.GetPathSize(ipath) < 2) { return; } int start = mpsrc.GetPathStart(ipath); int end = mpsrc.GetPathEnd(ipath) - 1; com.epl.geometry.AttributeStreamOfDbl xy = (com.epl.geometry.AttributeStreamOfDbl)mpsrc.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.POSITION); bool bClosed = mpsrc.IsClosedPath(ipath); com.epl.geometry.AttributeStreamOfInt32 stack = new com.epl.geometry.AttributeStreamOfInt32(0); stack.Reserve(mpsrc.GetPathSize(ipath) + 1); com.epl.geometry.AttributeStreamOfInt32 resultStack = new com.epl.geometry.AttributeStreamOfInt32(0); resultStack.Reserve(mpsrc.GetPathSize(ipath) + 1); stack.Add(bClosed ? start : end); stack.Add(start); com.epl.geometry.Point2D pt = new com.epl.geometry.Point2D(); while (stack.Size() > 1) { int i1 = stack.GetLast(); stack.RemoveLast(); int i2 = stack.GetLast(); mpsrc.GetXY(i1, pt); lineHelper.SetStartXY(pt); mpsrc.GetXY(i2, pt); lineHelper.SetEndXY(pt); int mid = FindGreatestDistance(lineHelper, pt, xy, i1, i2, end); if (mid >= 0) { stack.Add(mid); stack.Add(i1); } else { resultStack.Add(i1); } } if (!bClosed) { resultStack.Add(stack.Get(0)); } int rs_size = resultStack.Size(); int path_size = mpsrc.GetPathSize(ipath); if (rs_size == path_size && rs_size == stack.Size()) { mpdst.AddPath(mpsrc, ipath, true); } else { if (resultStack.Size() > 0) { if (m_bRemoveDegenerateParts && resultStack.Size() <= 2) { if (bClosed || resultStack.Size() == 1) { return; } double d = com.epl.geometry.Point2D.Distance(mpsrc.GetXY(resultStack.Get(0)), mpsrc.GetXY(resultStack.Get(1))); if (d <= m_maxDeviation) { return; } } com.epl.geometry.Point point = new com.epl.geometry.Point(); for (int i = 0, n = resultStack.Size(); i < n; i++) { mpsrc.GetPointByVal(resultStack.Get(i), point); if (i == 0) { mpdst.StartPath(point); } else { mpdst.LineTo(point); } } if (bClosed) { for (int i_1 = resultStack.Size(); i_1 < 3; i_1++) { mpdst.LineTo(point); } mpdst.ClosePathWithLine(); } } } }