예제 #1
0
        }         // public void Build(GeometryGraph geomGraph)

        /// <summary>
        /// Insert nodes for all intersections on the edges of a Geometry.
        /// Label the created nodes the same as the edge label if they do not already have a label.
        ///	This allows nodes created by either self-intersections or
        ///	mutual intersections to be labelled.
        ///	Endpoint nodes will already be labelled from when they were inserted.
        /// Precondition: edge intersections have been computed.
        /// </summary>
        /// <param name="geomGraph"></param>
        /// <param name="argIndex"></param>
        public void ComputeIntersectionNodes(GeometryGraph geomGraph, int argIndex)
        {
            foreach (object obj in geomGraph.Edges)
            {
                Edge e    = (Edge)obj;
                int  eLoc = e.Label.GetLocation(argIndex);
                foreach (object objEdgeIntersection in e.EdgeIntersectionList)
                {
                    EdgeIntersection ei = (EdgeIntersection)objEdgeIntersection;
                    RelateNode       n  = (RelateNode)_nodes.AddNode(ei.Coordinate);
                    if (eLoc == Location.Boundary)
                    {
                        n.SetLabelBoundary(argIndex);
                    }
                    else
                    {
                        if (n.Label.IsNull(argIndex))
                        {
                            n.SetLabel(argIndex, Location.Interior);
                        }                         // if ( n.Label.IsNull( argIndex ) )
                    }
                    //Trace.WriteLine( n.ToString() );
                }
            }     // foreach ( object obj in geomGraph.Edges )
        }         // public void ComputeIntersectionNodes( GeometryGraph geomGraph, int argIndex )
예제 #2
0
        /// <summary>
        /// Insert nodes for all intersections on the edges of a Geometry.
        /// Label the created nodes the same as the edge label if they do not already
        /// have a label.
        /// This allows nodes created by either self-intersections or
        /// mutual intersections to be labelled.
        /// Endpoint nodes will already be labelled from when they were inserted.
        /// <para>
        /// Precondition: edge intersections have been computed.
        /// </para>
        /// </summary>
        public void ComputeIntersectionNodes(GeometryGraph geomGraph, int argIndex)
        {
            for (IEdgeEnumerator edgeIt = geomGraph.EdgeIterator; edgeIt.MoveNext();)
            {
                Edge e    = edgeIt.Current;
                int  eLoc = e.Label.GetLocation(argIndex);

                for (IEnumerator eiIt = e.EdgeIntersectionList.Iterator(); eiIt.MoveNext();)
                {
                    EdgeIntersection ei = (EdgeIntersection)eiIt.Current;
                    RelateNode       n  = (RelateNode)nodes.AddNode(ei.coord);
                    if (eLoc == LocationType.Boundary)
                    {
                        n.SetLabelBoundary(argIndex);
                    }
                    else
                    {
                        if (n.Label.IsNull(argIndex))
                        {
                            n.SetLabel(argIndex, LocationType.Interior);
                        }
                    }
                }
            }
        }
예제 #3
0
 /// <summary>
 /// Copy all nodes from an arg point into this graph.
 /// The node label in the arg point overrides any previously computed
 /// label for that argIndex.
 /// (E.g. a node may be an intersection node with
 /// a computed label of Boundary,
 /// but in the original arg Geometry it is actually
 /// in the interior due to the Boundary Determination Rule)
 /// </summary>
 /// <param name="argIndex"></param>
 private void CopyNodesAndLabels(int argIndex)
 {
     foreach (Node graphNode in _arg[argIndex].Nodes)
     {
         Node newNode = _nodes.AddNode(graphNode.Coordinate);
         newNode.SetLabel(argIndex, graphNode.Label.GetLocation(argIndex));
     }
 }
예제 #4
0
 /// <summary>
 /// Copy all nodes from an arg point into this graph.
 /// The node label in the arg point overrides any previously computed
 /// label for that argIndex.
 /// (E.g. a node may be an intersection node with
 /// a computed label of Boundary,
 /// but in the original arg Geometry it is actually
 /// in the interior due to the Boundary Determination Rule)
 /// </summary>
 /// <param name="argIndex"></param>
 private void CopyNodesAndLabels(int argIndex)
 {
     for (IEnumerator i = arg[argIndex].GetNodeEnumerator(); i.MoveNext();)
     {
         Node graphNode = (Node)i.Current;
         Node newNode   = nodes.AddNode(graphNode.Coordinate);
         newNode.SetLabel(argIndex, graphNode.Label.GetLocation(argIndex));
     }
 }
예제 #5
0
        }         // private void ComputeProperIntersectionIM( SegmentIntersector intersector, IntersectionMatrix im )

        /// <summary>
        /// Copy all nodes from an arg geometry into ths graph.  The node label in the arg geometry
        /// overrides any previously computed label for that argIndex.  (e.g. a node may be an intersection
        /// node with a computed label of BOUNDARY, but in the original arg Geometry it is actually in the
        /// interior due to the Boundary Determination Rule.)
        /// </summary>
        /// <param name="argIndex"></param>
        private void CopyNodesAndLabels(int argIndex)
        {
            foreach (DictionaryEntry entry in _arg[argIndex].Nodes)
            {
                Node graphNode = (Node)entry.Value;
                Node newNode   = _nodes.AddNode(graphNode.GetCoordinate());
                newNode.SetLabel(argIndex, graphNode.Label.GetLocation(argIndex));
                //Trace.WriteLine( _node.ToString() );
            }     // foreach ( object obj in _arg[argIndex].Nodes )
        }         // private void CopyNodesAndLabels(int argIndex)
예제 #6
0
        private void InitializeMap()
        {
            var topBase = new Node(0, new Point(0.5, 0));

            topBase.ControllingPlayer = 0;
            _nodeMap.AddNode(topBase);
            _nodeMap.AddNode(new Node(1, new Point(0.375, 0.25)));
            _nodeMap.AddNode(new Node(2, new Point(0.625, 0.25)));
            _nodeMap.AddNode(new Node(3, new Point(0.25, 0.5)));
            _nodeMap.AddNode(new Node(4, new Point(0.5, 0.5)));
            _nodeMap.AddNode(new Node(5, new Point(0.75, 0.5)));
            _nodeMap.AddNode(new Node(6, new Point(0.375, 0.75)));
            _nodeMap.AddNode(new Node(7, new Point(0.625, 0.75)));
            var bottomBase = new Node(8, new Point(0.5, 1));

            bottomBase.ControllingPlayer = 1;
            _nodeMap.AddNode(bottomBase);

            _nodeMap.AddEdge(0, 1);
            _nodeMap.AddEdge(0, 2);
            _nodeMap.AddEdge(1, 3);
            _nodeMap.AddEdge(1, 4);
            _nodeMap.AddEdge(2, 4);
            _nodeMap.AddEdge(2, 5);
            _nodeMap.AddEdge(3, 6);
            _nodeMap.AddEdge(4, 6);
            _nodeMap.AddEdge(4, 7);
            _nodeMap.AddEdge(5, 7);
            _nodeMap.AddEdge(6, 8);
            _nodeMap.AddEdge(7, 8);
        }
예제 #7
0
    private void AddWorldChunk(Chunk chunk)
    {
        //Also need to add metadata/mob spawns/foilage etc from the patch
        Coordinate position;

        for (int map_y = chunk.yPos; map_y < chunk.yPos + chunk.chunkHeight; map_y++)
        {
            for (int map_x = chunk.xPos; map_x < chunk.xPos + chunk.chunkWidth; map_x++)
            {
                position = new Coordinate(map_x, map_y);
                if (world.IsBlocked(position))
                {
                    world.AddNode(position);
                    AddNodeGrid(position);
                }
            }
        }
    }
    /// <summary>
    /// Adds a node to the nodemap
    /// If no object is selected it adds it and makes it a neighbor of the last node in the map
    /// If an object is selected, but that object is not a node it does the same as above
    /// If an object is selected and it is a node it adds the node as a neighbor to the selected node
    /// </summary>
    private void OnAddNode()
    {
        if (GUILayout.Button("Add Node"))
        {
            map.UpdateAllNodes(false);

            spawnPoint  = map.transform.position;
            spawnOffset = new Vector3(5f, 0f, 0);

            Node newNode;

            // If the user is not selecting a node when adding a node then it will be neighbored to the last node added to the list
            if (selectedNodes == null || selectedNodes.Count == 0)
            {
                Debug.Log("A node is not selected");
                if (map.NodeList.Count > 0)
                {
                    spawnPoint = map.NodeList[map.NodeList.Count - 1].transform.position;
                    newNode    = map.AddNode(spawnPoint + spawnOffset);
                }
                else
                {
                    spawnPoint = map.transform.position;
                    newNode    = map.AddNode(spawnPoint + spawnOffset);
                }

                if (map.NodeList.Count > 1)
                {
                    map.AddNeighbor(newNode, map.NodeList[map.NodeList.Count - 2]);
                }
            }
            else
            {
                Debug.Log("A node is selected");

                // If the user is selecting a node when adding a node then make the new node the neighbor of the currently selected node
                spawnPoint = selectedNodes[0].transform.position;

                newNode = map.AddNode(spawnPoint + spawnOffset);

                map.AddNeighbor(newNode, selectedNodes[0]);
            }
        }
    }
예제 #9
0
 private void AddNodeGrid(Coordinate coordinate)
 {
     for (int x = 0; x < 5; x++)
     {
         for (int y = 0; y < 5; y++)
         {
             nodeMap.AddNode(coordinate * 4 + new Coordinate(x, y));
         }
     }
 }
예제 #10
0
 /// <summary>
 /// Insert nodes for all intersections on the edges of a Geometry.
 /// Label the created nodes the same as the edge label if they do not already have a label.
 /// This allows nodes created by either self-intersections or
 /// mutual intersections to be labelled.
 /// Endpoint nodes will already be labelled from when they were inserted.
 /// Precondition: edge intersections have been computed.
 /// </summary>
 /// <param name="geomGraph"></param>
 /// <param name="argIndex"></param>
 public void ComputeIntersectionNodes(GeometryGraph geomGraph, int argIndex)
 {
     foreach (var e in geomGraph.Edges)
     {
         var eLoc = e.Label.GetLocation(argIndex);
         foreach (var ei in e.EdgeIntersectionList)
         {
             var n = (RelateNode)_nodes.AddNode(ei.Coordinate);
             if (eLoc == Location.Boundary)
             {
                 n.SetLabelBoundary(argIndex);
             }
             else if (n.Label.IsNull(argIndex))
             {
                 n.SetLabel(argIndex, Location.Interior);
             }
         }
     }
 }
예제 #11
0
 /// <summary>
 /// Insert nodes for all intersections on the edges of a Geometry.
 /// Label the created nodes the same as the edge label if they do not already have a label.
 /// This allows nodes created by either self-intersections or
 /// mutual intersections to be labelled.
 /// Endpoint nodes will already be labelled from when they were inserted.
 /// Precondition: edge intersections have been computed.
 /// </summary>
 /// <param name="geomGraph"></param>
 /// <param name="argIndex"></param>
 public virtual void ComputeIntersectionNodes(GeometryGraph geomGraph, int argIndex)
 {
     for (IEnumerator edgeIt = geomGraph.GetEdgeEnumerator(); edgeIt.MoveNext();)
     {
         Edge      e    = (Edge)edgeIt.Current;
         Locations eLoc = e.Label.GetLocation(argIndex);
         for (IEnumerator eiIt = e.EdgeIntersectionList.GetEnumerator(); eiIt.MoveNext();)
         {
             EdgeIntersection ei = (EdgeIntersection)eiIt.Current;
             RelateNode       n  = (RelateNode)nodes.AddNode(ei.Coordinate);
             if (eLoc == Locations.Boundary)
             {
                 n.SetLabelBoundary(argIndex);
             }
             else if (n.Label.IsNull(argIndex))
             {
                 n.SetLabel(argIndex, Locations.Interior);
             }
         }
     }
 }
예제 #12
0
 public void TestIt()
 {
     List<object> results = new List<object>();
     NodeMap<LocalNode> locals = new NodeMap<LocalNode>();
     NodeMap<RemoteNode> remotes = new NodeMap<RemoteNode>();
     var NodeA = new LocalNode("NodeA", new string[] { "Calculator", "Printer" });
     locals.AddNode(NodeA);
     NodeA["Add"] = new FuncEx((sig, args, cb) =>
     {
         cb(new JArray(args[0].Value<int>() + args[1].Value<int>()));
     });
     NodeA["Print"] = new FuncEx((sig, args, cb) =>
     {
         results.Add(args[0].Value<int>());
     });
     Signal s = new Signal(locals, remotes);
     s.Load("NodeA.Calculator.Add(4,4)\n\t(res) => \n\t\tNodeA.Prinaster.Print(res)");
     s.Start();
     Assert.IsTrue(results.Count == 1 && (int)results[0] == 8);
 }