Beispiel #1
0
 private void AStarInit(out List <Node> prioQueue, MapLoc originMapLoc, MapLoc destinationMapLoc)
 {
     foreach (Node n in nodelist)
     {
         n.distanceTo[destinationMapLoc] = MapUtil.Distance(n.loc, destinationMapLoc);
     }
     nodeDict[originMapLoc].distanceFrom[originMapLoc] = 0f;
     prioQueue = new List <Node>();
     prioQueue.Add(nodeDict[originMapLoc]);
 }
Beispiel #2
0
    public static float CostStandard(MapLoc l, MapLoc n, float[,] _elevation, float _seaLevel, float _seaTravelCost)
    {
        float nelev = _elevation[n.x, n.y];
        float lelev = _elevation[l.x, l.y];
        float diff  = (nelev > _seaLevel && lelev > _seaLevel) ? Math.Abs(nelev - lelev) : _seaTravelCost;
        float dist  = MapUtil.Distance(n, l);

        diff *= dist;
        diff += dist;
        return(diff);
    }
        private bool UpdateGPSPositionIfSignificantChange(CLLocation newLocation, CLLocation previousLocation)
        {
            double lat1 = newLocation.Coordinate.Latitude;
            double lon1 = newLocation.Coordinate.Longitude;

            if (previousLocation == null || MapUtil.Distance(lat1, lon1, previousLocation.Coordinate.Latitude, previousLocation.Coordinate.Longitude, MapUtil.UnitOfLength.Meters) > distanceToUpdateAddress)
            {
                AppDelegate.current.mainViewController.InvokeOnMainThread(delegate
                {
                    AppDelegate.current.locationManager.lastPositionType = PositionTypeConst.found;
                    NSNotificationCenter.DefaultCenter.PostNotificationName(EventConst.setupPosition, null);

                    NSNotificationCenter.DefaultCenter.PostNotificationName(EventConst.centerCurrentLocation, null);
                });

                return(true);
            }

            return(false);
        }
Beispiel #4
0
 public MapPainter(float[,] _elevation, float _seaLevel)
 {
     nodelist      = new List <Node>();
     elevation     = _elevation;
     seaLevel      = _seaLevel;
     xDim          = _elevation.GetLength(0);
     yDim          = _elevation.GetLength(1);
     Node[,] nodes = new Node[xDim, yDim];
     for (int x = 0; x < xDim; x++)
     {
         for (int y = 0; y < yDim; y++)
         {
             nodes[x, y] = new Node(x, y);
         }
     }
     for (int x = 0; x < xDim; x++)
     {
         for (int y = 0; y < yDim; y++)
         {
             Node n = nodes[x, y];
             n.Visited = false;
             MapLoc l = new MapLoc(x, y);
             Dictionary <MapLoc, float> d = MapUtil.GetValidNeighbors(_elevation, l);
             foreach (KeyValuePair <MapLoc, float> kvp in d)
             {
                 if ((_elevation[x, y] > _seaLevel && _elevation[kvp.Key.x, kvp.Key.y] > _seaLevel) ||
                     (_elevation[x, y] < _seaLevel && _elevation[kvp.Key.x, kvp.Key.y] < _seaLevel))
                 {
                     n.neighborWeights[nodes[kvp.Key.x, kvp.Key.y]] = MapUtil.Distance(kvp.Key, l);
                     n.neighbors.Add(nodes[kvp.Key.x, kvp.Key.y]);
                 }
             }
             nodelist.Add(n);
             nodedict[n.loc] = n;
         }
     }
     Paint();
 }
Beispiel #5
0
    private void AddPath(MapLoc origin, MapLoc destination, bool addBetweenPaths = false)
    {
        float       dP           = 0f;
        List <Node> shortestPath = new List <Node>();
        Node        thisNode     = nodeDict[destination];

        shortestPath.Add(thisNode);
        while (!thisNode.loc.Equals(origin))
        {
            dP      += thisNode.neighborWeights[thisNode.NearestTo[origin]];
            thisNode = thisNode.NearestTo[origin];
            shortestPath.Add(thisNode);
        }
        shortestPath.Reverse();
        float dE = MapUtil.Distance(origin, destination);
        Path  p  = new Path(origin, destination, shortestPath, dP, dE);

        PathDict[new PathOD(origin, destination)] = p;
        if (addBetweenPaths)
        {
            List <PathOD> betweenPaths = new List <PathOD>();
            int           iWindow      = shortestPath.Count - 2;
            while (iWindow > 0)
            {
                for (int i = 0; i < (shortestPath.Count - iWindow); i++)
                {
                    PathOD betweenPath = new PathOD(shortestPath[i].loc, shortestPath[i + iWindow].loc);
                    betweenPaths.Add(betweenPath);
                }
                iWindow--;
            }
            foreach (PathOD pOD in betweenPaths)
            {
                AddPath(pOD.origin, pOD.destination, false);
            }
        }
    }