Repository: RafaelKuebler/DelaunayVoronoi Branch: master Commit: 1e4bbd13435d Files: 22 Total size: 83.7 KB Directory structure: gitextract_vqdk94c3/ ├── .gitignore ├── DelaunayVoronoi/ │ ├── App.config │ ├── App.xaml │ ├── App.xaml.cs │ ├── Delaunay.cs │ ├── DelaunayVoronoi.csproj │ ├── Edge.cs │ ├── MainWindow.xaml │ ├── MainWindow.xaml.cs │ ├── Point.cs │ ├── Properties/ │ │ ├── Annotations.cs │ │ ├── AssemblyInfo.cs │ │ ├── Resources.Designer.cs │ │ ├── Resources.resx │ │ ├── Settings.Designer.cs │ │ └── Settings.settings │ ├── Triangle.cs │ └── Voronoi.cs ├── DelaunayVoronoi.sln ├── DelaunayVoronoi.sln.DotSettings ├── LICENSE.txt └── README.md ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ # Modified from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore # User-specific files *.suo *.user *.userosscache *.sln.docstates # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs # Build results [Dd]ebug/ [Dd]ebugPublic/ [Rr]elease/ [Rr]eleases/ x64/ x86/ bld/ [Bb]in/ [Oo]bj/ [Ll]og/ # Visual Studio 2015/2017 cache/options directory .vs/ # Visual Studio 2017 auto generated files Generated\ Files/ # .NET Core project.lock.json project.fragment.lock.json artifacts/ # Files built by Visual Studio *_i.c *_p.c *_i.h *.ilk *.meta *.obj *.iobj *.pch *.pdb *.ipdb *.pgc *.pgd *.rsp *.sbr *.tlb *.tli *.tlh *.tmp *.tmp_proj *.log *.vspscc *.vssscc .builds *.pidb *.svclog *.scc # Visual Studio code coverage results *.coverage *.coveragexml # NuGet Packages *.nupkg # The packages folder can be ignored because of Package Restore **/[Pp]ackages/* # except build/, which is used as an MSBuild target. !**/[Pp]ackages/build/ # Uncomment if necessary however generally it will be regenerated when needed #!**/[Pp]ackages/repositories.config # NuGet v3's project.json files produces more ignorable files *.nuget.props *.nuget.targets # Visual Studio cache files # files ending in .cache can be ignored *.[Cc]ache # but keep track of directories ending in .cache !*.[Cc]ache/ ================================================ FILE: DelaunayVoronoi/App.config ================================================  ================================================ FILE: DelaunayVoronoi/App.xaml ================================================  ================================================ FILE: DelaunayVoronoi/App.xaml.cs ================================================ using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Linq; using System.Threading.Tasks; using System.Windows; namespace DelaunayVoronoi { /// /// Interaction logic for App.xaml /// public partial class App : Application { } } ================================================ FILE: DelaunayVoronoi/Delaunay.cs ================================================ using System; using System.Collections.Generic; using System.Linq; namespace DelaunayVoronoi { public class DelaunayTriangulator { private double MaxX { get; set; } private double MaxY { get; set; } private IEnumerable border; public IEnumerable GeneratePoints(int amount, double maxX, double maxY) { MaxX = maxX; MaxY = maxY; // TODO make more beautiful var point0 = new Point(0, 0); var point1 = new Point(0, MaxY); var point2 = new Point(MaxX, MaxY); var point3 = new Point(MaxX, 0); var points = new List() { point0, point1, point2, point3 }; var tri1 = new Triangle(point0, point1, point2); var tri2 = new Triangle(point0, point2, point3); border = new List() { tri1, tri2 }; var random = new Random(); for (int i = 0; i < amount - 4; i++) { var pointX = random.NextDouble() * MaxX; var pointY = random.NextDouble() * MaxY; points.Add(new Point(pointX, pointY)); } return points; } public IEnumerable BowyerWatson(IEnumerable points) { //var supraTriangle = GenerateSupraTriangle(); var triangulation = new HashSet(border); foreach (var point in points) { var badTriangles = FindBadTriangles(point, triangulation); var polygon = FindHoleBoundaries(badTriangles); foreach (var triangle in badTriangles) { foreach (var vertex in triangle.Vertices) { vertex.AdjacentTriangles.Remove(triangle); } } triangulation.RemoveWhere(o => badTriangles.Contains(o)); foreach (var edge in polygon.Where(possibleEdge => possibleEdge.Point1 != point && possibleEdge.Point2 != point)) { var triangle = new Triangle(point, edge.Point1, edge.Point2); triangulation.Add(triangle); } } //triangulation.RemoveWhere(o => o.Vertices.Any(v => supraTriangle.Vertices.Contains(v))); return triangulation; } private List FindHoleBoundaries(ISet badTriangles) { var edges = new List(); foreach (var triangle in badTriangles) { edges.Add(new Edge(triangle.Vertices[0], triangle.Vertices[1])); edges.Add(new Edge(triangle.Vertices[1], triangle.Vertices[2])); edges.Add(new Edge(triangle.Vertices[2], triangle.Vertices[0])); } var grouped = edges.GroupBy(o => o); var boundaryEdges = edges.GroupBy(o => o).Where(o => o.Count() == 1).Select(o => o.First()); return boundaryEdges.ToList(); } private Triangle GenerateSupraTriangle() { // 1 -> maxX // / \ // 2---3 // | // v maxY var margin = 500; var point1 = new Point(0.5 * MaxX, -2 * MaxX - margin); var point2 = new Point(-2 * MaxY - margin, 2 * MaxY + margin); var point3 = new Point(2 * MaxX + MaxY + margin, 2 * MaxY + margin); return new Triangle(point1, point2, point3); } private ISet FindBadTriangles(Point point, HashSet triangles) { var badTriangles = triangles.Where(o => o.IsPointInsideCircumcircle(point)); return new HashSet(badTriangles); } } } ================================================ FILE: DelaunayVoronoi/DelaunayVoronoi.csproj ================================================  Debug AnyCPU {0FC94494-D51B-49E9-927D-1F0007C1FEA1} WinExe Delaunay Delaunay v4.6.1 512 {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 4 true AnyCPU true full false bin\Debug\ DEBUG;TRACE prompt 4 AnyCPU pdbonly true bin\Release\ TRACE prompt 4 4.0 MSBuild:Compile Designer MSBuild:Compile Designer App.xaml Code MainWindow.xaml Code Code True True Resources.resx True Settings.settings True ResXFileCodeGenerator Resources.Designer.cs SettingsSingleFileGenerator Settings.Designer.cs ================================================ FILE: DelaunayVoronoi/Edge.cs ================================================ namespace DelaunayVoronoi { public class Edge { public Point Point1 { get; } public Point Point2 { get; } public Edge(Point point1, Point point2) { Point1 = point1; Point2 = point2; } public override bool Equals(object obj) { if (obj == null) return false; if (obj.GetType() != GetType()) return false; var edge = obj as Edge; var samePoints = Point1 == edge.Point1 && Point2 == edge.Point2; var samePointsReversed = Point1 == edge.Point2 && Point2 == edge.Point1; return samePoints || samePointsReversed; } public override int GetHashCode() { int hCode = (int)Point1.X ^ (int)Point1.Y ^ (int)Point2.X ^ (int)Point2.Y; return hCode.GetHashCode(); } } } ================================================ FILE: DelaunayVoronoi/MainWindow.xaml ================================================