Exemplo n.º 1
0
        internal Intersection[] ComputeIntersections()
        {
            List <Intersection> intersections = new List <Intersection>();

            foreach (ScanLine l in _horizontalScan.ToArray())
            {
                double scanPos = l.ScanPos;
                // all horizontal lines if it's a starting point
                foreach (LineSegmentDecorator ls in l.HorizontalLines.Where((x) => (x.Start.X == scanPos)))
                {
                    _verticalScan.Add(new ScanLine(ls, ls.Start.Y));
                }

                // check for interesections
                foreach (LineSegmentDecorator ls in l.VertiacalLines)
                {
                    LinkedAvlTreeNode <ScanLine> verticalScan = _verticalScan.LowerBound(new ScanLine(ls.MinY));
                    while (verticalScan != null)
                    {
                        double y = verticalScan.Data.ScanPos;
                        if (y > ls.MinY && y < ls.MaxY)
                        {
                            var intersection = new Intersection(this)
                            {
                                IntersectionPoint = new Point(scanPos, y),
                                Intersecting1     = ls.Connector,
                                Intersecting2     = verticalScan.Data.Connector,
                            };

                            intersections.Add(intersection);
                        }

                        else if (y > ls.MaxY)
                        {
                            break;
                        }
                        verticalScan = verticalScan.Next;
                    }
                }

                // remove all finished lines from the vertical scan line collection
                foreach (LineSegmentDecorator ls in l.HorizontalLines.Where((x) => (x.End.X == scanPos)))
                {
                    LinkedAvlTreeNode <ScanLine> vs = _verticalScan.LowerBound(new ScanLine(ls.Start.Y));
                    if (vs == null || vs.Data.ScanPos != ls.Start.Y)
                    {
                        continue;
                    }


                    System.Diagnostics.Debug.Assert(vs.Data.ScanPos == ls.Start.Y);
                    vs.Data.Remove(ls);
                    if (vs.Data.Count == 0)
                    {
                        _verticalScan.Delete(vs.Data);
                    }
                }
            }
            return(intersections.ToArray());
        }
Exemplo n.º 2
0
 void AddLineSegments(ConnectorUI ui)
 {
     foreach (LineSegmentDecorator l in LineSegmentDecorator.DecorateLineSegments(ui, lineSegments++))
     {
         if (l.IsHorizontal && l.IsVertical) // this is just a point!
         {
             continue;
         }
         _horizontalScan.Add(new ScanLine(l, l.Start.X));
         if (l.IsHorizontal)
         {
             System.Diagnostics.Debug.Assert(l.Start.X < l.End.X);
             _horizontalScan.Add(new ScanLine(l, l.End.X));
         }
     }
 }
Exemplo n.º 3
0
        public void InitalizeBoundSearchStructures(IList <Rect> bounds)
        {
            _horizontallySortedBounds = new LinkedAvlTree <BoundsComparer>();
            _verticallySortedBounds   = new LinkedAvlTree <BoundsComparer>();
            foreach (var r in bounds)
            {
                _horizontallySortedBounds.Add(new BoundsComparer(new RectangleWrapper(r),
                                                                 BoundsComparer.CompareType.CompareX));

                _verticallySortedBounds.Add(new BoundsComparer(new RectangleWrapper(r),
                                                               BoundsComparer.CompareType.CompareY));
            }
        }
Exemplo n.º 4
0
        public void InitalizeBoundSearchStructures(IEnumerable <IBoundsProvider> bounds)
        {
            _horizontallySortedBounds = new LinkedAvlTree <BoundsComparer>();
            _verticallySortedBounds   = new LinkedAvlTree <BoundsComparer>();
            if (bounds != null)
            {
                foreach (var b in bounds)
                {
                    _horizontallySortedBounds.Add(new BoundsComparer(b,
                                                                     BoundsComparer.CompareType.CompareX));

                    _verticallySortedBounds.Add(new BoundsComparer(b,
                                                                   BoundsComparer.CompareType.CompareY));
                }
            }
        }
Exemplo n.º 5
0
        void CreateRectangles(int count, LinkedAvlTree <BoundsComparer> tree,
                              List <Rect> rectangles)
        {
            var rand = new Random(-127);

            for (int i = 0; i < count; i++)
            {
                var x = rand.NextDouble() * 2048;
                var y = rand.NextDouble() * 1600;
                var w = 150;
                var h = 50;
                var p = new Point(x, y);
                var s = new Size(w, h);
                var r = new Rect(p, s);
                tree.Add(r);
                if (tree.Count == i + 1)
                {
                    rectangles.Add(r);
                }
            }
        }