using System; using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Shapes; namespace XP.ImageProcessing.RoiControl.Models { /// 一次点点距测量的所有视觉元素 public class MeasureGroup { public Ellipse Dot1 { get; set; } public Ellipse Dot2 { get; set; } public Line Line { get; set; } public TextBlock Label { get; set; } public Point P1 { get; set; } public Point P2 { get; set; } public double Distance { get { double dx = P2.X - P1.X, dy = P2.Y - P1.Y; return Math.Sqrt(dx * dx + dy * dy); } } public void UpdateLine() { Line.X1 = P1.X; Line.Y1 = P1.Y; Line.X2 = P2.X; Line.Y2 = P2.Y; Line.Visibility = Visibility.Visible; } public void UpdateLabel(string distanceText = null) { Label.Text = distanceText ?? $"{Distance:F2} px"; Canvas.SetLeft(Label, (P1.X + P2.X) / 2 + 8); Canvas.SetTop(Label, (P1.Y + P2.Y) / 2 - 18); Label.Visibility = Visibility.Visible; } } }