Esempio n. 1
0
        public void RemoveAnchor(int index)
        {
            PSplineAnchor a = Anchors[index];
            List <int>    segmentIndices = FindSegments(index);

            for (int i = 0; i < segmentIndices.Count; ++i)
            {
                int sIndex = segmentIndices[i];
                Segments[sIndex].Dispose();
            }

            Segments.RemoveAll(s => s.StartIndex == index || s.EndIndex == index);
            Segments.ForEach(s =>
            {
                if (s.StartIndex > index)
                {
                    s.StartIndex -= 1;
                }
                if (s.EndIndex > index)
                {
                    s.EndIndex -= 1;
                }
            });
            Anchors.RemoveAt(index);
        }
Esempio n. 2
0
 public void PrepareSegments()
 {
     Segments.ForEach(s => s.IsClipped = s.GetIsClipped(TopLeft, BottomRight) && !s.IsOutline);
     if (_clipping)
     {
         Segments.RemoveAll(s => s.IsClipped);
     }
     DoMergeCollinearSegments();
     SplitSegmentsThatOverlap();
     EndPoints.AddRange(Segments.Select(vs => vs.Start));
     EndPoints.AddRange(Segments.Select(vs => vs.End));
     DebugDrawSegments();
 }
Esempio n. 3
0
        public void RemoveAnchor(int index)
        {
            GSplineAnchor a = Anchors[index];

            Segments.RemoveAll(s => s.StartIndex == index || s.EndIndex == index);
            Segments.ForEach(s =>
            {
                if (s.StartIndex > index)
                {
                    s.StartIndex -= 1;
                }
                if (s.EndIndex > index)
                {
                    s.EndIndex -= 1;
                }
            });
            Anchors.RemoveAt(index);
        }
Esempio n. 4
0
        private void DoMergeCollinearSegments()
        {
            if (!MergeCollinearSegments)
            {
                return;
            }
            //int merges = 0;
            //int compares = 0;
            //int before = Segments.Count;

            //Stopwatch stopwatch = Stopwatch.StartNew();

            // Log of performance optimization of this very rouine.
            // Merged 287 to 149 segments (138 merges, 1710596 compares). 322 ms.
            // Merged 287 to 149 segments (138 merges, 105329 compares). 14 ms.
            // Merged 287 to 149 segments (138 merges, 84767 compares, 2 tries). 14 ms.
            // Merged 287 to 149 segments (138 merges, 84767 compares, 2 tries). 13 ms.
            // Merged 287 to 149 segments (138 merges, 1968 compares, 6 tries). 5 ms.
            // Merged 287 to 149 segments (138 merges, 1968 compares, 6 tries). 4 ms.

            int tries = 0;
            ILookup <Vector2, Segment> startpointLookup =
                Segments
                .ToLookup(s => s.Start.Point, s => s);

            while (tries++ < 4)
            {
                bool merged = false;
                for (int index = 0; index < Segments.Count; index++)
                {
                    Segment segment = Segments[index];
                    if (segment.Merged)
                    {
                        continue;
                    }

                    IEnumerable <Segment> startpoints = startpointLookup[segment.End.Point];

                    foreach (Segment other in startpoints)
                    {
                        //compares++;
                        if (other.Merged)
                        {
                            continue;
                        }

                        if (ShadowMathUtils.Approximately(segment.Slope, other.Slope))
                        {
                            other.Merged      = true;
                            segment.End.Point = other.End.Point;
                            //merges++;
                            merged = true;
                        }
                    }
                }

                Segments.RemoveAll(s => s.Merged);
                if (!merged)
                {
                    break;
                }
            }

            //Debug.LogFormat("Merged {0} to {1} segments ({2} merges, {3} compares, {5} tries). {4} ms.", before, Segments.Count, merges, compares, stopwatch.ElapsedMilliseconds, tries);
        }