Esempio 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());
        }
Esempio n. 2
0
        public double FindVerticalRoutingSlotRight(double left, double top, double bottom)
        {
            Rect r = new Rect(new Point(left, Math.Min(top, bottom)), new Size(10, Math.Abs(bottom - top)));
            var  p = _horizontallySortedBounds.LowerBound(r);

            while (p != null && p.Data.Left < r.Right)
            {
                if (p.Data.Item.Bounds.IntersectsWith(r))
                {
                    r.X = p.Data.Right + 5;
                }
                p = p.Next;
            }

            return(r.Left);
        }
Esempio n. 3
0
        public double FindHorizontalRoutingSlotBottom(double top, double left, double right)
        {
            Rect r     = new Rect(new Point(Math.Min(left, right), top), new Size(Math.Abs(right - left), 8));
            var  lower = _verticallySortedBounds.LowerBound(r);

            var p = lower;

            while (p != null && p.Data.Top < r.Bottom)
            {
                if (p.Data.Item.Bounds.IntersectsWith(r))
                {
                    r.Y = p.Data.Bottom + 20;
                }
                p = p.Next;
            }

            return(r.Top);
        }
Esempio n. 4
0
        public void TestBoundedItemOrder()
        {
            List <Rect> rectangles = new List <Rect>();
            LinkedAvlTree <BoundsComparer> tree = new LinkedAvlTree <BoundsComparer>();

            CreateRectangles(100, tree, rectangles);

            var left       = -1.0;
            var lowerBound = tree.LowerBound(rectangles.First());
            var previous   = lowerBound;

            while (lowerBound != null)
            {
                if (left > lowerBound.Data.Left)
                {
                    Assert.True(left <= lowerBound.Data.Left);
                }

                left       = lowerBound.Data.Left;
                previous   = lowerBound;
                lowerBound = lowerBound.Next;
            }
        }