public bool Equals(SourceSegment sourceSegment) { return(Line == sourceSegment.StartLine && Line == sourceSegment.EndLine && StartColumn == sourceSegment.StartColumn && EndColumn == sourceSegment.EndColumn); }
public IReadOnlyList <string> GetAlignedSourceSegment(int prefixCount) { int sourceLength = 0; foreach (Phrase phrase in Phrases) { if (phrase.TargetSegmentCut > prefixCount) { break; } if (phrase.SourceSegmentRange.End > sourceLength) { sourceLength = phrase.SourceSegmentRange.End; } } return(sourceLength == SourceSegment.Count ? SourceSegment : SourceSegment.Take(sourceLength).ToArray()); }
private void normalizeSourceSegment(SourceSegment s) { if (s.Segment.V1.X > s.Segment.V2.X) { double f = s.Segment.V1.X; s.Segment.V1.X = s.Segment.V2.X; s.Segment.V2.X = f; f = s.Segment.V1.Y; s.Segment.V1.Y = s.Segment.V2.Y; s.Segment.V2.Y = f; } }
private void splitSegmentsByCrossPoints(List<SplittedSegment> segmentsToSplit, List<ICoordinate> segmentsCrossPoints, SourceSegment currentSegment) { // Removes a previously processed the broken pieces and add the pieces to the list of unprocessed segments int i = 0; foreach (SplittedSegment ss in segmentsToSplit) { removeSplittedSegment(ss); if (ss.UsedByObject1) { SourceSegment s = new SourceSegment(); s.Segment = new Segment(ss.Segment.V1, segmentsCrossPoints[i]); if (!s.Segment.V1.ExactEquals(s.Segment.V2)) { s.ObjectNumber = 1; _sourceSegments.Add(s); } s = new SourceSegment(); s.Segment = new Segment(segmentsCrossPoints[i], ss.Segment.V2); if (!s.Segment.V1.ExactEquals(s.Segment.V2)) { s.ObjectNumber = 1; _sourceSegments.Add(s); } } if (ss.UsedByObject2) { SourceSegment s = new SourceSegment(); s.Segment = new Segment(ss.Segment.V1, segmentsCrossPoints[i]); if (!s.Segment.V1.ExactEquals(s.Segment.V2)) { s.ObjectNumber = 2; _sourceSegments.Add(s); } s = new SourceSegment(); s.Segment = new Segment(segmentsCrossPoints[i], ss.Segment.V2); if (!s.Segment.V1.ExactEquals(s.Segment.V2)) { s.ObjectNumber = 2; _sourceSegments.Add(s); } } i++; } // add to the list of points of intersection zlov i = 0; foreach (ICoordinate point in segmentsCrossPoints) { // unit used "owners" segments which crossed the current if (segmentsToSplit[i].UsedByObject1) addOrMergeNode(point, _sourceGeometry1); if (segmentsToSplit[i].UsedByObject2) addOrMergeNode(point, _sourceGeometry2); //as well as the "owner" of the current segment if (currentSegment.ObjectNumber == 1) addOrMergeNode(point, _sourceGeometry1); if (currentSegment.ObjectNumber == 2) addOrMergeNode(point, _sourceGeometry2); i++; } // split the initial segment PlanimetryAlgorithms.OrderPointsOverSegment(segmentsCrossPoints, currentSegment.Segment); segmentsCrossPoints.Insert(0, currentSegment.Segment.V1); segmentsCrossPoints.Add(currentSegment.Segment.V2); for (i = 0; i < segmentsCrossPoints.Count - 1; i++) { SourceSegment s = new SourceSegment(); s.Segment = new Segment(segmentsCrossPoints[i], segmentsCrossPoints[i + 1]); if (!s.Segment.V1.ExactEquals(s.Segment.V2)) { s.ObjectNumber = currentSegment.ObjectNumber; _sourceSegments.Add(s); } } }
private bool splitSegmentBySegments(List<SplittedSegment> relatedSegments, SourceSegment currentSegment) { // look for the intersection List<ICoordinate> segmentsCrossPoints = null; List<SplittedSegment> segmentsToSplit = null; foreach (SplittedSegment ss in relatedSegments) { Dimension crossKind = PlanimetryAlgorithms.RobustSegmentsIntersection(ss.Segment, currentSegment.Segment, out _pointStub, out _segmentStub); if (crossKind == Dimension.One) { if (_performSnapping) { PlanimetryAlgorithms.SnapToGrid(ref _segmentStub.V1, _gridOrigin, PlanimetryAlgorithms.Tolerance); PlanimetryAlgorithms.SnapToGrid(ref _segmentStub.V2, _gridOrigin, PlanimetryAlgorithms.Tolerance); if (_segmentStub.Length() / PlanimetryAlgorithms.Tolerance > 1.42) throw new InvalidOperationException(); else { crossKind = Dimension.Zero; _pointStub = _segmentStub.V1; } } else throw new InvalidOperationException(); } if (crossKind == Dimension.Zero) if (PerformSnapping) { PlanimetryAlgorithms.SnapToGrid(ref _pointStub, _gridOrigin, PlanimetryAlgorithms.Tolerance); if (!_pointStub.ExactEquals(currentSegment.Segment.V1) && !_pointStub.ExactEquals(currentSegment.Segment.V2)) { if (segmentsCrossPoints == null) { segmentsCrossPoints = new List<ICoordinate>(); segmentsToSplit = new List<SplittedSegment>(); } segmentsCrossPoints.Add(_pointStub); segmentsToSplit.Add(ss); } } else { if (!_pointStub.Equals(currentSegment.Segment.V1) && !_pointStub.Equals(currentSegment.Segment.V2)) { if (segmentsCrossPoints == null) { segmentsCrossPoints = new List<ICoordinate>(); segmentsToSplit = new List<SplittedSegment>(); } segmentsCrossPoints.Add(_pointStub); segmentsToSplit.Add(ss); } } } if (segmentsCrossPoints != null) splitSegmentsByCrossPoints(segmentsToSplit, segmentsCrossPoints, currentSegment); return segmentsCrossPoints != null; }
private bool splitSegmentByNodes(SourceSegment segment) { double tolerance = PlanimetryAlgorithms.Tolerance; List<ICoordinate> nodesCrossPoints = null; double x1 = segment.Segment.V1.X; double x2 = segment.Segment.V2.X; double minX = Math.Min(x1, x2); double maxX = Math.Max(x1, x2); int startNodesIndex = 0, endNodesIndex = _nodes.Count - 1; while (endNodesIndex - startNodesIndex > 1) { int index = startNodesIndex + (endNodesIndex - startNodesIndex) / 2; if (_nodes[index].Point.X < minX) startNodesIndex = index; else endNodesIndex = index; } while (startNodesIndex > 0 && _nodes[startNodesIndex].Point.X >= minX) startNodesIndex--; while (endNodesIndex < _nodes.Count - 1 && _nodes[endNodesIndex].Point.X <= maxX) endNodesIndex++; for (int i = startNodesIndex; i <= endNodesIndex; i++) { PlanarGraphNode node = _nodes[i]; // exclude the end-points bool isNotCurrentSegmentVertex = (!_performSnapping && (PlanimetryAlgorithms.Distance(node.Point, segment.Segment.V1) > tolerance && PlanimetryAlgorithms.Distance(node.Point, segment.Segment.V2) > tolerance)) || (_performSnapping && (!node.Point.ExactEquals(segment.Segment.V1) && !node.Point.ExactEquals(segment.Segment.V2))); if (isNotCurrentSegmentVertex) { if (PlanimetryAlgorithms.DistanceToSegment(node.Point, segment.Segment) < tolerance / 1.45) { if (nodesCrossPoints == null) nodesCrossPoints = new List<ICoordinate>(); nodesCrossPoints.Add(node.Point); } } } if (nodesCrossPoints != null) { for (int i = 0; i < nodesCrossPoints.Count; i++) { IGeometry obj = segment.ObjectNumber == 1 ? _sourceGeometry1 : _sourceGeometry2; addOrMergeNode(nodesCrossPoints[i], obj); } PlanimetryAlgorithms.OrderPointsOverSegment(nodesCrossPoints, segment.Segment); nodesCrossPoints.Insert(0, segment.Segment.V1); nodesCrossPoints.Add(segment.Segment.V2); for (int i = 0; i < nodesCrossPoints.Count - 1; i++) { SourceSegment ss = new SourceSegment(); ss.Segment = new Segment(nodesCrossPoints[i], nodesCrossPoints[i + 1]); if (!ss.Segment.V1.ExactEquals(ss.Segment.V2)) { ss.ObjectNumber = segment.ObjectNumber; _sourceSegments.Add(ss); } } } return nodesCrossPoints != null; }
private bool updateSplittedSegment(List<SplittedSegment> relatedSegments, SourceSegment segment) { foreach (SplittedSegment ss in relatedSegments) if ((_performSnapping && ss.Segment.ExactEquals(segment.Segment)) || (!_performSnapping && ss.Segment == segment.Segment)) { // current segment coincided with the previously calculated if (_sourceGeometry1 is Polygon) // For polygons segment - the border. "Use" is defined by the parity of entry. ss.UsedByObject1 = ss.UsedByObject1 ^ segment.ObjectNumber == 1; else { // For polyline segment - interior. "Use" is defined by the fact of the entry. ss.UsedByObject1 = ss.UsedByObject1 || segment.ObjectNumber == 1; } if (_sourceGeometry2 is Polygon) ss.UsedByObject2 = ss.UsedByObject2 ^ segment.ObjectNumber == 2; else ss.UsedByObject2 = ss.UsedByObject2 || segment.ObjectNumber == 2; if (segment.ObjectNumber == 1) ss.Object1OccurrencesCount++; else ss.Object2OccurrencesCount++; return true; } return false; }
private void addSourceSegments(IGeometry g, int objectNumber) { SourceSegment ss; if (g is Polygon) { foreach (Contour c in ((Polygon)g).Contours) { if (c.Vertices.Count > 1) { int i; Segment s; ICoordinate initialPoint = c.Vertices[0]; for (i = 0; i < c.Vertices.Count - 1; i++) { s = new Segment(initialPoint.X, initialPoint.Y, c.Vertices[i + 1].X, c.Vertices[i + 1].Y); ss = new SourceSegment(); ss.Segment = s; if (!ss.Segment.V1.ExactEquals(ss.Segment.V2)) { ss.ObjectNumber = objectNumber; _sourceSegments.Add(ss); } initialPoint = c.Vertices[i + 1]; } s = new Segment(initialPoint.X, initialPoint.Y, c.Vertices[0].X, c.Vertices[0].Y); ss = new SourceSegment(); ss.Segment = s; if (!ss.Segment.V1.ExactEquals(ss.Segment.V2)) { ss.ObjectNumber = objectNumber; _sourceSegments.Add(ss); } } } return; } if (g is Polyline) { foreach (LinePath path in ((Polyline)g).Paths) { if (path.Vertices.Count > 1) { int i; Segment s; ICoordinate initialPoint = path.Vertices[0]; for (i = 0; i < path.Vertices.Count - 1; i++) { s = new Segment(initialPoint.X, initialPoint.Y, path.Vertices[i + 1].X, path.Vertices[i + 1].Y); ss = new SourceSegment(); ss.Segment = s; ss.ObjectNumber = objectNumber; _sourceSegments.Add(ss); initialPoint = path.Vertices[i + 1]; } } } return; } if (g is PointD || g is MultiPoint) return; throw new NotSupportedException(string.Format("Planar graph building for \"{0}\" is not supported.", g.GetType().FullName)); }