diff --git a/DelauneyTriangulation/Models/Geometries.cs b/DelauneyTriangulation/Models/Geometries.cs index 61934a9..396a959 100644 --- a/DelauneyTriangulation/Models/Geometries.cs +++ b/DelauneyTriangulation/Models/Geometries.cs @@ -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; diff --git a/DelauneyTriangulation/ViewModels/MainWindowViewModel.cs b/DelauneyTriangulation/ViewModels/MainWindowViewModel.cs index 703b3ee..58bb017 100644 --- a/DelauneyTriangulation/ViewModels/MainWindowViewModel.cs +++ b/DelauneyTriangulation/ViewModels/MainWindowViewModel.cs @@ -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 Points { get; } = new(); - public ObservableCollection Edges { get; } = new(); - public ObservableCollection 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 Points { get; } = new(); + public ObservableCollection Edges { get; } = new(); + public ObservableCollection 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); + } } \ No newline at end of file diff --git a/DelauneyTriangulation/Views/MainWindow.axaml b/DelauneyTriangulation/Views/MainWindow.axaml index cb8f164..166b166 100644 --- a/DelauneyTriangulation/Views/MainWindow.axaml +++ b/DelauneyTriangulation/Views/MainWindow.axaml @@ -54,16 +54,11 @@ - - - - - + - @@ -88,45 +83,59 @@ Height="{Binding Bounds.Height, ElementName=Scene}" IsHitTestVisible="False"> - + + + - + - - + + + - - + + - + IsHitTestVisible="False" + > - + + + - + + Width="{Binding Size}" + Height="{Binding Size}" + > + + + + +