Exemple #1
0
 // StitchWays takes a list of WaysFactory objects to connect those that belong together. The way it works, is it takes the last street from that list
 // it then compares it to all other streets in that list if it can be stitched. Two streets can be stitched (conncected without gaps) if they share points with the same id.
 // If it finds streets with identical Ids, it combines them in the same Street object, and starts over until there are no more streets to connect.
 // This is necessary to combine street sections that belong to same street, but are split up in the XML
 private void StitchWays(List <WaysFactory> queue)
 {
     while (queue.Count > 0)
     {
         string name   = "";
         Street street = new Street();
         for (int i = queue.Count - 1; i >= 0; i--)
         {
             // Get last object in the list
             WaysFactory item = queue[i];
             if (street.Stitch(xmlBaseFactory, item))
             {
                 if (!name.Contains(item.name))
                 {
                     if (name.Length > 0)
                     {
                         name += " ";
                     }
                     name += item.name;
                 }
                 // Remove waterway from list if stitched
                 queue.RemoveAt(i);
                 i = queue.Count - 1;
             }
         }
         // Check if the way contains at least 3 IDs to avoid misplaced items with no connections
         if (street.nodes.Count > 2)
         {
             CreateWaterway(street, name);
         }
     }
 }
Exemple #2
0
    // Calculates the center point of all ids that belong to a way4
    // Returns the local origin
    public Vector3 GetOrigin(WaysFactory allPoints)
    {
        Vector3 sum = new Vector3(0, 0, 0);

        foreach (var w in allPoints.ndref)
        {
            sum += allNodes[w];
        }
        return(sum / allPoints.ndref.Count);
    }
Exemple #3
0
 // Passes all ways to retrieve a list of all way objects
 private void GetWays(XmlNodeList xmlNodeList)
 {
     foreach (XmlNode xmlNode in xmlNodeList)
     {
         WaysFactory waysFactory = new WaysFactory(xmlNode);
         // List of objects of type WaysFactory
         allWayNodes.Add(waysFactory);
         // Center of all points that belong to a way
         GetOrigin(waysFactory);
     }
 }
Exemple #4
0
 //StitchWays takes a list of WaysFactory objects to connect those that belong together. The way it works, is it takes the last street from that list
 //it then compares it to all other streets in that list if it can be stitched. Two streets can be stitched (conncected without gaps) if they share points with the same id.
 //If it finds streets with identical Ids, it combines them in the same Street object, and starts over until there are no more streets to connect.
 //This is necessary to combine street sections that belong to same street, but are split up in the XML
 private void StitchWays(List <WaysFactory> queue)
 {
     while (queue.Count > 0)
     {
         Street street = new Street();
         for (int i = queue.Count - 1; i >= 0; i--)
         {
             // Get last object in the list
             WaysFactory item = queue[i];
             if (street.Stitch(xmlBaseFactory, item))
             {
                 // Remove street from list if stitched
                 queue.RemoveAt(i);
                 i = queue.Count - 1;
             }
         }
         // Check if the way contains at least 3 IDs to avoid misplaced items with no connections
         if (street.nodes.Count > 2)
         {
             CreateStreet(street);
         }
     }
 }
Exemple #5
0
        // Function to stitch the street to the current list of nodes
        public bool Stitch(XmlBaseFactory xmlBaseFactory, WaysFactory street)
        {
            // Create list to append
            List <StreetNode> append = new List <StreetNode>();

            for (int i = 0; i < street.ndref.Count; i++)
            {
                StreetNode node = new StreetNode();
                node.id       = street.ndref[i];
                node.position = xmlBaseFactory.allNodes[node.id] - xmlBaseFactory.boundsFactory.center;
                node.waterway = street.isWaterway;
                append.Add(node);
            }

            // Atemmpt to stitch append list to current list of nodes

            // If street is empty
            if (nodes.Count == 0)
            {
                nodes = append;
            }
            // if the first node in the street is the same as the first node in the street we're trying to stich
            else if (nodes[0].id == append[0].id)
            {
                nodes.Reverse();
                nodes.AddRange(append);
            }
            // if the first node in the street is the same as the last node in the street we're trying to stitch
            else if (nodes[0].id == append[append.Count - 1].id)
            {
                append.AddRange(nodes);
                nodes = append;
            }
            // if the last node in the street is the same as the first node in the street we're trying to stitch
            else if (nodes[nodes.Count - 1].id == append[0].id)
            {
                nodes.AddRange(append);
            }
            // if the last node in the street is the same as the last node in the street we're trying to stitch
            else if (nodes[nodes.Count - 1].id == append[append.Count - 1].id)
            {
                append.Reverse();
                nodes.AddRange(append);
            }
            else
            {
                return(false);
            }

            // Cleanup data
            // Remove duplicate ids
            List <StreetNode> copy = new List <StreetNode>();

            for (int i = 0; i < nodes.Count; i++)
            {
                if (copy.Count == 0 || copy[copy.Count - 1].id != nodes[i].id)
                {
                    copy.Add(nodes[i]);
                }
            }
            nodes = copy;

            // Remove single waterways
            for (int i = 0; i < nodes.Count; i++)
            {
                bool fPrev = i - 1 >= 0 ? nodes[i - 1].waterway : !nodes[i].waterway;
                bool fNext = i + 1 < nodes.Count ? nodes[i + 1].waterway : !nodes[i].waterway;
                bool fCurr = nodes[i].waterway;
                if (fCurr != fPrev && fCurr != fNext)
                {
                    nodes[i].waterway = !(nodes[i].waterway);
                }
            }

            // Check if waterway is looped
            looped = nodes.Count > 2 && nodes[0].id == nodes[nodes.Count - 1].id;

            return(true);
        }