public static SimpleNode GetCareerCupTreeSimple1()
        {
            SimpleNode l4 = new SimpleNode() { Value = 4 };
            SimpleNode l8 = new SimpleNode() { Value = 8 };
            SimpleNode left = new SimpleNode() { Value = 3, Left = l4, Right = l8 };

            SimpleNode r6 = new SimpleNode() { Value = 6 }; ;
            SimpleNode r2 = new SimpleNode() { Value = 2 }; ;
            SimpleNode rn2 = new SimpleNode() { Value = -2, Right = r2 }; ;
            SimpleNode right = new SimpleNode() { Value = 5, Left = r6, Right = rn2 };

            return new SimpleNode() { Value = 2, Left = left, Right = right };
        }
Beispiel #2
0
 /// <summary>
 /// Attempts to remove an item from the queue.  The item does not need to be the head of the queue.
 /// Useful for multi-threading, where the queue may become empty between calls to Contains() and Remove()
 /// Returns true if the item was successfully removed, false if it wasn't in the queue.
 /// If multiple copies of the item are enqueued, only the first one is removed.
 /// O(log n)
 /// </summary>
 public bool TryRemove(TItem item)
 {
     lock (_queue)
     {
         SimpleNode removeMe = GetExistingNode(item);
         if (removeMe == null)
         {
             return(false);
         }
         _queue.Remove(removeMe);
         RemoveFromNodeCache(removeMe);
         return(true);
     }
 }
Beispiel #3
0
        /// <summary>
        /// Removes the head of the queue (node with minimum priority; ties are broken by order of insertion), and returns it.
        /// If queue is empty, throws an exception
        /// O(log n)
        /// </summary>
        public TItem Dequeue()
        {
            lock (_queue)
            {
                if (_queue.Count <= 0)
                {
                    throw new InvalidOperationException("Cannot call Dequeue() on an empty queue");
                }

                SimpleNode node = _queue.Dequeue();
                RemoveFromNodeCache(node);
                return(node.Data);
            }
        }
Beispiel #4
0
 /// <summary>
 /// Attempt to get the priority of the given item.
 /// Useful for multi-threading, where the queue may become empty between calls to Contains() and GetPriority()
 /// If the item is enqueued multiple times, only the priority of the first will be returned.
 /// (If your requirements are complex enough that you need to enqueue the same item multiple times <i>and</i> be able
 /// to query all their priorities, please wrap your items in a wrapper class so they can be distinguished).
 /// Returns true if the item was found in the queue, false otherwise
 /// O(1)
 /// </summary>
 public bool TryGetPriority(TItem item, out TPriority priority)
 {
     lock (_queue)
     {
         SimpleNode findMe = GetExistingNode(item);
         if (findMe == null)
         {
             priority = default(TPriority);
             return(false);
         }
         priority = findMe.Priority;
         return(true);
     }
 }
Beispiel #5
0
        /// <summary>
        /// Adds an item to the Node-cache to allow for many methods to be O(1) or O(log n)
        /// </summary>
        private void AddToNodeCache(SimpleNode node)
        {
            if (node.Data == null)
            {
                _nullNodesCache.Add(node);
                return;
            }

            if (!_itemToNodesCache.ContainsKey(node.Data))
            {
                _itemToNodesCache[node.Data] = new List <SimpleNode>();
            }
            _itemToNodesCache[node.Data].Add(node);
        }
Beispiel #6
0
        /// <summary>
        /// Renders the input reader using the context into the output writer.
        /// To be used when a template is dynamically constructed, or want to
        /// use Velocity as a token replacer.
        /// </summary>
        /// <param name="context">context to use in rendering input string
        /// </param>
        /// <param name="out"> Writer in which to render the output
        /// </param>
        /// <param name="logTag"> string to be used as the template name for log messages
        /// in case of error
        /// </param>
        /// <param name="reader">Reader containing the VTL to be rendered
        /// </param>
        /// <returns>true if successful, false otherwise.  If false, see
        /// Velocity runtime log
        /// @since Velocity v1.1
        /// </returns>
        public bool Evaluate(IContext context, TextWriter writer, String logTag, TextReader reader)
        {
            SimpleNode nodeTree = null;

            try
            {
                nodeTree = ri.parse(reader, logTag);
            }
            catch (ParseException pex)
            {
                throw new ParseErrorException(pex.Message);
            }

            /*
             * now we want to init and render
             */
            if (nodeTree != null)
            {
                InternalContextAdapterImpl ica = new InternalContextAdapterImpl(context);

                ica.PushCurrentTemplateName(logTag);

                try
                {
                    try
                    {
                        nodeTree.init(ica, ri);
                    }
                    catch (Exception e)
                    {
                        ri.error("Velocity.evaluate() : init exception for tag = " + logTag + " : " + e);
                    }

                    /*
                     *  now render, and let any exceptions fly
                     */

                    nodeTree.render(ica, writer);
                }
                finally
                {
                    ica.PopCurrentTemplateName();
                }

                return(true);
            }

            return(false);
        }
        protected override VisualGroup UpdateVisual(IRenderContext context, VisualGroup oldVisual, INode node)
        {
            var layout = node.Layout;

            if (oldVisual.Children.Count != 2)
            {
                // something's wrong - re-create visual
                return(CreateVisual(context, node));
            }
            // get the child visuals from the container
            var wrappedVisual = oldVisual.Children[0];
            var image         = oldVisual.Children.Count > 1?oldVisual.Children[1]:null;

            // update wrapped visual - delegate to renderer of wrapped style
            wrappedVisual = wrapped.Renderer.GetVisualCreator(node, wrapped).UpdateVisual(context, wrappedVisual);
            if (wrappedVisual != oldVisual.Children[0])
            {
                oldVisual.Children[0] = wrappedVisual;
            }
            var oldImageUrl = oldVisual.GetRenderDataCache <string>();

            if (imageUrl != oldImageUrl)
            {
                // update image
                imageStyle.Image = new BitmapImage(new Uri(imageUrl, UriKind.Relative));
            }
            SimpleNode dummyNode = new SimpleNode
            {
                Layout = new RectD(layout.X + layout.Width - (decoratorSize.Width * 0.5), layout.Y - decoratorSize.Height * 0.5, decoratorSize.Width, decoratorSize.Height)
            };

            image = imageStyle.Renderer.GetVisualCreator(dummyNode, imageStyle).UpdateVisual(context, image);
            if (oldVisual.Children.Count > 1)
            {
                if (image == null)
                {
                    oldVisual.Children.RemoveAt(1);
                }
                else if (oldVisual.Children[1] != image)
                {
                    oldVisual.Children[1] = image;
                }
            }
            else if (image != null)
            {
                oldVisual.Add(image);
            }
            return(oldVisual);
        }
Beispiel #8
0
        /// <summary>
        /// Removes the head of the queue (node with minimum priority; ties are broken by order of insertion), and sets it to first.
        /// Useful for multi-threading, where the queue may become empty between calls to Contains() and Dequeue()
        /// Returns true if successful; false if queue was empty
        /// O(log n)
        /// </summary>
        public bool TryDequeue(out TItem first)
        {
            lock (_queue) {
                if (_queue.Count <= 0)
                {
                    first = default(TItem);
                    return(false);
                }

                SimpleNode node = _queue.Dequeue();
                first = node.Data;
                RemoveFromNodeCache(node);
                return(true);
            }
        }
Beispiel #9
0
    private static SimpleNode CreateStartNode(System.Guid nodeGuid)
    {
        SimpleNode node = null;

        node = new SimpleNode(nodeGuid, SimpleNodeType.StartNode);

        Port outPort = node.InstantiatePort(Orientation.Horizontal, Direction.Output, Port.Capacity.Single, m_objectType);

        node.m_outputPorts.Add(outPort);
        node.outputContainer.Add(outPort);
        node.RefreshPorts();
        node.RefreshExpandedState();

        return(node);
    }
Beispiel #10
0
        public SimpleNode <T> Peak()
        {
            if (_head == null)
            {
                return(null);
            }

            SimpleNode <T> temp = _head;

            while (temp.HasNext())
            {
                temp = temp.GetNext();
            }
            return(temp);
        }
Beispiel #11
0
            internal void parseTree(InternalContextAdapter ica)
            {
                try
                {
                    //UPGRADE_ISSUE: The equivalent of constructor 'java.io.BufferedReader.BufferedReader' is incompatible with the expected type in C#. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1109"'
                    TextReader br = new StringReader(macrobody);

                    nodeTree = Enclosing_Instance.rsvc.parse(br, "VM:" + macroname, true);
                    nodeTree.init(ica, null);
                }
                catch (System.Exception e)
                {
                    Enclosing_Instance.rsvc.error("VelocimacroManager.parseTree() : exception " + macroname + " : " + StringUtils.stackTrace(e));
                }
            }
Beispiel #12
0
        /// <summary>
        /// Call this method to change the priority of an item.
        /// Useful for multi-threading, where the queue may become empty between calls to Contains() and UpdatePriority()
        /// If the item is enqueued multiple times, only the first one will be updated.
        /// (If your requirements are complex enough that you need to enqueue the same item multiple times <i>and</i> be able
        /// to update all of them, please wrap your items in a wrapper class so they can be distinguished).
        /// Returns true if the item priority was updated, false otherwise. O(log n)
        /// </summary>
        public bool TryUpdatePriority(TItem item, TPriority priority)
        {
            lock (_queue)
            {
                SimpleNode updateMe = GetExistingNode(item);

                if (updateMe == null)
                {
                    return(false);
                }

                _queue.UpdatePriority(updateMe, priority);
                return(true);
            }
        }
Beispiel #13
0
        public void testMultipleObjectIndexMethodPairs()         // throws OgnlException
        {
            SimpleNode expression = (SimpleNode)Ognl.parseExpression("#ka.sunk[#root]");

            context ["ka"] = (new Test5());
            try
            {
                Ognl.getValue(expression, context, "aksdj");
                Assert.Fail();
            }
            catch (OgnlException ex)
            {
                /* Should throw */
            }
        }
Beispiel #14
0
        /// <summary>
        /// Adds an item to the Node-cache to allow for many methods to be O(1) or O(log n)
        /// </summary>
        private void AddToNodeCache(SimpleNode node)
        {
            if (node.data == null)
            {
                this._nullNodesCache.Add(node);
                return;
            }

            if (!this._itemToNodesCache.TryGetValue(node.data, out IList <SimpleNode> nodes))
            {
                nodes = new List <SimpleNode>();
                this._itemToNodesCache[node.data] = nodes;
            }
            nodes.Add(node);
        }
Beispiel #15
0
        /* Override this method if you want to customize how the node dumps
         * out its children. */

        public void Dump(string prefix)
        {
            System.Console.Out.WriteLine(ToString(prefix));
            if (children != null)
            {
                for (int i = 0; i < children.Length; ++i)
                {
                    SimpleNode n = (SimpleNode)children[i];
                    if (n != null)
                    {
                        n.Dump(prefix + " ");
                    }
                }
            }
        }
Beispiel #16
0
        private static void AddSimpleChildren(SimpleNode sourceNode, List <SimpleNode> simpleTree, XmlTree source)
        {
            foreach (var id in sourceNode.Children)
            {
                var node       = source.Nodes.FirstOrDefault(e => e.Id == id);
                var simpleNode = new SimpleNode(id, sourceNode.Id);
                foreach (var bond in node.Bonds)
                {
                    simpleNode.Add(bond);
                }
                simpleTree.Add(simpleNode);

                AddSimpleChildren(simpleNode, simpleTree, source);
            }
        }
Beispiel #17
0
        public void Append(T value)
        {
            if (_head == null)
            {
                _head = new SimpleNode <T>(value);
                return;
            }
            SimpleNode <T> temp = _head;

            while (temp.HasNext())
            {
                temp = temp.GetNext();
            }
            temp.SetNext(new SimpleNode <T>(value));
        }
 /// <summary>
 /// Call this method to change the priority of an item.
 /// Calling this method on a item not in the queue will throw an exception.
 /// If the item is enqueued multiple times, only the first one will be updated.
 /// (If your requirements are complex enough that you need to enqueue the same item multiple times <i>and</i> be able
 /// to update all of them, please wrap your items in a wrapper class so they can be distinguished).
 /// O(n)
 /// </summary>
 public void UpdatePriority(TItem item, TPriority priority)
 {
     lock (_queue)
     {
         try
         {
             SimpleNode updateMe = GetExistingNode(item);
             _queue.UpdatePriority(updateMe, priority);
         }
         catch (InvalidOperationException ex)
         {
             throw new InvalidOperationException("Cannot call UpdatePriority() on a node which is not enqueued: " + item, ex);
         }
     }
 }
Beispiel #19
0
        public bool Evaluate(IContext context, TextWriter writer, string logTag, TextReader reader)
        {
            SimpleNode simpleNode = null;

            try
            {
                simpleNode = this.ri.Parse(reader, logTag);
            }
            catch (ParseException ex)
            {
                throw new ParseErrorException(ex.Message, ex);
            }
            bool result;

            if (simpleNode != null)
            {
                InternalContextAdapterImpl internalContextAdapterImpl = new InternalContextAdapterImpl(context);
                internalContextAdapterImpl.PushCurrentTemplateName(logTag);
                try
                {
                    try
                    {
                        simpleNode.Init(internalContextAdapterImpl, this.ri);
                    }
                    catch (System.Exception ex2)
                    {
                        this.ri.Error(string.Concat(new object[]
                        {
                            "Velocity.evaluate() : init exception for tag = ",
                            logTag,
                            " : ",
                            ex2
                        }));
                    }
                    simpleNode.Render(internalContextAdapterImpl, writer);
                }
                finally
                {
                    internalContextAdapterImpl.PopCurrentTemplateName();
                }
                result = true;
            }
            else
            {
                result = false;
            }
            return(result);
        }
Beispiel #20
0
        protected override void WriteInner(System.Xml.XmlWriter writer)
        {
            var container = new ComplexNode();

            container.Classes.Add("image-container");

            var img = new SimpleNode("img", string.Empty);

            img.Attributes.Add("src", _imagePath);
            img.Styles.Add("width", "100%");

            container.ChildNodes.Add(img);
            ChildNodes.Add(container);

            base.WriteInner(writer);
        }
Beispiel #21
0
            internal void parseTree(IInternalContextAdapter internalContextAdapter)
            {
                try
                {
                    //UPGRADE_ISSUE: The equivalent of constructor 'java.io.BufferedReader.BufferedReader' is incompatible with the expected type in C#. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1109"'
                    TextReader br = new StringReader(macroBody);

                    nodeTree = Enclosing_Instance.runtimeServices.Parse(br, string.Format("VM:{0}", macroName), true);
                    nodeTree.Init(internalContextAdapter, null);
                }
                catch (System.Exception e)
                {
                    Enclosing_Instance.runtimeServices.Error(
                        string.Format("VelocimacroManager.parseTree() : exception {0} : {1}", macroName, e));
                }
            }
Beispiel #22
0
        /// <summary>
        /// Creates the dummy connector edge for the given label.
        /// </summary>
        private IEdge CreateConnectorEdge(ILabel label)
        {
            // create a dummy node at the location of the label
            var labelNodeDummy = new SimpleNode {
                Layout = label.GetLayout().GetBounds(), Style = new ShapeNodeStyle()
            };

            labelNodeDummy.Ports = new ListEnumerable <IPort>(new[] { new SimplePort(labelNodeDummy, LabelPortLocation) });

            // create a connecting edge between the dummy node and the owner of the label
            return(new SimpleEdge(new SimplePort(labelNodeDummy, OwnerPortLocation),
                                  new SimplePort((IPortOwner)label.Owner, OwnerPortLocation))
            {
                Style = ConnectorEdgeStyle
            });
        }
Beispiel #23
0
        public void ValidateSampleOneFromAToF()
        {
            var a = new SimpleNode("A");
            var b = new SimpleNode("B");
            var c = new SimpleNode("C");
            var d = new SimpleNode("D");
            var e = new SimpleNode("E");
            var f = new SimpleNode("F");

            a.ConnectTo(b, 4);
            a.ConnectTo(c, 2);
            b.ConnectTo(c, 1);
            b.ConnectTo(d, 5);
            c.ConnectTo(d, 8);
            c.ConnectTo(e, 10);
            d.ConnectTo(f, 6);
            d.ConnectTo(e, 2);
            e.ConnectTo(f, 2);

            var dijkstra = new Dijkstra.Dijkstra();
            var result   = dijkstra.FindShortestPath(a, f);

            Assert.NotNull(result);
            Assert.Equal(6, result.Length);
            Assert.Equal("A", result[0].Label);
            Assert.Equal("C", result[1].Label);
            Assert.Equal("B", result[2].Label);
            Assert.Equal("D", result[3].Label);
            Assert.Equal("E", result[4].Label);
            Assert.Equal("F", result[5].Label);

            var weight = 0;

            for (var i = 0; i < result.Length; i++)
            {
                var currentWeight = 0;
                if (i < result.Length - 1)
                {
                    currentWeight = result[i].Neighbors
                                    .Single(n => n.Node.Label.Equals(result[i + 1].Label))
                                    .WeightToNode;
                }
                weight += currentWeight;
            }

            Assert.Equal(12, weight);
        }
Beispiel #24
0
        /// <summary>
        /// Called to render the combo box items.
        /// </summary>
        private void DrawComboBoxItem(object sender, DrawItemEventArgs e)
        {
            e.DrawBackground();
            e.DrawFocusRectangle();
            var node      = Nodes[e.Index];
            var item      = (INeo4jNode)node.Tag;
            var style     = new Neo4JNodeStyle();
            var dummyNode = new SimpleNode {
                Layout = new RectD(0, 0, 240, 75), Tag = item, Style = style
            };
            var context = new RenderContext(e.Graphics, canvasControl);
            var visual  = style.Renderer.GetVisualCreator(dummyNode, style).CreateVisual(context);

            ((VisualGroup)visual).Transform = new Matrix();
            ((VisualGroup)visual).Transform.Translate(e.Bounds.X, e.Bounds.Y);
            visual.Paint(context, e.Graphics);
        }
Beispiel #25
0
        public void testPop()
        {
            Stack <int> tester = new Stack <int>();

            tester.Push(0);
            tester.Push(1);
            tester.Push(2);
            SimpleNode <int> popped = tester.Pop();

            Assert.AreEqual(popped.GetValue(), 2);
            popped = tester.Pop();
            Assert.AreEqual(popped.GetValue(), 1);
            Assert.AreEqual(tester.Size(), 1);
            popped = tester.Pop();
            Assert.AreEqual(popped.GetValue(), 0);
            Assert.Null(tester.Pop());
        }
Beispiel #26
0
        private ComplexNode CreateAchor(string imagePath, string filePath, string text)
        {
            var anchor = new ComplexNode("a");

            anchor.Attributes.Add("href", "FileDownload/DownloadFile?fileName=" + filePath);

            var img = new SimpleNode("img", string.Empty);

            img.Attributes.Add("src", @"Content/Images/help/" + imagePath);

            anchor.ChildNodes.Add(img);

            var span = new SimpleNode("span", text);

            anchor.ChildNodes.Add(span);
            return(anchor);
        }
Beispiel #27
0
            public void InitializeDrag(IInputModeContext context)
            {
                wrappedHandler.InitializeDrag(context);
                this.shadowLocation = node.Layout.GetTopLeft();
                this.emulatedOffset = PointD.Origin;
                var dummyNode = new SimpleNode {
                    Layout = new DynamicRectangle(shadowLocation, node.Layout),
                    Style  =
                        new ShapeNodeStyle {
                        Shape = ShapeNodeShape.RoundRectangle,
                        Brush = Brushes.Transparent,
                        Pen   = new Pen(Brushes.Gray, 2)
                    }
                };

                shadowObject = context.CanvasControl.RootGroup.AddChild(dummyNode, GraphModelManager.DefaultNodeDescriptor).ToFront();
            }
Beispiel #28
0
        protected override void WriteInner(XmlWriter writer)
        {
            var aNode = new SimpleNode("div", string.Empty);

            aNode.Attributes.Add("parentId", _parentId);
            aNode.Attributes.Add("style", "display:none;float:left;");
            ChildNodes.Add(aNode);
            ChildNodes.Add(new UserInputNode(_data, _parentId));
            ChildNodes.Add(new UserImageNode());

            var userName = _data.Attribute("firstName").Value + " " + _data.Attribute("lastName").Value;

            ChildNodes.Add(new UserNameNode(userName));


            base.WriteInner(writer);
        }
Beispiel #29
0
 /// <summary>
 /// Enqueue a node to the priority queue.  Lower values are placed in front. Ties are broken by first-in-first-out.
 /// This queue automatically resizes itself, so there's no concern of the queue becoming 'full'.
 /// Duplicates and null-values are allowed.
 /// O(log n)
 /// </summary>
 public void Enqueue(TItem item, TPriority priority)
 {
     lock (_queue) {
         IList <SimpleNode> nodes;
         if (item == null)
         {
             nodes = _nullNodesCache;
         }
         else if (!_itemToNodesCache.TryGetValue(item, out nodes))
         {
             nodes = new List <SimpleNode>();
             _itemToNodesCache[item] = nodes;
         }
         SimpleNode node = EnqueueNoLockOrCache(item, priority);
         nodes.Add(node);
     }
 }
Beispiel #30
0
        /// <summary>
        /// Adds an item to the Node-cache to allow for many methods to be O(1) or O(log n)
        /// </summary>
        private void AddToNodeCache(SimpleNode node)
        {
            if (node.Data == null)
            {
                _nullNodesCache.Add(node);
                return;
            }

            IList <SimpleNode> nodes;

            if (!_itemToNodesCache.TryGetValue(node.Data, out nodes))
            {
                nodes = new List <SimpleNode>();
                _itemToNodesCache[node.Data] = nodes;
            }
            nodes.Add(node);
        }
Beispiel #31
0
        public int Length()
        {
            SimpleNode <T> temp = _head;

            if (temp == null)
            {
                return(0);
            }
            int result = 0;

            do
            {
                result++;
                temp = temp.GetNext();
            }while (temp != _head);
            return(result);
        }
Beispiel #32
0
        public void Setup()
        {
            m_workflowBuilder = new WorkflowBuilder();
            InitializeEventReceiver receiver = new InitializeEventReceiver();
            m_simpleNode1 = new SimpleNode();
            m_simpleNode2 = new SimpleNode();
            m_simpleNode3 = new SimpleNode();
            m_workflowBuilder.Add(receiver);
            m_workflowBuilder.Add(m_simpleNode1);
            m_workflowBuilder.Add(m_simpleNode2);
            m_workflowBuilder.Add(m_simpleNode3);

            m_workflowBuilder.Connect(receiver.Pin(x => x.Fired), m_simpleNode1);
            m_workflowBuilder.Connect(m_simpleNode1.Pin(x => x.Next), m_simpleNode2);
            m_workflowBuilder.Connect(m_simpleNode2.Pin(x => x.Next), m_simpleNode3);

            m_debuggerMock = new Mock<IDebugger>();
        }
Beispiel #33
0
    public void CreateGridOLD(SimpleNode[] nodes)
    {
        Grid grid = new Grid();
        grids = new Grid[1] { grid };
        grid.width = nodes.Length;
        grid.depth = 1;

        staticNodes = new Node[1][,];
        staticNodes[0] = new Node[grid.width, grid.depth];
        totalNodeAmount = nodes.Length;

        for (int x = 0; x < nodes.Length; x++)
        {
            Node node = new Node();
            node.pos = new Int3(x, 0, 0);
            nodes[x].pos = node.pos;
            node.vectorPos = nodes[x].vectorPos;

            staticNodes[0][x, 0] = node;
        }

        for (int x = 0; x < nodes.Length; x++)
        {
            Node node = staticNodes[0][x, 0];

            node.neighbours = new Node[nodes[x].neighbours.Length];
            node.costs = new int[nodes[x].neighbours.Length];
            node.angles = new float[nodes[x].neighbours.Length];
            node.neighboursKeys = new int[nodes[x].neighbours.Length];

            for (int i = 0; i < node.neighbours.Length; i++)
            {
                node.neighbours[i] = GetNode(nodes[x].neighbours[i].pos);
                node.costs[i] = nodes[x].costs == null ? (int)(Vector3.Distance(node.neighbours[i].vectorPos, node.vectorPos) * 100) : nodes[x].costs[i];
                node.angles[i] = nodes[x].angles == null ? 0 : nodes[x].angles[i];
                node.neighboursKeys[i] = i;
            }
        }

        Bounds b = new Bounds(staticNodes[0][0, 0].vectorPos, Vector3.zero);
        for (int x = 0; x < nodes.Length; x++)
        {
            b.Encapsulate(staticNodes[0][x, 0].vectorPos);
        }

        b.extents += Vector3.one * boundsMargin;

        grid.globalWidth = b.size.x;
        grid.globalDepth = b.size.z;
        grid.globalHeight = b.size.y;

        grid.globalOffset = (b.center - b.extents);

        FloodFillAll();

        binaryHeap = new BinaryHeap(Mathf.CeilToInt(totalNodeAmount * heapSize));
    }
Beispiel #34
0
        /// <summary> Default constructor: sets up the Velocity
        /// Runtime, creates the visitor for traversing
        /// the node structure and then produces the
        /// visual representation by the visitation.
        /// </summary>
        public TemplateNodeView(System.String template)
        {
            try {
            RuntimeSingleton.init("velocity.properties");

            System.IO.StreamReader isr = new InputStreamReader(new System.IO.FileStream(template, System.IO.FileMode.Open, System.IO.FileAccess.Read), RuntimeSingleton.getString(RuntimeSingleton.INPUT_ENCODING))
            ;

            //UPGRADE_ISSUE: The equivalent of constructor 'java.io.BufferedReader.BufferedReader' is incompatible with the expected type in C#. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1109"'
            System.IO.StreamReader br = new System.IO.StreamReader(isr.BaseStream);

            document = RuntimeSingleton.parse(br, template)
            ;

            visitor = new NodeViewMode();
            visitor.Context = null;
            //UPGRADE_ISSUE: The equivalent of parameter java.lang.System.out is incompatible with the expected type in C#. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1109"'
            visitor.Writer = new System.IO.StreamWriter(System.Console.Out);
            document.jjtAccept(visitor, null);
            } catch (System.Exception e) {
            System.Console.Out.WriteLine(e);
            SupportClass.WriteStackTrace(e, Console.Error);
            }
        }
        public void the_remove_method_puts_a_node_removed_event_on_the_chain()
        {
            var chain = new BehaviorChain();
            chain.AddToEnd(new SimpleNode());

            var nodeToBeRemoved = new SimpleNode();
            chain.AddToEnd(nodeToBeRemoved);

            chain.AddToEnd(new SimpleNode());
            chain.AddToEnd(new SimpleNode());

            nodeToBeRemoved.Remove();

            chain.As<ITracedModel>().StagedEvents.Last()
                .ShouldEqual(new NodeRemoved(nodeToBeRemoved));
        }
        public void the_replace_method_puts_a_node_replaced_event_on_the_chain()
        {
            var original = new SimpleNode();
            var newNode = new SimpleNode();

            var chain = new BehaviorChain();
            chain.AddToEnd(original);

            original.ReplaceWith(newNode);

            chain.As<ITracedModel>().StagedEvents.Last()
                .ShouldEqual(new NodeReplaced(original, newNode));
        }
	public void CreateGrid (SimpleNode[][] nodes) {
		if (nodes.Length < 1) {
			Debug.LogError ("Make sure you use at least one grid");
		}
		
		
			
		Grid[] allGrids = new Grid[nodes.Length];
		for (int i=0;i<allGrids.Length;i++) {
			allGrids[i] = new Grid ();
			allGrids[i].width = nodes[i].Length;
			allGrids[i].depth = 1;
			
			if (allGrids[i].width < 1) {
				Debug.LogError ("Make sure you use at least one node for each grid");
				return;
			}
		}
		
		staticNodes = new Node[allGrids.Length][,];
		totalNodeAmount = 0;
		
		for (int i=0;i<allGrids.Length;i++) {
			Grid grid = allGrids[i];
			staticNodes[i] = new Node [grid.width,grid.depth];
			totalNodeAmount+= grid.width*grid.depth;
		}
		
		for (int y=0;y<allGrids.Length;y++) {
			
			SimpleNode[] gridNodes = nodes[y];
			
			for (int x=0;x<gridNodes.Length;x++) {
				Node node = new Node ();
				node.pos = new Int3(x,y,0);
				gridNodes[x].pos = node.pos;
				node.vectorPos = gridNodes[x].vectorPos;
				staticNodes[y][x,0] = node;
			}
		}
		
		for (int y=0;y<allGrids.Length;y++) {
			Grid grid = allGrids[y];
			
			SimpleNode[] gridNodes = nodes[y];
			
			for (int x=0;x<gridNodes.Length;x++) {
				Node node = staticNodes[y][x,0];
				
				node.connections = new Connection[gridNodes[x].neighbours.Length];
				
				for (int i=0;i<node.connections.Length;i++) {
					Node neighbour = GetNode (gridNodes[x].neighbours[i].pos);
					int cost = gridNodes[x].costs == null ? (int)(Vector3.Distance (neighbour.vectorPos,node.vectorPos)*100) : gridNodes[x].costs[i];
					float angle = gridNodes[x].angles == null ? 0 : gridNodes[x].angles[i];
					
					node.connections[i] = new Connection (neighbour,cost,angle,true);
				}
				
				node.GenerateEnabledConnections ();
			}
			
			
			Bounds b = new Bounds (staticNodes[y][0,0].vectorPos,Vector3.zero);
			for (int x=0;x<gridNodes.Length;x++) {
				b.Encapsulate (staticNodes[y][x,0].vectorPos);
			}
			
			b.extents += Vector3.one * boundsMargin;
			
			grid.globalWidth = b.size.x;
			grid.globalDepth = b.size.z;
			grid.globalHeight = b.size.y;
			
			grid.globalOffset = (b.center-b.extents);
		}
		grids = allGrids;
		FloodFillAll ();
		
		binaryHeap = new BinaryHeap (Mathf.CeilToInt (totalNodeAmount*heapSize));
	}
	public void CreateGrid (SimpleNode[] nodes) {
		SimpleNode[][] nds = new SimpleNode[1][];
		nds[0] = nodes;
		CreateGrid (nds);
	}