Exemple #1
0
        public void DrawDebug(Color col)
        {
            Vector2 center = Vector2.zero;

            for (int i = 0; i < size; i++)
            {
                int ib = (i + 1) % size;
                OffsetShapeLog.DrawLine(_nodes[i].position, _nodes[ib].position, col);
                center += _nodes[i].position;
            }
            center /= size;

            OffsetShapeLog.DrawEdge(_liveEdge, Color.magenta);
            OffsetShapeLog.DrawDirection(Utils.ToV3(center), _tangent, "tangent", col);
        }
Exemple #2
0
        private void AddFace(Edge liveEdge, Node staticNodeA, Node staticNodeB)
        {
            OffsetShapeLog.DrawEdge(liveEdge, Color.red);
            OffsetShapeLog.DrawLabel(liveEdge.nodeA.position, "new face");
            SkeletonFace face = new SkeletonFace(liveEdge, staticNodeA, staticNodeB);

            _faces.Add(face);

            if (!_edgeDic.ContainsKey(liveEdge.nodeA))
            {
                _edgeDic.Add(liveEdge.nodeA, new List <SkeletonFace>());
                _edgeDic[liveEdge.nodeA].Add(face);
            }
            else
            {
                _edgeDic[liveEdge.nodeA].Add(face);
            }

            if (!_edgeDic.ContainsKey(liveEdge.nodeB))
            {
                _edgeDic.Add(liveEdge.nodeB, new List <SkeletonFace>());
                _edgeDic[liveEdge.nodeB].Add(face);
            }
            else
            {
                _edgeDic[liveEdge.nodeB].Add(face);
            }

            if (!_nodeDic.ContainsKey(liveEdge))
            {
                _nodeDic.Add(liveEdge, face);
            }
            else
            {
                _nodeDic[liveEdge] = face;
            }
        }
Exemple #3
0
        /// <summary>
        /// Remove any live edges that are now parallel and will no longer serve a purpose
        /// </summary>
        /// <param name="data"></param>
        public static void CheckParrallel(Shape data)
        {
            int liveEdgeCount = data.liveEdges.Count;

            for (int a = 0; a < liveEdgeCount; a++)
            {
                for (int b = 0; b < liveEdgeCount; b++)
                {
                    if (a == b)
                    {
                        continue;
                    }
                    Edge    edgeA = data.liveEdges[a];
                    Edge    edgeB = data.liveEdges[b];
                    Vector2 dirA  = edgeA.direction;
                    Vector2 dirB  = edgeB.direction;

                    if (ParallelLines(dirA, dirB))
                    {
                        Node nodeAA = edgeA.nodeA;
                        Node nodeAB = edgeA.nodeB;
                        Node nodeBA = edgeB.nodeA;
                        Node nodeBB = edgeB.nodeB;

                        bool connectedA = nodeAA == nodeBA || nodeAA == nodeBB;
                        bool connectedB = nodeAB == nodeBA || nodeAB == nodeBB;

                        if (connectedA && connectedB)//connected parallel lines serve no purpose
                        {
                            OffsetShapeLog.AddLine("Parallel Lines!");
                            OffsetShapeLog.AddLine(edgeA.ToString());
                            OffsetShapeLog.AddLine(edgeB.ToString());
                            OffsetShapeLog.DrawEdge(edgeA, new Color(1, 1, 0, 0.8f));
                            OffsetShapeLog.DrawEdge(edgeB, new Color(1, 0, 1, 0.8f));
                            OffsetShapeLog.LabelNode(nodeAA);
                            OffsetShapeLog.LabelNode(nodeAB);
                            OffsetShapeLog.LabelNode(nodeBA);
                            OffsetShapeLog.LabelNode(nodeBB);
                            Node newStaticNodeA = new Node(nodeAA.position, nodeAA.height);
                            Node newStaticNodeB = new Node(nodeAB.position, nodeAB.height);
                            data.liveEdges.Remove(edgeA);
                            data.liveEdges.Remove(edgeB);
                            data.liveNodes.Remove(nodeAA);
                            data.liveNodes.Remove(nodeAB);

                            newStaticNodeA = data.AddStaticNode(newStaticNodeA);
                            newStaticNodeB = data.AddStaticNode(newStaticNodeB);
                            data.edges.Add(edgeA);
                            data.edges.Add(edgeB);

                            RetireFormingEdge(data, nodeAA, newStaticNodeA);
                            RetireFormingEdge(data, nodeAB, newStaticNodeB);

                            NewFormingEdge(data, newStaticNodeA, nodeAA);
                            NewFormingEdge(data, newStaticNodeB, nodeAB);

                            CalculateNodeDirAng(data, nodeAA);
                            CalculateNodeDirAng(data, nodeAB);

                            a             = 0;
                            b             = 0;
                            liveEdgeCount = data.liveEdges.Count;
                        }
                        //                        else
                        //                        {
                        //                            OffsetShapeLog.AddLine("Parallel Lines but!");
                        //                            OffsetShapeLog.AddLine(edgeA.ToString());
                        //                            OffsetShapeLog.AddLine(edgeB.ToString());
                        //                        }
                    }
                }
            }
        }