Esempio n. 1
0
 public void Drawer_NullReadonlyVoronoi_IOException()
 {
     ReadonlyBitmap.Set(null);
     using (var writer = new Drawer(new Bitmap(10, 10)))
     {
         writer.DrawVoronoi(Fortunes.Run(9, 9, new Point2D[] {}));
     }
 }
Esempio n. 2
0
        public void LotsaPoints_Random_VerifyRegions()
        {
            var output  = Fortunes.Run(1000, 1000, 1000);
            var lines   = output.OutputLines(1000, 1000);
            var origins = output.Sites;
            var count   = origins.Count(site => output.OutputRegion(site, lines).Count == 0);

            Assert.IsTrue(count < 5);
        }
Esempio n. 3
0
 public void Drawer_HappyPath_IsHappy()
 {
     ReadonlyBitmap.Set(new Bitmap(10, 10));
     using (var writer = new Drawer(ReadonlyBitmap.Get()))
     {
         writer.DrawVoronoi(Fortunes.Run(9, 9, new[] { new Point2D(0, 0), new Point2D(5, 5) }));
         writer.SaveToNewImageFile("a.png", Directory.GetCurrentDirectory());
         writer.SaveToNewImageFile("a.png", Directory.GetCurrentDirectory());
     }
 }
Esempio n. 4
0
        public void OnePoint_Normal_CorrectSize()
        {
            var set = new Point2D[1];

            set[0] = new Point2D(5, 5);

            var output  = Fortunes.Run(9, 9, set);
            var lines   = output.OutputLines(9, 9);
            var origins = output.Sites;
            var region  = output.OutputRegion(origins[0], lines);

            Assert.AreEqual(1, origins.Length);
            Assert.AreEqual(81, region.Count);
        }
Esempio n. 5
0
        public void TwoPoints_DuplicatePoints_Happy()
        {
            var set = new Point2D[2];

            set[0] = new Point2D(5, 5);
            set[1] = new Point2D(5, 5);

            var output  = Fortunes.Run(9, 9, set);
            var lines   = output.OutputLines(9, 9);
            var origins = output.Sites;
            var region  = output.OutputRegion(origins[0], lines);

            Assert.AreEqual(2, origins.Length);
            Assert.AreEqual(81, region.Count);
        }
Esempio n. 6
0
        private static void Run(int iterations, Bitmap newImage, string fileName, string fileDirectory, int numberOfPointsToPlot)
        {
            ReadonlyBitmap.Set(newImage);
            var nums   = Enumerable.Range(0, iterations).ToArray();
            var result = new ConcurrentDictionary <VoronoiOutput, double>();

            Parallel.ForEach(nums, _ =>
            {
                var voronoiOutput = Fortunes.Run(ReadonlyBitmap.Get().Width, ReadonlyBitmap.Get().Height, numberOfPointsToPlot);
                var averageDeltaE = voronoiOutput.CalculateAccuracy();
                result.TryAdd(voronoiOutput, averageDeltaE);
            });
            var bestVoronoi = result.Aggregate((l, r) => l.Value < r.Value ? l : r).Key;

            using (var writer = new Drawer(newImage))
            {
                writer.DrawVoronoi(bestVoronoi);
                writer.SaveToNewImageFile(fileName, fileDirectory);
            }
        }
Esempio n. 7
0
        public void TwoPoints_Diag_CorrectSize()
        {
            var set = new Point2D[2];

            set[0] = new Point2D(3, 3);
            set[1] = new Point2D(7, 7);

            var output  = Fortunes.Run(9, 9, set);
            var lines   = output.OutputLines(9, 9);
            var origins = output.Sites;
            var region1 = output.OutputRegion(origins[0], lines);
            var region2 = output.OutputRegion(origins[1], lines);

            //Line endpoints are right, in 0,0 index
            Assert.IsTrue(lines[8, 0]);
            Assert.IsTrue(lines[0, 8]);

            Assert.AreEqual(2, origins.Length);
            Assert.AreEqual(72, region1.Count + region2.Count); //9*9-9(for the line) = 72
            Assert.AreEqual(36, region1.Count);
        }
Esempio n. 8
0
        private static void Main()
        {
            Console.Out.WriteLine("Started");
            var output  = Fortunes.Run(Width, Height, NumSites);
            var lines   = output.OutputLines(Width, Height);
            var origins = output.Sites;

            output.OutputConsole();

            output.OutputFile(Width, Height);
            Console.Out.WriteLine("File Created");


            foreach (var site in origins)
            {
                var region = output.OutputRegion(site, lines);
                //TODO Process regions
            }

            output.PrintRegions(Width, Height);

            Console.Out.WriteLine("Finished");
        }