private void btnPoints_Click(object sender, RoutedEventArgs e) { Random rnd = new Random(); for (int index = 0; index < int.Parse(txtNumberPoints.Text) && !(_pointsUI.Count > MAXPOINT); index++) { System.Windows.Point tmp; do { tmp = GenerateRandomPoint(rnd, cnvPoints.ActualHeight * 1); tmp.X = (int)(tmp.X + cnvPoints.ActualWidth / 2); tmp.Y = (int)(tmp.Y + cnvPoints.ActualHeight / 2); } while (tmp.X > cnvPoints.ActualWidth || tmp.Y > cnvPoints.ActualHeight || tmp.X < 0 || tmp.Y < 0); // If the point exit to the margin of the canvas recalculate it if (!((tmp.X > cnvPoints.ActualWidth) || (tmp.Y > cnvPoints.ActualHeight))) { UIPoint _new = new UIPoint(new Point(tmp.X, tmp.Y, Point.Type.KMEANS)); _new.AddFatherPoint(cnvPoints); _pointsUI.Add(_new); } if (!_firstPlay) { _dsp.Start(); } } }
private void cnvPoints_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { if (_pointsUI.Count < MAXPOINT) { System.Windows.Point tmp = Mouse.GetPosition(cnvPoints); UIPoint _new; if ((bool)rbPoint.IsChecked) { _new = new UIPoint(new Point(tmp.X, tmp.Y, Point.Type.KMEANS)); _new.AddFatherPoint(cnvPoints); _pointsUI.Add(_new); } else if ((bool)rbCluster.IsChecked) { UICluster uic = new UICluster(tmp.X, tmp.Y, new Random()); uic.AddFather(cnvPoints); _clusterUI.Add(uic); } else { MessageBox.Show("Scegliere se usare il Kmeans o il KNN", "Informazione", MessageBoxButton.OK, MessageBoxImage.Information); return; } if (!_firstPlay) { _dsp.Start(); } } }