예제 #1
0
 public LineSegOverlay(ISegIdx index, double ang_tol, double dist_tol)
 {
     m_index  = index;
     m_atol   = Vector.GetParTolerance(ang_tol);
     m_dtol   = dist_tol;
     m_dtolsq = dist_tol * dist_tol;
 }
예제 #2
0
        //protected override double LineSegLength { get { return 0.002; } }

        protected override void DumpIndex(ISegIdx i)
        {
            if (i is PMQTree)
            {
                return;
            }

            PMQTree tr = i as PMQTree;

            foreach (Pair <int, Aabb> p in tr.Dump())
            {
                Console.Error.WriteLine("DUMP: node(" + p.First + "," + p.Second + ")");
            }
            foreach (IIndexedSeg l in tr.AllSegments)
            {
                Console.Error.WriteLine("DUMP: line(" + l.Val.LineSeg.ToString() + ")");
            }
        }
예제 #3
0
        public void TestUnrelated()
        {
            // Super strict...
            double ang_tol              = System.Double.Epsilon;
            double dist_tol             = System.Double.Epsilon;
            Dictionary <int, bool> seen = new Dictionary <int, bool>();

            ISegIdx spidx = GetIndex(dist_tol, ang_tol);
            LineSegOverlay <NumLineSeg> overlay =
                new LineSegOverlay <NumLineSeg>(spidx,
                                                ang_tol, dist_tol);

            int idx = 0;

            foreach (LineSeg l in Take(TestCount, LineSegs))
            {
                overlay.Insert(new NumLineSeg(l, idx++));
            }

            foreach (Pair <LineSeg, IEnumerable <NumLineSeg> > res in overlay.Segments)
            {
                bool here = false;
                foreach (NumLineSeg r in res.Second)
                {
                    Assert.IsFalse(seen.ContainsKey(r.Idx));
                    Assert.IsFalse(here);
                    seen[r.Idx] = true;
                    here        = true;
                }
            }

            for (int i = 0; i < TestCount; i++)
            {
                Assert.IsTrue(seen[i]);
            }

            DumpIndex(spidx);
        }
예제 #4
0
 protected virtual void DumpIndex(ISegIdx i)
 {
     // do nothing
 }
예제 #5
0
        public void TestBeforeAndAfter()
        {
            int    count               = TestCount;
            double ang_tol             = 0.0001;
            double dist_tol            = 0.000001;
            Dictionary <int, int> seen = new Dictionary <int, int>();

            ISegIdx spidx = GetIndex(dist_tol, ang_tol);
            LineSegOverlay <NumLineSeg> overlay =
                new LineSegOverlay <NumLineSeg>(spidx,
                                                ang_tol, dist_tol);

            int idx = 0;

            LineSeg[] lines = new LineSeg[count];
            foreach (LineSeg ll in Take(count, LineSegs))
            {
                LineSeg l = ll;
                if (idx == 0)
                {
                    l = LineSeg.FromEndpoints(new Vector(0, 0),
                                              new Vector(0, 1));
                }
                lines[idx] = l;

                idx++;
            }

            for (int i = 0; i < lines.Length; i++)
            {
                double ta = -0.75;
                double tb = 0.25;
                ta = 0.75;
                tb = 1.75;
                // The 'before' half:
                LineSeg bl = LineSeg.FromEndpoints(lines[i].Start + (ta * lines[i].Dir),
                                                   lines[i].Start + (tb * lines[i].Dir));

                // the 'after' half:
                ta = -0.75;
                tb = 0.25;
                LineSeg al = LineSeg.FromEndpoints(lines[i].Start + (ta * lines[i].Dir),
                                                   lines[i].Start + (tb * lines[i].Dir));

                NumLineSeg a = new NumLineSeg(al, count + i);
                NumLineSeg b = new NumLineSeg(bl, 2 * count + i);
                NumLineSeg c = new NumLineSeg(lines[i], i);
                switch (Int(6))
                {
                case 0:
                    overlay.Insert(a); overlay.Insert(b); overlay.Insert(c);
                    break;

                case 5:
                    overlay.Insert(a); overlay.Insert(c); overlay.Insert(b);
                    break;

                case 1:
                    overlay.Insert(b); overlay.Insert(a); overlay.Insert(c);
                    break;

                case 4:
                    overlay.Insert(b); overlay.Insert(c); overlay.Insert(a);
                    break;

                case 2:
                    overlay.Insert(c); overlay.Insert(b); overlay.Insert(a);
                    break;

                case 3:
                    overlay.Insert(c); overlay.Insert(a); overlay.Insert(b);
                    break;
                }
            }

            DumpIndex(spidx);

            int rcount = 0;

            foreach (Pair <LineSeg, IEnumerable <NumLineSeg> > res in overlay.Segments)
            {
                //	Console.Error.WriteLine("Res-----");
                foreach (NumLineSeg r in res.Second)
                {
                    // Console.Error.WriteLine("  Portion: " + r.Idx);
                    if (!seen.ContainsKey(r.Idx))
                    {
                        seen[r.Idx] = 0;
                    }
                    seen[r.Idx]++;
                }
                rcount++;
            }

            Assert.AreEqual(5 * count, rcount);

            for (int i = 0; i < 3 * count; i++)
            {
                if (i < count)
                {
                    Assert.AreEqual(3, seen[i]);
                }
                if (i > count)
                {
                    Assert.AreEqual(2, seen[i]);
                }
            }
        }