Ejemplo n.º 1
0
        /**
         * Check if the number of NPC's in an area are 2 or less.
         * @param NPC
         * @return
         */
        private Boolean lessThanTwoCheck(Node[] NPC)
        {
            // NPCs are zero
            if (NPC.Length == 0)
            {
                return(true);
            }
            // create first linked list node.
            head = new DblLinkedList(NPC[0]);
            prev = head;
            if (NPC.Length == 1)
            {
                return(true);
            }
            // Else prepare the second linked list.
            DblLinkedList DLL_Two = new DblLinkedList(NPC[1]);

            head.setNext(DLL_Two);
            DLL_Two.setPrev(head);
            curr = DLL_Two;
            if (NPC.Length == 2)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 2
0
        public void algoTop(Node[] node)
        {
            // check if we need to perform a convex hull algorithm.
            if (lessThanTwoCheck(node))
            {
                return;
            }

            // Go through all but the first and last index's
            for (int trav = 2; trav < size; trav++)
            {
                // find out if the current point is part of the convex hull or not.
                double        hCheck = hullCheck(node, prev, curr, trav);
                DblLinkedList DLL    = new DblLinkedList(node[trav]);

                /*
                 * Check if the convex Hull should be outside of the current node
                 */
                if (hCheck < curr.getNode().yVal)
                {
                    /*
                     * Check each previous node on the convex hull until up until we are sure no current
                     * node will be fully contained in the new convex hull.
                     */
                    while (prev != head)
                    {
                        /*
                         * Check each new convex hull compared to the previous node.
                         */
                        double newHullCheck = hullCheck(node, prev.getPrev(), prev, trav);
                        if (newHullCheck < prev.getNode().yVal)
                        {
                            prev = prev.getPrev();
                            prev.setNext(DLL);
                        }

                        /*
                         * once we verify that we've found a previous convex hull node that won't change from the
                         * current new node, we quit.
                         */
                        else
                        {
                            break;
                        }
                    }

                    /*
                     * This handles the same situation as directly above but takes care not to go past the
                     * head.
                     */
                    if (prev == head)
                    {
                        double newHullCheck = hullCheck(node, prev, prev.getNext(), trav);
                        if (newHullCheck < prev.getNode().yVal)
                        {
                            prev.setNext(DLL);
                        }
                    }

                    /*
                     * update the connection between the new next convex hull node and the last verified node
                     * on the convex hull.
                     */
                    DLL.setPrev(prev);
                    prev.setNext(DLL);
                }

                /*
                 * If the Current Node is Outside the convex hull Then it becomes a part of the new
                 * convex hull
                 */
                else
                {
                    curr.setNext(DLL);
                    DLL.setPrev(curr);
                    prev = curr;
                }

                /*
                 * update the current node along the convex hull.
                 */
                curr = DLL;
                // printCurrList();
            }
            topEnd = curr;
            algoBottom(node);
        }