canvas moe nog geflipped worden, en scaling shit. kga stoppe voor vandaag

This commit is contained in:
BuildTools
2020-07-30 11:44:28 +02:00
parent 8a0386a5c4
commit dee6b3a496
35 changed files with 180 additions and 83 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -27,6 +27,12 @@ namespace Globals
PolygonPunten.Add(new PolygonPunten(polygon, naam));
}
VindMaximumEnMinimum(PolygonPunten);
bool sw = false;
foreach (PolygonPunten p in PolygonPunten)
{
if (sw) p.Punten.Reverse();
sw = !sw;
}
}
private void VindMaximumEnMinimum(List<PolygonPunten> polygonPunten)
@@ -35,6 +41,7 @@ namespace Globals
MaximumY = polygonPunten.Max(p => p.MaximumY);
MinimumX = polygonPunten.Max(p => p.MinimumX);
MinimumY = polygonPunten.Max(p => p.MinimumY);
}

View File

@@ -42,6 +42,7 @@ namespace Globals
Punten.Add(new Punt(pos.Longitude, pos.Latitude, naam));
}
}
Punten.Reverse();
}
public override string ToString()

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -43,7 +43,7 @@ namespace Logica
return TriangulatePolygon(polygon);
}
public PolygonPunten ScalePolygon(PolygonPunten polygon, double scaleX, double scaleY)
public PolygonPunten ScalePolygon(PolygonPunten polygon, double scaleX, double scaleY, double offsetX = 0, double offsetY = 0)
{
double maxX = polygon.MaximumX;
double maxY = polygon.MaximumY;
@@ -57,16 +57,18 @@ namespace Logica
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));
}
return new PolygonPunten(returnWaarde, polygon.Naam);
}
public MultiPolygonPunten ScaleMultiPolygon(MultiPolygonPunten multiPolygon, double scaleX, double scaleY)
public MultiPolygonPunten ScaleMultiPolygon(MultiPolygonPunten multiPolygon, double scaleX, double scaleY, double offsetX = 0, double offsetY = 0)
{
double maxX = multiPolygon.MaximumX;
double maxY = multiPolygon.MaximumY;
@@ -83,9 +85,11 @@ namespace Logica
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));
}
@@ -95,7 +99,8 @@ namespace Logica
return new MultiPolygonPunten(pp, multiPolygon.Naam);
}
public List<MultiPolygonPunten> ScaleMultiPolygons(List<MultiPolygonPunten> multiPolygons, double scaleX, double scaleY)
//todo (offset var voor center op canvas, vree ambetant)
public List<MultiPolygonPunten> ScaleMultiPolygons(List<MultiPolygonPunten> multiPolygons, double scaleX, double scaleY, double offsetX = 0, double offsetY = 0)
{
double maxX = multiPolygons.Max(m => m.MaximumX);
double maxY = multiPolygons.Max(m => m.MaximumY);
@@ -114,9 +119,11 @@ namespace Logica
double x = punt.X - minX;
x /= maxX;
x *= scaleX;
x += offsetX;
double y = punt.Y - minY;
y /= maxY;
y *= scaleY;
y += offsetY;
punten.Add(new Punt(x, y, punt.Naam));
}
pp.Add(new PolygonPunten(punten, poly.Naam));

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -9,7 +9,7 @@
<Grid>
<Canvas x:Name="someCanvas" RenderTransformOrigin="0.5,0.5" Margin="436,114,128,113">
<Canvas.RenderTransform>
<TransformGroup>
<TransformGroup x:Name="someTransformGroup">
<ScaleTransform ScaleY="-1" ScaleX="-1"/>
<SkewTransform/>
<RotateTransform/>
@@ -17,11 +17,12 @@
</TransformGroup>
</Canvas.RenderTransform>
</Canvas>
<ListBox x:Name="lb" Margin="10,94,568,93" SelectionChanged="lb_SelectionChanged"/>
<ListBox x:Name="lb" Margin="10,94,568,93" SelectionChanged="lb_SelectionChanged" SelectionMode="Multiple"/>
<Button x:Name="LoadFile" Content="LoadFile" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Height="27" Width="65" Click="LoadFile_Click"/>
<Slider HorizontalAlignment="Left" Margin="10,406,0,0" VerticalAlignment="Top" Width="120" Maximum="100" SmallChange="1"/>
<Label Content="Epsilon (0.001 - 0.1%)" HorizontalAlignment="Left" Margin="8,375,0,0" VerticalAlignment="Top"/>
<CheckBox x:Name="Triangulate" Content="Triangulate" HorizontalAlignment="Left" Margin="10,346,0,0" VerticalAlignment="Top"/>
<CheckBox x:Name="Scale" Content="Scale" HorizontalAlignment="Left" Margin="107,349,0,0" VerticalAlignment="Top"/>
</Grid>
</Window>

View File

@@ -39,6 +39,7 @@ namespace opdracht2
List<Polygon> buffer;
ListBox l;
CheckBox triangulate;
CheckBox scale;
PolygonManipulatie pm;
JsonReader j;
public MainWindow()
@@ -53,7 +54,8 @@ namespace opdracht2
c = (Canvas)this.FindName("someCanvas");
CompositionTarget.Rendering += DoUpdates;
l = (ListBox)this.FindName("lb");
triangulate = (CheckBox)this.FindName("triangulate");
triangulate = (CheckBox)this.FindName("Triangulate");
scale = (CheckBox)this.FindName("Scale");
Debug.Write("done");
}
@@ -159,7 +161,7 @@ namespace opdracht2
List<MultiPolygonPunten> mpps = new List<MultiPolygonPunten>();
foreach (Object o in lb.SelectedItems)
{
if (o.GetType().ToString() == "PolygonPunten") {
if (o.GetType().Name == "PolygonPunten" ) {
PolygonPunten p = (PolygonPunten)o;
mpps.Add(p.ToMultiPolygonPunten());
} else
@@ -168,7 +170,8 @@ namespace opdracht2
}
}
//peuker implementatie moet ook nog gebeuren, code is er al, maar wanneer moet deze aangeroepen worden
mpps = pm.ScaleMultiPolygons(mpps, 100, 100);
if (scale.IsChecked == true) mpps = pm.ScaleMultiPolygons(mpps, c.Width/2, c.Height/2, c.Width/2, c.Height/2);
foreach(MultiPolygonPunten mp in mpps)
{
if (triangulate.IsChecked == true) //kan blkbr ook null zijn, raar
@@ -190,36 +193,56 @@ namespace opdracht2
}
}
}
else
else if (lb.SelectedItems.Count == 1)
{
switch (lb.SelectedItem.GetType().Name)
{
case "MultiPolygonPunten":
Debug.WriteLine(lb.SelectedItem.GetType().Name);
c.Children.Clear();
MultiPolygonPunten mp = pm.ScaleMultiPolygon((MultiPolygonPunten)lb.SelectedItem, 100, 100);
MultiPolygonPunten mp = (MultiPolygonPunten)lb.SelectedItem;
if (scale.IsChecked == true) mp = pm.ScaleMultiPolygon(mp, c.Width / 2, c.Height / 2, c.Width / 2, c.Height / 2);
//hier ervoor zorgen dat scaling, triangulation etc gebeurt door gebruik van logica layer functies te callen
foreach (PolygonPunten pp in mp.PolygonPunten)
{
if(triangulate.IsChecked == true)
{
foreach (PolygonPunten ppd in pm.TriangulatePolygon(pp))
{
c.Children.Add(getPolygon(ppd));
}
}
foreach (Polygon po in getPolygon(mp))
} else
{
//c.Children.Add(po);
c.Children.Add(getPolygon(pp));
}
}
break;
case "PolygonPunten":
Debug.WriteLine(lb.SelectedItem.GetType().Name);
c.Children.Clear();
PolygonPunten p = pm.ScalePolygon((PolygonPunten)lb.SelectedItem, 100, 100);
PolygonPunten p = (PolygonPunten)lb.SelectedItem;
if (scale.IsChecked == true) p = pm.ScalePolygon(p, c.Width / 2, c.Height / 2, c.Width / 2, c.Height / 2);
if (triangulate.IsChecked == true)
{
foreach(PolygonPunten pp in pm.TriangulatePolygon(p))
{
c.Children.Add(getPolygon(pp));
}
} else
{
c.Children.Add(getPolygon(p));
}
break;
}
} else
{
c.Children.Clear();
}

View File

@@ -1,4 +1,4 @@
#pragma checksum "..\..\..\MainWindow.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "05D515F609A8E8D2AFAF26E4ADD6AF1BBA9D6ED8"
#pragma checksum "..\..\..\MainWindow.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "E92F073CEE6714AF0A5CB02DB34D14A9EC5D8B57"
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
@@ -50,6 +50,14 @@ namespace opdracht2 {
#line hidden
#line 12 "..\..\..\MainWindow.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Media.TransformGroup someTransformGroup;
#line default
#line hidden
#line 20 "..\..\..\MainWindow.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.ListBox lb;
@@ -65,6 +73,22 @@ namespace opdracht2 {
#line default
#line hidden
#line 24 "..\..\..\MainWindow.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.CheckBox Triangulate;
#line default
#line hidden
#line 25 "..\..\..\MainWindow.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.CheckBox Scale;
#line default
#line hidden
private bool _contentLoaded;
/// <summary>
@@ -99,6 +123,9 @@ namespace opdracht2 {
this.someCanvas = ((System.Windows.Controls.Canvas)(target));
return;
case 2:
this.someTransformGroup = ((System.Windows.Media.TransformGroup)(target));
return;
case 3:
this.lb = ((System.Windows.Controls.ListBox)(target));
#line 20 "..\..\..\MainWindow.xaml"
@@ -107,7 +134,7 @@ namespace opdracht2 {
#line default
#line hidden
return;
case 3:
case 4:
this.LoadFile = ((System.Windows.Controls.Button)(target));
#line 21 "..\..\..\MainWindow.xaml"
@@ -116,6 +143,12 @@ namespace opdracht2 {
#line default
#line hidden
return;
case 5:
this.Triangulate = ((System.Windows.Controls.CheckBox)(target));
return;
case 6:
this.Scale = ((System.Windows.Controls.CheckBox)(target));
return;
}
this._contentLoaded = true;
}

View File

@@ -1,5 +1,4 @@
// Updated by XamlIntelliSenseFileGenerator 7/30/2020 9:49:33 AM
#pragma checksum "..\..\..\MainWindow.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "05D515F609A8E8D2AFAF26E4ADD6AF1BBA9D6ED8"
#pragma checksum "..\..\..\MainWindow.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "E92F073CEE6714AF0A5CB02DB34D14A9EC5D8B57"
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
@@ -34,39 +33,61 @@ using System.Windows.Shell;
using opdracht2;
namespace opdracht2
{
namespace opdracht2 {
/// <summary>
/// MainWindow
/// </summary>
public partial class MainWindow : System.Windows.Window, System.Windows.Markup.IComponentConnector
{
public partial class MainWindow : System.Windows.Window, System.Windows.Markup.IComponentConnector {
#line 10 "..\..\..\MainWindow.xaml"
#line 10 "..\..\..\MainWindow.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.Canvas someCanvas;
#line default
#line hidden
#line default
#line hidden
#line 20 "..\..\..\MainWindow.xaml"
#line 12 "..\..\..\MainWindow.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Media.TransformGroup someTransformGroup;
#line default
#line hidden
#line 20 "..\..\..\MainWindow.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.ListBox lb;
#line default
#line hidden
#line default
#line hidden
#line 21 "..\..\..\MainWindow.xaml"
#line 21 "..\..\..\MainWindow.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.Button LoadFile;
#line default
#line hidden
#line default
#line hidden
#line 24 "..\..\..\MainWindow.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.CheckBox Triangulate;
#line default
#line hidden
#line 25 "..\..\..\MainWindow.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.CheckBox Scale;
#line default
#line hidden
private bool _contentLoaded;
@@ -75,20 +96,18 @@ namespace opdracht2
/// </summary>
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.8.1.0")]
public void InitializeComponent()
{
if (_contentLoaded)
{
public void InitializeComponent() {
if (_contentLoaded) {
return;
}
_contentLoaded = true;
System.Uri resourceLocater = new System.Uri("/opdracht2;component/mainwindow.xaml", System.UriKind.Relative);
#line 1 "..\..\..\MainWindow.xaml"
#line 1 "..\..\..\MainWindow.xaml"
System.Windows.Application.LoadComponent(this, resourceLocater);
#line default
#line hidden
#line default
#line hidden
}
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
@@ -97,36 +116,42 @@ namespace opdracht2
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes")]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
{
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
switch (connectionId)
{
case 1:
this.someCanvas = ((System.Windows.Controls.Canvas)(target));
return;
case 2:
this.lb = ((System.Windows.Controls.ListBox)(target));
#line 20 "..\..\..\MainWindow.xaml"
this.lb.SelectionChanged += new System.Windows.Controls.SelectionChangedEventHandler(this.lb_SelectionChanged);
#line default
#line hidden
this.someTransformGroup = ((System.Windows.Media.TransformGroup)(target));
return;
case 3:
this.lb = ((System.Windows.Controls.ListBox)(target));
#line 20 "..\..\..\MainWindow.xaml"
this.lb.SelectionChanged += new System.Windows.Controls.SelectionChangedEventHandler(this.lb_SelectionChanged);
#line default
#line hidden
return;
case 4:
this.LoadFile = ((System.Windows.Controls.Button)(target));
#line 21 "..\..\..\MainWindow.xaml"
#line 21 "..\..\..\MainWindow.xaml"
this.LoadFile.Click += new System.Windows.RoutedEventHandler(this.LoadFile_Click);
#line default
#line hidden
#line default
#line hidden
return;
case 5:
this.Triangulate = ((System.Windows.Controls.CheckBox)(target));
return;
case 6:
this.Scale = ((System.Windows.Controls.CheckBox)(target));
return;
}
this._contentLoaded = true;
}
internal System.Windows.Controls.CheckBox Triangulate;
}
}