diff --git a/.vs/opdracht2/DesignTimeBuild/.dtbcache.v2 b/.vs/opdracht2/DesignTimeBuild/.dtbcache.v2 index 0987f7f..d9bb835 100644 Binary files a/.vs/opdracht2/DesignTimeBuild/.dtbcache.v2 and b/.vs/opdracht2/DesignTimeBuild/.dtbcache.v2 differ diff --git a/.vs/opdracht2/v16/.suo b/.vs/opdracht2/v16/.suo index c3f06d1..7207dd9 100644 Binary files a/.vs/opdracht2/v16/.suo and b/.vs/opdracht2/v16/.suo differ diff --git a/Datalaag/obj/Debug/Datalaag.csprojAssemblyReference.cache b/Datalaag/obj/Debug/Datalaag.csprojAssemblyReference.cache index e4d0fe0..38e8623 100644 Binary files a/Datalaag/obj/Debug/Datalaag.csprojAssemblyReference.cache and b/Datalaag/obj/Debug/Datalaag.csprojAssemblyReference.cache differ diff --git a/Globals/PolygonPunten.cs b/Globals/PolygonPunten.cs index 1dc49a7..6e8f95e 100644 --- a/Globals/PolygonPunten.cs +++ b/Globals/PolygonPunten.cs @@ -5,8 +5,6 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Shapes; using GeoJSON.Net.Geometry; -using Polygon = GeoJSON.Net.Geometry.Polygon; - namespace Globals { public class PolygonPunten @@ -25,7 +23,7 @@ namespace Globals MinimumY = punten.Min(punt => punt.Y); } - public PolygonPunten(Polygon p, string naam = "") + public PolygonPunten(GeoJSON.Net.Geometry.Polygon p, string naam = "") { Naam = naam; Punten = new List(); @@ -45,6 +43,7 @@ namespace Globals } } } + } } diff --git a/Globals/Punt.cs b/Globals/Punt.cs index da20ea7..7907b0d 100644 --- a/Globals/Punt.cs +++ b/Globals/Punt.cs @@ -24,7 +24,7 @@ namespace Globals else return Naam; } - public Point GetPoint() + public Point ToPoint() { return new Point(X, Y); } diff --git a/Globals/obj/Debug/DesignTimeResolveAssemblyReferences.cache b/Globals/obj/Debug/DesignTimeResolveAssemblyReferences.cache new file mode 100644 index 0000000..a7bdf91 Binary files /dev/null and b/Globals/obj/Debug/DesignTimeResolveAssemblyReferences.cache differ diff --git a/Globals/obj/Debug/Globals.csprojAssemblyReference.cache b/Globals/obj/Debug/Globals.csprojAssemblyReference.cache index 89b013e..10cf3cd 100644 Binary files a/Globals/obj/Debug/Globals.csprojAssemblyReference.cache and b/Globals/obj/Debug/Globals.csprojAssemblyReference.cache differ diff --git a/Logica/Logica.csproj b/Logica/Logica.csproj index cef4a9c..47d5b4a 100644 --- a/Logica/Logica.csproj +++ b/Logica/Logica.csproj @@ -41,7 +41,7 @@ - + diff --git a/Logica/Class1.cs b/Logica/PolygonManipulatie.cs similarity index 50% rename from Logica/Class1.cs rename to Logica/PolygonManipulatie.cs index 25a0957..5b29148 100644 --- a/Logica/Class1.cs +++ b/Logica/PolygonManipulatie.cs @@ -16,28 +16,67 @@ namespace Logica JsonReader = jsonReader; } - public List getPolygons() + public List GetPolygons() { return JsonReader._polygons; } - public List getMultiPolygons() + public List GetMultiPolygons() { return JsonReader._multiPolygons; } - public List getAllPolygons() + public PolygonPunten GetPolygonByName(string naam) + { + return JsonReader._polygons.Find(punten => punten.Naam == naam); + } + + public List GetTrianglesPolygon(PolygonPunten polygon, double scaleX + = 1, double scaleY = 1, double epsilonPercet = 0) + { + double grootsteAfstandX = Math.Abs(polygon.MaximumX - polygon.MinimumX); + double grootsteAfstandY = Math.Abs(polygon.MaximumY - polygon.MinimumY); + double epsilon = ((grootsteAfstandX + grootsteAfstandY) / 2) * epsilonPercet; + polygon.Punten = Peuker(polygon.Punten, epsilon); + polygon = ScalePolygon(polygon, scaleX, scaleY); + return TriangulatePolygon(polygon); + } + + private PolygonPunten ScalePolygon(PolygonPunten polygon, double scaleX, double scaleY) + { + double maxX = polygon.MaximumX; + double maxY = polygon.MaximumY; + double minX = polygon.MinimumX; + double minY = polygon.MinimumY; + maxX -= minX; + maxY -= minY; + List returnWaarde = new List(); + foreach (Punt punt in polygon.Punten) + { + double x = punt.X - minX; + x /= maxX; + x *= scaleX; + double y = punt.Y - minY; + y /= maxY; + y *= scaleY; + returnWaarde.Add(new Punt(x, y, punt.Naam)); + + } + return new PolygonPunten(returnWaarde, polygon.Naam); + } + + public List GetAllPolygons() { List lijst = new List(); - lijst.AddRange(getPolygons()); - foreach (MultiPolygonPunten multiPolygonPunten in getMultiPolygons()) + lijst.AddRange(GetPolygons()); + foreach (MultiPolygonPunten multiPolygonPunten in GetMultiPolygons()) { lijst.AddRange(multiPolygonPunten.PolygonPunten); } return lijst; } - public List triangulatePolygon(List punten) + public List TriangulatePolygon(List punten) { List returnWaarde = new List(); int i = 0; @@ -45,7 +84,6 @@ namespace Logica int BACKBACKUP = punten.Count; while (true) { - if (i >= punten.Count) { i = 0; @@ -56,13 +94,11 @@ namespace Logica BACKBACKUP = punten.Count; } - int punt1Index = i; int punt2Index = i + 1; if (punt2Index >= punten.Count) punt2Index -= punten.Count; int punt3Index = i + 2; if (punt3Index >= punten.Count) punt3Index -= punten.Count; - if (punten.Count < 3) { break; @@ -71,20 +107,14 @@ namespace Logica if (hoek < 180) { returnWaarde.Add(MaakNieuweDriehoek(punten[punt2Index], punten[punt3Index], - punten[punt1Index])); + punten[punt1Index], punten[punt1Index].Naam)); punten.RemoveAt(punt2Index); Debug.WriteLine("added a triangle, polygonLijst count " + punten.Count); i = punt1Index; BACKUP = 0; continue; - - } Debug.WriteLine(hoek); - - - - i++; if (BACKUP >= punten.Count) { @@ -92,10 +122,61 @@ namespace Logica break; } } - return returnWaarde; } + public List TriangulatePolygon(PolygonPunten polygon) + { + List punten = polygon.Punten; + List returnWaarde = new List(); + int i = 0; + int BACKUP = 0; + int BACKBACKUP = punten.Count; + while (true) + { + if (i >= punten.Count) + { + i = 0; + if (punten.Count == BACKBACKUP) + { + BACKUP++; + } + + BACKBACKUP = punten.Count; + } + int punt1Index = i; + int punt2Index = i + 1; + if (punt2Index >= punten.Count) punt2Index -= punten.Count; + int punt3Index = i + 2; + if (punt3Index >= punten.Count) punt3Index -= punten.Count; + if (punten.Count < 3) + { + break; + } + double hoek = VindHoek(punten[punt2Index], punten[punt1Index], punten[punt3Index]); + if (hoek < 180) + { + returnWaarde.Add(MaakNieuweDriehoek(punten[punt2Index], punten[punt3Index], + punten[punt1Index], punten[punt1Index].Naam)); + punten.RemoveAt(punt2Index); + Debug.WriteLine("added a triangle, polygonLijst count " + punten.Count); + i = punt1Index; + BACKUP = 0; + continue; + } + Debug.WriteLine(hoek); + i++; + if (BACKUP >= punten.Count) + { + Debug.WriteLine("FUCK, couldnt parse " + punten.Count + " points"); + break; + } + } + return returnWaarde; + } + + + private PolygonPunten MaakNieuweDriehoek(Punt punt, Punt punt1, Punt punt2, string naam = "") { return new PolygonPunten(new List() { punt, punt1, punt2 }, naam); @@ -111,7 +192,7 @@ namespace Logica return hoek; } - private List peuker(List punten, double epsilon) + private List Peuker(List punten, double epsilon) { double dmax = -1; int index = 0; @@ -132,8 +213,8 @@ namespace Logica if (dmax > epsilon) { - List recResults1 = peuker(punten.GetRange(0, index), epsilon); - List recResults2 = peuker(punten.GetRange(index, end - 1 - index), epsilon); + List recResults1 = Peuker(punten.GetRange(0, index), epsilon); + List recResults2 = Peuker(punten.GetRange(index, end - 1 - index), epsilon); returnWaarde.AddRange(recResults1); diff --git a/Logica/obj/Debug/Logica.csprojAssemblyReference.cache b/Logica/obj/Debug/Logica.csprojAssemblyReference.cache index 24df8ab..8b2ee19 100644 Binary files a/Logica/obj/Debug/Logica.csprojAssemblyReference.cache and b/Logica/obj/Debug/Logica.csprojAssemblyReference.cache differ diff --git a/opdracht2/MainWindow.xaml b/opdracht2/MainWindow.xaml index 64e4917..e238ee0 100644 --- a/opdracht2/MainWindow.xaml +++ b/opdracht2/MainWindow.xaml @@ -7,7 +7,7 @@ mc:Ignorable="d" Title="MainWindow" Height="450" Width="800"> - + @@ -17,6 +17,10 @@ + +