Fixed Point plotting -> TODO: fix plotting of circles and edges
TODO: Generate Points distinct from eachother
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
using Avalonia;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
|
||||
namespace DelauneyTriangulation.Models;
|
||||
|
||||
public class Geometries
|
||||
public static class Geometries
|
||||
{
|
||||
public sealed class GeomPoint(double x, double y, double z = 3)
|
||||
public sealed class Point(double x, double y, double z = 3)
|
||||
{
|
||||
public double X { get; } = x;
|
||||
public double Y { get; } = y;
|
||||
@@ -15,18 +15,18 @@ public class Geometries
|
||||
public double Size => 2 * R;
|
||||
}
|
||||
|
||||
public sealed class GeomEdge(double x1, double y1, double x2, double y2)
|
||||
public sealed class Edge(double x1, double y1, double x2, double y2)
|
||||
{
|
||||
public double X1 { get; } = x1;
|
||||
public double X2 { get; } = x2;
|
||||
public double Y1 { get; } = y1;
|
||||
public double Y2 { get; } = y2;
|
||||
|
||||
public Point Start => new(X1, Y1);
|
||||
public Point End => new(X2, Y2);
|
||||
public Avalonia.Point Start => new(X1, Y1);
|
||||
public Avalonia.Point End => new(X2, Y2);
|
||||
}
|
||||
|
||||
public sealed class GeomCircle(double x, double y, double r)
|
||||
public sealed class Circle(double x, double y, double r)
|
||||
{
|
||||
public double X { get; } = x;
|
||||
public double Y { get; } = y;
|
||||
|
||||
@@ -8,26 +8,43 @@ namespace DelauneyTriangulation.ViewModels;
|
||||
|
||||
public partial class MainWindowViewModel : ViewModelBase
|
||||
{
|
||||
[ObservableProperty] private int _pointCount = 20;
|
||||
private int _pointCount = 20;
|
||||
[ObservableProperty] private double _panX;
|
||||
[ObservableProperty] private double _panY;
|
||||
[ObservableProperty] private double _zoom = 1.0;
|
||||
public double Width { get; set; } = 1280;
|
||||
public double Height { get; set; } = 720;
|
||||
|
||||
public ObservableCollection<Geometries.GeomPoint> Points { get; } = new();
|
||||
public ObservableCollection<Geometries.GeomEdge> Edges { get; } = new();
|
||||
public ObservableCollection<Geometries.GeomCircle> Circles { get; } = new();
|
||||
|
||||
public MainWindowViewModel()
|
||||
public int PointCount
|
||||
{
|
||||
var rand = new Random();
|
||||
|
||||
for (int i = 0; i < PointCount; i++)
|
||||
get => _pointCount;
|
||||
set
|
||||
{
|
||||
double x = rand.NextDouble() * Width;
|
||||
double y = rand.NextDouble() * Height;
|
||||
Points.Add(new Geometries.GeomPoint(x, y));
|
||||
_pointCount = value;
|
||||
OnPropertyChanged(nameof(PointCount));
|
||||
GenerateRandomPoints(value);
|
||||
}
|
||||
}
|
||||
|
||||
public ObservableCollection<Geometries.Point> Points { get; } = new();
|
||||
public ObservableCollection<Geometries.Edge> Edges { get; } = new();
|
||||
public ObservableCollection<Geometries.Circle> Circles { get; } = new();
|
||||
|
||||
void GenerateRandomPoints(int count)
|
||||
{
|
||||
Points.Clear();
|
||||
var rand = new Random();
|
||||
|
||||
for (var i = 0; i < PointCount; i++)
|
||||
{
|
||||
var x = rand.NextDouble() * Width;
|
||||
var y = rand.NextDouble() * Height;
|
||||
Points.Add(new Geometries.Point(x, y));
|
||||
}
|
||||
}
|
||||
|
||||
public MainWindowViewModel()
|
||||
{
|
||||
GenerateRandomPoints(_pointCount);
|
||||
}
|
||||
}
|
||||
@@ -54,16 +54,11 @@
|
||||
<TextBlock Text="Delaunay Triangulation" FontSize="18" Foreground="White"/>
|
||||
</Border>
|
||||
<Border Classes="InnerCard">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="4*"/>
|
||||
<ColumnDefinition Width="1*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid ColumnDefinitions="4*,1*">
|
||||
<Slider Grid.Column="0" Value="{Binding PointCount, Mode=TwoWay}" Margin="5" Minimum="20" Maximum="500"/>
|
||||
<TextBox Grid.Column="1" Text="{Binding PointCount, Mode=TwoWay}" FontSize="18" Foreground="White" Background="#30ffffff" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</Grid>
|
||||
@@ -88,45 +83,59 @@
|
||||
Height="{Binding Bounds.Height, ElementName=Scene}"
|
||||
IsHitTestVisible="False">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate><Canvas/></ItemsPanelTemplate>
|
||||
<ItemsPanelTemplate>
|
||||
<Canvas/>
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate x:DataType="models:Geometries+GeomEdge">
|
||||
<DataTemplate x:DataType="models:Geometries+Edge">
|
||||
<Line StartPoint="{Binding Start}"
|
||||
EndPoint="{Binding End}"
|
||||
Stroke="LightGray" StrokeThickness="1"/>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
|
||||
<ItemsControl ItemsSource="{Binding Circles}"
|
||||
Width="{Binding Bounds.Width, ElementName=Scene}"
|
||||
Height="{Binding Bounds.Height, ElementName=Scene}"
|
||||
IsHitTestVisible="False">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate><Canvas/></ItemsPanelTemplate>
|
||||
<ItemsPanelTemplate>
|
||||
<Canvas/>
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate x:DataType="models:Geometries+GeomCircle">
|
||||
<Ellipse Stroke="Lime" StrokeThickness="1.5"
|
||||
Width="{Binding Diameter}" Height="{Binding Diameter}"
|
||||
Canvas.Left="{Binding Left}" Canvas.Top="{Binding Top}"/>
|
||||
<DataTemplate x:DataType="models:Geometries+Circle">
|
||||
<Ellipse Stroke="DarkOrange" StrokeThickness="1.5"
|
||||
Width="{Binding Diameter}"
|
||||
Height="{Binding Diameter}"
|
||||
Canvas.Left="{Binding Left}"
|
||||
Canvas.Top="{Binding Top}"
|
||||
/>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
|
||||
<ItemsControl ItemsSource="{Binding Points}"
|
||||
Width="{Binding Bounds.Width, ElementName=Scene}"
|
||||
Height="{Binding Bounds.Height, ElementName=Scene}"
|
||||
IsHitTestVisible="False">
|
||||
IsHitTestVisible="False"
|
||||
>
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate><Canvas/></ItemsPanelTemplate>
|
||||
<ItemsPanelTemplate>
|
||||
<Canvas/>
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate x:DataType="models:Geometries+GeomPoint">
|
||||
<DataTemplate x:DataType="models:Geometries+Point">
|
||||
<Ellipse Fill="White" Stroke="Black" StrokeThickness="1"
|
||||
Width="{Binding Size}" Height="{Binding Size}"
|
||||
Canvas.Left="{Binding Left}" Canvas.Top="{Binding Top}"/>
|
||||
Width="{Binding Size}"
|
||||
Height="{Binding Size}"
|
||||
>
|
||||
<Ellipse.RenderTransform>
|
||||
<!-- Nutze Left/Top aus dem VM (oder X/Y, wenn das deine Top-Left-Koords sind) -->
|
||||
<TranslateTransform X="{Binding Left}" Y="{Binding Top}"/>
|
||||
</Ellipse.RenderTransform>
|
||||
</Ellipse>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
|
||||
Reference in New Issue
Block a user