コード例 #1
0
        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();
                }
            }
        }