public void UpdatePositionInData(Point mousePos, Vector screenDistance, CoordinateTransform transform) { Point mousePosInData = mousePos.ScreenToData(transform); _lastMousePosInData = mousePosInData; PositionAndCheckDistance pcd = new PositionAndCheckDistance(mousePos, screenDistance, transform); OnNearestPointUpdated(pcd); }
private void CheckPosAgainstData(PositionAndCheckDistance currentPos) { IEnumerable <(Point start, Point end, string label)> lines = null; IEnumerable <(Point start, Point end, string label)> rectangles = null; Dispatcher.Invoke(() => { lines = NearestVisualSources.OfType <NearestLineSource>().Select(nsl => nsl.ItemsSource).Where(items => items != null).SelectMany(x => x).ToList(); rectangles = NearestVisualSources.OfType <NearestRectangleSource>().Select(nsl => nsl.ItemsSource).Where(items => items != null).SelectMany(x => x).ToList(); }); Point dataPosition = currentPos.DataPosition; Point screenPosition = currentPos.ScreenPosition; Point dataBottomLeft = currentPos.DataBottomLeft; Point dataTopRight = currentPos.DataTopRight; double?minDistance = currentPos.ScreenDistance.X; string closestLine = null; Point? closestScreenPoint = null; // First see if mouse is inside one of the rectangles foreach (var rectangle in rectangles) { DataRect dataRect = new DataRect(rectangle.start, rectangle.end); if (dataRect.Contains(dataPosition)) { minDistance = 0; closestScreenPoint = screenPosition; closestLine = rectangle.label; break; } } if (!closestScreenPoint.HasValue) { // Get the rectangle sides var rectangleLines = rectangles.Select(rect => { return(new[] { (rect.start, new Point(rect.start.X, rect.end.Y), rect.label), (new Point(rect.start.X, rect.end.Y), rect.end, rect.label), (rect.end, new Point(rect.end.X, rect.start.Y), rect.label), (new Point(rect.end.X, rect.start.Y), rect.start, rect.label) });