Ejemplo n.º 1
0
        /// Insert a new value and return a handle to it
        public IIndexedSeg Insert(IHasLine val)
        {
            if (val == null || val.LineSeg == null)
            {
                throw new Exception("WTFERY,it's null!!");
            }
            LSeg r = new LSeg(this, val);

            m_allsegs[r.Keyval] = r;
            m_root.Insert(r);
            return(r);
        }
Ejemplo n.º 2
0
        /// In-place split an existing line segment into two parts.
        public Pair <IIndexedSeg, IIndexedSeg> Split(IIndexedSeg tosplit,
                                                     IHasLine a,
                                                     IHasLine b)
        {
            LSeg l = tosplit as LSeg;
            Pair <LSeg, LSeg> r = l.DoSplit(a, b);

            m_allsegs[r.First.Keyval]  = r.First;
            m_allsegs[r.Second.Keyval] = r.Second;
            m_allsegs.Remove(l.Keyval);

            return(new Pair <IIndexedSeg, IIndexedSeg>(r.First, r.Second));
        }
Ejemplo n.º 3
0
            public override Node Insert(LSeg l)
            {
                if (m_s == null)
                {
                    m_s = new LNode(m_o, l.Val.LineSeg.BBox.Square.Grown(l.Val.LineSeg.BBox.W * 0.01)); // grow 1%
                }
                else
                {
                    int dir = 0; // Sloppy: grow m_s (in rotating directions)
                                 // until it contains the segment.

                    while (!m_s.Contains(l.Val.LineSeg))
                    {
                        Aabb bigger, vll, vlr, vul, vur;
                        Aabb sbounds = m_s.Bounds;
                        int  c       = sbounds.ConstructNeighborsTowards(dir % 4,
                                                                         out vll, out vlr,
                                                                         out vul, out vur,
                                                                         out bigger);
                        Node nll = (c == 0) ? m_s : new LNode(m_o, vll);
                        Node nlr = (c == 1) ? m_s : new LNode(m_o, vlr);
                        Node nul = (c == 2) ? m_s : new LNode(m_o, vul);
                        Node nur = (c == 3) ? m_s : new LNode(m_o, vur);

                        dir++;

                        if (nll == null || nlr == null || nul == null || nur == null)
                        {
                            throw new Exception("Hmmm here 1");
                        }

                        if (dir > 100)
                        {
                            throw new Exception("Issues fitting " + l.Val.LineSeg + " inside " + m_s.Bounds);
                        }

                        m_s = new QNode(m_o, bigger, nll, nlr, nul, nur);
                    }
                }
                m_s = m_s.Insert(l);
                return(this);
            }
Ejemplo n.º 4
0
            public override Node Insert(LSeg l)
            {
                if (ll.Intersects(l.Val.LineSeg))
                {
                    ll = ll.Insert(l);
                }
                if (lr.Intersects(l.Val.LineSeg))
                {
                    lr = lr.Insert(l);
                }
                if (ul.Intersects(l.Val.LineSeg))
                {
                    ul = ul.Insert(l);
                }
                if (ur.Intersects(l.Val.LineSeg))
                {
                    ur = ur.Insert(l);
                }

                return(this);
            }
Ejemplo n.º 5
0
            public Pair <LSeg, LSeg> DoSplit(IHasLine a, IHasLine b)
            {
                LSeg         ar       = new LSeg(m_o, a);
                LSeg         br       = new LSeg(m_o, b);
                List <LNode> thenodes = new List <LNode>(m_nodes);

                foreach (LNode n in thenodes)
                {
                    n.RemoveLSeg(this);
                    if (n.Intersects(a.LineSeg))
                    {
                        n.AddSeg(ar);
                    }
                    if (n.Intersects(b.LineSeg))
                    {
                        n.AddSeg(br);
                    }
                    //n.CheckSplit();
                }

                return(new Pair <LSeg, LSeg>(ar, br));
            }
Ejemplo n.º 6
0
            // Perform splits.
            public Node CheckSplit()
            {
                if (m_segs.Count > m_o.m_split_thresh)
                {
                    Aabb ll, lr, ul, ur;
                    m_bound.QuadBreak(out ll, out lr, out ul, out ur);
                    LNode nll = new LNode(m_o, ll);
                    LNode nlr = new LNode(m_o, lr);
                    LNode nul = new LNode(m_o, ul);
                    LNode nur = new LNode(m_o, ur);
                    foreach (Pair <LSeg, LinkedListNode <LNode> > segvs in m_segs.Values)
                    {
                        LSeg l = segvs.First;

                        // remove backreferences from the segment to this.
                        l.ClearNode(segvs.Second);

                        int ic = 0;
                        foreach (LNode n in new LNode[] { nll, nlr, nul, nur })
                        {
                            if (n.m_bound.Intersects(l.Val.LineSeg))
                            {
                                n.AddSeg(l);
                                ic++;
                            }
                        }
                    }
                    m_segs.Clear();
                    m_segs = null; // poison this node... exceptions on access now!

                    // Create a new 'parent' node
                    QNode qn = new QNode(m_o, m_bound, nll, nlr, nul, nur);
                    return(qn);
                }
                else
                {
                    return(this);
                }
            }
Ejemplo n.º 7
0
 public void AddSeg(LSeg l)
 {
     m_segs[l.Keyval] =
         new Pair <LSeg, LinkedListNode <LNode> >(l, l.AddLeaf(this));
 }
Ejemplo n.º 8
0
 public override Node Insert(LSeg l)
 {
     AddSeg(l);
     return(CheckSplit());
 }
Ejemplo n.º 9
0
 public void RemoveLSeg(LSeg l)
 {
     m_segs.Remove(l.Keyval);
 }
Ejemplo n.º 10
0
 public abstract Node Insert(LSeg l);