Example #1
0
        /// <summary>
        /// 指定された座標が Edge 上にあるかどうかを判断します。
        /// </summary>
        /// <param name="x">X座標</param>
        /// <param name="y">Y座標</param>
        public bool CheckMouseOn(float x, float y)
        {
            Vector2D vector1 = new Vector2D(((VertexView)vertex2).GetPosition().X - ((VertexView)vertex1).GetPosition().X, ((VertexView)vertex2).GetPosition().Y - ((VertexView)vertex1).GetPosition().Y);
            Vector2D vector2 = new Vector2D(x - ((VertexView)vertex1).GetPosition().X, y - ((VertexView)vertex1).GetPosition().Y);

            if (vector1.Getnorm() < vector2.Getnorm())
                return false;

            vector1.Normalization();
            vector2.Normalization();

            return (Vector2D.Inner(vector1, vector2) > 0.9999) ? true : false;
        }
        /// <summary>
        /// Fruchterman-Reingold-Layoutを適用します。
        /// </summary>
        /// <param name="width">描画領域幅</param>
        /// <param name="height">描画領域高</param>
        public void Fruchterman_Reingold_Layout(float width, float height)
        {
            if (vertexNum == 1)
                return;

            Vector2D[] Vpos = new Vector2D[vertexNum];
            Vector2D[] Vdisp = new Vector2D[vertexNum];
            Vector2D delta = new Vector2D();
            float rate = 0.9f;
            float k = (float)Math.Sqrt((double)(width * rate * height * rate) / vertexNum);
            float t = 0.1f;
            float d;

            for (int i = 0; i < vertexNum; i++)
            {
                Vpos[i] = new Vector2D(((VertexView)vertex[i]).GetPosition().X, ((VertexView)vertex[i]).GetPosition().Y);
                Vdisp[i] = new Vector2D();
            }

            for (int count = 0; count < 50; count++)
            {
                for (int i = 0; i < Vpos.Length; i++)
                {
                    Vdisp[i].Init();

                    for (int j = 0; j < Vpos.Length; j++)
                    {
                        if (i != j)
                        {
                            delta = Vpos[i] - Vpos[j];
                            d = delta.Getnorm();
                            delta.Normalization();
                            Vdisp[i] += delta * f_r(d, k);
                        }
                    }
                }

                for (int i = 0; i < edgeNum; i++)
                {
                    int n1 = vertex.IndexOf((VertexView)edge[i].GetEdgeVertex(Edge.VERTEX_FIRST));
                    int n2 = vertex.IndexOf((VertexView)edge[i].GetEdgeVertex(Edge.VERTEX_SECOND));
                    if (n1 != -1 && n2 != -1)
                    {
                        delta = Vpos[n1] - Vpos[n2];
                        d = delta.Getnorm();
                        delta.Normalization();
                        Vdisp[n1] -= delta * f_a(d, k);
                        Vdisp[n2] += delta * f_a(d, k);
                    }
                }

                for (int i = 0; i < Vpos.Length; i++)
                {
                    d = Vdisp[i].Getnorm();
                    Vpos[i] += (Vdisp[i] / d) * Math.Min(d, t);
                    Vpos[i].X = (float)Math.Min(width * rate, Math.Max(width * (1 - rate), Vpos[i].X));
                    Vpos[i].Y = (float)Math.Min(height * rate, Math.Max(height * (1 - rate), Vpos[i].Y));
                    ((VertexView)vertex[i]).SetPosition(Vpos[i].X, Vpos[i].Y);
                }
            }
        }