private static void CalculateIntersections(SegmentBase segment1, SegmentBase segment2, bool skipInner, bool skipOuter) { if (!segment1.PolylineApproximation.BoundingBox.IntersectsWith(segment2.PolylineApproximation.BoundingBox)) { return; } ConvertTimer.ThrowIfOvertime(); var iterator1 = new LineIterator(segment1.PolylineApproximation); while (iterator1.MoveNextLine()) { var iterator2 = new LineIterator(segment2.PolylineApproximation); var skipCurrentPart1 = true; while (iterator2.MoveNextLine()) { if (!iterator1.CurrentPart.BoundingBox.IntersectsWith(iterator2.CurrentPart.BoundingBox)) { iterator2.SkipCurrentPart(); continue; } skipCurrentPart1 = false; if ((skipInner && iterator1.IsLastLine && iterator2.IsFirstLine) || (skipOuter && iterator1.IsFirstLine && iterator2.IsLastLine)) { continue; } var intersection = CalculateIntersection(iterator1.CurrentStartPoint, iterator1.CurrentEndPoint, iterator2.CurrentStartPoint, iterator2.CurrentEndPoint); if (intersection.HasValue) { segment1.Intersections.Add(intersection.Value); segment2.Intersections.Add(intersection.Value); } } if (skipCurrentPart1) { iterator1.SkipCurrentPart(); } } }
private static void CalculateSelfIntersections(SegmentBase segment) { if (!(segment is CubicBezierSegment)) { // only cubic bezier segment can self-intersect return; } ConvertTimer.ThrowIfOvertime(); var iterator1 = new LineIterator(segment.PolylineApproximation); while (iterator1.MoveNextLine()) { var iterator2 = iterator1.Clone(); if (!iterator2.MoveNextLine()) { return; } var skipCurrentPart1 = true; while (iterator2.MoveNextLine()) { if (!iterator1.CurrentPart.BoundingBox.IntersectsWith(iterator2.CurrentPart.BoundingBox)) { iterator2.SkipCurrentPart(); continue; } skipCurrentPart1 = false; var intersection = CalculateIntersection(iterator1.CurrentStartPoint, iterator1.CurrentEndPoint, iterator2.CurrentStartPoint, iterator2.CurrentEndPoint); if (intersection.HasValue) { segment.Intersections.Add(intersection.Value); } } if (skipCurrentPart1) { iterator1.SkipCurrentPart(); } } }