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(); } } }
public Point(double x, double y, Type t) { X = x; Y = y; Element = new UIPoint(this); Typology = t; }
public int Compare(UIPoint x, UIPoint y) { double distance1 = Math.Sqrt(Math.Pow(x.Element.X - X, 2) + Math.Pow(x.Element.Y - Y, 2)); double distance2 = Math.Sqrt(Math.Pow(y.Element.X - X, 2) + Math.Pow(y.Element.Y - Y, 2)); if (x.Element.Member == null && y.Element.Member == null) { return(0); } if (x.Element.Member == null) { return(1); } else if (y.Element.Member == null) { return(-1); } return(distance1.CompareTo(distance2)); }
public Point() { Element = new UIPoint(this); }