コード例 #1
0
ファイル: ArborViewer.cs プロジェクト: Serg-Norseman/BSLib
        public ArborViewer()
        {
            base.BackColor      = Color.White;
            base.BorderStyle    = BorderStyle.Fixed3D;
            base.DoubleBuffered = true;
            base.TabStop        = true;
            base.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            base.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);

            // repulsion - отталкивание, stiffness - тугоподвижность, friction - сила трения
            fSystem = new ArborSystemEx(10000.0f, 500.0f /*1000.0f*/, 0.1f, this);
            fSystem.SetViewSize(Width, Height);
            fSystem.AutoStop = true;
            fSystem.Graph    = new Graph();

            fDragged       = null;
            fEnergyDebug   = false;
            fNodesDragging = false;

            fDrawFont = new Font("Calibri", 9);

            fLinePen          = new Pen(Color.Gray, 1);
            fLinePen.StartCap = LineCap.NoAnchor;
            fLinePen.EndCap   = LineCap.ArrowAnchor;

            fStrFormat               = new StringFormat();
            fStrFormat.Alignment     = StringAlignment.Center;
            fStrFormat.LineAlignment = StringAlignment.Center;

            fBlackBrush = new SolidBrush(Color.Black);
            fWhiteBrush = new SolidBrush(Color.White);
        }
コード例 #2
0
        private ArborPoint NewRandomPoint()
        {
            ArborPoint lt = fGraphBounds.LeftTop;
            ArborPoint rb = fGraphBounds.RightBottom;
            ArborPoint dt = rb.Sub(lt);
            double     x  = lt.X + (dt.X * ArborSystem.GetRandom());
            double     y  = lt.Y + (dt.Y * ArborSystem.GetRandom());

            return(new ArborPoint(x, y));
        }
コード例 #3
0
ファイル: BarnesHutTree.cs プロジェクト: Serg-Norseman/BSLib
        public void Insert(ArborNode node)
        {
            try {
                Branch           branch = fRoot;
                List <ArborNode> gst    = new List <ArborNode>();
                gst.Add(node);
                while (gst.Count > 0)
                {
                    ArborNode h = gst[0];
                    gst.RemoveAt(0);

                    double m  = h.Mass;
                    int    qd = GetQuad(h, branch);
                    object fp = branch.Q[qd];

                    if (fp == null)
                    {
                        branch.Q[qd] = h;

                        branch.Mass += m;
                        branch.Pt    = branch.Pt.Add(h.Pt.Mul(m));
                    }
                    else
                    {
                        if (fp is Branch)
                        {
                            branch.Mass += m;
                            branch.Pt    = branch.Pt.Add(h.Pt.Mul(m));

                            branch = (Branch)fp;

                            gst.Insert(0, h);
                        }
                        else
                        {
                            ArborPoint l = branch.Size.Div(2);
                            ArborPoint n = branch.Origin;

                            if (qd == QSe || qd == QSw)
                            {
                                n.Y += l.Y;
                            }
                            if (qd == QNe || qd == QSe)
                            {
                                n.X += l.X;
                            }

                            ArborNode o = (ArborNode)fp;
                            fp           = new Branch(n, l);
                            branch.Q[qd] = fp;

                            branch.Mass = m;
                            branch.Pt   = h.Pt.Mul(m);

                            branch = (Branch)fp;

                            ArborPoint oPt = o.Pt;
                            if (oPt.X == h.Pt.X && oPt.Y == h.Pt.Y)
                            {
                                double lX = l.X * 0.08f;
                                double lY = l.Y * 0.08f;
                                oPt.X = Math.Min(n.X + l.X, Math.Max(n.X, oPt.X - lX / 2 + ArborSystem.GetRandom() * lX));
                                oPt.Y = Math.Min(n.Y + l.Y, Math.Max(n.Y, oPt.Y - lY / 2 + ArborSystem.GetRandom() * lY));
                                o.Pt  = oPt;
                            }

                            gst.Add(o);
                            gst.Insert(0, h);
                        }
                    }
                }
            } catch (Exception ex) {
                Debug.WriteLine("BarnesHutTree.Insert(): " + ex.Message);
            }
        }