예제 #1
0
        private static void Traverse(CircularLinkedList <Vector2> subject,
                                     CircularLinkedList <Vector2> clip,
                                     CircularLinkedList <Vector2> entering,
                                     CircularLinkedList <Vector2> exiting,
                                     List <CircularLinkedList <Vector2> > polygons,
                                     Operation operation)
        {
            while (entering.Count > 0)
            {
                CircularLinkedList <Vector2> polygon = new CircularLinkedList <Vector2>();
                Vector2 start = entering.First.Value;
                LinkedListNode <Vector2> curNode = subject.Find(start);
                polygon.AddLast(curNode.Value);
                curNode = subject.NextOrFirst(curNode);
                bool IsSubjectNode = true;
                while (curNode.Value != start)
                {
                    polygon.AddLast(curNode.Value);
                    if (entering.Contains(curNode.Value))
                    {
                        entering.Remove(curNode.Value);
                        IsSubjectNode = true;
                        curNode       = subject.Find(curNode.Value);
                    }
                    if (exiting.Contains(curNode.Value))
                    {
                        exiting.Remove(curNode.Value);

                        IsSubjectNode = false;
                        curNode       = clip.Find(curNode.Value);
                    }
                    if (IsSubjectNode)
                    {
                        curNode = subject.NextOrFirst(curNode);
                    }
                    else
                    {
                        curNode = clip.NextOrFirst(curNode);
                    }
                }
                entering.Remove(curNode.Value);
                polygons.Add(polygon);
            }
        }
예제 #2
0
        private static LinkedListNode <Vector2> TraverseList(CircularLinkedList <Vector2> contour,
                                                             CircularLinkedList <Vector2> entering,
                                                             CircularLinkedList <Vector2> exiting,
                                                             CircularLinkedList <Vector2> polygon,
                                                             LinkedListNode <Vector2> currentNode,
                                                             Vector2 startNode,
                                                             CircularLinkedList <Vector2> contour2)
        {
            LinkedListNode <Vector2> contourNode = contour.Find(currentNode.Value);

            if (contourNode == null)
            {
                return(null);
            }

            entering.Remove(currentNode.Value);

            while (contourNode != null
                   &&
                   !entering.Contains(contourNode.Value)
                   &&
                   !exiting.Contains(contourNode.Value)
                   )
            {
                polygon.AddLast(contourNode.Value);
                contourNode = contour.NextOrFirst(contourNode);

                if (contourNode.Value == startNode)
                {
                    return(null);
                }
            }

            entering.Remove(contourNode.Value);
            polygon.AddLast(contourNode.Value);

            return(contour2.NextOrFirst(contour2.Find(contourNode.Value)));
        }