diff --git a/.vs/opdracht2/DesignTimeBuild/.dtbcache.v2 b/.vs/opdracht2/DesignTimeBuild/.dtbcache.v2 index efc49bb..d0d2c7a 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 15d72dc..db43ccb 100644 Binary files a/.vs/opdracht2/v16/.suo and b/.vs/opdracht2/v16/.suo differ diff --git a/Datalaag/bin/Debug/Globals.dll b/Datalaag/bin/Debug/Globals.dll index 3a5af45..d3f540e 100644 Binary files a/Datalaag/bin/Debug/Globals.dll and b/Datalaag/bin/Debug/Globals.dll differ diff --git a/Datalaag/bin/Debug/Globals.pdb b/Datalaag/bin/Debug/Globals.pdb index 74def9e..9027ee6 100644 Binary files a/Datalaag/bin/Debug/Globals.pdb and b/Datalaag/bin/Debug/Globals.pdb differ diff --git a/Datalaag/obj/Debug/Datalaag.csprojAssemblyReference.cache b/Datalaag/obj/Debug/Datalaag.csprojAssemblyReference.cache index 1fd8d94..56a26df 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 e1e53e3..d9a7fd3 100644 --- a/Globals/PolygonPunten.cs +++ b/Globals/PolygonPunten.cs @@ -31,7 +31,9 @@ namespace Globals { foreach (Position pos in l.Coordinates) { - Punten.Add(new Punt(pos.Longitude, pos.Latitude, naam)); + Punt pu = new Punt(pos.Longitude, pos.Latitude, naam); + if (!Punten.Contains(pu)) Punten.Add(pu); //dit vertraagd programma enorm, maar zorgt ervoor dat peuker beter werkt denk ik + //de vertraging komt vooral door de .Contains methode, deze mag weggelaten worden voor snelheid maar peuker zal niet meer zo goed werken } } Punten.Reverse(); diff --git a/Globals/Punt.cs b/Globals/Punt.cs index 9072a95..5060c29 100644 --- a/Globals/Punt.cs +++ b/Globals/Punt.cs @@ -16,8 +16,8 @@ namespace Globals Naam = naam; if (Graden) { - X = ConvertToRadians(x); - Y = ConvertToRadians(y); + X = ConvertToRadians(x) * 100; + Y = ConvertToRadians(y) * 100; } else { @@ -44,5 +44,17 @@ namespace Globals public bool Graden = true; + public override bool Equals(object obj) + { + try + { + Punt p = (Punt)obj; + return (p.X == this.X && p.Y == this.Y); // && this.Name = p.Name + + } catch (Exception) + { + return false; + } + } } } diff --git a/Globals/bin/Debug/Globals.dll b/Globals/bin/Debug/Globals.dll index 3a5af45..d3f540e 100644 Binary files a/Globals/bin/Debug/Globals.dll and b/Globals/bin/Debug/Globals.dll differ diff --git a/Globals/bin/Debug/Globals.pdb b/Globals/bin/Debug/Globals.pdb index 74def9e..9027ee6 100644 Binary files a/Globals/bin/Debug/Globals.pdb and b/Globals/bin/Debug/Globals.pdb differ diff --git a/Globals/obj/Debug/DesignTimeResolveAssemblyReferences.cache b/Globals/obj/Debug/DesignTimeResolveAssemblyReferences.cache index 80efde4..7ecb882 100644 Binary files a/Globals/obj/Debug/DesignTimeResolveAssemblyReferences.cache 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 75de654..486b77d 100644 Binary files a/Globals/obj/Debug/Globals.csprojAssemblyReference.cache and b/Globals/obj/Debug/Globals.csprojAssemblyReference.cache differ diff --git a/Globals/obj/Debug/Globals.dll b/Globals/obj/Debug/Globals.dll index 3a5af45..d3f540e 100644 Binary files a/Globals/obj/Debug/Globals.dll and b/Globals/obj/Debug/Globals.dll differ diff --git a/Globals/obj/Debug/Globals.pdb b/Globals/obj/Debug/Globals.pdb index 74def9e..9027ee6 100644 Binary files a/Globals/obj/Debug/Globals.pdb and b/Globals/obj/Debug/Globals.pdb differ diff --git a/Logica/PolygonManipulatie.cs b/Logica/PolygonManipulatie.cs index 105fa69..a4123ad 100644 --- a/Logica/PolygonManipulatie.cs +++ b/Logica/PolygonManipulatie.cs @@ -41,36 +41,36 @@ namespace Logica List returnWaarde = new List(); foreach (Punt punt in polygon.Punten) { - //Punt x = ScalePoint(scaleX, scaleY, punt, maxX, maxY, offsetX, offsetY); + Punt x = ScalePoint(scaleX, scaleY, punt, maxX, maxY, offsetX, offsetY, minX, minY); - double x = punt.X - minX; - x /= maxX; - x *= scaleX; - x += offsetX; - double y = punt.Y - minY; - y /= maxY; - y *= scaleY; - y += offsetY; - returnWaarde.Add(new Punt(x, y, punt.Naam)); + //double x = punt.X - minX; + //x /= maxX; + //x *= scaleX; + //x += offsetX; + //double y = punt.Y - minY; + //y /= maxY; + //y *= scaleY; + //y += offsetY; + //returnWaarde.Add(new Punt(x, y, punt.Naam)); //x.Naam = punt.Naam; - //returnWaarde.Add(x); + returnWaarde.Add(x); } return new PolygonPunten(returnWaarde, polygon.Naam); } //lat en long = graden, graden => coords (/360 * scale? - private static Punt ScalePoint(double scaleX, double scaleY, Punt punt, double maxX = 360, double maxY = 360, double offsetX = 180, double - offsetY = 180) + private static Punt ScalePoint(double scaleX, double scaleY, Punt punt, double maxX = 360, double maxY = 360, double offsetX = 180, double + offsetY = 180, double minX = 0, double minY = 0) { - double x = punt.X; + double x = punt.X - minX; x /= maxX; x *= scaleX; x += offsetX; - double y = punt.Y; + double y = punt.Y - minY; y /= maxY; y *= scaleY; y += offsetY; - return new Punt(x, y); + return new Punt(x, y, punt.Naam); } public MultiPolygonPunten ScaleMultiPolygon(MultiPolygonPunten multiPolygon, double scaleX, double scaleY, double offsetX = 0, double offsetY = 0) @@ -98,8 +98,7 @@ namespace Logica y += offsetY; returnWaarde.Add(new Punt(x, y, punt.Naam));*/ - Punt x = ScalePoint(scaleX, scaleY,punt, maxX, maxY, offsetX, offsetY); - x.Naam = punt.Naam; + Punt x = ScalePoint(scaleX, scaleY, punt, maxX, maxY, offsetX, offsetY, minX, minY); returnWaarde.Add(x); } @@ -126,7 +125,7 @@ namespace Logica foreach (Punt punt in poly.Punten) { - Punt x = ScalePoint(scaleX, scaleY,punt, maxX, maxY, offsetX, offsetY); + Punt x = ScalePoint(scaleX, scaleY,punt, maxX, maxY, offsetX, offsetY, minX, minY); x.Naam = punt.Naam; punten.Add(x); /*double x = punt.X - minX; @@ -285,17 +284,34 @@ namespace Logica public MultiPolygonPunten Peuker(MultiPolygonPunten polygons, double epsilon) { - double nX = Math.Abs(Math.Abs(polygons.MaximumX) - Math.Abs(polygons.MinimumX)); - double nY = Math.Abs(Math.Abs(polygons.MaximumY) - Math.Abs(polygons.MinimumY)); - epsilon = ((nX + nY) / 2) * epsilon; foreach (PolygonPunten polygon in polygons.PolygonPunten) { + double nX = Math.Abs(Math.Abs(polygon.MaximumX) - Math.Abs(polygon.MinimumX)); + double nY = Math.Abs(Math.Abs(polygon.MaximumY) - Math.Abs(polygon.MinimumY)); + epsilon = ((nX + nY) / 2) * epsilon; polygon.Punten = Peuker(polygon.Punten, epsilon); } return polygons; } + + + // + /* + * De reden dat peuker enkel werkte op bepaalde landen was wegens de grote van deze landen/ polygons in deze landen. + * Sommige landen waren zo klein dat het double datatype een limiet bereikt had van precisie (bv 0.00000000005 0.00000000007 zouden worden herleid naar 0.0000000001) + * De afstands methode die een afstand probeert te berekenen tussen 2 punten doet op een bepaald moment een aftrekking en als de punten gelijk waren komt in die var een 0 + * daarna wordt deze var gebruikt voor een deling, en een deling door 0 geeft geen error, maar een NaN type in het double datatype + * Daardoor ging peuker niet op kleinere landen zoals lichtenstein + * D + * + *De oplossing voor dit probleem was door het gebruik van de contains methode in de polygonpunten klasse + * elk punt dat toegevoegd wordt wordt gechecked of het al in de lijst zit. Dit vertraagd het inladen van de data enorm, maar zorgt ervoor dat alle landen puntvermindering kunnen krijgen + * + * + * + */ private List Peuker(List punten, double epsilon) { double dmax = -1; @@ -309,6 +325,10 @@ namespace Logica { index = i; dmax = distance; + } + else + { + Debug.WriteLine("hmm"); } } @@ -334,8 +354,14 @@ namespace Logica private double PerpendicularDistance2(Punt point, Punt l1, Punt l2) { - return Math.Abs((l2.X - l1.X) * (l1.Y - point.Y) - (l1.X - point.X) * (l2.Y - l1.Y)) / + double temp = Math.Abs((l2.X - l1.X) * (l1.Y - point.Y) - (l1.X - point.X) * (l2.Y - l1.Y)) / Math.Sqrt(Math.Pow(l2.X - l1.X, 2) + Math.Pow(l2.Y - l1.Y, 2)); + if (double.IsNaN(temp)) + { + Debug.WriteLine("wtf fam"); + return 0; + } + return temp; } } } diff --git a/Logica/bin/Debug/Globals.dll b/Logica/bin/Debug/Globals.dll index 3a5af45..d3f540e 100644 Binary files a/Logica/bin/Debug/Globals.dll and b/Logica/bin/Debug/Globals.dll differ diff --git a/Logica/bin/Debug/Globals.pdb b/Logica/bin/Debug/Globals.pdb index 74def9e..9027ee6 100644 Binary files a/Logica/bin/Debug/Globals.pdb and b/Logica/bin/Debug/Globals.pdb differ diff --git a/Logica/bin/Debug/Logica.dll b/Logica/bin/Debug/Logica.dll index 8e7b741..8f3a0ce 100644 Binary files a/Logica/bin/Debug/Logica.dll and b/Logica/bin/Debug/Logica.dll differ diff --git a/Logica/bin/Debug/Logica.pdb b/Logica/bin/Debug/Logica.pdb index 95c530e..a721a1a 100644 Binary files a/Logica/bin/Debug/Logica.pdb and b/Logica/bin/Debug/Logica.pdb differ diff --git a/Logica/obj/Debug/Logica.csprojAssemblyReference.cache b/Logica/obj/Debug/Logica.csprojAssemblyReference.cache index c6444ac..e6b66eb 100644 Binary files a/Logica/obj/Debug/Logica.csprojAssemblyReference.cache and b/Logica/obj/Debug/Logica.csprojAssemblyReference.cache differ diff --git a/Logica/obj/Debug/Logica.dll b/Logica/obj/Debug/Logica.dll index 8e7b741..8f3a0ce 100644 Binary files a/Logica/obj/Debug/Logica.dll and b/Logica/obj/Debug/Logica.dll differ diff --git a/Logica/obj/Debug/Logica.pdb b/Logica/obj/Debug/Logica.pdb index 95c530e..a721a1a 100644 Binary files a/Logica/obj/Debug/Logica.pdb and b/Logica/obj/Debug/Logica.pdb differ diff --git a/opdracht2/MainWindow.xaml.cs b/opdracht2/MainWindow.xaml.cs index a32fa55..6c19bbe 100644 --- a/opdracht2/MainWindow.xaml.cs +++ b/opdracht2/MainWindow.xaml.cs @@ -135,7 +135,7 @@ namespace opdracht2 } //scale de polygon als de checkbox aan staat - if (scale.IsChecked == true) mpps = pm.ScaleMultiPolygons(mpps, 10000, 10000, 0, 0); + if (scale.IsChecked == true) mpps = pm.ScaleMultiPolygons(mpps, c.ActualWidth/2, c.ActualHeight/2, 0, 0); foreach(MultiPolygonPunten mp in mpps) { @@ -170,7 +170,7 @@ namespace opdracht2 Debug.WriteLine(lb.SelectedItem.GetType().Name); // voor debug redenen schrijf naam naar console c.Children.Clear(); // delete alle vorige afbeeldingen MultiPolygonPunten mp = (MultiPolygonPunten)lb.SelectedItem; //haal multipolygon uit lijst - if (scale.IsChecked == true) mp = pm.ScaleMultiPolygon(mp, 10000, 10000, 0, 0); //schaal multipolygon + if (scale.IsChecked == true) mp = pm.ScaleMultiPolygon(mp, c.ActualWidth / 2, c.ActualHeight / 2, 0, 0); //schaal multipolygon if (peuker.IsChecked == true) mp = pm.Peuker(mp, peukerPercent.Value/1000); // als peuker (puntvermindering) moet gebeuren, doe dit hier foreach (PolygonPunten pp in mp.PolygonPunten) //loop doorheen polygons in multipolygon { @@ -192,7 +192,7 @@ namespace opdracht2 Debug.WriteLine(lb.SelectedItem.GetType().Name); c.Children.Clear(); //delete alle vorige afbeeldingen PolygonPunten p = (PolygonPunten)lb.SelectedItem; // haal land uit lijst - if (scale.IsChecked == true) p = pm.ScalePolygon(p, 10000, 10000, 0, 0); // schaal polygon + if (scale.IsChecked == true) p = pm.ScalePolygon(p, c.ActualWidth/2, c.ActualHeight/2, 0, 0); // schaal polygon if (peuker.IsChecked == true) p = pm.Peuker(p, peukerPercent.Value / 1000); // peuker (puntvermindering) if (triangulate.IsChecked == true) //triangulation check { diff --git a/opdracht2/bin/Debug/netcoreapp3.1/Globals.dll b/opdracht2/bin/Debug/netcoreapp3.1/Globals.dll index 3a5af45..d3f540e 100644 Binary files a/opdracht2/bin/Debug/netcoreapp3.1/Globals.dll and b/opdracht2/bin/Debug/netcoreapp3.1/Globals.dll differ diff --git a/opdracht2/bin/Debug/netcoreapp3.1/Globals.pdb b/opdracht2/bin/Debug/netcoreapp3.1/Globals.pdb index 74def9e..9027ee6 100644 Binary files a/opdracht2/bin/Debug/netcoreapp3.1/Globals.pdb and b/opdracht2/bin/Debug/netcoreapp3.1/Globals.pdb differ diff --git a/opdracht2/bin/Debug/netcoreapp3.1/Logica.dll b/opdracht2/bin/Debug/netcoreapp3.1/Logica.dll index 8e7b741..8f3a0ce 100644 Binary files a/opdracht2/bin/Debug/netcoreapp3.1/Logica.dll and b/opdracht2/bin/Debug/netcoreapp3.1/Logica.dll differ diff --git a/opdracht2/bin/Debug/netcoreapp3.1/Logica.pdb b/opdracht2/bin/Debug/netcoreapp3.1/Logica.pdb index 95c530e..a721a1a 100644 Binary files a/opdracht2/bin/Debug/netcoreapp3.1/Logica.pdb and b/opdracht2/bin/Debug/netcoreapp3.1/Logica.pdb differ diff --git a/opdracht2/bin/Debug/netcoreapp3.1/opdracht2.dll b/opdracht2/bin/Debug/netcoreapp3.1/opdracht2.dll index 6f88adb..034aab3 100644 Binary files a/opdracht2/bin/Debug/netcoreapp3.1/opdracht2.dll and b/opdracht2/bin/Debug/netcoreapp3.1/opdracht2.dll differ diff --git a/opdracht2/bin/Debug/netcoreapp3.1/opdracht2.pdb b/opdracht2/bin/Debug/netcoreapp3.1/opdracht2.pdb index 8a6ab61..f455552 100644 Binary files a/opdracht2/bin/Debug/netcoreapp3.1/opdracht2.pdb and b/opdracht2/bin/Debug/netcoreapp3.1/opdracht2.pdb differ diff --git a/opdracht2/obj/Debug/netcoreapp3.1/opdracht2.csprojAssemblyReference.cache b/opdracht2/obj/Debug/netcoreapp3.1/opdracht2.csprojAssemblyReference.cache index c9b4b90..4da17a5 100644 Binary files a/opdracht2/obj/Debug/netcoreapp3.1/opdracht2.csprojAssemblyReference.cache and b/opdracht2/obj/Debug/netcoreapp3.1/opdracht2.csprojAssemblyReference.cache differ diff --git a/opdracht2/obj/Debug/netcoreapp3.1/opdracht2.dll b/opdracht2/obj/Debug/netcoreapp3.1/opdracht2.dll index 6f88adb..034aab3 100644 Binary files a/opdracht2/obj/Debug/netcoreapp3.1/opdracht2.dll and b/opdracht2/obj/Debug/netcoreapp3.1/opdracht2.dll differ diff --git a/opdracht2/obj/Debug/netcoreapp3.1/opdracht2.pdb b/opdracht2/obj/Debug/netcoreapp3.1/opdracht2.pdb index 8a6ab61..f455552 100644 Binary files a/opdracht2/obj/Debug/netcoreapp3.1/opdracht2.pdb and b/opdracht2/obj/Debug/netcoreapp3.1/opdracht2.pdb differ