Example #1
0
        public void TestRemoveLeaf()
        {
            var beachLine = new BeachLine(0);
            var site1     = new Point {
                X = 40, Y = 60
            };
            var site2 = new Point {
                X = 20, Y = 40
            };
            var site3 = new Point {
                X = 60, Y = 40
            };

            beachLine.InsertSite(site1);
            beachLine.InsertSite(site2);
            var insert = beachLine.InsertSite(site3);

            var circleEvents = beachLine.GenerateCircleEvent(insert.Leaves, site3.Y);
            var circleEvent  = circleEvents.Single();

            beachLine.RemoveLeaf(circleEvent.Arc);

            var rightSubtree = ((Node)beachLine.Root).Right as Node;
            var leafLeft     = rightSubtree.Left as Leaf;
            var leafRight    = rightSubtree.Right as Leaf;

            Assert.IsNotNull(leafLeft);
            Assert.IsNotNull(leafRight);

            Assert.AreEqual(rightSubtree.Breakpoint.Left, site3);
            Assert.AreEqual(rightSubtree.Breakpoint.Right, site1);
            Assert.AreEqual(leafLeft.Site, site3);
            Assert.AreEqual(leafRight.Site, site1);
        }
Example #2
0
        public void TestFindCircleEventAbove()
        {
            var beachLine = new BeachLine(0);
            var site1     = new Point {
                X = 130, Y = 160
            };
            var site2 = new Point {
                X = 110, Y = 150
            };
            var site3 = new Point {
                X = 170, Y = 140
            };
            var site4 = new Point {
                X = 140, Y = 120
            };


            beachLine.InsertSite(site1);
            //beachLine.GenerateCircleEvent(site1);
            beachLine.InsertSite(site2);
            //beachLine.GenerateCircleEvent(site2);
            var insert = beachLine.InsertSite(site3);

            var circleEvents = beachLine.GenerateCircleEvent(insert.Leaves, site3.Y);
            var result       = beachLine.FindCircleEventAbove(site4);

            Assert.IsNotNull(result);
            Assert.AreEqual(circleEvents.Single().Point, result.Point);
        }
Example #3
0
        public void TestGenerateCircleEvent()
        {
            var beachLine = new BeachLine(0);
            var site1     = new Point {
                X = 130, Y = 160
            };
            var site2 = new Point {
                X = 110, Y = 150
            };
            var site3 = new Point {
                X = 170, Y = 140
            };

            beachLine.InsertSite(site1);
            beachLine.InsertSite(site2);
            var insert = beachLine.InsertSite(site3);

            var expectedCricleEvent = new Point {
                X = 136, Y = 84
            };

            var result = beachLine.GenerateCircleEvent(insert.Leaves, site3.Y);

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(expectedCricleEvent.XInt, result.Single().Point.XInt);
            Assert.AreEqual(expectedCricleEvent.YInt, result.Single().Point.YInt);
            //Assert.AreEqual(site2, result.Single().LeftArc.Site);
            Assert.AreEqual(site1, result.Single().Arc.Site);
            //Assert.AreEqual(site3, result.Single().RightArc.Site);
        }
Example #4
0
        public void TestGenerateCircleEventZeroLengthArc()
        {
            var beachLine = new BeachLine(2000);
            var site1     = new Point {
                X = 40, Y = 60
            };
            var site2 = new Point {
                X = 20, Y = 40
            };
            var site3 = new Point {
                X = 60, Y = 40
            };

            beachLine.InsertSite(site1);
            beachLine.InsertSite(site2);
            var insert = beachLine.InsertSite(site3);

            var expectedCricleEvent = new Point {
                X = 40, Y = 20
            };

            var result = beachLine.GenerateCircleEvent(insert.Leaves, site3.Y);

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(expectedCricleEvent, result.Single().Point);
            //Assert.AreEqual(site2, result.Single().LeftArc.Site);
            Assert.AreEqual(site1, result.Single().Arc.Site);
            //Assert.AreEqual(site3, result.Single().RightArc.Site);
        }
        public ICollection <IGeometry> HandleEvent(SiteEvent sweepEvent, EventQueue eventQueue, BeachLine beachLine)
        {
            var circleEvent = beachLine.FindCircleEventAbove(sweepEvent.Point);

            if (circleEvent != null)
            {
                Logger.Instance.Log($"SiteEvent: {sweepEvent.Point.ToString()}: Remove CircleEvent {circleEvent.Point} from queue.");
                eventQueue.Remove(circleEvent);
            }

            Logger.Instance.Log($"SiteEvent: {sweepEvent.Point.ToString()}: Insert site into beach line");
            var result = beachLine.InsertSite(sweepEvent.Point);

            var circleEvents = beachLine.GenerateCircleEvent(result?.Leaves, sweepEvent.Point.Y);

            eventQueue.Insert(circleEvents);

            if (result != null)
            {
                return new List <IGeometry> {
                           result.HalfEdge
                }
            }
            ;
            return(new List <IGeometry>());
        }
    }
Example #6
0
        public void TestAddThreeLeaves()
        {
            var beachLine = new BeachLine(2000);
            var site1     = new Point {
                X = 20, Y = 1000
            };
            var site2 = new Point {
                X = 4000, Y = 500
            };
            var site3 = new Point {
                X = 464, Y = 64
            };

            beachLine.InsertSite(site1);
            beachLine.InsertSite(site2);
            beachLine.InsertSite(site3);

            var root = beachLine.Root as Node;

            Assert.IsNotNull(root);

            var nodeLeft         = root.Left as Node;
            var nodeLeftLeft     = nodeLeft.Left as Node;
            var nodeLeftLeftLeft = nodeLeftLeft.Left as Node;

            Assert.IsNotNull(nodeLeft);
            Assert.IsNotNull(nodeLeftLeft);
            Assert.IsNotNull(nodeLeftLeftLeft);

            var leafRight             = root.Right as Leaf;
            var leafLeftRight         = nodeLeft.Right as Leaf;
            var leafLeftLeftRight     = nodeLeftLeft.Right as Leaf;
            var leafLeftLeftLeftLeft  = nodeLeftLeftLeft.Left as Leaf;
            var leafLeftLeftLeftRight = nodeLeftLeftLeft.Right as Leaf;

            Assert.IsNotNull(leafRight);
            Assert.IsNotNull(leafLeftRight);
            Assert.IsNotNull(leafLeftLeftRight);
            Assert.IsNotNull(leafLeftLeftLeftLeft);
            Assert.IsNotNull(leafLeftLeftLeftRight);

            Assert.AreEqual(site1, leafRight.Site);
            Assert.AreEqual(site2, leafLeftRight.Site);
            Assert.AreEqual(site1, leafLeftLeftRight.Site);
            Assert.AreEqual(site1, leafLeftLeftLeftLeft.Site);
            Assert.AreEqual(site3, leafLeftLeftLeftRight.Site);
        }
Example #7
0
        public void TestAddTwoLeaves()
        {
            var beachLine = new BeachLine(2000);
            var site1     = new Point {
                X = 20, Y = 1000
            };
            var site2 = new Point {
                X = 464, Y = 500
            };

            beachLine.InsertSite(site1);
            beachLine.InsertSite(site2);

            var root = beachLine.Root as Node;

            Assert.IsNotNull(root);
            Assert.IsNotNull(root.HalfEdge);
            Assert.AreEqual(site1, root.HalfEdge.Right);
            Assert.AreEqual(site2, root.HalfEdge.Left);

            var nodeLeft = root.Left as Node;

            Assert.IsNotNull(nodeLeft);
            Assert.IsNotNull(nodeLeft.HalfEdge);
            Assert.AreEqual(site1, nodeLeft.HalfEdge.Left);
            Assert.AreEqual(site2, nodeLeft.HalfEdge.Right);

            var leafRight     = root.Right as Leaf;
            var leafLeftLeft  = nodeLeft.Left as Leaf;
            var leafLeftRight = nodeLeft.Right as Leaf;

            Assert.IsNotNull(leafRight);
            Assert.IsNotNull(leafLeftLeft);
            Assert.IsNotNull(leafLeftRight);

            Assert.AreEqual(site2, leafLeftRight.Site);
            Assert.AreEqual(site1, leafLeftLeft.Site);
            Assert.AreEqual(site1, leafRight.Site);

            Assert.AreEqual(root.Breakpoint.Left, site2);
            Assert.AreEqual(root.Breakpoint.Right, site1);
            Assert.AreEqual(nodeLeft.Breakpoint.Left, site1);
            Assert.AreEqual(nodeLeft.Breakpoint.Right, site2);
        }
        public void TestHandleEvent()
        {
            var beachLine = new BeachLine(10);
            var center    = beachLine.InsertSite(new Point(4, 6));
            var right     = beachLine.InsertSite(new Point(6, 4));
            var left      = beachLine.InsertSite(new Point(2, 3));

            //var centerLeaf = ((Node)((Node)((Node)beachLine.Root).Left).Left).Right;

            //var sweepEvent = new CircleEvent
            //{
            //    LeftArc = new Leaf(new Point(2, 3)),
            //    CenterArc = left.Leaves[0],
            //    RightArc = new Leaf(new Point(6, 4)),
            //    Edges = new List<HalfEdge> {
            //        halfEdgesLeft[1],
            //        halfEdgesRight[1]
            //    },
            //    Point = new Point(4, 2),
            //    Vertex = new Point(4, 4)
            //};
            //var eventQueue = new EventQueue();

            //var strategy = new CircleEventHandlerStrategy();
            //var result = strategy.HandleEvent(sweepEvent, eventQueue, beachLine).ToList();

            //Assert.IsNotNull(result);
            //var vertex = ((Vertex)result.Single(g => g is Vertex));
            //Assert.AreEqual(sweepEvent.Vertex, vertex.Point);
            //Assert.AreEqual(3, vertex.HalfEdges.Count);

            //var start = vertex.HalfEdges.Single(h => h.Start != null);
            //Assert.IsNull(start.End);
            //Assert.AreEqual(new Point(2, 3), start.Left);
            //Assert.AreEqual(new Point(6, 4), start.Right);

            //var ends = vertex.HalfEdges.Where(h => h.End != null);
            //Assert.AreEqual(2, ends.Count());
            //Assert.IsTrue(!ends.Contains(start));
            //Assert.IsTrue(ends.All(h => h.Start == null));
        }
Example #9
0
        public void TestAddSingleLeaf()
        {
            var beachLine = new BeachLine(2000);
            var site      = new Point {
                X = 464, Y = 500
            };

            beachLine.InsertSite(site);

            var leaf = beachLine.Root as Leaf;

            Assert.IsNotNull(leaf);
            Assert.AreEqual(site, leaf.Site);
        }