public void Load(string starsFile)
        {
            Stars = new List <LocalSectorStar>();

            CsvReader reader = new CsvReader(File.OpenText(starsFile), System.Globalization.CultureInfo.CurrentCulture);

            reader.Read();
            reader.ReadHeader();
            while (reader.Read())
            {
                string designation = reader["Designation"];

                if (string.IsNullOrEmpty(designation) || designation.StartsWith("A("))
                {
                    continue;
                }

                LocalSectorStar star = new LocalSectorStar();
                star.Designation = designation;

                string pos = reader["Position"];
                if (!string.IsNullOrEmpty(pos) && Point3d.TryParse(pos, out var position))
                {
                    star.Position = position;
                }

                star.Name    = reader["Name"];
                star.Cluster = reader["Cluster"];

                Stars.Add(star);
            }
        }
Example #2
0
        public void NearestStars()
        {
            LocalSectorStarsReader reader = new LocalSectorStarsReader();

            reader.Load(Path.Combine(TestingUtilities.Config["DataPath"], "LocalSector Stars.csv"));
            IList <LocalSectorStar> stars = reader.Stars;

            string          starName = "Little Ophiuchi";
            LocalSectorStar star     = stars.Where(s => s.Name == starName).First();

            double distance = 20 / 3.261633;
            var    nearest  = stars.Where(s => AstronomicalFunctions.Distance(s.Position, star.Position) <= distance);

            if (nearest != null)
            {
                using (StreamWriter writer = new StreamWriter(Path.Combine(TestingUtilities.Config["DataPath"], "Closest.txt")))
                {
                    foreach (LocalSectorStar s in nearest)
                    {
                        writer.Write(s.Designation);
                        writer.Write(" - ");
                        writer.Write(s.Name);
                        writer.Write(" - ");
                        writer.Write(s.Cluster);
                        writer.Write(" - ");
                        writer.WriteLine(AstronomicalFunctions.Distance(s.Position, star.Position) * 3.261633);
                    }
                }
            }
        }