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[] {})); } }
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); }
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()); } }
public List <Fortune> Any(Fortunes request) { var fortunes = new List <Fortune>(); fortunes.AddRange(Db.Select <Fortune>()); fortunes.Add(new Fortune { id = 0, message = "Additional fortune added at request time." }); fortunes.Sort(); return(fortunes); }
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); }
private void Start() { Fortunes fortunes = new Fortunes(); List <FortuneSite> sites = new List <FortuneSite> { new FortuneSite(100, 200), new FortuneSite(500, 200), new FortuneSite(300, 300) }; LinkedList <Edge> edges = fortunes.GenerateVoronoi(sites, 0, 0, 800, 800); Debug.Log("Edges size: " + edges.Count); }
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); }
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); } }
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); }
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"); }