Fixed Point plotting -> TODO: fix plotting of circles and edges

TODO: Generate Points distinct from eachother
This commit is contained in:
ti_mo
2025-10-21 00:05:06 +02:00
parent eece186bf3
commit 4f5530c87e
3 changed files with 65 additions and 39 deletions
+7 -7
View File
@@ -1,10 +1,10 @@
using Avalonia; using CommunityToolkit.Mvvm.Input;
namespace DelauneyTriangulation.Models; 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 X { get; } = x;
public double Y { get; } = y; public double Y { get; } = y;
@@ -15,18 +15,18 @@ public class Geometries
public double Size => 2 * R; 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 X1 { get; } = x1;
public double X2 { get; } = x2; public double X2 { get; } = x2;
public double Y1 { get; } = y1; public double Y1 { get; } = y1;
public double Y2 { get; } = y2; public double Y2 { get; } = y2;
public Point Start => new(X1, Y1); public Avalonia.Point Start => new(X1, Y1);
public Point End => new(X2, Y2); 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 X { get; } = x;
public double Y { get; } = y; public double Y { get; } = y;
@@ -8,26 +8,43 @@ namespace DelauneyTriangulation.ViewModels;
public partial class MainWindowViewModel : ViewModelBase public partial class MainWindowViewModel : ViewModelBase
{ {
[ObservableProperty] private int _pointCount = 20; private int _pointCount = 20;
[ObservableProperty] private double _panX; [ObservableProperty] private double _panX;
[ObservableProperty] private double _panY; [ObservableProperty] private double _panY;
[ObservableProperty] private double _zoom = 1.0; [ObservableProperty] private double _zoom = 1.0;
public double Width { get; set; } = 1280; public double Width { get; set; } = 1280;
public double Height { get; set; } = 720; public double Height { get; set; } = 720;
public ObservableCollection<Geometries.GeomPoint> Points { get; } = new(); public int PointCount
public ObservableCollection<Geometries.GeomEdge> Edges { get; } = new();
public ObservableCollection<Geometries.GeomCircle> Circles { get; } = new();
public MainWindowViewModel()
{ {
var rand = new Random(); get => _pointCount;
set
for (int i = 0; i < PointCount; i++)
{ {
double x = rand.NextDouble() * Width; _pointCount = value;
double y = rand.NextDouble() * Height; OnPropertyChanged(nameof(PointCount));
Points.Add(new Geometries.GeomPoint(x, y)); 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);
}
} }
+29 -20
View File
@@ -54,16 +54,11 @@
<TextBlock Text="Delaunay Triangulation" FontSize="18" Foreground="White"/> <TextBlock Text="Delaunay Triangulation" FontSize="18" Foreground="White"/>
</Border> </Border>
<Border Classes="InnerCard"> <Border Classes="InnerCard">
<Grid> <Grid ColumnDefinitions="4*,1*">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="4*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Slider Grid.Column="0" Value="{Binding PointCount, Mode=TwoWay}" Margin="5" Minimum="20" Maximum="500"/> <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"/> <TextBox Grid.Column="1" Text="{Binding PointCount, Mode=TwoWay}" FontSize="18" Foreground="White" Background="#30ffffff" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
</Grid> </Grid>
</Border> </Border>
</StackPanel> </StackPanel>
</Border> </Border>
</Grid> </Grid>
@@ -88,45 +83,59 @@
Height="{Binding Bounds.Height, ElementName=Scene}" Height="{Binding Bounds.Height, ElementName=Scene}"
IsHitTestVisible="False"> IsHitTestVisible="False">
<ItemsControl.ItemsPanel> <ItemsControl.ItemsPanel>
<ItemsPanelTemplate><Canvas/></ItemsPanelTemplate> <ItemsPanelTemplate>
<Canvas/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel> </ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate> <ItemsControl.ItemTemplate>
<DataTemplate x:DataType="models:Geometries+GeomEdge"> <DataTemplate x:DataType="models:Geometries+Edge">
<Line StartPoint="{Binding Start}" <Line StartPoint="{Binding Start}"
EndPoint="{Binding End}" EndPoint="{Binding End}"
Stroke="LightGray" StrokeThickness="1"/> Stroke="LightGray" StrokeThickness="1"/>
</DataTemplate> </DataTemplate>
</ItemsControl.ItemTemplate> </ItemsControl.ItemTemplate>
</ItemsControl> </ItemsControl>
<ItemsControl ItemsSource="{Binding Circles}" <ItemsControl ItemsSource="{Binding Circles}"
Width="{Binding Bounds.Width, ElementName=Scene}" Width="{Binding Bounds.Width, ElementName=Scene}"
Height="{Binding Bounds.Height, ElementName=Scene}" Height="{Binding Bounds.Height, ElementName=Scene}"
IsHitTestVisible="False"> IsHitTestVisible="False">
<ItemsControl.ItemsPanel> <ItemsControl.ItemsPanel>
<ItemsPanelTemplate><Canvas/></ItemsPanelTemplate> <ItemsPanelTemplate>
<Canvas/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel> </ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate> <ItemsControl.ItemTemplate>
<DataTemplate x:DataType="models:Geometries+GeomCircle"> <DataTemplate x:DataType="models:Geometries+Circle">
<Ellipse Stroke="Lime" StrokeThickness="1.5" <Ellipse Stroke="DarkOrange" StrokeThickness="1.5"
Width="{Binding Diameter}" Height="{Binding Diameter}" Width="{Binding Diameter}"
Canvas.Left="{Binding Left}" Canvas.Top="{Binding Top}"/> Height="{Binding Diameter}"
Canvas.Left="{Binding Left}"
Canvas.Top="{Binding Top}"
/>
</DataTemplate> </DataTemplate>
</ItemsControl.ItemTemplate> </ItemsControl.ItemTemplate>
</ItemsControl> </ItemsControl>
<ItemsControl ItemsSource="{Binding Points}" <ItemsControl ItemsSource="{Binding Points}"
Width="{Binding Bounds.Width, ElementName=Scene}" Width="{Binding Bounds.Width, ElementName=Scene}"
Height="{Binding Bounds.Height, ElementName=Scene}" Height="{Binding Bounds.Height, ElementName=Scene}"
IsHitTestVisible="False"> IsHitTestVisible="False"
>
<ItemsControl.ItemsPanel> <ItemsControl.ItemsPanel>
<ItemsPanelTemplate><Canvas/></ItemsPanelTemplate> <ItemsPanelTemplate>
<Canvas/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel> </ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate> <ItemsControl.ItemTemplate>
<DataTemplate x:DataType="models:Geometries+GeomPoint"> <DataTemplate x:DataType="models:Geometries+Point">
<Ellipse Fill="White" Stroke="Black" StrokeThickness="1" <Ellipse Fill="White" Stroke="Black" StrokeThickness="1"
Width="{Binding Size}" Height="{Binding Size}" Width="{Binding Size}"
Canvas.Left="{Binding Left}" Canvas.Top="{Binding Top}"/> 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> </DataTemplate>
</ItemsControl.ItemTemplate> </ItemsControl.ItemTemplate>
</ItemsControl> </ItemsControl>