示例#1
0
    /// <summary>
    /// ドウカー表示を出力する
    /// </summary>
    public void DowkerNotation()
    {
        thisKnot.GetAllThings();
        thisKnot.MakeOrientation();
        int NodeID, NodeRID, StartNodeID, StartNodeRID;
        int JointCount = 0;

        for (int i = 0; i < thisKnot.AllNodes.Length; i++)
        {
            if (thisKnot.AllNodes[i].Joint)
            {
                JointCount++;
            }
        }
        if (JointCount > 0)
        {
            Edge ed = thisKnot.AllEdges[0];//とりあえず0番から始める
            if (ed == null)
            {
                return;
            }
            StartNodeID  = ed.ANodeID;
            StartNodeRID = ed.ANodeRID;
            NodeID       = ed.BNodeID;
            NodeRID      = ed.BNodeRID;
            int[]  DowkerSet   = new int[JointCount * 2];
            bool[] WhetherOver = new bool[JointCount * 2];
            int    repeatCount = 0;
            Node   nd          = thisKnot.GetNodeByID(NodeID);
            if (nd == null)
            {
                return;
            }
            if (nd.Joint)
            {
                DowkerSet[repeatCount]   = NodeID;
                WhetherOver[repeatCount] = (NodeRID == 0 || NodeRID == 2);
                repeatCount++;
            }
            switch (NodeRID)
            {
            case 0: NodeRID = 2; break;

            case 1: NodeRID = 3; break;

            case 2: NodeRID = 0; break;

            case 3: NodeRID = 1; break;
            }

            //Debug.Log(NodeID + "," + NodeRID + "->");
            for (int repeat = 0; repeat < thisKnot.AllEdges.Length; repeat++)
            {
                bool OK = false;
                for (int e = 0; e < thisKnot.AllEdges.Length; e++)
                {
                    ed = thisKnot.AllEdges[e];
                    //Debug.Log("   "+ed.ANodeID + "," + ed.ANodeRID+"||"+ ed.BNodeID + "," + ed.BNodeRID);
                    if (ed.ANodeID == NodeID && ed.ANodeRID == NodeRID)
                    {
                        NodeID  = ed.BNodeID;
                        NodeRID = ed.BNodeRID;
                        Debug.Log(ed.ANodeID + "," + ed.ANodeRID + ":" + ed.BNodeID + "," + ed.BNodeRID);
                        nd = thisKnot.GetNodeByID(NodeID);
                        if (nd == null)
                        {
                            return;
                        }
                        OK = true;
                        if (nd.Joint)
                        {
                            Debug.Log(NodeID + "," + repeatCount);
                            DowkerSet[repeatCount]   = NodeID;
                            WhetherOver[repeatCount] = (NodeRID == 0 || NodeRID == 2);
                            repeatCount++;
                        }
                        switch (NodeRID)
                        {
                        case 0: NodeRID = 2; break;

                        case 1: NodeRID = 3; break;

                        case 2: NodeRID = 0; break;

                        case 3: NodeRID = 1; break;
                        }
                        break;
                    }
                }
                if (NodeID == StartNodeID && NodeRID == StartNodeRID)
                {
                    break;
                }
                if (!OK)
                {
                    return;
                }
            }
            if (repeatCount != JointCount * 2)
            {
                Debug.Log("This is not a knot but a link.");
                return;
            }
            string ret = "";
            for (int i = 0; i < JointCount; i++)
            {
                for (int j = 0; j < JointCount; j++)
                {
                    if (DowkerSet[2 * i] == DowkerSet[2 * j + 1] && WhetherOver[2 * i] != WhetherOver[2 * j + 1])
                    {
                        if (WhetherOver[2 * j + 1])
                        {
                            ret += ((-2 * j - 2) + " ");
                        }
                        else
                        {
                            ret += ((2 * j + 2) + " ");
                        }
                    }
                }
            }
            Debug.Log(ret);
        }
    }