Пример #1
0
        public int FindTile(Coordinates c, int hint = -1)
        {
            int[] indices;
            if (hint < 0)
            {
                indices = Enumerable.Range(0, Tiles.Length).ToArray();
            }
            else
            {
                var tmp = Tiles[hint].Neighbours;
                indices    = new int[1 + tmp.Length];
                indices[0] = hint;
                for (int i = 0; i < tmp.Length; i++)
                {
                    indices[i + 1] = tmp[i];
                }
            }

            int    bestidx  = -1;
            double bestdist = double.MaxValue;

            foreach (int i in indices)
            {
                double dist = Coordinates.Distance(c, Tiles[i].Center);
                if (dist < bestdist)
                {
                    bestidx  = i;
                    bestdist = dist;
                }
            }

            return(bestidx);
        }
Пример #2
0
        void UpdatePositionWorker()
        {
            lock (this)
            {
                if (NextPosition == LastUpdatedPosition)
                {
                    return;
                }

                LastUpdatedPosition = NextPosition;
            }

            data.RemoveOldElements(x => Coordinates.Distance(LastUpdatedPosition, Tiles[x].Center));

                        #if false
            foreach (var i in FindTiles(LastUpdatedPosition, 0.05))
            {
                data[i].Load(TileData.Computationlevel.MAX);
            }
                        #else
            int tile = FindTile(LastUpdatedPosition);
            if (tile == LastTile)
            {
                return;
            }
            LastTile = tile;

            data[LastTile].Load(TileData.ComputationLevel.MAX);
                        #endif
        }
Пример #3
0
        public List <int> FindTiles(Coordinates c, double distance, int hint = -1)
        {
            /*List<int> ret = new List<int>();
             * ret.Add(FindTile(c, hint));
             *
             * while(true)
             * {
             *      List<int> newtiles = ret.SelectMany(x => Tiles[x].Neighbours).Where(x => Coordinates.Distance(Tiles[x].Center, c) < distance && !ret.Contains(x)).ToList();
             *      if (newtiles.Count == 0)
             *              return ret;
             *      ret.AddRange(newtiles);
             * }*/

            return(Enumerable.Range(0, Tiles.Length).Where(x => Coordinates.Distance(Tiles[x].Center, c) < distance).ToList());
        }
Пример #4
0
        public Bezier(List <Coordinates> coordinates, double radius)
        {
            if (coordinates.Count < 2)
            {
                throw new ArgumentException("At least two coordinates are required", "coordinates");
            }

            coord       = coordinates;
            this.radius = radius;
            length      = 0;

            for (int i = 1, n = coord.Count; i < n; i++)
            {
                length += Coordinates.Distance(coord[i - 1], coord[i]);
            }

            ComputeCnp();
        }
Пример #5
0
 public double Heuristic(int index1, int index2)
 {
     return(Coordinates.Distance(Tiles[index1].Center, Tiles[index2].Center));
 }
Пример #6
0
 public double Cost(int index1, int index2)
 {
     return(Coordinates.Distance(Tiles[index1].Center, Tiles[index2].Center));            // FIXME
 }