private static double GetLineAngle([NotNull] CutSubcurve subcurve, SubcurveNode atNode) { var segments = (ISegmentCollection)subcurve.Path; ISegment segment; var reverseOrientation = false; if (atNode == subcurve.ToNode) { // use last segment and the line needs to be inverted segment = segments.Segment[segments.SegmentCount - 1]; reverseOrientation = true; } else { segment = segments.Segment[0]; } var line = segment as ILine; if (line == null) { line = new LineClass(); segment.QueryTangent(esriSegmentExtension.esriNoExtension, 1, true, 10, line); } double angle = line.Angle; if (reverseOrientation) { angle = angle >= Math.PI ? angle - Math.PI : angle + Math.PI; } return(angle); }
private static CutSubcurve CreateCutSubcurve( [NotNull] IPath path, [CanBeNull] IPointCollection intersectionPoints, [NotNull] IDictionary <SubcurveNode, SubcurveNode> allNodes, bool?touchingDifferentParts, IPolyline targetPolyline, double stitchPointSearchTol) { var touchAtFromPoint = false; var touchAtToPoint = false; if (intersectionPoints != null) { touchAtFromPoint = GeometryUtils.Intersects( path.FromPoint, (IGeometry)intersectionPoints); touchAtToPoint = GeometryUtils.Intersects( path.ToPoint, (IGeometry)intersectionPoints); } var fromNode = new SubcurveNode(path.FromPoint.X, path.FromPoint.Y); if (allNodes.ContainsKey(fromNode)) { fromNode = allNodes[fromNode]; } else { allNodes.Add(fromNode, fromNode); } var toNode = new SubcurveNode(path.ToPoint.X, path.ToPoint.Y); if (allNodes.ContainsKey(toNode)) { toNode = allNodes[toNode]; } else { allNodes.Add(toNode, toNode); } var cutSubcurve = new CutSubcurve(path, touchAtFromPoint, touchAtToPoint, fromNode, toNode, touchingDifferentParts); // Identify stitch points, i.e. points that do not exist in the target and should not end up in the // reshaped geometry if several adjacent cutsubcurves are applied together. if (touchAtFromPoint) { IPoint point = cutSubcurve.Path.FromPoint; ISegment targetSegment; cutSubcurve.FromPointIsStitchPoint = IsNoTargetVertex( point, targetPolyline, stitchPointSearchTol, out targetSegment); cutSubcurve.TargetSegmentAtFromPoint = targetSegment; } if (touchAtToPoint) { IPoint point = cutSubcurve.Path.ToPoint; ISegment targetSegment; cutSubcurve.ToPointIsStitchPoint = IsNoTargetVertex( point, targetPolyline, stitchPointSearchTol, out targetSegment); cutSubcurve.TargetSegmentAtToPoint = targetSegment; } fromNode.ConnectedSubcurves.Add(cutSubcurve); toNode.ConnectedSubcurves.Add(cutSubcurve); return(cutSubcurve); }
private static CutSubcurve Replace(CutSubcurve cutSubcurve1, CutSubcurve cutSubcurve2, SubcurveNode mergeNode) { IGeometryCollection mergedCollection = ReshapeUtils.GetSimplifiedReshapeCurves( new List <CutSubcurve> { cutSubcurve1, cutSubcurve2 }); Assert.AreEqual(1, mergedCollection.GeometryCount, "Unexpected number of geometries after merging adjacent subcurves"); var newPath = (IPath)mergedCollection.get_Geometry(0); bool touchAtFrom; SubcurveNode oldNodeAtFrom = GetNodeAt(newPath.FromPoint, cutSubcurve1, cutSubcurve2, out touchAtFrom); bool touchAtTo; SubcurveNode oldNodeAtTo = GetNodeAt(newPath.ToPoint, cutSubcurve1, cutSubcurve2, out touchAtTo); if (oldNodeAtFrom.ConnectedSubcurves.Contains(cutSubcurve1)) { oldNodeAtFrom.ConnectedSubcurves.Remove(cutSubcurve1); } if (oldNodeAtFrom.ConnectedSubcurves.Contains(cutSubcurve2)) { oldNodeAtFrom.ConnectedSubcurves.Remove(cutSubcurve2); } if (oldNodeAtTo.ConnectedSubcurves.Contains(cutSubcurve1)) { oldNodeAtTo.ConnectedSubcurves.Remove(cutSubcurve1); } if (oldNodeAtTo.ConnectedSubcurves.Contains(cutSubcurve2)) { oldNodeAtTo.ConnectedSubcurves.Remove(cutSubcurve2); } var result = new CutSubcurve(newPath, touchAtFrom, touchAtTo, oldNodeAtFrom, oldNodeAtTo); result.Source = cutSubcurve1.Source; oldNodeAtFrom.ConnectedSubcurves.Add(result); oldNodeAtTo.ConnectedSubcurves.Add(result); // Old target intersection points: Add them if they were not stitch points removed after simplify: IPoint connectPoint = GeometryFactory.CreatePoint(mergeNode.X, mergeNode.Y, newPath.SpatialReference); int partIdx; int?connectIndex = GeometryUtils.FindHitVertexIndex( newPath, connectPoint, GeometryUtils.GetXyTolerance(newPath), out partIdx); if (connectIndex != null) { result.AddExtraPotentialTargetInsertPoint( ((IPointCollection)newPath).get_Point((int)connectIndex)); } return(result); }