public ShapeWithPoints(PointCollection points) { double LowestY = points.Min(x => x.Y); double HighestY = points.Max(x => x.Y); this.Height = HighestY - LowestY; double LowestX = points.Min(x => x.X); double HighestX = points.Max(x => x.X); this.Width = HighestX - LowestX; this.Points = points; }
private IEnumerable <Point> GetPolygonRegion(PointCollection points) { var maxX = Math.Floor(points.Max(p => p.X) / GRID_SIZE); var maxY = Math.Floor(points.Max(p => p.Y) / GRID_SIZE); var minX = Math.Floor(points.Min(p => p.X) / GRID_SIZE); var minY = Math.Floor(points.Min(p => p.Y) / GRID_SIZE); for (double x = minX; x <= maxX; x++) { for (double y = minY; y <= maxY; y++) { yield return(new Point(x, y)); } } }
protected override void UpdateCenterPoint() { // If the polygon contains at least three points then... if (PointCollection.Count > 2) { // Get the minimum X coordinate double xMin = PointCollection.Min(point => point.X); // Get the maximum X coordinate double xMax = PointCollection.Max(point => point.X); // Get the minimum Y coordinate double yMin = PointCollection.Min(point => point.Y); // Get the maximum Y coordinate double yMax = PointCollection.Max(point => point.Y); // Calculate the center of the polygon CenterPoint.X = (xMax - xMin) / 2.0 + xMin; CenterPoint.Y = (yMax - yMin) / 2.0 + yMin; // Notify the view that the center has changed RaisePropertyChanged(nameof(CenterPoint)); } // Update the point labels UpdatePointLabels(); }
private void MouseMove(object sender, MouseEventArgs e) { Point position = e.GetPosition(M_FiguresCanvas); m_originalPoints.Add(position); m_polyline.Points = m_originalPoints; m_CurrentPoints.Add(CanvasToMsi(position)); base.OriginStart = new Point(m_originalPoints.Min((Point p) => p.X), m_originalPoints.Min((Point p) => p.Y)); base.OriginEnd = new Point(m_originalPoints.Max((Point p) => p.X), m_originalPoints.Max((Point p) => p.Y)); base.CurrentStart = CanvasToMsi(base.OriginStart); base.CurrentEnd = CanvasToMsi(base.OriginEnd); base.TextBlock_info = CalcMeasureInfo(); base.AnnoControl.Tbk.Text = null; base.AnnoControl.Tbk.Text = CalcMeasureInfo(); }
public myPolyline(AnnotationBase ab) { m_originalPoints = new PointCollection(); m_CurrentPoints = new PointCollection(); base.Calibration = ab.Calibration; base.SlideZoom = ab.SlideZoom; base.AnnotationType = AnnotationType.Polygon; base.AnnotationDescription = ab.AnnotationDescription; base.ControlName = ab.ControlName; base.Zoom = ab.Zoom; m_CurrentPoints = ab.PointCollection; base.msi = ab.msi; base.isMsVisble = ab.isMsVisble; base.FiguresCanvas = ab.FiguresCanvas; base.objectlist = ab.objectlist; base.AnnoControl = ab.AnnoControl; foreach (Point currentPoint in m_CurrentPoints) { m_originalPoints.Add(MsiToCanvas(currentPoint)); } base.OriginStart = new Point(m_originalPoints.Min((Point p) => p.X), m_originalPoints.Min((Point p) => p.Y)); base.OriginEnd = new Point(m_originalPoints.Max((Point p) => p.X), m_originalPoints.Max((Point p) => p.Y)); base.CurrentStart = CanvasToMsi(base.OriginStart); base.CurrentEnd = CanvasToMsi(base.OriginEnd); base.Size = ab.Size; base.BorderBrush = ab.BorderBrush; base.isVisble = ab.isVisble; base.isHidden = ab.isHidden; base.AnnotationName = ab.AnnotationName; base.isFinish = true; m_polyline = new Polyline(); m_polyline.StrokeThickness = base.Size; m_polyline.Stroke = base.BorderBrush; m_polyline.Name = base.ControlName; m_polyline.Points = OriginalPoints; M_FiguresCanvas.Children.Add(m_polyline); base.objectlist.Insert(0, this); CreateMTextBlock(); UpdateCB(); CreateThumb(); m_polyline.MouseLeftButtonDown += Select_MouseDown; m_polyline.MouseEnter += GotFocus; base.UpadteTextBlock(); IsActive(Visibility.Collapsed); base.AnnoControl.CB.SelectedIndex = -1; }
private void tableRefresh() { if (pointsource == null) { return; } else if (pointsource.Count == 0) { return; } PointRange[0] = pointsource.Min(u => u.X); PointRange[1] = pointsource.Max(u => u.X); if (PointRange[1] - PointRange[0] == 0) { PointRange[1] = PointRange[0] + 1; } PointRange[2] = pointsource.Min(u => u.Y); PointRange[3] = pointsource.Max(u => u.Y); if (PointRange[3] - PointRange[2] == 0) { PointRange[3] = PointRange[2] + 1; } double WidthStep_Concrete = WidthStep; double HeightStep_Concrete = HeightStep; int XD = (int)(RenderSize.Width / WidthStep) + 1; int YD = (int)(RenderSize.Height / HeightStep) + 1; if (XYCount.Width != 0) { XD = (int)XYCount.Width; WidthStep_Concrete = RenderSize.Width / XD; } if (XYCount.Height != 0) { YD = (int)XYCount.Height; HeightStep_Concrete = RenderSize.Height / YD; } rootgrid.Children.Clear(); var line = new Polyline(); Grid.SetColumnSpan(line, XD); Grid.SetRowSpan(line, YD); line.HorizontalAlignment = HorizontalAlignment.Left; line.VerticalAlignment = VerticalAlignment.Bottom; //line.Stroke = Application.Current.Resources["SystemControlForegroundAccentBrush"] as SolidColorBrush; line.Stroke = new SolidColorBrush(Colors.Orchid); line.StrokeThickness = 3; double YP = RenderSize.Height / (PointRange[3] - PointRange[2]); double XP = RenderSize.Width / (PointRange[1] - PointRange[0]); pointdraw = new PointCollection(); foreach (var p in pointsource) { pointdraw.Add(new Point() { X = XP * (p.X - PointRange[0]), Y = YP * (p.Y - PointRange[2]) }); } line.Points = pointdraw; line.StrokeLineJoin = PenLineJoin.Bevel; line.Stretch = Stretch.Fill; rootgrid.Children.Add(line); rootgrid.RowDefinitions.Clear(); YLabelGrid.RowDefinitions.Clear(); YLabelGrid.Children.Clear(); for (int i = 0; i < YD; ++i) { var RowDef = new RowDefinition(); RowDef.Height = new GridLength(1, GridUnitType.Star); rootgrid.RowDefinitions.Add(RowDef); if (i % 2 != 0) { var rect = new Rectangle(); Grid.SetRow(rect, i); Grid.SetColumnSpan(rect, XD); rect.Fill = Application.Current.Resources["SystemControlHighlightAltListAccentLowBrush"] as SolidColorBrush; rootgrid.Children.Add(rect); } var RowDefYLabel = new RowDefinition(); RowDefYLabel.Height = new GridLength(1, GridUnitType.Star); YLabelGrid.RowDefinitions.Add(RowDefYLabel); var YLabelText = new TextBlock(); YLabelText.VerticalAlignment = VerticalAlignment.Bottom; var TextValue = (PointRange[2] + HeightStep_Concrete * i / YP); if (TextValue > PointRange[3] + HeightStep_Concrete / YP) { YLabelText.Text = ""; } else { YLabelText.Text = TextValue.ToString("#0.00"); } YLabelText.Foreground = Application.Current.Resources["SystemControlForegroundAccentBrush"] as SolidColorBrush; Grid.SetRow(YLabelText, YD - 1 - i); YLabelGrid.Children.Add(YLabelText); } YMax.Text = (PointRange[2] + HeightStep_Concrete * YD / YP).ToString("#0.00"); YMax.Foreground = Application.Current.Resources["SystemControlForegroundAccentBrush"] as SolidColorBrush; rootgrid.ColumnDefinitions.Clear(); XLabelGrid.ColumnDefinitions.Clear(); XLabelGrid.Children.Clear(); for (int i = 0; i < XD; ++i) { var ColDef = new ColumnDefinition(); ColDef.Width = new GridLength(1, GridUnitType.Star); rootgrid.ColumnDefinitions.Add(ColDef); var ColDefYLabel = new ColumnDefinition(); ColDefYLabel.Width = new GridLength(1, GridUnitType.Star); XLabelGrid.ColumnDefinitions.Add(ColDefYLabel); var XLabelText = new TextBlock(); XLabelText.HorizontalAlignment = HorizontalAlignment.Left; var TextValue = (PointRange[0] + WidthStep_Concrete * i / XP); if (TextValue > PointRange[1] + WidthStep_Concrete / XP) { XLabelText.Text = ""; } else { XLabelText.Text = XStringFormatFunc(TextValue); } XLabelText.Foreground = Application.Current.Resources["SystemControlForegroundAccentBrush"] as SolidColorBrush; Grid.SetColumn(XLabelText, i); XLabelGrid.Children.Add(XLabelText); var bord = new Border(); Grid.SetColumn(bord, i); Grid.SetRowSpan(bord, YD); bord.BorderThickness = new Thickness(1, 1, 1, 1); bord.BorderBrush = Application.Current.Resources["SystemControlHighlightAltListAccentHighBrush"] as SolidColorBrush; rootgrid.Children.Add(bord); } XMax.Text = XStringFormatFunc(PointRange[0] + WidthStep_Concrete * XD / XP); XMax.Foreground = Application.Current.Resources["SystemControlForegroundAccentBrush"] as SolidColorBrush; }