Example #1
0
        public void Build()
        {
            //htree.Clear();
            htree = new TreeDictionary <double, ISorted <Edge <T> > >(dc);

            TreeSet <Edge <T> > vtree = new TreeSet <Edge <T> >(lc);
            double lastx = Double.NegativeInfinity;

            foreach (KeyValuePair <EndPoint, Edge <T> > p in endpoints)
            {
                if (dc.Compare(p.Key.x, lastx) > 0)
                {
                    //Put an empty snapshot at -infinity!
                    htree[lastx]      = (ISorted <Edge <T> >)(vtree.Snapshot());
                    lc.X              = lastx = p.Key.x;
                    lc.compareToRight = false;
                }

                if (p.Key.start)
                {
                    if (!lc.compareToRight)
                    {
                        lc.compareToRight = true;
                    }
                    Debug.Assert(vtree.Check());
                    bool chk = vtree.Add(p.Value);
                    Debug.Assert(vtree.Check());

                    Debug.Assert(chk, "edge was not added!", "" + p.Value);
                }
                else
                {
                    Debug.Assert(!lc.compareToRight);

                    Debug.Assert(vtree.Check("C"));

                    bool chk = vtree.Remove(p.Value);
                    Debug.Assert(vtree.Check("D"));

                    Debug.Assert(chk, "edge was not removed!", "" + p.Value);
                }
            }
            lc.compareToRight = true;

            htree[lastx] = (TreeSet <Edge <T> >)(vtree.Snapshot());
            built        = true;
        }