Example #1
0
        private static void UpdateNeighbours(RouteFeature[] features)
        {
            Console.WriteLine("Updating feature neigbours");

            double amount = 0, temp = 0, all = features.Length;

            for (var i = 0; i < features.Length - 1; i++)
            {
                amount++;
                temp++;
                if (temp > all / 100)
                {
                    Console.WriteLine(Math.Round(amount / all * 100, 2));
                    temp = 0;
                }

                for (var j = i + 1; j < features.Length; j++)
                {
                    if (DistanceHelpers.AreNeighbours(features[i].Data.Coordinates.Select(x => x.ToDoubleArray()).ToArray(), features[j].Data.Coordinates.Select(x => x.ToDoubleArray()).ToArray()))
                    {
                        features[i].Neighbours.Add(features[j]);
                        features[j].Neighbours.Add(features[i]);
                    }
                }
            }
        }
Example #2
0
        //TODO optimize for neigboring cells
        private void UpdateNeighbours(Dictionary <string, CellData> cellToFeatures, GridCell cell)
        {
            //Console.WriteLine("Updating feature neigbhours");


            var neighbourinCells = GetTempGridCells(new[] { cell });


            double amount = 0, temp = 0, all = cellToFeatures[cell.Index].BorderFeatures.Length;

            var newFeatures = cellToFeatures[cell.Index].BorderFeatures;

            var borderFeatures = cellToFeatures.Where(x => x.Key != cell.Index && neighbourinCells.Any(y => y.Index == x.Key)).SelectMany(x => x.Value.BorderFeatures)
                                 .ToArray();

            for (var i = 0; i < all; i++)
            {
                amount++;
                temp++;
                if (temp > all / 100)
                {
                    //Console.WriteLine(Math.Round(amount / all * 100, 2));
                    temp = 0;
                }

                for (var j = 0; j < borderFeatures.Length; j++)
                {
                    if (DistanceHelpers.AreNeighbours(
                            newFeatures[i].Data.Coordinates.Select(x => x.ToDoubleArray()).ToArray(),
                            borderFeatures[j].Data.Coordinates.Select(x => x.ToDoubleArray()).ToArray()))
                    {
                        newFeatures[i].Neighbours.Add(borderFeatures[j]);
                        borderFeatures[j].Neighbours.Add(newFeatures[i]);
                    }
                }
            }
        }