public void Test_BarnesHutTree_GetQuad()
        {
            var bht = new BarnesHutTree(new ArborPoint(-1, -1), new ArborPoint(+1, +1), 0.5f);

            var node = new ArborNode("x");

            node.Pt = new ArborPoint(0.5f, 0.5f);
            int qd = BarnesHutTree.GetQuad(node, bht.Root);

            Assert.AreEqual(BarnesHutTree.QSe, qd);

            node.Pt = new ArborPoint(-0.5f, 0.5f);
            qd      = BarnesHutTree.GetQuad(node, bht.Root);
            Assert.AreEqual(BarnesHutTree.QSw, qd);

            node.Pt = new ArborPoint(-0.5f, -0.5f);
            qd      = BarnesHutTree.GetQuad(node, bht.Root);
            Assert.AreEqual(BarnesHutTree.QNw, qd);

            node.Pt = new ArborPoint(0.5f, -0.5f);
            qd      = BarnesHutTree.GetQuad(node, bht.Root);
            Assert.AreEqual(BarnesHutTree.QNe, qd);

            node.Pt = ArborPoint.Null;
            qd      = BarnesHutTree.GetQuad(node, bht.Root);
            Assert.AreEqual(BarnesHutTree.QNone, qd);

            qd = BarnesHutTree.GetQuad(null, bht.Root);
            Assert.AreEqual(BarnesHutTree.QNone, qd);
        }
        public void Test_BarnesHutTree_ApplyForces()
        {
            var bht = new BarnesHutTree(new ArborPoint(-1, -1), new ArborPoint(+1, +1), 0.5f);

            var node = new ArborNode("x");

            node.Pt = new ArborPoint(0.5f, 0.5f);
            bht.ApplyForces(node, 10000.0f);
        }
        public void Test_BarnesHutTree_Insert()
        {
            var bht = new BarnesHutTree(new ArborPoint(-1, -1), new ArborPoint(+1, +1), 0.5f);

            var node = new ArborNode("x");

            node.Pt = new ArborPoint(0.5f, 0.5f);
            bht.Insert(node);
        }
        public void Test_BarnesHutTree_ctor()
        {
            var bht = new BarnesHutTree(new ArborPoint(-1, -1), new ArborPoint(+1, +1), 0.5f);

            Assert.IsNotNull(bht);

            bht.Reset();
            Assert.AreEqual(0, bht.Root.Mass);
            Assert.AreEqual(ArborPoint.Zero, bht.Root.Pt);
        }
Exemple #5
0
        private void UpdateGraphBounds()
        {
            ArborPoint lt = new ArborPoint(-1.0f, -1.0f);
            ArborPoint rb = new ArborPoint(+1.0f, +1.0f);

            for (int i = 0, nodesCount = fNodes.Count; i < nodesCount; i++)
            {
                ArborPoint pt = fNodes[i].Pt;
                if (pt.IsExploded())
                {
                    continue;
                }

                if (pt.X < lt.X)
                {
                    lt.X = pt.X;
                }
                if (pt.Y < lt.Y)
                {
                    lt.Y = pt.Y;
                }
                if (pt.X > rb.X)
                {
                    rb.X = pt.X;
                }
                if (pt.Y > rb.Y)
                {
                    rb.Y = pt.Y;
                }
            }

            lt.X -= 1.2f;
            lt.Y -= 1.2f;
            rb.X += 1.2f;
            rb.Y += 1.2f;

            ArborPoint sz   = rb.Sub(lt);
            ArborPoint cent = lt.Add(sz.Div(2.0f));
            ArborPoint d    = new ArborPoint(Math.Max(sz.X, 4.0f), Math.Max(sz.Y, 4.0f)).Div(2.0f);

            fGraphBounds = new PSBounds(cent.Sub(d), cent.Add(d));
            fBHTree      = new BarnesHutTree(fGraphBounds.LeftTop, fGraphBounds.RightBottom, Theta);
        }