CreateStickyIntersectionsConnectLineCalculator( [NotNull] IPolyline geometryToReshapeAsPolyline, [NotNull] IPolyline highLevelReshapePath, [NotNull] List <KeyValuePair <IPoint, IPoint> > intersectingSourceTargetPoints) { var connectLineCalculator = new StickyIntersectionConnectLineCalculator(highLevelReshapePath, geometryToReshapeAsPolyline, intersectingSourceTargetPoints, _individualReshapes) { GeometriesToReshape = _reshapeGeometryCloneByOriginal.Values }; return(connectLineCalculator); }
private static void TryAddCutBackBoundaryConnectLine( IGeometry geometryToReshape, IPath usablePathOnTarget, StickyIntersectionConnectLineCalculator connectLineCalculator, bool searchForward, IDictionary <AdjustedCutSubcurve, IGeometry> toResult) { if (usablePathOnTarget == null) { return; } IPath connectLine = connectLineCalculator.FindConnectionAtBoundaryCutOff(usablePathOnTarget, searchForward); if (connectLine != null) { // TODO: zero-length checks AddReshapeConnect(connectLine, usablePathOnTarget, toResult, geometryToReshape); } }
private void AddCutBackBoundariesConnectLines( IGeometry geometryToReshape, StickyIntersectionConnectLineCalculator connectLineCalculator, IPolyline splitReshapeLine, Dictionary <AdjustedCutSubcurve, IGeometry> toResult) { IPath usablePathOnTarget = null; foreach (IPath pathOnTarget in GeometryUtils.GetPaths(splitReshapeLine)) { if (HasLengthZero(pathOnTarget)) { // duplicate split points result in 0-length parts continue; } TryAddCutBackBoundaryConnectLine(geometryToReshape, pathOnTarget, connectLineCalculator, true, toResult); TryAddCutBackBoundaryConnectLine(geometryToReshape, pathOnTarget, connectLineCalculator, false, toResult); if (usablePathOnTarget == null) { usablePathOnTarget = GeometryFactory.Clone(pathOnTarget); } else { // usablePathOnTarget != null: // the last path on target did not properly connect back to source - add this part plus its end connect line ((ISegmentCollection)usablePathOnTarget).AddSegmentCollection( (ISegmentCollection)pathOnTarget); TryAddCutBackBoundaryConnectLine(geometryToReshape, usablePathOnTarget, connectLineCalculator, true, toResult); TryAddCutBackBoundaryConnectLine(geometryToReshape, usablePathOnTarget, connectLineCalculator, false, toResult); } // always calculate both ends, because it depends on the other end's position on the unreshaped from/to point! //IPath connectLineAtEnd; //connectLineCalculator.FindConnection(polylineToReshape, // usablePathOnTarget, false, // out connectLineAtEnd); IPoint sourcePoint; if (!connectLineCalculator.IsTargetIntersectionPoint(usablePathOnTarget.ToPoint, out sourcePoint)) { // try adding the next part of the sketch to the usable part continue; } //if (connectLineAtStart != null && HasLengthZero(connectLineAtStart) && // HasLengthZero(connectLineAtEnd)) //{ // //consolidatedPathsOnTarget.Add(usablePathOnTarget); // // already reshaped normally, could result in invalid reshape line error! // usablePathOnTarget = null; // continue; //} //if (connectLineAtEnd != null) //{ // AddReshapeConnect(connectLineAtEnd, usablePathOnTarget, toResult, // geometryToReshape); //} usablePathOnTarget = null; } }
private IEnumerable <AdjustedCutSubcurve> CalculateSourceTargetPointAdjustSubcurves( IGeometry geometryToReshape, IPolyline highLevelReshapePath, IPolyline splitHighLevelReshapePath, List <KeyValuePair <IPoint, IPoint> > intersectingSourceTargetPoints, out StickyIntersectionConnectLineCalculator connectLineCalculator) { var polyToReshapeBoundary = (IPolyline)GeometryUtils.GetBoundary(geometryToReshape); connectLineCalculator = CreateStickyIntersectionsConnectLineCalculator(polyToReshapeBoundary, highLevelReshapePath, intersectingSourceTargetPoints); IPath usablePathOnTarget = null; IPath startConnectLine = null; var adjustCurves = new List <AdjustedCutSubcurve>(); foreach (IPath pathOnTarget in GeometryUtils.GetPaths(splitHighLevelReshapePath)) { if (HasLengthZero(pathOnTarget)) { // duplicate split points result in 0-length parts continue; } if (usablePathOnTarget == null) { startConnectLine = connectLineCalculator.FindConnection(polyToReshapeBoundary, pathOnTarget, true); } IPath endConnectLine = connectLineCalculator.FindConnection(polyToReshapeBoundary, pathOnTarget, false); if (usablePathOnTarget != null) { // the last path on target did not properly connect back to source - add this part plus its end connect line // and add a stitch point between the paths on the target IPoint potentialStitchpoint = usablePathOnTarget.ToPoint; AddPotentialStitchPoint(highLevelReshapePath, potentialStitchpoint); ((ISegmentCollection)usablePathOnTarget).AddSegmentCollection( (ISegmentCollection)pathOnTarget); } else { usablePathOnTarget = GeometryFactory.Clone(pathOnTarget); } if (startConnectLine == null) { // completely useless usablePathOnTarget = null; continue; } if (endConnectLine == null) { // try adding the next part of the sketch to the usable part continue; } if (HasLengthZero(startConnectLine) && HasLengthZero(endConnectLine)) { // already reshaped normally, could result in invalid reshape line error! usablePathOnTarget = null; continue; } if (HasLengthZero(startConnectLine)) { AddPotentialStitchPoint(highLevelReshapePath, usablePathOnTarget.FromPoint); } if (HasLengthZero(endConnectLine)) { AddPotentialStitchPoint(highLevelReshapePath, usablePathOnTarget.ToPoint); } // Theoretically consecutive adjustCurves could be merged to reduce the amount of reshapes // but this results in more frequent cases of reshapes to the wrong side. adjustCurves.Add( new AdjustedCutSubcurve(usablePathOnTarget, startConnectLine, endConnectLine)); usablePathOnTarget = null; } Marshal.ReleaseComObject(polyToReshapeBoundary); return(adjustCurves); }