Ejemplo n.º 1
0
        public static bool IsPointInPolygon(Polygon polygon, PointF testPoint, Size box)
        {
            bool result = false;
            int  j      = polygon.polygonPoints.Count() - 1;

            for (int i = 0; i < polygon.polygonPoints.Count(); i++)
            {
                PointF leftPoint  = HelperFunctions.CoordinateToPoint(polygon.polygonPoints[i], box);
                PointF rightPoint = HelperFunctions.CoordinateToPoint(polygon.polygonPoints[j], box);
                if (leftPoint.Y < testPoint.Y && rightPoint.Y >= testPoint.Y || rightPoint.Y < testPoint.Y && leftPoint.Y >= testPoint.Y)
                {
                    if (leftPoint.X + (testPoint.Y - leftPoint.Y) / (rightPoint.Y - leftPoint.Y) * (rightPoint.X - leftPoint.X) < testPoint.X)
                    {
                        result = !result;
                    }
                }
                j = i;
            }
            return(result);
        }
Ejemplo n.º 2
0
        void ProcessData()
        {
            Dictionary <string, string> savedLocations = new Dictionary <string, string>();
            StreamReader reader = new StreamReader("infected.csv");
            var          dates  = HelperFunctions.SplitCsv(reader.ReadLine());

            dates.Skip(4).ToList().ForEach((date) => this.dates.Add(DateTime.Parse(date)));

            while (!reader.EndOfStream)
            {
                var    entry  = HelperFunctions.SplitCsv(reader.ReadLine());
                PointD coords = new PointD(double.Parse(entry[2]), double.Parse(entry[3]));

                List <int> infected = new List <int>();
                entry.Skip(4).ToList().ForEach((infection) =>
                {
                    try { infected.Add(int.Parse(infection)); }
                    catch { try { infected.Add(infected.Last()); } catch { infected.Add(0); } }
                });
                if (savedLocations.ContainsKey(entry[1]))
                {
                    if (countries[savedLocations[entry[1]]].infected.Count == 0)
                    {
                        countries[savedLocations[entry[1]]].infected = infected;
                    }
                    else
                    {
                        for (int i = 0; i < countries[savedLocations[entry[1]]].infected.Count; i++)
                        {
                            countries[savedLocations[entry[1]]].infected[i] += infected[i];
                        }
                    }
                    continue;
                }
                if (countries.ContainsKey(entry[1]))
                {
                    if (countries[entry[1]].infected.Count == 0)
                    {
                        countries[entry[1]].infected = infected;
                    }
                    else
                    {
                        for (int i = 0; i < countries[entry[1]].infected.Count; i++)
                        {
                            countries[entry[1]].infected[i] += infected[i];
                        }
                    }
                    continue;
                }
                foreach (var country in countries.Values)
                {
                    bool inside = false;
                    foreach (var poly in country.polygons)
                    {
                        if (HelperFunctions.IsPointInPolygon(poly, HelperFunctions.CoordinateToPoint(coords, bmp.Size), bmp.Size))
                        {
                            inside = true;
                        }
                    }
                    if (inside)
                    {
                        savedLocations.Add(entry[1], country.name);
                        if (country.infected.Count == 0)
                        {
                            country.infected = infected;
                        }
                        else
                        {
                            for (int i = 0; i < country.infected.Count; i++)
                            {
                                country.infected[i] += infected[i];
                            }
                            this.slider_timeline.Maximum = country.infected.Count - 1;
                        }
                        break;
                    }
                }
            }
            reader = new StreamReader("dead.csv");
            reader.ReadLine();
            while (!reader.EndOfStream)
            {
                var        entry  = HelperFunctions.SplitCsv(reader.ReadLine());
                PointD     coords = new PointD(double.Parse(entry[2]), double.Parse(entry[3]));
                List <int> dead   = new List <int>();
                entry.Skip(4).ToList().ForEach((death) =>

                {
                    try { dead.Add(int.Parse(death)); }
                    catch { try { dead.Add(dead.Last()); } catch { dead.Add(0); } }
                });
                if (savedLocations.ContainsKey(entry[1]))
                {
                    if (countries[savedLocations[entry[1]]].dead.Count == 0)
                    {
                        countries[savedLocations[entry[1]]].dead = dead;
                    }
                    else
                    {
                        for (int i = 0; i < countries[savedLocations[entry[1]]].dead.Count; i++)
                        {
                            countries[savedLocations[entry[1]]].dead[i] += dead[i];
                        }
                    }
                    continue;
                }
                foreach (var country in countries.Values)
                {
                    bool inside = false;
                    foreach (var poly in country.polygons)
                    {
                        if (HelperFunctions.IsPointInPolygon(poly, HelperFunctions.CoordinateToPoint(coords, bmp.Size), bmp.Size))
                        {
                            inside = true;
                        }
                    }

                    if (inside)
                    {
                        if (country.dead.Count == 0)
                        {
                            country.dead = dead;
                        }
                        else
                        {
                            for (int i = 0; i < country.dead.Count; i++)
                            {
                                country.dead[i] += dead[i];
                            }
                        }
                        break;
                    }
                }
            }
            reader = new StreamReader("recovered.csv");
            reader.ReadLine();
            while (!reader.EndOfStream)
            {
                var        entry     = HelperFunctions.SplitCsv(reader.ReadLine());
                PointD     coords    = new PointD(double.Parse(entry[2]), double.Parse(entry[3]));
                List <int> recovered = new List <int>();
                entry.Skip(4).ToList().ForEach((recover) =>

                {
                    try { recovered.Add(int.Parse(recover)); }
                    catch { try { recovered.Add(recovered.Last()); } catch { recovered.Add(0); } }
                }); if (savedLocations.ContainsKey(entry[1]))
                {
                    if (countries[savedLocations[entry[1]]].recovered.Count == 0)
                    {
                        countries[savedLocations[entry[1]]].recovered = recovered;
                    }
                    else
                    {
                        for (int i = 0; i < countries[savedLocations[entry[1]]].recovered.Count; i++)
                        {
                            countries[savedLocations[entry[1]]].recovered[i] += recovered[i];
                        }
                    }
                    continue;
                }
                foreach (var country in countries.Values)
                {
                    bool inside = false;
                    foreach (var poly in country.polygons)
                    {
                        if (HelperFunctions.IsPointInPolygon(poly, HelperFunctions.CoordinateToPoint(coords, bmp.Size), bmp.Size))
                        {
                            inside = true;
                        }
                    }
                    if (inside)
                    {
                        if (country.recovered.Count == 0)
                        {
                            country.recovered = recovered;
                        }
                        else
                        {
                            for (int i = 0; i < country.recovered.Count; i++)
                            {
                                country.recovered[i] += recovered[i];
                            }
                        }
                        break;
                    }
                }
            }

            reader.Close();
        }